@@ -26,7 +26,7 @@ import (
26
26
)
27
27
28
28
/* PullEngine is an object that performs pull-based gossip, and maintains an internal state of items
29
- identified by uint64 numbers.
29
+ identified by string numbers.
30
30
The protocol is as follows:
31
31
1) The Initiator sends a Hello message with a specific NONCE to a set of remote peers.
32
32
2) Each remote peer responds with a digest of its messages and returns that NONCE.
@@ -82,14 +82,14 @@ type PullAdapter interface {
82
82
83
83
// SendDigest sends a digest to a remote PullEngine.
84
84
// The context parameter specifies the remote engine to send to.
85
- SendDigest (digest []uint64 , nonce uint64 , context interface {})
85
+ SendDigest (digest []string , nonce uint64 , context interface {})
86
86
87
87
// SendReq sends an array of items to a certain remote PullEngine identified
88
88
// by a string
89
- SendReq (dest string , items []uint64 , nonce uint64 )
89
+ SendReq (dest string , items []string , nonce uint64 )
90
90
91
91
// SendRes sends an array of items to a remote PullEngine identified by a context.
92
- SendRes (items []uint64 , context interface {}, nonce uint64 )
92
+ SendRes (items []string , context interface {}, nonce uint64 )
93
93
}
94
94
95
95
// PullEngine is the component that actually invokes the pull algorithm
@@ -98,7 +98,7 @@ type PullEngine struct {
98
98
PullAdapter
99
99
stopFlag int32
100
100
state * util.Set
101
- item2owners map [uint64 ][]string
101
+ item2owners map [string ][]string
102
102
peers2nonces map [string ]uint64
103
103
nonces2peers map [uint64 ]string
104
104
acceptingDigests int32
@@ -115,7 +115,7 @@ func NewPullEngine(participant PullAdapter, sleepTime time.Duration) *PullEngine
115
115
PullAdapter : participant ,
116
116
stopFlag : int32 (0 ),
117
117
state : util .NewSet (),
118
- item2owners : make (map [uint64 ][]string ),
118
+ item2owners : make (map [string ][]string ),
119
119
peers2nonces : make (map [string ]uint64 ),
120
120
nonces2peers : make (map [uint64 ]string ),
121
121
acceptingDigests : int32 (0 ),
@@ -190,12 +190,12 @@ func (engine *PullEngine) processIncomingDigests() {
190
190
engine .lock .Lock ()
191
191
defer engine .lock .Unlock ()
192
192
193
- requestMapping := make (map [string ][]uint64 )
193
+ requestMapping := make (map [string ][]string )
194
194
for n , sources := range engine .item2owners {
195
195
// select a random source
196
196
source := sources [rand .Intn (len (sources ))]
197
197
if _ , exists := requestMapping [source ]; ! exists {
198
- requestMapping [source ] = make ([]uint64 , 0 )
198
+ requestMapping [source ] = make ([]string , 0 )
199
199
}
200
200
// append the number to that source
201
201
requestMapping [source ] = append (requestMapping [source ], n )
@@ -218,13 +218,13 @@ func (engine *PullEngine) endPull() {
218
218
atomic .StoreInt32 (& (engine .acceptingResponses ), int32 (0 ))
219
219
engine .outgoingNONCES .Clear ()
220
220
221
- engine .item2owners = make (map [uint64 ][]string )
221
+ engine .item2owners = make (map [string ][]string )
222
222
engine .peers2nonces = make (map [string ]uint64 )
223
223
engine .nonces2peers = make (map [uint64 ]string )
224
224
}
225
225
226
226
// OnDigest notifies the engine that a digest has arrived
227
- func (engine * PullEngine ) OnDigest (digest []uint64 , nonce uint64 , context interface {}) {
227
+ func (engine * PullEngine ) OnDigest (digest []string , nonce uint64 , context interface {}) {
228
228
if ! engine .isAcceptingDigests () || ! engine .outgoingNONCES .Exists (nonce ) {
229
229
return
230
230
}
@@ -246,14 +246,14 @@ func (engine *PullEngine) OnDigest(digest []uint64, nonce uint64, context interf
246
246
}
247
247
248
248
// Add adds items to the state
249
- func (engine * PullEngine ) Add (seqs ... uint64 ) {
249
+ func (engine * PullEngine ) Add (seqs ... string ) {
250
250
for _ , seq := range seqs {
251
251
engine .state .Add (seq )
252
252
}
253
253
}
254
254
255
255
// Remove removes items from the state
256
- func (engine * PullEngine ) Remove (seqs ... uint64 ) {
256
+ func (engine * PullEngine ) Remove (seqs ... string ) {
257
257
for _ , seq := range seqs {
258
258
engine .state .Remove (seq )
259
259
}
@@ -267,21 +267,21 @@ func (engine *PullEngine) OnHello(nonce uint64, context interface{}) {
267
267
})
268
268
269
269
a := engine .state .ToArray ()
270
- digest := make ([]uint64 , len (a ))
270
+ digest := make ([]string , len (a ))
271
271
for i , item := range a {
272
- digest [i ] = item .(uint64 )
272
+ digest [i ] = item .(string )
273
273
}
274
274
engine .SendDigest (digest , nonce , context )
275
275
}
276
276
277
277
// OnReq notifies the engine a request has arrived
278
- func (engine * PullEngine ) OnReq (items []uint64 , nonce uint64 , context interface {}) {
278
+ func (engine * PullEngine ) OnReq (items []string , nonce uint64 , context interface {}) {
279
279
if ! engine .incomingNONCES .Exists (nonce ) {
280
280
return
281
281
}
282
282
engine .lock .Lock ()
283
283
284
- var items2Send []uint64
284
+ var items2Send []string
285
285
for _ , item := range items {
286
286
if engine .state .Exists (item ) {
287
287
items2Send = append (items2Send , item )
@@ -294,7 +294,7 @@ func (engine *PullEngine) OnReq(items []uint64, nonce uint64, context interface{
294
294
}
295
295
296
296
// OnRes notifies the engine a response has arrived
297
- func (engine * PullEngine ) OnRes (items []uint64 , nonce uint64 ) {
297
+ func (engine * PullEngine ) OnRes (items []string , nonce uint64 ) {
298
298
if ! engine .outgoingNONCES .Exists (nonce ) || ! engine .isAcceptingResponses () {
299
299
return
300
300
}
0 commit comments