Exemplo n.º 1
0
func init() {

	var thekey string
	var metadata map[string]string
	metadata = make(map[string]string)
	log.Println("[GPG] Engine started")

	if thekey = config.GetTribeID(); len(thekey) < 32 {
		log.Println("[GPG] EEK: TribeID %d ", len(thekey))
		log.Println("[GPG] EEK: TribeID shorter than 32 bytes. Generating a random one")
		thekey = tools.RandSeq(42) // 42 because of yes.
		log.Println("[GPG] your 1-node tribe is: " + thekey)
	}

	log.Println("[GPG] TribeID is: " + thekey)
	test_cleartext := tools.RandSeq(128)
	metadata["Command"] = "NOOP"
	metadata["Group"] = "it.doesnt.exists"
	log.Println("[GPG] GPG Integrity test initiated")
	log.Println("[GPG] GPG Encrypted payload below: \n", GpgEncrypt(test_cleartext, metadata))
	log.Println("[GPG] GPG Integrity Test passed: ", test_cleartext == GpgDecrypt(GpgEncrypt(test_cleartext, metadata)))
	d_Command := GpgGetHeaders(GpgEncrypt(test_cleartext, metadata))
	log.Println("[GPG] GPG Serialization Test #1 passed: ", d_Command["Command"] == metadata["Command"])
	log.Println("[GPG] GPG Serialization Test #2 passed: ", d_Command["Group"] == metadata["Group"])
}
Exemplo n.º 2
0
func init() {

	AllNodes = make(map[wendy.NodeID]string)

	RandID := md5.Sum([]byte(config.GetTribeID())) // since it is sent in clear, we can't use TribeID in clear

	WendyID := tools.RandSeq(16)
	log.Printf("[DHT] Volatile node ID: %s", WendyID)

	id, err = wendy.NodeIDFromBytes([]byte(WendyID))
	if err != nil {
		log.Printf("[DHT] Can't create the NodeID: %s", WendyID)
	}

	mynode = wendy.NewNode(id, tools.ReadIpFromHost(), tools.ReadIpFromHost(), "Tribes", config.GetClusterPort())
	log.Printf("[DHT] Node %s created for %s", mynode.ID.String(), WendyID)

	cred = wendy.Passphrase(string(RandID[:]))

	cluster = wendy.NewCluster(mynode, cred)
	log.Printf("[DHT] Cluster initialized")

	go cluster.Listen()
	log.Printf("[DHT] Listening")

	if tmpBoot := config.GetBootStrapHost(); tmpBoot != "127.0.0.1" {
		tmpPort := config.GetBootStrapPort()
		cluster.Join(tmpBoot, tmpPort)
		log.Printf("[DHT] Trying to join cluster at %s:%d", tmpBoot, tmpPort)
	}

	app := &WendyApplication{}
	cluster.RegisterCallback(app)
	log.Printf("[DHT] Engine functional ")

	cluster.SetHeartbeatFrequency(5)
	cluster.SetNetworkTimeout(300)

}
Exemplo n.º 3
0
func NNTP_POST_ReadAndSave(conn net.Conn, groupname string) {

	const layout = "0601021504"
	orario := time.Now()

	rawMsgId := tools.RandSeq(38)
	id_message := rawMsgId + "@" + orario.Format(layout)

	answer_ok := "340 Ok, recommended ID <" + id_message + ">\r\n"
	conn.Write([]byte(answer_ok))
	log.Printf("[FYI] %s", answer_ok)

	var body []string
	var headers []string
	var is_header = true
	var body_lines int = 0
	var body_bytes int = 0

	scanner_h := bufio.NewScanner(conn)
	for {
		ok := scanner_h.Scan()
		if !ok {
			break
		}
		line := scanner_h.Text()

		if (strings.HasPrefix(line, "Newsgroups:")) && (groupname == "garbage") {

			log.Printf("[FYI] ng was %s", groupname)
			grp_hdr := strings.Split(line, ":")
			if grp_hdr != nil {
				groupname = grp_hdr[1]
			}
			log.Printf("[FYI] ng now is %s", groupname)
			grp_hdr = strings.Split(groupname, ",")
			if grp_hdr != nil {
				groupname = grp_hdr[0]
			}
			groupname = strings.Trim(groupname, " ")
			log.Printf("[FYI] tried to fix with %s", groupname)

		}

		if strings.HasPrefix(line, "Newsgroups:") {

			line = "Newsgroups: " + groupname
			log.Printf("[FYI] Normalization of NG Header as: %s", line)
		}

		if strings.HasPrefix(line, "Message-ID:") {
			log.Printf("[WARN] not permitted to set MSGID ->%s<-", line)
			continue
		}

		if strings.HasPrefix(line, "Xref:") {
			log.Printf("[WARN] not permitted to set Xref: ->%s<-", line)
			continue
		}

		if strings.HasPrefix(line, "Path:") {
			log.Printf("[WARN] not permitted to set Path ->%s<-", line)
			continue
		}

		if (line == "") && (is_header == true) {
			log.Printf("[FYI] body starts after empty line ->%s<-", line)
			is_header = false
			continue
		}

		if is_header {
			log.Printf("[FYI] header line is:  ->%s<-", line)
			headers = append(headers, line)
		} else {
			log.Printf("[FYI] body line is:  ->%s<-", line)
			body_lines++
			body_bytes += len(line)
			body = append(body, line)

		}
		if line == "." {
			break
		}
	}

	headers = append(headers, "Message-ID: <"+id_message+">")
	headers = append(headers, "Lines: "+strconv.Itoa(body_lines))
	headers = append(headers, "Bytes: "+strconv.Itoa(body_bytes))

	num_message, _ := strconv.Atoi(GetLastNumByGroup(groupname))
	num_message++

	msgnum_str := fmt.Sprintf("%05d", num_message)

	headers = append(headers, "Xref: averno "+groupname+":"+msgnum_str)
	headers = append(headers, "Path: averno")

	headers = HeaderCompliance(headers)

	// SaveXOVERLineForPost(headers, groupname, id_message, msgnum_str)
	var xover []string
	xover = append(xover, GenerateXOVERLineFromHeader(headers, groupname, id_message, msgnum_str))

	header_file := filepath.Join(tools.MessagesFolder, "h-"+groupname+"-"+msgnum_str+"-"+id_message)
	body_file := filepath.Join(tools.MessagesFolder, "b-"+groupname+"-"+msgnum_str+"-"+id_message)
	xover_file := filepath.Join(tools.MessagesFolder, "x-"+groupname+"-"+msgnum_str+"-"+id_message)

	err := tools.WriteMessages(headers, header_file)
	if err != nil {
		log.Printf("[WTF] cannot write headers on %s", header_file)
	} else {
		tribe.BCastMsgHeaders(headers, groupname, rawMsgId)
		log.Printf("[FYI] headers saved in %s", header_file)
	}

	err = tools.WriteMessages(body, body_file)
	if err != nil {
		log.Printf("[WTF] cannot write body on %s", body_file)
	} else {
		tribe.BCastMsgBody(body, groupname, rawMsgId)
		log.Printf("[FYI] body saved in %s", body_file)
	}

	err = tools.WriteMessages(xover, xover_file)
	if err != nil {
		log.Printf("[WTF] cannot write body on %s", body_file)
	} else {
		tribe.BCastMsgXover(xover, groupname, rawMsgId)
		log.Printf("[FYI] Xover saved in %s", body_file)
	}

	conn.Write([]byte("240 article posted ok\r\n"))

}