forked from goraft/raft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_vote.go
47 lines (41 loc) · 1.39 KB
/
request_vote.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package raft
//------------------------------------------------------------------------------
//
// Typedefs
//
//------------------------------------------------------------------------------
// The request sent to a server to vote for a candidate to become a leader.
type RequestVoteRequest struct {
peer *Peer
Term uint64 `json:"term"`
CandidateName string `json:"candidateName"`
LastLogIndex uint64 `json:"lastLogIndex"`
LastLogTerm uint64 `json:"lastLogTerm"`
}
// The response returned from a server after a vote for a candidate to become a leader.
type RequestVoteResponse struct {
peer *Peer
Term uint64 `json:"term"`
VoteGranted bool `json:"voteGranted"`
}
//------------------------------------------------------------------------------
//
// Constructors
//
//------------------------------------------------------------------------------
// Creates a new RequestVote request.
func NewRequestVoteRequest(term uint64, candidateName string, lastLogIndex uint64, lastLogTerm uint64) *RequestVoteRequest {
return &RequestVoteRequest{
Term: term,
CandidateName: candidateName,
LastLogIndex: lastLogIndex,
LastLogTerm: lastLogTerm,
}
}
// Creates a new RequestVote response.
func NewRequestVoteResponse(term uint64, voteGranted bool) *RequestVoteResponse {
return &RequestVoteResponse{
Term: term,
VoteGranted: voteGranted,
}
}