@@ -31,6 +31,11 @@ import (
31
31
"github.com/op/go-logging"
32
32
)
33
33
34
+ const (
35
+ presumedDeadChanSize = 100
36
+ acceptChanSize = 100
37
+ )
38
+
34
39
type gossipServiceImpl struct {
35
40
presumedDead chan common.PKIidType
36
41
disc discovery.Discovery
@@ -51,7 +56,7 @@ type gossipServiceImpl struct {
51
56
// NewGossipService creates a new gossip instance
52
57
func NewGossipService (conf * Config , c comm.Comm , crypto discovery.CryptoService ) Gossip {
53
58
g := & gossipServiceImpl {
54
- presumedDead : make (chan common.PKIidType , 100 ),
59
+ presumedDead : make (chan common.PKIidType , presumedDeadChanSize ),
55
60
disc : nil ,
56
61
comm : c ,
57
62
conf : conf ,
@@ -75,7 +80,7 @@ func NewGossipService(conf *Config, c comm.Comm, crypto discovery.CryptoService)
75
80
76
81
g .pushPull = algo .NewPullEngine (g , conf .PullInterval )
77
82
78
- g .msgStore = newMessageStore (g . invalidationPolicy , func (m interface {}) {
83
+ g .msgStore = newMessageStore (proto . NewGossipMessageComparator ( g . conf . MaxMessageCountToStore ) , func (m interface {}) {
79
84
if dataMsg , isDataMsg := m .(* proto.DataMessage ); isDataMsg {
80
85
g .pushPull .Remove (dataMsg .Payload .SeqNum )
81
86
}
@@ -92,61 +97,6 @@ func (g *gossipServiceImpl) toDie() bool {
92
97
return atomic .LoadInt32 (& g .stopFlag ) == int32 (1 )
93
98
}
94
99
95
- func (g * gossipServiceImpl ) invalidationPolicy (this interface {}, that interface {}) invalidationResult {
96
- thisMsg := this .(* proto.GossipMessage )
97
- thatMsg := that .(* proto.GossipMessage )
98
- thisAliveMsg , thisIsAliveMessage := thisMsg .GetAliveMsg (), thisMsg .GetAliveMsg () != nil
99
- thatAliveMsg , thatIsAliveMessage := thatMsg .GetAliveMsg (), thatMsg .GetAliveMsg () != nil
100
-
101
- if thisIsAliveMessage && thatIsAliveMessage {
102
- return aliveInvalidationPolicy (thisAliveMsg , thatAliveMsg )
103
- }
104
-
105
- thisDataMsg , thisIsDataMessage := thisMsg .GetDataMsg (), thisMsg .GetDataMsg () != nil
106
- thatDataMsg , thatIsDataMessage := thatMsg .GetDataMsg (), thatMsg .GetDataMsg () != nil
107
-
108
- if thisIsDataMessage && thatIsDataMessage {
109
- if thisDataMsg .Payload .SeqNum == thatDataMsg .Payload .SeqNum {
110
- if thisDataMsg .Payload .Hash == thatDataMsg .Payload .Hash {
111
- return messageInvalidated
112
- }
113
- return messageNoAction
114
- }
115
-
116
- diff := util .Abs (thisDataMsg .Payload .SeqNum , thatDataMsg .Payload .SeqNum )
117
- if diff <= uint64 (g .conf .MaxMessageCountToStore ) {
118
- return messageNoAction
119
- }
120
-
121
- if thisDataMsg .Payload .SeqNum > thatDataMsg .Payload .SeqNum {
122
- return messageInvalidates
123
- }
124
- return messageInvalidated
125
- }
126
- return messageNoAction
127
- }
128
-
129
- func aliveInvalidationPolicy (thisMsg * proto.AliveMessage , thatMsg * proto.AliveMessage ) invalidationResult {
130
- if ! equalPKIIds (thisMsg .Membership .PkiID , thatMsg .Membership .PkiID ) {
131
- return messageNoAction
132
- }
133
-
134
- if thisMsg .Timestamp .IncNumber == thatMsg .Timestamp .IncNumber {
135
- if thisMsg .Timestamp .SeqNum > thatMsg .Timestamp .SeqNum {
136
- return messageInvalidates
137
- }
138
-
139
- if thisMsg .Timestamp .SeqNum < thatMsg .Timestamp .SeqNum {
140
- return messageInvalidated
141
- }
142
- return messageInvalidated
143
- }
144
- if thisMsg .Timestamp .IncNumber < thatMsg .Timestamp .IncNumber {
145
- return messageInvalidated
146
- }
147
- return messageInvalidates
148
- }
149
-
150
100
func (g * gossipServiceImpl ) handlePresumedDead () {
151
101
defer g .logger .Debug ("Exiting" )
152
102
g .stopSignal .Add (1 )
@@ -183,11 +133,10 @@ func (g *gossipServiceImpl) start() {
183
133
return false
184
134
}
185
135
186
- isAck := gMsg .GetGossipMessage ().GetAckMsg () != nil
187
136
isConn := gMsg .GetGossipMessage ().GetConn () != nil
188
137
isEmpty := gMsg .GetGossipMessage ().GetEmpty () != nil
189
138
190
- return ! (isAck || isConn || isEmpty )
139
+ return ! (isConn || isEmpty )
191
140
}
192
141
193
142
incMsgs := g .comm .Accept (msgSelector )
@@ -224,6 +173,7 @@ func (g *gossipServiceImpl) SelectPeers() []string {
224
173
225
174
func (g * gossipServiceImpl ) Hello (dest string , nonce uint64 ) {
226
175
helloMsg := & proto.GossipMessage {
176
+ Tag : proto .GossipMessage_EMPTY ,
227
177
Nonce : 0 ,
228
178
Content : & proto.GossipMessage_Hello {
229
179
Hello : & proto.GossipHello {
@@ -239,6 +189,7 @@ func (g *gossipServiceImpl) Hello(dest string, nonce uint64) {
239
189
240
190
func (g * gossipServiceImpl ) SendDigest (digest []uint64 , nonce uint64 , context interface {}) {
241
191
digMsg := & proto.GossipMessage {
192
+ Tag : proto .GossipMessage_EMPTY ,
242
193
Nonce : 0 ,
243
194
Content : & proto.GossipMessage_DataDig {
244
195
DataDig : & proto.DataDigest {
@@ -253,6 +204,7 @@ func (g *gossipServiceImpl) SendDigest(digest []uint64, nonce uint64, context in
253
204
254
205
func (g * gossipServiceImpl ) SendReq (dest string , items []uint64 , nonce uint64 ) {
255
206
req := & proto.GossipMessage {
207
+ Tag : proto .GossipMessage_EMPTY ,
256
208
Nonce : 0 ,
257
209
Content : & proto.GossipMessage_DataReq {
258
210
DataReq : & proto.DataRequest {
@@ -282,6 +234,7 @@ func (g *gossipServiceImpl) SendRes(requestedItems []uint64, context interface{}
282
234
}
283
235
284
236
returnedUpdate := & proto.GossipMessage {
237
+ Tag : proto .GossipMessage_EMPTY ,
285
238
Nonce : 0 ,
286
239
Content : & proto.GossipMessage_DataUpdate {
287
240
DataUpdate : & proto.DataUpdate {
@@ -355,6 +308,7 @@ func (g *gossipServiceImpl) handlePushPullMsg(msg comm.ReceivedMessage) {
355
308
items := make ([]uint64 , len (res .Data ))
356
309
for i , data := range res .Data {
357
310
dataMsg := & proto.GossipMessage {
311
+ Tag : proto .GossipMessage_EMPTY ,
358
312
Content : & proto.GossipMessage_DataMsg {
359
313
DataMsg : data ,
360
314
},
@@ -444,7 +398,7 @@ func (g *gossipServiceImpl) UpdateMetadata(md []byte) {
444
398
445
399
func (g * gossipServiceImpl ) Accept (acceptor common.MessageAcceptor ) <- chan * proto.GossipMessage {
446
400
inCh := g .AddChannel (acceptor )
447
- outCh := make (chan * proto.GossipMessage , 100 )
401
+ outCh := make (chan * proto.GossipMessage , acceptChanSize )
448
402
go func () {
449
403
for {
450
404
select {
0 commit comments