liuxiaolong
2020-09-16 4501e38ca66f09b35aaaf43fa5a316554930fcf4
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package client
 
import (
    "net"
    "time"
 
    "basic.com/valib/serf.git/coordinate"
    "basic.com/valib/serf.git/serf"
)
 
const (
    maxIPCVersion = 1
)
 
const (
    handshakeCommand       = "handshake"
    eventCommand           = "event"
    forceLeaveCommand      = "force-leave"
    joinCommand            = "join"
    membersCommand         = "members"
    membersFilteredCommand = "members-filtered"
    streamCommand          = "stream"
    stopCommand            = "stop"
    monitorCommand         = "monitor"
    leaveCommand           = "leave"
    installKeyCommand      = "install-key"
    useKeyCommand          = "use-key"
    removeKeyCommand       = "remove-key"
    listKeysCommand        = "list-keys"
    tagsCommand            = "tags"
    queryCommand           = "query"
    respondCommand         = "respond"
    authCommand            = "auth"
    statsCommand           = "stats"
    getCoordinateCommand   = "get-coordinate"
)
 
const (
    unsupportedCommand    = "Unsupported command"
    unsupportedIPCVersion = "Unsupported IPC version"
    duplicateHandshake    = "Handshake already performed"
    handshakeRequired     = "Handshake required"
    monitorExists         = "Monitor already exists"
    invalidFilter         = "Invalid event filter"
    streamExists          = "Stream with given sequence exists"
    invalidQueryID        = "No pending queries matching ID"
    authRequired          = "Authentication required"
    invalidAuthToken      = "Invalid authentication token"
)
 
const (
    queryRecordAck      = "ack"
    queryRecordResponse = "response"
    queryRecordDone     = "done"
)
 
// Request header is sent before each request
type requestHeader struct {
    Command string
    Seq     uint64
}
 
// Response header is sent before each response
type responseHeader struct {
    Seq   uint64
    Error string
}
 
type handshakeRequest struct {
    Version int32
}
 
type authRequest struct {
    AuthKey string
}
 
type coordinateRequest struct {
    Node string
}
 
type coordinateResponse struct {
    Coord coordinate.Coordinate
    Ok    bool
}
 
type eventRequest struct {
    Name     string
    Payload  []byte
    Coalesce bool
}
 
type forceLeaveRequest struct {
    Node  string
    Prune bool
}
 
type joinRequest struct {
    Existing []string
    Replay   bool
}
 
type joinResponse struct {
    Num int32
}
 
type membersFilteredRequest struct {
    Tags   map[string]string
    Status string
    Name   string
}
 
type membersResponse struct {
    Members []Member
}
 
type keyRequest struct {
    Key string
}
 
type keyResponse struct {
    Messages map[string]string
    Keys     map[string]int
    NumNodes int
    NumErr   int
    NumResp  int
}
 
type monitorRequest struct {
    LogLevel string
}
 
type streamRequest struct {
    Type string
}
 
type stopRequest struct {
    Stop uint64
}
 
type tagsRequest struct {
    Tags       map[string]string
    DeleteTags []string
}
 
type queryRequest struct {
    FilterNodes []string
    FilterTags  map[string]string
    RequestAck  bool
    RelayFactor uint8
    Timeout     time.Duration
    Name        string
    Payload     []byte
}
 
type respondRequest struct {
    ID      uint64
    Payload []byte
}
 
type queryRecord struct {
    Type    string
    From    string
    Payload []byte
}
 
// NodeResponse is used to return the response of a query
type NodeResponse struct {
    From    string
    Payload []byte
}
 
type logRecord struct {
    Log string
}
 
type userEventRecord struct {
    Event    string
    LTime    serf.LamportTime
    Name     string
    Payload  []byte
    Coalesce bool
}
 
// Member is used to represent a single member of the
// Serf cluster
type Member struct {
    Name        string // Node name
    Addr        net.IP // Address of the Serf node
    Port        uint16 // Gossip port used by Serf
    Tags        map[string]string
    Status      string
    ProtocolMin uint8 // Minimum supported Memberlist protocol
    ProtocolMax uint8 // Maximum supported Memberlist protocol
    ProtocolCur uint8 // Currently set Memberlist protocol
    DelegateMin uint8 // Minimum supported Serf protocol
    DelegateMax uint8 // Maximum supported Serf protocol
    DelegateCur uint8 // Currently set Serf protocol
}
 
type memberEventRecord struct {
    Event   string
    Members []Member
}