Esempio n. 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())
	}
}
Esempio n. 2
0
File: state.go Progetto: pooya/craft
func VoteIfEligible(sender string, term int) {
	highestTerm := logger.GetHighestTerm()
	if term <= highestTerm {
		log.Print("Ignoring vote request for term: ", term,
			" since we are at ", highestTerm)
	} else {
		node.VoteFor(sender)
		logger.SetHighestTerm(term)
	}
}
Esempio n. 3
0
func getVoteTail() string {
	return fmt.Sprintf("%d/%s", logger.GetHighestTerm(), config.UniqueId)
}