@@ -36,7 +36,6 @@ function makeBlock (cb) {
36
36
37
37
describe ( 'bitswap' , ( ) => {
38
38
let inProcNode // Node spawned inside this process
39
- // let swarmAddrsBak
40
39
41
40
beforeEach ( ( done ) => {
42
41
const repo = createTempRepo ( )
@@ -73,50 +72,34 @@ describe('bitswap', () => {
73
72
inProcNode . on ( 'start' , ( ) => done ( ) )
74
73
} )
75
74
76
- afterEach ( ( done ) => {
77
- inProcNode . on ( 'stop' , ( ) => done ( ) )
78
- inProcNode . stop ( )
79
- } )
75
+ afterEach ( ( done ) => inProcNode . stop ( ( ) => done ( ) ) )
80
76
81
77
describe ( 'connections' , ( ) => {
82
78
function wire ( targetNode , dialerNode , done ) {
83
79
targetNode . id ( ( err , identity ) => {
84
80
expect ( err ) . to . not . exist ( )
85
81
const addr = identity . addresses
86
- . map ( ( addr ) => {
87
- const ma = multiaddr ( addr . toString ( ) . split ( 'ipfs' ) [ 0 ] )
88
- return ma
89
- } )
90
- . filter ( ( addr ) => {
91
- return _ . includes ( addr . protoNames ( ) , 'ws' )
92
- } ) [ 0 ]
93
-
94
- let targetAddr
95
- if ( addr ) {
96
- targetAddr = addr . encapsulate ( multiaddr ( `/ipfs/${ identity . id } ` ) ) . toString ( )
97
- targetAddr = targetAddr . replace ( '0.0.0.0' , '127.0.0.1' )
98
- } else {
99
- // Note: the browser doesn't have a websockets listening addr
82
+ . map ( ( addr ) => multiaddr ( addr . toString ( ) . split ( 'ipfs' ) [ 0 ] ) )
83
+ . filter ( ( addr ) => _ . includes ( addr . protoNames ( ) , 'ws' ) ) [ 0 ]
100
84
101
- // What we really need is a way to dial to a peerId only and another
102
- // to dial to peerInfo
85
+ if ( ! addr ) {
86
+ // Note: the browser doesn't have a websockets listening addr
103
87
return done ( )
104
- // targetAddr = multiaddr(`/ip4/127.0.0.1/tcp/0/ws/ipfs/${identity.id}`).toString()
105
88
}
106
89
90
+ const targetAddr = addr
91
+ . encapsulate ( multiaddr ( `/ipfs/${ identity . id } ` ) ) . toString ( )
92
+ . replace ( '0.0.0.0' , '127.0.0.1' )
93
+
107
94
dialerNode . swarm . connect ( targetAddr , done )
108
95
} )
109
96
}
110
97
111
98
function connectNodes ( remoteNode , ipn , done ) {
112
99
series ( [
113
- ( cb ) => {
114
- wire ( remoteNode , ipn , cb )
115
- } ,
100
+ ( cb ) => wire ( remoteNode , ipn , cb ) ,
116
101
( cb ) => setTimeout ( ( ) => {
117
- // need timeout so we wait for identify
118
- // to happen.
119
-
102
+ // need timeout so we wait for identify to happen.
120
103
// This call is just to ensure identify happened
121
104
wire ( ipn , remoteNode , cb )
122
105
} , 300 )
@@ -129,9 +112,7 @@ describe('bitswap', () => {
129
112
const apiUrl = `/ip4/127.0.0.1/tcp/31${ num } `
130
113
const remoteNode = new API ( apiUrl )
131
114
132
- connectNodes ( remoteNode , inProcNode , ( err ) => {
133
- done ( err , remoteNode )
134
- } )
115
+ connectNodes ( remoteNode , inProcNode , ( err ) => done ( err , remoteNode ) )
135
116
}
136
117
137
118
describe ( 'fetches a remote block' , ( ) => {
0 commit comments