55const chai = require ( 'chai' )
66const dirtyChai = require ( 'dirty-chai' )
77const expect = chai . expect
8- chai . use ( dirtyChai )
98const waterfall = require ( 'async/waterfall' )
109const parallel = require ( 'async/parallel' )
1110const isNode = require ( 'detect-node' )
1211
1312const IPFS = require ( '../../src/core' )
1413const createTempRepo = require ( '../utils/create-repo-node.js' )
1514
15+ chai . use ( dirtyChai )
16+
1617describe ( 'circuit' , ( ) => {
1718 if ( ! isNode ) {
1819 return
1920 }
2021
2122 describe ( 'transfer over circuit' , function ( ) {
22- this . timeout ( 5000 )
23+ this . timeout ( 50000 )
2324
2425 let ipfsRelay
25- let ipfsSrc
2626 let ipfsDst
27+ let ipfsSrc
2728
2829 before ( ( done ) => {
2930 ipfsRelay = new IPFS ( {
@@ -32,14 +33,16 @@ describe('circuit', () => {
3233 Addresses : {
3334 Swarm : [
3435 '/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'
3637 ]
3738 } ,
3839 Bootstrap : [ ] ,
39- Relay : {
40- Circuit : {
41- Enabled : true ,
42- Active : true
40+ Experimental : {
41+ Relay : {
42+ Circuit : {
43+ Enabled : true ,
44+ Active : false
45+ }
4346 }
4447 } ,
4548 Identity : {
@@ -49,24 +52,24 @@ describe('circuit', () => {
4952 }
5053 } )
5154
52- ipfsSrc = new IPFS ( {
55+ ipfsDst = new IPFS ( {
5356 repo : createTempRepo ( ) ,
5457 config : {
5558 Addresses : {
5659 Swarm : [
57- '/ip4/0.0.0.0/tcp/9001 '
60+ '/ip4/0.0.0.0/tcp/9002 '
5861 ]
5962 } ,
6063 Bootstrap : [ ]
6164 }
6265 } )
6366
64- ipfsDst = new IPFS ( {
67+ ipfsSrc = new IPFS ( {
6568 repo : createTempRepo ( ) ,
6669 config : {
6770 Addresses : {
6871 Swarm : [
69- '/ip4/0.0.0.0/tcp/9002 /ws'
72+ '/ip4/0.0.0.0/tcp/9003 /ws'
7073 ]
7174 } ,
7275 Bootstrap : [ ]
@@ -78,20 +81,20 @@ describe('circuit', () => {
7881 ( pCb ) => ipfsSrc . once ( 'start' , pCb ) ,
7982 ( pCb ) => ipfsDst . once ( 'start' , pCb )
8083 ] , ( ) => {
81- // get everything inter-connected
8284 waterfall ( [
8385 ( cb ) => ipfsSrc
8486 . 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 ) ,
8789 ( cb ) => ipfsDst
8890 . 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 ) ,
9193 ( 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 ) ,
9396 ( 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 ( ) )
9598 ] , done )
9699 } )
97100 } )
@@ -105,27 +108,24 @@ describe('circuit', () => {
105108 } )
106109
107110 it ( 'should be able to connect over circuit' , ( done ) => {
108- ipfsDst . id ( ( err , id ) => {
111+ ipfsSrc . swarm . connect ( ipfsDst . _peerInfo , ( err , conn ) => {
109112 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 ( )
115115 } )
116116 } )
117117
118118 it ( 'should be able to transfer data over circuit' , ( done ) => {
119119 waterfall ( [
120- ( cb ) => ipfsDst . id ( cb ) ,
121120 // 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 ) {
129129 expect ( err ) . to . be . null ( )
130130
131131 var res = ''
0 commit comments