func AnnounceMyPresence() {

	localPrint := cryptowrapper.GetLocalFingerPrint()
	ap := customtypes.AnnouncePresence{localPrint, tcpPort}
	var annMsg customtypes.AnnounceMsg
	annMsg.Payload = ap
	annMsg.Kind = "ap"

	annMsgBytes, err := json.Marshal(annMsg)
	CheckError(err)

	listenConn.WriteToUDP(annMsgBytes, serverUDPAddr)
}
コード例 #2
0
//initialize all variables
func (c *CalendarInfo) Init() {
	c.Hostname = cryptowrapper.GetLocalFingerPrint()
	fmt.Println("fingerprint:" + c.Hostname)

	//c.Hostname = name
	c.GroupMember = make(map[string]map[string]int)
	c.RcvQueue = make(chan customtypes.TsMessage, 1024)
	c.AddrMap = make(map[string]string)
	//    c.GroupMember["group1"] = make(map[string]int)
	//    c.GroupMember["group2"] = make(map[string]int)
	// c.GroupMember["group1"]["a"]=0
	// c.GroupMember["group1"]["b"]=1
	// c.GroupMember["group1"]["c"]=2
	// c.GroupMember["group2"]["b"]=0
	// c.GroupMember["group2"]["c"]=1
	c.ReadFromFile("config.txt")
	announce_client.AnnounceMyPresence()
	addr := announce_client.GetInfo(c.Hostname)
	c.AddrMap[c.Hostname] = addr.IP.String() + ":9200"
	ipMap := make(map[string]*net.TCPAddr)
	for _, ms := range c.GroupMember {
		for m, _ := range ms {
			_, ok := ipMap[m]
			if !ok {
				ipMap[m] = nil
			}
		}
	}
	announce_client.GetInfoStruct(ipMap) //map[string]string
	for mem, ip := range ipMap {
		c.AddrMap[mem] = ip.IP.String() + ":9200"
	}
	// c.AddrMap["a"]="127.0.0.1:1234"
	// c.AddrMap["b"]="127.0.0.1:1235"
	// c.AddrMap["c"]="127.0.0.1:1236"
}