@@ -13,12 +13,13 @@ const waterfall = require('async/waterfall')
13
13
const multiaddr = require ( 'multiaddr' )
14
14
const crypto = require ( 'crypto' )
15
15
const IPFS = require ( 'ipfs' )
16
- const createRepo = require ( './utils/create-repo-nodejs' )
17
16
18
17
const isNode = require ( 'detect-node' )
19
18
20
19
const DaemonFactory = require ( 'ipfsd-ctl' )
21
- const df = DaemonFactory . create ( )
20
+ const jsDf = DaemonFactory . create ( { type : 'js' } )
21
+ const goDf = DaemonFactory . create ( { type : 'go' } )
22
+ const procDf = DaemonFactory . create ( { type : 'proc' , exec : IPFS } )
22
23
23
24
const baseConf = {
24
25
Bootstrap : [ ] ,
@@ -38,9 +39,7 @@ function setupInProcNode (factory, addrs, hop, callback) {
38
39
hop = false
39
40
}
40
41
41
- const node = new IPFS ( {
42
- repo : createRepo ( ) ,
43
- init : { bits : 1024 } ,
42
+ procDf . spawn ( {
44
43
config : Object . assign ( { } , baseConf , {
45
44
Addresses : {
46
45
Swarm : addrs
@@ -54,10 +53,11 @@ function setupInProcNode (factory, addrs, hop, callback) {
54
53
}
55
54
}
56
55
} )
57
- } )
58
-
59
- node . once ( 'ready' , ( ) => {
60
- callback ( null , node )
56
+ } , ( err , ipfsd ) => {
57
+ expect ( err ) . to . not . exist ( )
58
+ ipfsd . api . id ( ( err , id ) => {
59
+ callback ( err , { ipfsd, addrs : circuitFilter ( id . addresses ) } )
60
+ } )
61
61
} )
62
62
}
63
63
@@ -67,8 +67,7 @@ function setUpJsNode (addrs, hop, callback) {
67
67
hop = false
68
68
}
69
69
70
- df . spawn ( {
71
- type : 'js' ,
70
+ jsDf . spawn ( {
72
71
config : Object . assign ( { } , baseConf , {
73
72
Addresses : {
74
73
Swarm : addrs
@@ -84,8 +83,8 @@ function setUpJsNode (addrs, hop, callback) {
84
83
} )
85
84
} , ( err , ipfsd ) => {
86
85
expect ( err ) . to . not . exist ( )
87
- ipfsd . api . swarm . localAddrs ( ( err , addrs ) => {
88
- callback ( err , { ipfsd, addrs : circuitFilter ( addrs ) } )
86
+ ipfsd . api . id ( ( err , id ) => {
87
+ callback ( err , { ipfsd, addrs : circuitFilter ( id . addresses ) } )
89
88
} )
90
89
} )
91
90
}
@@ -96,7 +95,7 @@ function setUpGoNode (addrs, hop, callback) {
96
95
hop = false
97
96
}
98
97
99
- df . spawn ( {
98
+ goDf . spawn ( {
100
99
config : Object . assign ( { } , baseConf , {
101
100
Addresses : {
102
101
Swarm : addrs
@@ -114,17 +113,6 @@ function setUpGoNode (addrs, hop, callback) {
114
113
} )
115
114
}
116
115
117
- function addAndCat ( node1 , node2 , data , callback ) {
118
- waterfall ( [
119
- ( cb ) => node1 . files . add ( data , cb ) ,
120
- ( res , cb ) => node2 . files . cat ( res [ 0 ] . hash , cb ) ,
121
- ( buffer , cb ) => {
122
- expect ( buffer ) . to . deep . equal ( data )
123
- cb ( )
124
- }
125
- ] , callback )
126
- }
127
-
128
116
const circuitFilter = ( addrs ) => addrs . map ( ( a ) => a . toString ( ) ) . filter ( ( a ) => ! a . includes ( '/p2p-circuit' ) )
129
117
const wsAddr = ( addrs ) => addrs . map ( ( a ) => a . toString ( ) ) . find ( ( a ) => a . includes ( '/ws' ) )
130
118
const tcpAddr = ( addrs ) => addrs . map ( ( a ) => a . toString ( ) ) . find ( ( a ) => ! a . includes ( '/ws' ) )
@@ -135,16 +123,17 @@ function tests (relayType) {
135
123
136
124
let goTCP
137
125
let goTCPAddr
138
- let jsWSAddr
139
126
let jsWS
127
+ let jsWSAddr
140
128
let jsWSCircuitAddr
141
129
142
130
let nodes
143
- before ( ( done ) => {
131
+
132
+ before ( function ( done ) {
144
133
parallel ( [
145
134
( cb ) => setUpGoNode ( [ `${ base } /35003` ] , cb ) ,
146
135
( cb ) => setUpJsNode ( [ `${ base } /35004/ws` ] , cb )
147
- ] , ( err , res ) => {
136
+ ] , function ( err , res ) {
148
137
expect ( err ) . to . not . exist ( )
149
138
nodes = res . map ( ( node ) => node . ipfsd )
150
139
@@ -161,18 +150,26 @@ function tests (relayType) {
161
150
162
151
after ( ( done ) => parallel ( nodes . map ( ( node ) => ( cb ) => node . stop ( cb ) ) , done ) )
163
152
164
- it ( 'should connect and transfer' , function ( done ) {
165
- const data = crypto . randomBytes ( 128 )
153
+ it ( 'should connect' , function ( done ) {
166
154
series ( [
167
155
( cb ) => this . relay . api . swarm . connect ( goTCPAddr , cb ) ,
168
156
( cb ) => setTimeout ( cb , 1000 ) ,
169
157
( cb ) => this . relay . api . swarm . connect ( jsWSAddr , cb ) ,
170
158
( cb ) => setTimeout ( cb , 1000 ) ,
171
159
( cb ) => goTCP . swarm . connect ( jsWSCircuitAddr , cb )
172
- ] , ( err ) => {
173
- expect ( err ) . to . not . exist ( )
174
- addAndCat ( goTCP , jsWS , data , done )
175
- } )
160
+ ] , done )
161
+ } )
162
+
163
+ it ( 'should transfer' , function ( done ) {
164
+ const data = crypto . randomBytes ( 128 )
165
+ waterfall ( [
166
+ ( cb ) => goTCP . files . add ( data , cb ) ,
167
+ ( res , cb ) => jsWS . files . cat ( res [ 0 ] . hash , cb ) ,
168
+ ( buffer , cb ) => {
169
+ expect ( buffer ) . to . deep . equal ( data )
170
+ cb ( )
171
+ }
172
+ ] , done )
176
173
} )
177
174
} )
178
175
@@ -207,18 +204,26 @@ function tests (relayType) {
207
204
208
205
after ( ( done ) => parallel ( nodes . map ( ( node ) => ( cb ) => node . stop ( cb ) ) , done ) )
209
206
210
- it ( 'should connect and transfer' , function ( done ) {
211
- const data = crypto . randomBytes ( 128 )
207
+ it ( 'should connect' , function ( done ) {
212
208
series ( [
213
209
( cb ) => this . relay . api . swarm . connect ( jsTCPAddr , cb ) ,
214
210
( cb ) => setTimeout ( cb , 1000 ) ,
215
211
( cb ) => this . relay . api . swarm . connect ( jsWSAddr , cb ) ,
216
212
( cb ) => setTimeout ( cb , 1000 ) ,
217
213
( cb ) => jsWS . swarm . connect ( jsTCPCircuitAddr , cb )
218
- ] , ( err ) => {
219
- expect ( err ) . to . not . exist ( )
220
- addAndCat ( jsTCP , jsWS , data , done )
221
- } )
214
+ ] , done )
215
+ } )
216
+
217
+ it ( 'should transfer' , function ( done ) {
218
+ const data = crypto . randomBytes ( 128 )
219
+ waterfall ( [
220
+ ( cb ) => jsTCP . files . add ( data , cb ) ,
221
+ ( res , cb ) => jsWS . files . cat ( res [ 0 ] . hash , cb ) ,
222
+ ( buffer , cb ) => {
223
+ expect ( buffer ) . to . deep . equal ( data )
224
+ cb ( )
225
+ }
226
+ ] , done )
222
227
} )
223
228
} )
224
229
@@ -253,18 +258,26 @@ function tests (relayType) {
253
258
254
259
after ( ( done ) => parallel ( nodes . map ( ( node ) => ( cb ) => node . stop ( cb ) ) , done ) )
255
260
256
- it ( 'should connect and transfer' , function ( done ) {
257
- const data = crypto . randomBytes ( 128 )
261
+ it ( 'should connect' , function ( done ) {
258
262
series ( [
259
263
( cb ) => this . relay . api . swarm . connect ( goTCPAddr , cb ) ,
260
264
( cb ) => setTimeout ( cb , 1000 ) ,
261
265
( cb ) => this . relay . api . swarm . connect ( goWSAddr , cb ) ,
262
266
( cb ) => setTimeout ( cb , 1000 ) ,
263
267
( cb ) => goWS . swarm . connect ( goTCPCircuitAddr , cb )
264
- ] , ( err ) => {
265
- expect ( err ) . to . not . exist ( )
266
- addAndCat ( goTCP , goWS , data , done )
267
- } )
268
+ ] , done )
269
+ } )
270
+
271
+ it ( 'should transfer' , function ( done ) {
272
+ const data = crypto . randomBytes ( 128 )
273
+ waterfall ( [
274
+ ( cb ) => goTCP . files . add ( data , cb ) ,
275
+ ( res , cb ) => goWS . files . cat ( res [ 0 ] . hash , cb ) ,
276
+ ( buffer , cb ) => {
277
+ expect ( buffer ) . to . deep . equal ( data )
278
+ cb ( )
279
+ }
280
+ ] , done )
268
281
} )
269
282
} )
270
283
@@ -287,28 +300,34 @@ function tests (relayType) {
287
300
( cb ) => setupInProcNode ( [ ] , false , cb )
288
301
] , ( err , nodes ) => {
289
302
expect ( err ) . to . not . exist ( )
290
- browserNode1 = nodes [ 0 ]
291
- browserNode2 = nodes [ 1 ]
292
- browserNode2 . id ( ( err , id ) => {
293
- expect ( err ) . to . not . exist ( )
294
- browserNode2Addrs = id . addresses
295
- done ( )
296
- } )
303
+ browserNode1 = nodes [ 0 ] . ipfsd . api
304
+ browserNode2 = nodes [ 1 ] . ipfsd . api
305
+
306
+ browserNode2Addrs = nodes [ 1 ] . addrs
307
+ done ( )
297
308
} )
298
309
} )
299
310
300
- it ( 'should connect and transfer' , function ( done ) {
301
- const data = crypto . randomBytes ( 128 )
311
+ it ( 'should connect' , function ( done ) {
302
312
series ( [
303
313
( cb ) => browserNode1 . swarm . connect ( wsAddr ( this . relayAddrs ) , cb ) ,
304
314
( cb ) => setTimeout ( cb , 1000 ) ,
305
315
( cb ) => browserNode2 . swarm . connect ( wsAddr ( this . relayAddrs ) , cb ) ,
306
316
( cb ) => setTimeout ( cb , 1000 ) ,
307
317
( cb ) => browserNode1 . swarm . connect ( browserNode2Addrs [ 0 ] , cb )
308
- ] , ( err ) => {
309
- expect ( err ) . to . not . exist ( )
310
- addAndCat ( browserNode1 , browserNode2 , data , done )
311
- } )
318
+ ] , done )
319
+ } )
320
+
321
+ it ( 'should transfer' , function ( done ) {
322
+ const data = crypto . randomBytes ( 128 )
323
+ waterfall ( [
324
+ ( cb ) => browserNode1 . files . add ( data , cb ) ,
325
+ ( res , cb ) => browserNode2 . files . cat ( res [ 0 ] . hash , cb ) ,
326
+ ( buffer , cb ) => {
327
+ expect ( buffer ) . to . deep . equal ( data )
328
+ cb ( )
329
+ }
330
+ ] , done )
312
331
} )
313
332
} )
314
333
@@ -341,17 +360,25 @@ function tests (relayType) {
341
360
after ( ( done ) => jsTCP . stop ( done ) )
342
361
343
362
it ( 'should connect and transfer' , function ( done ) {
344
- const data = crypto . randomBytes ( 128 )
345
363
series ( [
346
364
( cb ) => browserNode1 . swarm . connect ( wsAddr ( this . relayAddrs ) , cb ) ,
347
365
( cb ) => setTimeout ( cb , 1000 ) ,
348
366
( cb ) => jsTCP . api . swarm . connect ( tcpAddr ( this . relayAddrs ) , cb ) ,
349
367
( cb ) => setTimeout ( cb , 1000 ) ,
350
368
( cb ) => browserNode1 . swarm . connect ( jsTCPAddrs [ 0 ] , cb )
351
- ] , ( err ) => {
352
- expect ( err ) . to . not . exist ( )
353
- addAndCat ( browserNode1 , jsTCP . api , data , done )
354
- } )
369
+ ] , done )
370
+ } )
371
+
372
+ it ( 'should transfer' , function ( done ) {
373
+ const data = crypto . randomBytes ( 128 )
374
+ waterfall ( [
375
+ ( cb ) => browserNode1 . files . add ( data , cb ) ,
376
+ ( res , cb ) => jsTCP . files . cat ( res [ 0 ] . hash , cb ) ,
377
+ ( buffer , cb ) => {
378
+ expect ( buffer ) . to . deep . equal ( data )
379
+ cb ( )
380
+ }
381
+ ] , done )
355
382
} )
356
383
} )
357
384
@@ -384,39 +411,47 @@ function tests (relayType) {
384
411
385
412
after ( ( done ) => goTCP . stop ( done ) )
386
413
387
- it ( 'should connect and transfer' , function ( done ) {
388
- const data = crypto . randomBytes ( 128 )
414
+ it ( 'should connect' , function ( done ) {
389
415
series ( [
390
416
( cb ) => browserNode1 . swarm . connect ( wsAddr ( this . relayAddrs ) , cb ) ,
391
417
( cb ) => setTimeout ( cb , 1000 ) ,
392
418
( cb ) => goTCP . api . swarm . connect ( tcpAddr ( this . relayAddrs ) , cb ) ,
393
419
( cb ) => setTimeout ( cb , 1000 ) ,
394
420
( cb ) => browserNode1 . swarm . connect ( goTCPAddrs [ 0 ] , cb )
395
- ] , ( err ) => {
396
- expect ( err ) . to . not . exist ( )
397
- addAndCat ( browserNode1 , goTCP . api , data , done )
398
- } )
421
+ ] , done )
422
+ } )
423
+
424
+ it ( 'should transfer' , function ( done ) {
425
+ const data = crypto . randomBytes ( 128 )
426
+ waterfall ( [
427
+ ( cb ) => browserNode1 . files . add ( data , cb ) ,
428
+ ( res , cb ) => goTCP . files . cat ( res [ 0 ] . hash , cb ) ,
429
+ ( buffer , cb ) => {
430
+ expect ( buffer ) . to . deep . equal ( data )
431
+ cb ( )
432
+ }
433
+ ] , done )
399
434
} )
400
435
} )
401
436
}
402
437
403
- describe ( 'circuit' , ( ) => {
438
+ describe . only ( 'circuit' , ( ) => {
404
439
describe ( 'js relay' , function ( ) {
405
440
this . relay = null
406
441
this . relayAddrs = null
407
442
408
- beforeEach ( function ( done ) {
443
+ before ( function ( done ) {
409
444
this . timeout ( 50 * 1000 )
410
445
411
- setUpJsNode ( [ `${ base } /35002 ` , `${ base } /35001/ws ` ] , true , ( err , res ) => {
446
+ setUpJsNode ( [ `${ base } /35001/ws ` , `${ base } /35002 ` ] , true , ( err , res ) => {
412
447
expect ( err ) . to . not . exist ( )
413
448
this . relay = res . ipfsd
414
449
this . relayAddrs = res . addrs
415
450
done ( )
416
451
} )
417
452
} )
418
453
419
- afterEach ( function ( done ) { this . relay . stop ( done ) } )
454
+ after ( function ( done ) { this . relay . stop ( done ) } )
420
455
421
456
describe ( 'test js relay' , function ( ) {
422
457
tests ( 'jsRelay' )
@@ -427,18 +462,18 @@ describe('circuit', () => {
427
462
this . relay = null
428
463
this . relayAddrs = null
429
464
430
- beforeEach ( function ( done ) {
465
+ before ( function ( done ) {
431
466
this . timeout ( 50 * 1000 )
432
467
433
- setUpGoNode ( [ `${ base } /35002 ` , `${ base } /35001/ws ` ] , true , ( err , res ) => {
468
+ setUpGoNode ( [ `${ base } /35001/ws ` , `${ base } /35002 ` ] , true , ( err , res ) => {
434
469
expect ( err ) . to . not . exist ( )
435
470
this . relay = res . ipfsd
436
471
this . relayAddrs = res . addrs
437
472
done ( )
438
473
} )
439
474
} )
440
475
441
- afterEach ( function ( done ) { this . relay . stop ( done ) } )
476
+ after ( function ( done ) { this . relay . stop ( done ) } )
442
477
443
478
describe ( 'test go relay' , function ( ) {
444
479
tests ( 'goRelay' )
0 commit comments