func getNonceFromAserver(clientIpPort string, aserverIpPort string) int64 { clientConn := common.InitUDPConn(clientIpPort) aserverUDPAddr := common.ResolveUDPAddr(aserverIpPort) nonce := client.RetrieveNonce(clientConn, &aserverUDPAddr) clientConn.Close() return nonce.Nonce }
func RunClient(clientIpPort string, aserverIpPort string, secret int64) { clientConn := common.InitUDPConn(clientIpPort) aserverUDPAddr := common.ResolveUDPAddr(aserverIpPort) //Set 10 second timeout for ReadFromUDP clientConn.SetReadDeadline(time.Now().Add(10 * time.Second)) //Retrieve nonce from aserver and compute MD5(nonce + secret) nonceMsg := RetrieveNonce(clientConn, &aserverUDPAddr) hashMsg := common.ComputeHashMessage(nonceMsg.Nonce, secret) //Retrieve GoalMessage from aserver goalMsg := RetrieveGoalMsg(clientConn, &aserverUDPAddr, hashMsg) fmt.Println("Received goal message from aserver: ", goalMsg) }
func RunAuthServer(udpIpPort string, secret int64) { udpConn := common.InitUDPConn(udpIpPort) //Initialize hash table of (udpIpPort, nonce) key-value pairs var nonceMap concurrentMap nonceMap.m = make(map[string]int64) //Start listen/receive connection loop for { var buf [1024]byte msgLen, clientUDPAddr, err := udpConn.ReadFromUDP(buf[:]) if err != nil { fmt.Println("Error on ReadFromUDP: ", err) } else { //Start go routine to handle client, continue listening for new clients go handleUDPConn(udpConn, clientUDPAddr, nonceMap, secret, buf[0:msgLen]) } } udpConn.Close() }