func startVoting() { fmt.Println("Start voting!") time.Sleep(time.Second * 10) // Send you adress to all. In this case it really doesn't matter msg := message.NewVoteMessage(myAddress) mm, _ := xml.Marshal(msg) _, err := writeMulticast.WriteToUDP(mm, multicastAddr) check(err) // Wait 10 seconds c := time.After(time.Second * 10) <-c // Check if we got any address that is bigger for addr, _ := range knownAddresess { if addr > myAddress { return } } // Become the server if we are the greatest msga := message.NewCoordinatorMessage(string(myAddress)) mmm, _ := xml.Marshal(msga) writeMulticast.WriteToUDP(mmm, multicastAddr) fmt.Println("NOW I AM BECOME DEATH") }
func startBecomingTheServer() { // ? Send message saying that I'm the new server msga := message.NewCoordinatorMessage(string(myAddress)) mmm, _ := xml.Marshal(msga) writeMulticast.WriteToUDP(mmm, multicastAddr) fmt.Println("NOW I AM BECOME DEATH") // Start the server s := ServerPetition{GlobalPort} startServer <- s stopVotingProcess() }