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

Commit

Permalink
feat: add multiplex support by default
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dignifiedquire authored Feb 24, 2017
1 parent ddfbc19 commit d4e6356
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
],
"scripts": {
"lint": "aegir-lint",
"test": "gulp test",
"test": "gulp test --dom",
"test:node": "gulp test:node",
"test:browser": "gulp test:browser",
"test:browser": "gulp test:browser --dom",
"build": "gulp build",
"release": "gulp release",
"release-minor": "gulp release --type minor",
"release-major": "gulp release --type major",
"release": "gulp release --dom",
"release-minor": "gulp release --type minor --dom",
"release-major": "gulp release --type major --dom",
"coverage": "gulp coverage",
"coverage-publish": "aegir-coverage publish"
},
Expand Down Expand Up @@ -44,10 +44,11 @@
},
"dependencies": {
"libp2p": "~0.5.4",
"libp2p-multiplex": "^0.4.1",
"libp2p-railing": "~0.4.1",
"libp2p-secio": "~0.6.7",
"libp2p-spdy": "~0.10.4",
"libp2p-swarm": "~0.26.17",
"libp2p-swarm": "~0.26.18",
"libp2p-webrtc-star": "~0.8.8",
"libp2p-websockets": "~0.9.2",
"mafmt": "^2.1.6",
Expand All @@ -64,4 +65,4 @@
"greenkeeperio-bot <support@greenkeeper.io>",
"kumavis <aaron@kumavis.me>"
]
}
}
29 changes: 26 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,35 @@
const WS = require('libp2p-websockets')
const WebRTCStar = require('libp2p-webrtc-star')
const spdy = require('libp2p-spdy')
const multiplex = require('libp2p-multiplex')
const secio = require('libp2p-secio')
const Railing = require('libp2p-railing')
const libp2p = require('libp2p')

function mapMuxers (list) {
return list.map((pref) => {
if (typeof pref !== 'string') {
return pref
}
switch (pref.trim().toLowerCase()) {
case 'spdy':
return spdy
case 'multiplex':
return multiplex
default:
throw new Error(pref + ' muxer not available')
}
})
}

function getMuxers (options) {
if (options) {
return mapMuxers(options)
} else {
return [multiplex, spdy]
}
}

class Node extends libp2p {
constructor (peerInfo, peerBook, options) {
options = options || {}
Expand All @@ -18,9 +43,7 @@ class Node extends libp2p {
webRTCStar
],
connection: {
muxer: [
spdy
],
muxer: getMuxers(options.muxer),
crypto: [
secio
]
Expand Down
11 changes: 11 additions & 0 deletions test/websockets-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ describe('libp2p-ipfs-browser (websockets only)', () => {
})
})

it('create libp2pNode with multiplex only', (done) => {
PeerInfo.create((err, info) => {
expect(err).to.not.exist
const b = new Node(info, null, {muxer: ['multiplex']})
expect(b.modules.connection.muxer).to.eql([
require('libp2p-multiplex')
])
done()
})
})

it('start libp2pNode', (done) => {
nodeA.start(done)
})
Expand Down

0 comments on commit d4e6356

Please sign in to comment.