@@ -10,6 +10,7 @@ chai.use(dirtyChai)
10
10
const sinon = require ( 'sinon' )
11
11
const PeerBook = require ( 'peer-book' )
12
12
const parallel = require ( 'async/parallel' )
13
+ const series = require ( 'async/series' )
13
14
const WS = require ( 'libp2p-websockets' )
14
15
const TCP = require ( 'libp2p-tcp' )
15
16
const secio = require ( 'libp2p-secio' )
@@ -25,16 +26,18 @@ describe('dialFSM', () => {
25
26
let switchA
26
27
let switchB
27
28
let switchC
29
+ let switchDialOnly
28
30
let peerAId
29
31
let peerBId
30
32
let protocol
31
33
32
- before ( ( done ) => createInfos ( 3 , ( err , infos ) => {
34
+ before ( ( done ) => createInfos ( 4 , ( err , infos ) => {
33
35
expect ( err ) . to . not . exist ( )
34
36
35
37
const peerA = infos [ 0 ]
36
38
const peerB = infos [ 1 ]
37
39
const peerC = infos [ 2 ]
40
+ const peerDialOnly = infos [ 3 ]
38
41
39
42
peerAId = peerA . id . toB58String ( )
40
43
peerBId = peerB . id . toB58String ( )
@@ -48,22 +51,27 @@ describe('dialFSM', () => {
48
51
switchA = new Switch ( peerA , new PeerBook ( ) )
49
52
switchB = new Switch ( peerB , new PeerBook ( ) )
50
53
switchC = new Switch ( peerC , new PeerBook ( ) )
54
+ switchDialOnly = new Switch ( peerDialOnly , new PeerBook ( ) )
51
55
52
56
switchA . transport . add ( 'tcp' , new TCP ( ) )
53
57
switchB . transport . add ( 'tcp' , new TCP ( ) )
54
58
switchC . transport . add ( 'ws' , new WS ( ) )
59
+ switchDialOnly . transport . add ( 'ws' , new WS ( ) )
55
60
56
61
switchA . connection . crypto ( secio . tag , secio . encrypt )
57
62
switchB . connection . crypto ( secio . tag , secio . encrypt )
58
63
switchC . connection . crypto ( secio . tag , secio . encrypt )
64
+ switchDialOnly . connection . crypto ( secio . tag , secio . encrypt )
59
65
60
66
switchA . connection . addStreamMuxer ( multiplex )
61
67
switchB . connection . addStreamMuxer ( multiplex )
62
68
switchC . connection . addStreamMuxer ( multiplex )
69
+ switchDialOnly . connection . addStreamMuxer ( multiplex )
63
70
64
71
switchA . connection . reuse ( )
65
72
switchB . connection . reuse ( )
66
73
switchC . connection . reuse ( )
74
+ switchDialOnly . connection . reuse ( )
67
75
68
76
parallel ( [
69
77
( cb ) => switchA . start ( cb ) ,
@@ -155,6 +163,30 @@ describe('dialFSM', () => {
155
163
} )
156
164
} )
157
165
166
+ it ( 'should clear the blacklist for a peer that connected to us' , ( done ) => {
167
+ series ( [
168
+ // Attempt to dial the peer that's not listening
169
+ ( cb ) => switchC . dial ( switchDialOnly . _peerInfo , ( err ) => {
170
+ expect ( err ) . to . exist ( )
171
+ cb ( )
172
+ } ) ,
173
+ // Dial from the dial only peer
174
+ ( cb ) => switchDialOnly . dial ( switchC . _peerInfo , ( err ) => {
175
+ expect ( err ) . to . not . exist ( )
176
+ // allow time for muxing to occur
177
+ setTimeout ( cb , 100 )
178
+ } ) ,
179
+ // "Dial" to the dial only peer, this should reuse the existing connection
180
+ ( cb ) => switchC . dial ( switchDialOnly . _peerInfo , ( err ) => {
181
+ expect ( err ) . to . not . exist ( )
182
+ cb ( )
183
+ } )
184
+ ] , ( err ) => {
185
+ expect ( err ) . to . not . exist ( )
186
+ done ( )
187
+ } )
188
+ } )
189
+
158
190
it ( 'should emit a `closed` event when closed' , ( done ) => {
159
191
protocol = '/closed/1.0.0'
160
192
switchB . handle ( protocol , ( ) => { } )
0 commit comments