Esempio n. 1
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)

}
Esempio n. 2
0
func (this *Upnp) SearchGateway() (err error) {
	defer func(err error) {
		if errTemp := recover(); errTemp != nil {
			log.Println("[UPnP] Timeout", errTemp)
			err = errTemp.(error)
		}
	}(err)

	if this.LocalHost == "" {
		this.MappingPort = MappingPortStruct{
			lock: new(sync.Mutex),
		}
		this.LocalHost = tools.ReadIpFromHost()
	}
	searchGateway := SearchGateway{upnp: this}
	if searchGateway.Send() {
		return nil
	}
	return errors.New("No UPnP Gateway")
}