@@ -22,10 +22,10 @@ func (g *gauge) Dec() {
22
22
func TestEmpty (t * testing.T ) {
23
23
pwm := newPeerWantManager (& gauge {})
24
24
25
- if len (pwm .GetWantBlocks ()) > 0 {
25
+ if len (pwm .getWantBlocks ()) > 0 {
26
26
t .Fatal ("Expected GetWantBlocks() to have length 0" )
27
27
}
28
- if len (pwm .GetWantHaves ()) > 0 {
28
+ if len (pwm .getWantHaves ()) > 0 {
29
29
t .Fatal ("Expected GetWantHaves() to have length 0" )
30
30
}
31
31
}
@@ -38,11 +38,11 @@ func TestPrepareBroadcastWantHaves(t *testing.T) {
38
38
cids2 := testutil .GenerateCids (2 )
39
39
cids3 := testutil .GenerateCids (2 )
40
40
41
- pwm .AddPeer (peers [0 ])
42
- pwm .AddPeer (peers [1 ])
41
+ pwm .addPeer (peers [0 ])
42
+ pwm .addPeer (peers [1 ])
43
43
44
44
// Broadcast 2 cids to 2 peers
45
- bcst := pwm .PrepareBroadcastWantHaves (cids )
45
+ bcst := pwm .prepareBroadcastWantHaves (cids )
46
46
if len (bcst ) != 2 {
47
47
t .Fatal ("Expected 2 peers" )
48
48
}
@@ -53,13 +53,13 @@ func TestPrepareBroadcastWantHaves(t *testing.T) {
53
53
}
54
54
55
55
// Broadcasting same cids should have no effect
56
- bcst2 := pwm .PrepareBroadcastWantHaves (cids )
56
+ bcst2 := pwm .prepareBroadcastWantHaves (cids )
57
57
if len (bcst2 ) != 0 {
58
58
t .Fatal ("Expected 0 peers" )
59
59
}
60
60
61
61
// Broadcast 2 other cids
62
- bcst3 := pwm .PrepareBroadcastWantHaves (cids2 )
62
+ bcst3 := pwm .prepareBroadcastWantHaves (cids2 )
63
63
if len (bcst3 ) != 2 {
64
64
t .Fatal ("Expected 2 peers" )
65
65
}
@@ -70,7 +70,7 @@ func TestPrepareBroadcastWantHaves(t *testing.T) {
70
70
}
71
71
72
72
// Broadcast mix of old and new cids
73
- bcst4 := pwm .PrepareBroadcastWantHaves (append (cids , cids3 ... ))
73
+ bcst4 := pwm .prepareBroadcastWantHaves (append (cids , cids3 ... ))
74
74
if len (bcst4 ) != 2 {
75
75
t .Fatal ("Expected 2 peers" )
76
76
}
@@ -84,9 +84,9 @@ func TestPrepareBroadcastWantHaves(t *testing.T) {
84
84
// Sending want-block for a cid should prevent broadcast to that peer
85
85
cids4 := testutil .GenerateCids (4 )
86
86
wantBlocks := []cid.Cid {cids4 [0 ], cids4 [2 ]}
87
- pwm .PrepareSendWants (peers [0 ], wantBlocks , []cid.Cid {})
87
+ pwm .prepareSendWants (peers [0 ], wantBlocks , []cid.Cid {})
88
88
89
- bcst5 := pwm .PrepareBroadcastWantHaves (cids4 )
89
+ bcst5 := pwm .prepareBroadcastWantHaves (cids4 )
90
90
if len (bcst4 ) != 2 {
91
91
t .Fatal ("Expected 2 peers" )
92
92
}
@@ -105,8 +105,8 @@ func TestPrepareBroadcastWantHaves(t *testing.T) {
105
105
}
106
106
107
107
// Add another peer
108
- pwm .AddPeer (peers [2 ])
109
- bcst6 := pwm .PrepareBroadcastWantHaves (cids )
108
+ pwm .addPeer (peers [2 ])
109
+ bcst6 := pwm .prepareBroadcastWantHaves (cids )
110
110
if len (bcst6 ) != 1 {
111
111
t .Fatal ("Expected 1 peer" )
112
112
}
@@ -126,11 +126,11 @@ func TestPrepareSendWants(t *testing.T) {
126
126
cids := testutil .GenerateCids (2 )
127
127
cids2 := testutil .GenerateCids (2 )
128
128
129
- pwm .AddPeer (p0 )
130
- pwm .AddPeer (p1 )
129
+ pwm .addPeer (p0 )
130
+ pwm .addPeer (p1 )
131
131
132
132
// Send 2 want-blocks and 2 want-haves to p0
133
- wb , wh := pwm .PrepareSendWants (p0 , cids , cids2 )
133
+ wb , wh := pwm .prepareSendWants (p0 , cids , cids2 )
134
134
if ! testutil .MatchKeysIgnoreOrder (wb , cids ) {
135
135
t .Fatal ("Expected 2 want-blocks" )
136
136
}
@@ -143,7 +143,7 @@ func TestPrepareSendWants(t *testing.T) {
143
143
// - 1 old want-have and 2 new want-haves
144
144
cids3 := testutil .GenerateCids (2 )
145
145
cids4 := testutil .GenerateCids (2 )
146
- wb2 , wh2 := pwm .PrepareSendWants (p0 , append (cids3 , cids [0 ]), append (cids4 , cids2 [0 ]))
146
+ wb2 , wh2 := pwm .prepareSendWants (p0 , append (cids3 , cids [0 ]), append (cids4 , cids2 [0 ]))
147
147
if ! testutil .MatchKeysIgnoreOrder (wb2 , cids3 ) {
148
148
t .Fatal ("Expected 2 want-blocks" )
149
149
}
@@ -154,7 +154,7 @@ func TestPrepareSendWants(t *testing.T) {
154
154
// Send to p0 as want-blocks: 1 new want-block, 1 old want-have
155
155
cids5 := testutil .GenerateCids (1 )
156
156
newWantBlockOldWantHave := append (cids5 , cids2 [0 ])
157
- wb3 , wh3 := pwm .PrepareSendWants (p0 , newWantBlockOldWantHave , []cid.Cid {})
157
+ wb3 , wh3 := pwm .prepareSendWants (p0 , newWantBlockOldWantHave , []cid.Cid {})
158
158
// If a want was sent as a want-have, it should be ok to now send it as a
159
159
// want-block
160
160
if ! testutil .MatchKeysIgnoreOrder (wb3 , newWantBlockOldWantHave ) {
@@ -167,7 +167,7 @@ func TestPrepareSendWants(t *testing.T) {
167
167
// Send to p0 as want-haves: 1 new want-have, 1 old want-block
168
168
cids6 := testutil .GenerateCids (1 )
169
169
newWantHaveOldWantBlock := append (cids6 , cids [0 ])
170
- wb4 , wh4 := pwm .PrepareSendWants (p0 , []cid.Cid {}, newWantHaveOldWantBlock )
170
+ wb4 , wh4 := pwm .prepareSendWants (p0 , []cid.Cid {}, newWantHaveOldWantBlock )
171
171
// If a want was previously sent as a want-block, it should not be
172
172
// possible to now send it as a want-have
173
173
if ! testutil .MatchKeysIgnoreOrder (wh4 , cids6 ) {
@@ -178,7 +178,7 @@ func TestPrepareSendWants(t *testing.T) {
178
178
}
179
179
180
180
// Send 2 want-blocks and 2 want-haves to p1
181
- wb5 , wh5 := pwm .PrepareSendWants (p1 , cids , cids2 )
181
+ wb5 , wh5 := pwm .prepareSendWants (p1 , cids , cids2 )
182
182
if ! testutil .MatchKeysIgnoreOrder (wb5 , cids ) {
183
183
t .Fatal ("Expected 2 want-blocks" )
184
184
}
@@ -200,41 +200,41 @@ func TestPrepareSendCancels(t *testing.T) {
200
200
allwb := append (wb1 , wb2 ... )
201
201
allwh := append (wh1 , wh2 ... )
202
202
203
- pwm .AddPeer (p0 )
204
- pwm .AddPeer (p1 )
203
+ pwm .addPeer (p0 )
204
+ pwm .addPeer (p1 )
205
205
206
206
// Send 2 want-blocks and 2 want-haves to p0
207
- pwm .PrepareSendWants (p0 , wb1 , wh1 )
207
+ pwm .prepareSendWants (p0 , wb1 , wh1 )
208
208
// Send 3 want-blocks and 3 want-haves to p1
209
209
// (1 overlapping want-block / want-have with p0)
210
- pwm .PrepareSendWants (p1 , append (wb2 , wb1 [1 ]), append (wh2 , wh1 [1 ]))
210
+ pwm .prepareSendWants (p1 , append (wb2 , wb1 [1 ]), append (wh2 , wh1 [1 ]))
211
211
212
- if ! testutil .MatchKeysIgnoreOrder (pwm .GetWantBlocks (), allwb ) {
212
+ if ! testutil .MatchKeysIgnoreOrder (pwm .getWantBlocks (), allwb ) {
213
213
t .Fatal ("Expected 4 cids to be wanted" )
214
214
}
215
- if ! testutil .MatchKeysIgnoreOrder (pwm .GetWantHaves (), allwh ) {
215
+ if ! testutil .MatchKeysIgnoreOrder (pwm .getWantHaves (), allwh ) {
216
216
t .Fatal ("Expected 4 cids to be wanted" )
217
217
}
218
218
219
219
// Cancel 1 want-block and 1 want-have that were sent to p0
220
- res := pwm .PrepareSendCancels ([]cid.Cid {wb1 [0 ], wh1 [0 ]})
220
+ res := pwm .prepareSendCancels ([]cid.Cid {wb1 [0 ], wh1 [0 ]})
221
221
// Should cancel the want-block and want-have
222
222
if len (res ) != 1 {
223
223
t .Fatal ("Expected 1 peer" )
224
224
}
225
225
if ! testutil .MatchKeysIgnoreOrder (res [p0 ], []cid.Cid {wb1 [0 ], wh1 [0 ]}) {
226
226
t .Fatal ("Expected 2 cids to be cancelled" )
227
227
}
228
- if ! testutil .MatchKeysIgnoreOrder (pwm .GetWantBlocks (), append (wb2 , wb1 [1 ])) {
228
+ if ! testutil .MatchKeysIgnoreOrder (pwm .getWantBlocks (), append (wb2 , wb1 [1 ])) {
229
229
t .Fatal ("Expected 3 want-blocks" )
230
230
}
231
- if ! testutil .MatchKeysIgnoreOrder (pwm .GetWantHaves (), append (wh2 , wh1 [1 ])) {
231
+ if ! testutil .MatchKeysIgnoreOrder (pwm .getWantHaves (), append (wh2 , wh1 [1 ])) {
232
232
t .Fatal ("Expected 3 want-haves" )
233
233
}
234
234
235
235
// Cancel everything
236
236
allCids := append (allwb , allwh ... )
237
- res2 := pwm .PrepareSendCancels (allCids )
237
+ res2 := pwm .prepareSendCancels (allCids )
238
238
// Should cancel the remaining want-blocks and want-haves
239
239
if len (res2 ) != 2 {
240
240
t .Fatal ("Expected 2 peers" , len (res2 ))
@@ -247,10 +247,10 @@ func TestPrepareSendCancels(t *testing.T) {
247
247
if ! testutil .MatchKeysIgnoreOrder (res2 [p1 ], remainingP2 ) {
248
248
t .Fatal ("Expected un-cancelled cids to be cancelled" )
249
249
}
250
- if len (pwm .GetWantBlocks ()) != 0 {
250
+ if len (pwm .getWantBlocks ()) != 0 {
251
251
t .Fatal ("Expected 0 want-blocks" )
252
252
}
253
- if len (pwm .GetWantHaves ()) != 0 {
253
+ if len (pwm .getWantHaves ()) != 0 {
254
254
t .Fatal ("Expected 0 want-haves" )
255
255
}
256
256
}
@@ -264,18 +264,18 @@ func TestStats(t *testing.T) {
264
264
cids := testutil .GenerateCids (2 )
265
265
cids2 := testutil .GenerateCids (2 )
266
266
267
- pwm .AddPeer (p0 )
267
+ pwm .addPeer (p0 )
268
268
269
269
// Send 2 want-blocks and 2 want-haves to p0
270
- pwm .PrepareSendWants (p0 , cids , cids2 )
270
+ pwm .prepareSendWants (p0 , cids , cids2 )
271
271
272
272
if g .count != 2 {
273
273
t .Fatal ("Expected 2 want-blocks" )
274
274
}
275
275
276
276
// Send 1 old want-block and 2 new want-blocks to p0
277
277
cids3 := testutil .GenerateCids (2 )
278
- pwm .PrepareSendWants (p0 , append (cids3 , cids [0 ]), []cid.Cid {})
278
+ pwm .prepareSendWants (p0 , append (cids3 , cids [0 ]), []cid.Cid {})
279
279
280
280
if g .count != 4 {
281
281
t .Fatal ("Expected 4 want-blocks" )
@@ -284,7 +284,7 @@ func TestStats(t *testing.T) {
284
284
// Cancel 1 want-block that was sent to p0
285
285
// and 1 want-block that was not sent
286
286
cids4 := testutil .GenerateCids (1 )
287
- pwm .PrepareSendCancels (append (cids4 , cids [0 ]))
287
+ pwm .prepareSendCancels (append (cids4 , cids [0 ]))
288
288
289
289
if g .count != 3 {
290
290
t .Fatal ("Expected 3 want-blocks" , g .count )
0 commit comments