Exemple #1
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
}
Exemple #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)

}