@@ -15,7 +15,7 @@ import (
15
15
bhost "github.com/libp2p/go-libp2p/p2p/host/blank"
16
16
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
17
17
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
18
- "github.com/libp2p/go-libp2p/p2p/protocol/autonatv2/pbv2 "
18
+ "github.com/libp2p/go-libp2p/p2p/protocol/autonatv2/pb "
19
19
20
20
"github.com/libp2p/go-msgio/pbio"
21
21
ma "github.com/multiformats/go-multiaddr"
@@ -38,7 +38,7 @@ func newAutoNAT(t *testing.T, dialer host.Host, opts ...AutoNATOption) *AutoNAT
38
38
return an
39
39
}
40
40
41
- func parseAddrs (t * testing.T , msg * pbv2 .Message ) []ma.Multiaddr {
41
+ func parseAddrs (t * testing.T , msg * pb .Message ) []ma.Multiaddr {
42
42
t .Helper ()
43
43
req := msg .GetDialRequest ()
44
44
addrs := make ([]ma.Multiaddr , 0 )
@@ -93,7 +93,7 @@ func TestClientRequest(t *testing.T) {
93
93
p .SetStreamHandler (DialProtocol , func (s network.Stream ) {
94
94
gotReq .Store (true )
95
95
r := pbio .NewDelimitedReader (s , maxMsgSize )
96
- var msg pbv2 .Message
96
+ var msg pb .Message
97
97
if err := r .ReadMsg (& msg ); err != nil {
98
98
t .Error (err )
99
99
return
@@ -139,12 +139,12 @@ func TestClientServerError(t *testing.T) {
139
139
}},
140
140
{handler : func (s network.Stream ) {
141
141
r := pbio .NewDelimitedReader (s , maxMsgSize )
142
- var msg pbv2 .Message
142
+ var msg pb .Message
143
143
r .ReadMsg (& msg )
144
144
w := pbio .NewDelimitedWriter (s )
145
- w .WriteMsg (& pbv2 .Message {
146
- Msg : & pbv2 .Message_DialRequest {
147
- DialRequest : & pbv2 .DialRequest {
145
+ w .WriteMsg (& pb .Message {
146
+ Msg : & pb .Message_DialRequest {
147
+ DialRequest : & pb .DialRequest {
148
148
Addrs : [][]byte {},
149
149
Nonce : 0 ,
150
150
},
@@ -182,12 +182,12 @@ func TestClientDataRequest(t *testing.T) {
182
182
}{
183
183
{handler : func (s network.Stream ) {
184
184
r := pbio .NewDelimitedReader (s , maxMsgSize )
185
- var msg pbv2 .Message
185
+ var msg pb .Message
186
186
r .ReadMsg (& msg )
187
187
w := pbio .NewDelimitedWriter (s )
188
- w .WriteMsg (& pbv2 .Message {
189
- Msg : & pbv2 .Message_DialDataRequest {
190
- DialDataRequest : & pbv2 .DialDataRequest {
188
+ w .WriteMsg (& pb .Message {
189
+ Msg : & pb .Message_DialDataRequest {
190
+ DialDataRequest : & pb .DialDataRequest {
191
191
AddrIdx : 0 ,
192
192
NumBytes : 10000 ,
193
193
},
@@ -210,12 +210,12 @@ func TestClientDataRequest(t *testing.T) {
210
210
}},
211
211
{handler : func (s network.Stream ) {
212
212
r := pbio .NewDelimitedReader (s , maxMsgSize )
213
- var msg pbv2 .Message
213
+ var msg pb .Message
214
214
r .ReadMsg (& msg )
215
215
w := pbio .NewDelimitedWriter (s )
216
- w .WriteMsg (& pbv2 .Message {
217
- Msg : & pbv2 .Message_DialDataRequest {
218
- DialDataRequest : & pbv2 .DialDataRequest {
216
+ w .WriteMsg (& pb .Message {
217
+ Msg : & pb .Message_DialDataRequest {
218
+ DialDataRequest : & pb .DialDataRequest {
219
219
AddrIdx : 1 ,
220
220
NumBytes : 10000 ,
221
221
},
@@ -229,12 +229,12 @@ func TestClientDataRequest(t *testing.T) {
229
229
}},
230
230
{handler : func (s network.Stream ) {
231
231
r := pbio .NewDelimitedReader (s , maxMsgSize )
232
- var msg pbv2 .Message
232
+ var msg pb .Message
233
233
r .ReadMsg (& msg )
234
234
w := pbio .NewDelimitedWriter (s )
235
- w .WriteMsg (& pbv2 .Message {
236
- Msg : & pbv2 .Message_DialDataRequest {
237
- DialDataRequest : & pbv2 .DialDataRequest {
235
+ w .WriteMsg (& pb .Message {
236
+ Msg : & pb .Message_DialDataRequest {
237
+ DialDataRequest : & pb .DialDataRequest {
238
238
AddrIdx : 0 ,
239
239
NumBytes : 1000_000 ,
240
240
},
@@ -275,18 +275,18 @@ func TestClientDialBacks(t *testing.T) {
275
275
{
276
276
handler : func (s network.Stream ) {
277
277
r := pbio .NewDelimitedReader (s , maxMsgSize )
278
- var msg pbv2 .Message
278
+ var msg pb .Message
279
279
if err := r .ReadMsg (& msg ); err != nil {
280
280
t .Error (err )
281
281
}
282
- resp := & pbv2 .DialResponse {
283
- Status : pbv2 .DialResponse_ResponseStatus_OK ,
284
- DialStatus : pbv2 .DialStatus_OK ,
282
+ resp := & pb .DialResponse {
283
+ Status : pb .DialResponse_ResponseStatus_OK ,
284
+ DialStatus : pb .DialStatus_OK ,
285
285
AddrIdx : 0 ,
286
286
}
287
287
w := pbio .NewDelimitedWriter (s )
288
- w .WriteMsg (& pbv2 .Message {
289
- Msg : & pbv2 .Message_DialResponse {
288
+ w .WriteMsg (& pb .Message {
289
+ Msg : & pb .Message_DialResponse {
290
290
DialResponse : resp ,
291
291
},
292
292
})
@@ -297,7 +297,7 @@ func TestClientDialBacks(t *testing.T) {
297
297
{
298
298
handler : func (s network.Stream ) {
299
299
r := pbio .NewDelimitedReader (s , maxMsgSize )
300
- var msg pbv2 .Message
300
+ var msg pb .Message
301
301
r .ReadMsg (& msg )
302
302
req := msg .GetDialRequest ()
303
303
addrs := parseAddrs (t , & msg )
@@ -311,15 +311,15 @@ func TestClientDialBacks(t *testing.T) {
311
311
return
312
312
}
313
313
w := pbio .NewDelimitedWriter (as )
314
- w .WriteMsg (& pbv2 .DialBack {Nonce : req .Nonce })
314
+ w .WriteMsg (& pb .DialBack {Nonce : req .Nonce })
315
315
as .CloseWrite ()
316
316
317
317
w = pbio .NewDelimitedWriter (s )
318
- w .WriteMsg (& pbv2 .Message {
319
- Msg : & pbv2 .Message_DialResponse {
320
- DialResponse : & pbv2 .DialResponse {
321
- Status : pbv2 .DialResponse_ResponseStatus_OK ,
322
- DialStatus : pbv2 .DialStatus_OK ,
318
+ w .WriteMsg (& pb .Message {
319
+ Msg : & pb .Message_DialResponse {
320
+ DialResponse : & pb .DialResponse {
321
+ Status : pb .DialResponse_ResponseStatus_OK ,
322
+ DialStatus : pb .DialStatus_OK ,
323
323
AddrIdx : 0 ,
324
324
},
325
325
},
@@ -331,7 +331,7 @@ func TestClientDialBacks(t *testing.T) {
331
331
{
332
332
handler : func (s network.Stream ) {
333
333
r := pbio .NewDelimitedReader (s , maxMsgSize )
334
- var msg pbv2 .Message
334
+ var msg pb .Message
335
335
r .ReadMsg (& msg )
336
336
req := msg .GetDialRequest ()
337
337
addrs := parseAddrs (t , & msg )
@@ -346,7 +346,7 @@ func TestClientDialBacks(t *testing.T) {
346
346
return
347
347
}
348
348
ww := pbio .NewDelimitedWriter (as )
349
- if err := ww .WriteMsg (& pbv2 .DialBack {Nonce : req .Nonce - 1 }); err != nil {
349
+ if err := ww .WriteMsg (& pb .DialBack {Nonce : req .Nonce - 1 }); err != nil {
350
350
s .Reset ()
351
351
as .Reset ()
352
352
return
@@ -359,11 +359,11 @@ func TestClientDialBacks(t *testing.T) {
359
359
}()
360
360
361
361
w := pbio .NewDelimitedWriter (s )
362
- w .WriteMsg (& pbv2 .Message {
363
- Msg : & pbv2 .Message_DialResponse {
364
- DialResponse : & pbv2 .DialResponse {
365
- Status : pbv2 .DialResponse_ResponseStatus_OK ,
366
- DialStatus : pbv2 .DialStatus_OK ,
362
+ w .WriteMsg (& pb .Message {
363
+ Msg : & pb .Message_DialResponse {
364
+ DialResponse : & pb .DialResponse {
365
+ Status : pb .DialResponse_ResponseStatus_OK ,
366
+ DialStatus : pb .DialStatus_OK ,
367
367
AddrIdx : 0 ,
368
368
},
369
369
},
@@ -375,7 +375,7 @@ func TestClientDialBacks(t *testing.T) {
375
375
{
376
376
handler : func (s network.Stream ) {
377
377
r := pbio .NewDelimitedReader (s , maxMsgSize )
378
- var msg pbv2 .Message
378
+ var msg pb .Message
379
379
r .ReadMsg (& msg )
380
380
req := msg .GetDialRequest ()
381
381
addrs := parseAddrs (t , & msg )
@@ -391,7 +391,7 @@ func TestClientDialBacks(t *testing.T) {
391
391
}
392
392
393
393
w := pbio .NewDelimitedWriter (as )
394
- if err := w .WriteMsg (& pbv2 .DialBack {Nonce : req .Nonce }); err != nil {
394
+ if err := w .WriteMsg (& pb .DialBack {Nonce : req .Nonce }); err != nil {
395
395
t .Error ("failed to write nonce" , err )
396
396
s .Reset ()
397
397
as .Reset ()
@@ -406,11 +406,11 @@ func TestClientDialBacks(t *testing.T) {
406
406
407
407
w = pbio .NewDelimitedWriter (s )
408
408
409
- w .WriteMsg (& pbv2 .Message {
410
- Msg : & pbv2 .Message_DialResponse {
411
- DialResponse : & pbv2 .DialResponse {
412
- Status : pbv2 .DialResponse_ResponseStatus_OK ,
413
- DialStatus : pbv2 .DialStatus_OK ,
409
+ w .WriteMsg (& pb .Message {
410
+ Msg : & pb .Message_DialResponse {
411
+ DialResponse : & pb .DialResponse {
412
+ Status : pb .DialResponse_ResponseStatus_OK ,
413
+ DialStatus : pb .DialStatus_OK ,
414
414
AddrIdx : 1 ,
415
415
},
416
416
},
@@ -422,7 +422,7 @@ func TestClientDialBacks(t *testing.T) {
422
422
{
423
423
handler : func (s network.Stream ) {
424
424
r := pbio .NewDelimitedReader (s , maxMsgSize )
425
- var msg pbv2 .Message
425
+ var msg pb .Message
426
426
r .ReadMsg (& msg )
427
427
req := msg .GetDialRequest ()
428
428
addrs := parseAddrs (t , & msg )
@@ -438,7 +438,7 @@ func TestClientDialBacks(t *testing.T) {
438
438
}
439
439
440
440
w := pbio .NewDelimitedWriter (as )
441
- if err := w .WriteMsg (& pbv2 .DialBack {Nonce : req .Nonce }); err != nil {
441
+ if err := w .WriteMsg (& pb .DialBack {Nonce : req .Nonce }); err != nil {
442
442
t .Error ("failed to write nonce" , err )
443
443
s .Reset ()
444
444
as .Reset ()
@@ -453,11 +453,11 @@ func TestClientDialBacks(t *testing.T) {
453
453
454
454
w = pbio .NewDelimitedWriter (s )
455
455
456
- w .WriteMsg (& pbv2 .Message {
457
- Msg : & pbv2 .Message_DialResponse {
458
- DialResponse : & pbv2 .DialResponse {
459
- Status : pbv2 .DialResponse_ResponseStatus_OK ,
460
- DialStatus : pbv2 .DialStatus_OK ,
456
+ w .WriteMsg (& pb .Message {
457
+ Msg : & pb .Message_DialResponse {
458
+ DialResponse : & pb .DialResponse {
459
+ Status : pb .DialResponse_ResponseStatus_OK ,
460
+ DialStatus : pb .DialStatus_OK ,
461
461
AddrIdx : 10 ,
462
462
},
463
463
},
@@ -480,12 +480,12 @@ func TestClientDialBacks(t *testing.T) {
480
480
} else {
481
481
require .NoError (t , err )
482
482
require .Equal (t , res .Reachability , network .ReachabilityUnknown )
483
- require .NotEqual (t , res .Status , pbv2 .DialStatus_OK , "got: %d" , res .Status )
483
+ require .NotEqual (t , res .Status , pb .DialStatus_OK , "got: %d" , res .Status )
484
484
}
485
485
} else {
486
486
require .NoError (t , err )
487
487
require .Equal (t , res .Reachability , network .ReachabilityPublic )
488
- require .Equal (t , res .Status , pbv2 .DialStatus_OK )
488
+ require .Equal (t , res .Status , pb .DialStatus_OK )
489
489
}
490
490
})
491
491
}
0 commit comments