5
5
const chai = require ( 'chai' )
6
6
const dirtyChai = require ( 'dirty-chai' )
7
7
const expect = chai . expect
8
- chai . use ( dirtyChai )
9
8
const waterfall = require ( 'async/waterfall' )
10
9
const parallel = require ( 'async/parallel' )
11
10
const isNode = require ( 'detect-node' )
12
11
13
12
const IPFS = require ( '../../src/core' )
14
13
const createTempRepo = require ( '../utils/create-repo-node.js' )
15
14
15
+ chai . use ( dirtyChai )
16
+
16
17
describe ( 'circuit' , ( ) => {
17
18
if ( ! isNode ) {
18
19
return
19
20
}
20
21
21
22
describe ( 'transfer over circuit' , function ( ) {
22
- this . timeout ( 5000 )
23
+ this . timeout ( 50000 )
23
24
24
25
let ipfsRelay
25
- let ipfsSrc
26
26
let ipfsDst
27
+ let ipfsSrc
27
28
28
29
before ( ( done ) => {
29
30
ipfsRelay = new IPFS ( {
@@ -32,14 +33,16 @@ describe('circuit', () => {
32
33
Addresses : {
33
34
Swarm : [
34
35
'/ip4/0.0.0.0/tcp/9000' ,
35
- '/ip4/0.0.0.0/tcp/9000 /ws'
36
+ '/ip4/0.0.0.0/tcp/9001 /ws'
36
37
]
37
38
} ,
38
39
Bootstrap : [ ] ,
39
- Relay : {
40
- Circuit : {
41
- Enabled : true ,
42
- Active : true
40
+ Experimental : {
41
+ Relay : {
42
+ Circuit : {
43
+ Enabled : true ,
44
+ Active : false
45
+ }
43
46
}
44
47
} ,
45
48
Identity : {
@@ -49,24 +52,24 @@ describe('circuit', () => {
49
52
}
50
53
} )
51
54
52
- ipfsSrc = new IPFS ( {
55
+ ipfsDst = new IPFS ( {
53
56
repo : createTempRepo ( ) ,
54
57
config : {
55
58
Addresses : {
56
59
Swarm : [
57
- '/ip4/0.0.0.0/tcp/9001 '
60
+ '/ip4/0.0.0.0/tcp/9002 '
58
61
]
59
62
} ,
60
63
Bootstrap : [ ]
61
64
}
62
65
} )
63
66
64
- ipfsDst = new IPFS ( {
67
+ ipfsSrc = new IPFS ( {
65
68
repo : createTempRepo ( ) ,
66
69
config : {
67
70
Addresses : {
68
71
Swarm : [
69
- '/ip4/0.0.0.0/tcp/9002 /ws'
72
+ '/ip4/0.0.0.0/tcp/9003 /ws'
70
73
]
71
74
} ,
72
75
Bootstrap : [ ]
@@ -78,20 +81,20 @@ describe('circuit', () => {
78
81
( pCb ) => ipfsSrc . once ( 'start' , pCb ) ,
79
82
( pCb ) => ipfsDst . once ( 'start' , pCb )
80
83
] , ( ) => {
81
- // get everything inter-connected
82
84
waterfall ( [
83
85
( cb ) => ipfsSrc
84
86
. swarm
85
- . connect ( `/ip4/0.0.0.0/tcp/9000/ ipfs/QmUGuDXBhWKJwoNNMhnsLGSzzDfjdSt81SoTHcMu1dXBrV` ,
86
- ( ) => cb ( ) ) ,
87
+ . connect ( `/ip4/0.0.0.0/tcp/9001/ws/ ipfs/QmUGuDXBhWKJwoNNMhnsLGSzzDfjdSt81SoTHcMu1dXBrV` , ( ) => cb ( ) ) ,
88
+ ( cb ) => setTimeout ( cb , 1000 ) ,
87
89
( cb ) => ipfsDst
88
90
. swarm
89
- . connect ( `/ip4/0.0.0.0/tcp/9000/ws/ ipfs/QmUGuDXBhWKJwoNNMhnsLGSzzDfjdSt81SoTHcMu1dXBrV` ,
90
- ( ) => cb ( ) ) ,
91
+ . connect ( `/ip4/0.0.0.0/tcp/9000/ipfs/QmUGuDXBhWKJwoNNMhnsLGSzzDfjdSt81SoTHcMu1dXBrV` , ( ) => cb ( ) ) ,
92
+ ( cb ) => setTimeout ( cb , 1000 ) ,
91
93
( cb ) => ipfsSrc . id ( cb ) ,
92
- ( id , cb ) => ipfsRelay . swarm . connect ( `/ip4/0.0.0.0/tcp/9001/ipfs/${ id . id } ` , ( ) => cb ( ) ) ,
94
+ ( id , cb ) => ipfsRelay . swarm . connect ( `/ip4/0.0.0.0/tcp/9002/ipfs/${ id . id } ` , ( ) => cb ( ) ) ,
95
+ ( cb ) => setTimeout ( cb , 1000 ) ,
93
96
( cb ) => ipfsDst . id ( cb ) ,
94
- ( id , cb ) => ipfsRelay . swarm . connect ( `/ip4/0.0.0.0/tcp/9002 /ws/ipfs/${ id . id } ` , ( ) => cb ( ) )
97
+ ( id , cb ) => ipfsRelay . swarm . connect ( `/ip4/0.0.0.0/tcp/9003 /ws/ipfs/${ id . id } ` , ( ) => cb ( ) )
95
98
] , done )
96
99
} )
97
100
} )
@@ -105,27 +108,24 @@ describe('circuit', () => {
105
108
} )
106
109
107
110
it ( 'should be able to connect over circuit' , ( done ) => {
108
- ipfsDst . id ( ( err , id ) => {
111
+ ipfsSrc . swarm . connect ( ipfsDst . _peerInfo , ( err , conn ) => {
109
112
expect ( err ) . to . be . null ( )
110
- ipfsSrc . swarm . connect ( id . addresses [ 0 ] , ( err , conn ) => {
111
- expect ( err ) . to . be . null ( )
112
- expect ( conn ) . to . not . be . null ( )
113
- done ( )
114
- } )
113
+ expect ( conn ) . to . not . be . null ( )
114
+ done ( )
115
115
} )
116
116
} )
117
117
118
118
it ( 'should be able to transfer data over circuit' , ( done ) => {
119
119
waterfall ( [
120
- ( cb ) => ipfsDst . id ( cb ) ,
121
120
// dial destination over WS /ip4/0.0.0.0/tcp/9002/ws
122
- ( id , cb ) => ipfsSrc . swarm . connect ( id . addresses [ 0 ] , cb ) ,
123
- ( conn , cb ) => ipfsSrc . files . add ( new ipfsSrc . types . Buffer ( 'Hello world over circuit!' ) , ( err , res ) => {
124
- expect ( err ) . to . be . null ( )
125
- expect ( res [ 0 ] ) . to . not . be . null ( )
126
- cb ( null , res [ 0 ] . hash )
127
- } ) ,
128
- ( fileHash , cb ) => ipfsDst . files . cat ( fileHash , function ( err , stream ) {
121
+ ( cb ) => ipfsSrc . swarm . connect ( ipfsDst . _peerInfo , cb ) ,
122
+ ( conn , cb ) => ipfsDst . files . add ( new ipfsDst . types . Buffer ( 'Hello world over circuit!' ) ,
123
+ ( err , res ) => {
124
+ expect ( err ) . to . be . null ( )
125
+ expect ( res [ 0 ] ) . to . not . be . null ( )
126
+ cb ( null , res [ 0 ] . hash )
127
+ } ) ,
128
+ ( fileHash , cb ) => ipfsSrc . files . cat ( fileHash , function ( err , stream ) {
129
129
expect ( err ) . to . be . null ( )
130
130
131
131
var res = ''
0 commit comments