-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport.go
46 lines (35 loc) · 1.29 KB
/
transport.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
package yaft
import "net"
// RPC has a command, and provides a Reponse mechanism
type RPC struct {
// Type assert to determine the type
Command interface{}
RespChan chan<- RPCResponse
}
// RPCResponse captures both a response and a potential error
type RPCResponse struct {
Response interface{}
Error error
}
// Respond is used to respond with a response, error or both
func (r *RPC) Respond(resp interface{}, err error) {
r.RespChan <- RPCResponse{resp, err}
}
// Transport provides an interface for network transports
// to allow Raft to communicate with other nodes
type Transport interface {
// Consume returns a channel that can be used to
// consume and respond to RPC requests.
Consume() <-chan RPC
// LocalAddr is used to return the local address to distinguish from our peers
LocalAddr() net.Addr
// AppendEntries sends the appropriate RPC to the target node
AppendEntries(target net.Addr, args *AppendEntriesRequest, resp *AppendEntriesResponse) error
// RequestVote sends the appropriate RPC to the target node
RequestVote(target net.Addr, args *RequestVoteRequest, resp *RequestVoteResponse) error
// EncodePeer is used to serialize a peer name
EncodePeer(net.Addr) []byte
// DecodePeer is used to deserialize a peer name
DecodePeer([]byte) net.Addr
//TODO: Snapshots?
}