示例#1
0
func UPNP_Worker_Start() {

	upnp_renew := time.NewTicker(5 * time.Minute)
	mapping_DHT := new(Upnp)

	ClusterPort := config.GetClusterPort()

	err := mapping_DHT.SearchGateway()
	if err != nil {
		log.Printf("[UPnP] Problem getting the gateway:  %s...", err.Error())
	} else {
		log.Printf("[UPnP] Local ip address: %s", mapping_DHT.LocalHost)
		torn := strings.Split(mapping_DHT.Gateway.Host, ":")
		log.Printf("[UPnP] Gateway ip address is %s on port: %s", torn[0], torn[1])
	}

	err = mapping_DHT.ExternalIPAddr()
	if err != nil {
		log.Printf("[UPnP] Problem getting my external IP:  %s...", err.Error())

	} else {
		log.Printf("[UPnP] WAN ip address: %s", mapping_DHT.GatewayOutsideIP)

	}

	log.Printf("[UPnP] UPnP on TCP %d...", ClusterPort)

	for {

		if err = mapping_DHT.AddPortMapping(ClusterPort, ClusterPort, "TCP"); err == nil {
			log.Printf("[UPnP] UPnP redirect TCP %d : no errors from %s", ClusterPort, mapping_DHT.Gateway.Host)
		} else {
			log.Printf("[UPnP] No UPnP on TCP %d:  %s", ClusterPort, err.Error())
		}

		<-upnp_renew.C
		log.Printf("[UPnP] Renew the UPnP lease")
	}

}
示例#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)

}