Ejemplo n.º 1
0
func BCastMsgXover(payload []string, group string, messageID string) {

	var msgHdr map[string]string
	msgHdr = make(map[string]string)

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

	msgHdr[TRIBES_H_CMD] = TRIBES_XOVER
	msgHdr[TRIBES_H_GID] = group
	msgHdr[TRIBES_H_MID] = messageID + "@" + orario.Format(layout)

	msgPayload := SliceToString(payload) // we are printing it already when requested.

	wendyMsgString := dht.GpgEncrypt(msgPayload, msgHdr)

	id, err := wendy.NodeIDFromBytes([]byte("FakeID"))
	if err != nil {
		log.Printf("[DHT-BCAST] Xover, error creating fake nodeid %s", err.Error())
	}

	msg := cluster.NewMessage(byte(30), id, []byte(wendyMsgString))

	WendyBroadcast(msg)

	log.Printf("[DHT-BCAST] Xover spreading around XOVER for %s", messageID)

}
Ejemplo n.º 2
0
func NewServer() HermesServer {
	Server := HermesServer{}
	Server.Hostname, err := os.Hostname()
	if err != nil {
		fmt.Println(err)
	}

	Server.ID, err = wendy.NodeIDFromBytes([]byte(hostname))
	if err != nil {
		panic(err)
	}

	Server.localIP, Server.globalIP = getIPs()
	Server.Node = wendy.NewNode(Server.ID, Server.localIP,
								Server.globalIP, "angelhack",
								1337)

	credentials := wendy.Passphrase("Hermes")
	Server.Cluster = wendy.NewCluster(node, credentials)

	go func() {
		defer cluster.Stop()
		err := cluster.Listen()
		if err != nil {
			panic(err.Error())
		}
	}()

	app := &HermesApplication{}
	Server.Cluster.RegisterCallback(app)
	Server.Cluster.Join("ip of another Node", 1337)

	return Server
}
Ejemplo n.º 3
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)

}
Ejemplo n.º 4
0
func BCastGroup(groupname string) {

	var msgHdr map[string]string
	msgHdr = make(map[string]string)

	msgHdr[TRIBES_H_CMD] = TRIBES_NEWGROUP

	msgPayload := groupname // we are printing it already when requested.

	wendyMsgString := dht.GpgEncrypt(msgPayload, msgHdr)

	id, err := wendy.NodeIDFromBytes([]byte("010203"))
	if err != nil {
		log.Printf("[DHT-BCAST] BCgroup, error creating fake nodeid: %s", err.Error())
	}

	msg := cluster.NewMessage(byte(30), id, []byte(wendyMsgString))

	WendyBroadcast(msg)

	log.Printf("[DHT-BCAST] BCgroup , spreading around GROUP for %s", groupname)

}