Handle RequestVote response (candidate only).
(&mut self, peer: u64, resp: &RequestVoteResponse)
| 72 | |
| 73 | /// Handle RequestVote response (candidate only). |
| 74 | pub fn handle_request_vote_response(&mut self, peer: u64, resp: &RequestVoteResponse) { |
| 75 | if resp.term > self.hard_state.current_term { |
| 76 | self.become_follower(resp.term); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if self.role != NodeRole::Candidate { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | if resp.vote_granted { |
| 85 | self.votes_received.insert(peer); |
| 86 | let vote_count = self.votes_received.len() + 1; // +1 for self-vote |
| 87 | |
| 88 | if vote_count >= self.config.quorum() { |
| 89 | self.become_leader(); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | #[cfg(test)] |