Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

Commit d4e6356

Browse files
feat: add multiplex support by default
This also allows to set `options.muxer` to specify the used muxers BREAKING CHANGE: Prefer multiplex over spdy, as it works better with go-ipfs
1 parent ddfbc19 commit d4e6356

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
],
1010
"scripts": {
1111
"lint": "aegir-lint",
12-
"test": "gulp test",
12+
"test": "gulp test --dom",
1313
"test:node": "gulp test:node",
14-
"test:browser": "gulp test:browser",
14+
"test:browser": "gulp test:browser --dom",
1515
"build": "gulp build",
16-
"release": "gulp release",
17-
"release-minor": "gulp release --type minor",
18-
"release-major": "gulp release --type major",
16+
"release": "gulp release --dom",
17+
"release-minor": "gulp release --type minor --dom",
18+
"release-major": "gulp release --type major --dom",
1919
"coverage": "gulp coverage",
2020
"coverage-publish": "aegir-coverage publish"
2121
},
@@ -44,10 +44,11 @@
4444
},
4545
"dependencies": {
4646
"libp2p": "~0.5.4",
47+
"libp2p-multiplex": "^0.4.1",
4748
"libp2p-railing": "~0.4.1",
4849
"libp2p-secio": "~0.6.7",
4950
"libp2p-spdy": "~0.10.4",
50-
"libp2p-swarm": "~0.26.17",
51+
"libp2p-swarm": "~0.26.18",
5152
"libp2p-webrtc-star": "~0.8.8",
5253
"libp2p-websockets": "~0.9.2",
5354
"mafmt": "^2.1.6",
@@ -64,4 +65,4 @@
6465
"greenkeeperio-bot <[email protected]>",
6566
"kumavis <[email protected]>"
6667
]
67-
}
68+
}

src/index.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,35 @@
33
const WS = require('libp2p-websockets')
44
const WebRTCStar = require('libp2p-webrtc-star')
55
const spdy = require('libp2p-spdy')
6+
const multiplex = require('libp2p-multiplex')
67
const secio = require('libp2p-secio')
78
const Railing = require('libp2p-railing')
89
const libp2p = require('libp2p')
910

11+
function mapMuxers (list) {
12+
return list.map((pref) => {
13+
if (typeof pref !== 'string') {
14+
return pref
15+
}
16+
switch (pref.trim().toLowerCase()) {
17+
case 'spdy':
18+
return spdy
19+
case 'multiplex':
20+
return multiplex
21+
default:
22+
throw new Error(pref + ' muxer not available')
23+
}
24+
})
25+
}
26+
27+
function getMuxers (options) {
28+
if (options) {
29+
return mapMuxers(options)
30+
} else {
31+
return [multiplex, spdy]
32+
}
33+
}
34+
1035
class Node extends libp2p {
1136
constructor (peerInfo, peerBook, options) {
1237
options = options || {}
@@ -18,9 +43,7 @@ class Node extends libp2p {
1843
webRTCStar
1944
],
2045
connection: {
21-
muxer: [
22-
spdy
23-
],
46+
muxer: getMuxers(options.muxer),
2447
crypto: [
2548
secio
2649
]

test/websockets-only.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ describe('libp2p-ipfs-browser (websockets only)', () => {
4444
})
4545
})
4646

47+
it('create libp2pNode with multiplex only', (done) => {
48+
PeerInfo.create((err, info) => {
49+
expect(err).to.not.exist
50+
const b = new Node(info, null, {muxer: ['multiplex']})
51+
expect(b.modules.connection.muxer).to.eql([
52+
require('libp2p-multiplex')
53+
])
54+
done()
55+
})
56+
})
57+
4758
it('start libp2pNode', (done) => {
4859
nodeA.start(done)
4960
})

0 commit comments

Comments
 (0)