Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit e6142e2

Browse files
committed
feat: move circuit options under Experimental section
1 parent fe07126 commit e6142e2

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,13 @@
116116
"lodash.flatmap": "^4.5.0",
117117
"lodash.get": "^4.4.2",
118118
"lodash.has": "^4.5.2",
119-
"lodash.mapkeys": "^4.6.0",
120119
"lodash.set": "^4.3.2",
121120
"lodash.sortby": "^4.7.0",
122121
"lodash.values": "^4.3.0",
123122
"mafmt": "^2.1.8",
124123
"mkdirp": "^0.5.1",
125124
"multiaddr": "^2.3.0",
126-
"multihashes": "~0.4.5",
125+
"multihashes": "^0.4.5",
127126
"once": "^1.4.0",
128127
"path-exists": "^3.0.0",
129128
"peer-book": "~0.4.0",

src/core/components/libp2p.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const Node = require('libp2p-ipfs-nodejs')
44
const promisify = require('promisify-es6')
55
const get = require('lodash.get')
6-
const mapKeys = require('lodash.mapKeys')
76

87
module.exports = function libp2p (self) {
98
return {
@@ -21,11 +20,14 @@ module.exports = function libp2p (self) {
2120
bootstrap: get(config, 'Bootstrap'),
2221
dht: get(self._options, 'EXPERIMENTAL.dht'),
2322
modules: self._libp2pModules,
24-
relay: get(config, 'Relay')
23+
relay: {
24+
circuit: {
25+
enabled: get(config, 'Experimental.Relay.Circuit.Enabled'),
26+
active: get(config, 'Experimental.Relay.Circuit.Active')
27+
}
28+
}
2529
}
2630

27-
options.relay = mapKeys(get(config, 'Relay'), (v, k) => k.toLowerCase())
28-
2931
self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options)
3032

3133
self._libp2pNode.on('peer:discovery', (peerInfo) => {

test/core/circuit.spec.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@
55
const chai = require('chai')
66
const dirtyChai = require('dirty-chai')
77
const expect = chai.expect
8-
chai.use(dirtyChai)
98
const waterfall = require('async/waterfall')
109
const parallel = require('async/parallel')
1110
const isNode = require('detect-node')
1211

1312
const IPFS = require('../../src/core')
1413
const createTempRepo = require('../utils/create-repo-node.js')
1514

15+
chai.use(dirtyChai)
16+
1617
describe('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

Comments
 (0)