-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.go
71 lines (55 loc) · 1.26 KB
/
node.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Xenon
*
* Copyright 2018 The Xenon Authors.
* Code is licensed under the GPLv3.
*
*/
package model
const (
RPCNodesAdd = "NodeRPC.AddNodes"
RPCIdleNodesAdd = "NodeRPC.AddIdleNodes"
RPCNodesRemove = "NodeRPC.RemoveNodes"
RPCIdleNodesRemove = "NodeRPC.RemoveIdleNodes"
RPCNodes = "NodeRPC.GetNodes"
)
type NodeRPCRequest struct {
// The IP of this request
From string
// Node endpoint lists
Nodes []string
}
type NodeRPCResponse struct {
// The Epoch ID of the raft
EpochID uint64
// The View ID of the raft
ViewID uint64
// The State of the raft:
// FOLLOWER/CANDIDATE/LEADER/IDLE/INVALID
State string
// The Leader endpoint of the cluster
Leader string
// The Nodes(endpoint) of the cluster
Nodes []string
// Return code to rpc client:
// OK or other errors
RetCode string
}
func NewNodeRPCRequest() *NodeRPCRequest {
return &NodeRPCRequest{}
}
func (req *NodeRPCRequest) GetFrom() string {
return req.From
}
func (req *NodeRPCRequest) GetNodes() []string {
return req.Nodes
}
func NewNodeRPCResponse(code string) *NodeRPCResponse {
return &NodeRPCResponse{RetCode: code}
}
func (rsp *NodeRPCResponse) GetNodes() []string {
return rsp.Nodes
}
func (rsp *NodeRPCResponse) GetLeader() string {
return rsp.Leader
}