Beispiel #1
0
func handleVote(w http.ResponseWriter, r *http.Request) {
	vote := r.URL.Path[config.LenVotePath:]
	var term int
	var sender string

	fmt.Sscanf(vote, "%d/%s", &term, &sender)
	log.Print("got vote from ", sender, " with term ", term)
	if term != logger.GetHighestTerm() {
		log.Print("Vote is stale, since latestTerm is: ", logger.GetHighestTerm())
		return
	}
	if state.GetMyState() == state.CANDIDATE {
		state.VoteChan <- sender
	} else {
		log.Printf("We are in state %d, and did not request votes\n",
			state.GetMyState())
	}
}
Beispiel #2
0
func getStatus(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Status is: %d\n", state.GetMyState())
}