Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mplex #165

Merged
merged 3 commits into from
Feb 19, 2018
Merged

Mplex #165

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/chat/src/libp2p-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const WS = require('libp2p-websockets')
const Railing = require('libp2p-railing')
const spdy = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht')
const multiplex = require('libp2p-multiplex')
const mplex = require('libp2p-mplex')
const secio = require('libp2p-secio')
const libp2p = require('../../..')

Expand All @@ -17,7 +17,7 @@ function mapMuxers (list) {
}
switch (pref.trim().toLowerCase()) {
case 'spdy': return spdy
case 'multiplex': return multiplex
case 'mplex': return mplex
default:
throw new Error(pref + ' muxer not available')
}
Expand All @@ -31,7 +31,7 @@ function getMuxers (muxers) {
} else if (muxers) {
return mapMuxers(muxers)
} else {
return [multiplex, spdy]
return [mplex, spdy]
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/discovery-mechanisms/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex')
const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info')
const Railing = require('libp2p-railing')
Expand All @@ -26,7 +26,7 @@ class MyBundle extends libp2p {
const modules = {
transport: [new TCP()],
connection: {
muxer: [Multiplex],
muxer: [Mplex],
crypto: [SECIO]
},
discovery: [new Railing(bootstrapers)]
Expand Down
4 changes: 2 additions & 2 deletions examples/discovery-mechanisms/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex')
const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info')
const MulticastDNS = require('libp2p-mdns')
Expand All @@ -14,7 +14,7 @@ class MyBundle extends libp2p {
const modules = {
transport: [new TCP()],
connection: {
muxer: [Multiplex],
muxer: [Mplex],
crypto: [SECIO]
},
discovery: [new MulticastDNS(peerInfo, { interval: 1000 })]
Expand Down
6 changes: 3 additions & 3 deletions examples/discovery-mechanisms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ These mechanisms save configuration and enable a node to operate without any exp

## 1. Bootstrap list of Peers when booting a node

For this demo, we will connect to IPFS default bootstrapper nodes and so, we will need to support the same set of features those nodes have, that are: TCP, multiplex and SECIO. You can see the complete example at [1.js](./1.js).
For this demo, we will connect to IPFS default bootstrapper nodes and so, we will need to support the same set of features those nodes have, that are: TCP, mplex and SECIO. You can see the complete example at [1.js](./1.js).

First, we create our libp2p bundle.

Expand All @@ -18,7 +18,7 @@ class MyBundle extends libp2p {
const modules = {
transport: [new TCP()],
connection: {
muxer: [Multiplex],
muxer: [Mplex],
crypto: [SECIO]
},
discovery: [new Railing(bootstrapers)]
Expand Down Expand Up @@ -111,7 +111,7 @@ class MyBundle extends libp2p {
const modules = {
transport: [new TCP()],
connection: {
muxer: [Multiplex],
muxer: [Mplex],
crypto: [SECIO]
},
// We set the interval here to 1 second so that is faster to observe. The
Expand Down
6 changes: 3 additions & 3 deletions examples/echo/src/libp2p-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const WS = require('libp2p-websockets')
const Railing = require('libp2p-railing')
const spdy = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht')
const multiplex = require('libp2p-multiplex')
const mplex = require('libp2p-mplex')
const secio = require('libp2p-secio')
const libp2p = require('../../..')

Expand All @@ -17,7 +17,7 @@ function mapMuxers (list) {
}
switch (pref.trim().toLowerCase()) {
case 'spdy': return spdy
case 'multiplex': return multiplex
case 'mplex': return mplex
default:
throw new Error(pref + ' muxer not available')
}
Expand All @@ -31,7 +31,7 @@ function getMuxers (muxers) {
} else if (muxers) {
return mapMuxers(muxers)
} else {
return [multiplex, spdy]
return [mplex, spdy]
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/libp2p-in-the-browser/1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"detect-dom-ready": "^1.0.2",
"libp2p": "^0.13.0",
"libp2p-multiplex": "^0.5.0",
"libp2p-mplex": "^0.6.0",
"libp2p-railing": "^0.7.1",
"libp2p-secio": "^0.8.1",
"libp2p-spdy": "^0.11.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/libp2p-in-the-browser/1/src/browser-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const WebRTCStar = require('libp2p-webrtc-star')
const WebSockets = require('libp2p-websockets')

const Multiplex = require('libp2p-multiplex')
const Mplex = require('libp2p-mplex')
const SPDY = require('libp2p-spdy')
const SECIO = require('libp2p-secio')

Expand Down Expand Up @@ -37,7 +37,7 @@ class Node extends libp2p {
],
connection: {
muxer: [
Multiplex,
Mplex,
SPDY
],
crypto: [SECIO]
Expand Down
4 changes: 2 additions & 2 deletions examples/peer-and-content-routing/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex')
const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info')
const KadDHT = require('libp2p-kad-dht')
Expand All @@ -15,7 +15,7 @@ class MyBundle extends libp2p {
const modules = {
transport: [new TCP()],
connection: {
muxer: [Multiplex],
muxer: [Mplex],
crypto: [SECIO]
},
// we add the DHT module that will enable Peer and Content Routing
Expand Down
4 changes: 2 additions & 2 deletions examples/peer-and-content-routing/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex')
const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info')
const CID = require('cids')
Expand All @@ -16,7 +16,7 @@ class MyBundle extends libp2p {
const modules = {
transport: [new TCP()],
connection: {
muxer: [Multiplex],
muxer: [Mplex],
crypto: [SECIO]
},
// we add the DHT module that will enable Peer and Content Routing
Expand Down
2 changes: 1 addition & 1 deletion examples/peer-and-content-routing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MyBundle extends libp2p {
const modules = {
transport: [new TCP()],
connection: {
muxer: [Multiplex],
muxer: [Mplex],
crypto: [SECIO]
},
// we add the DHT module that will enable Peer and Content Routing
Expand Down
2 changes: 1 addition & 1 deletion examples/protocol-and-stream-muxing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The example above would require a node to create a whole new connection for ever

Stream multiplexing is a old concept, in fact it happens in many of the layers of the [OSI System](https://en.wikipedia.org/wiki/OSI_model), in libp2p we make this feature to our avail by letting the user pick which module for stream multiplexing to use.

Currently, we have two available [libp2p-spdy](https://github.com/libp2p/js-libp2p-spdy) and [libp2p-multiplex](https://github.com/libp2p/js-libp2p-multiplex) and pluging them in is as easy as adding another transport. Let's revisit our libp2p bundle.
Currently, we have two available [libp2p-spdy](https://github.com/libp2p/js-libp2p-spdy) and [libp2p-mplex](https://github.com/libp2p/js-libp2p-mplex) and pluging them in is as easy as adding another transport. Let's revisit our libp2p bundle.

```JavaScript
const SPDY = require('libp2p-spdy')
Expand Down
4 changes: 2 additions & 2 deletions examples/pubsub/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex')
const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info')
const MulticastDNS = require('libp2p-mdns')
Expand All @@ -15,7 +15,7 @@ class MyBundle extends libp2p {
const modules = {
transport: [new TCP()],
connection: {
muxer: [Multiplex],
muxer: [Mplex],
crypto: [SECIO]
},
discovery: [
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
"peer-info": "~0.11.6"
},
"devDependencies": {
"aegir": "^13.0.0",
"aegir": "^13.0.1",
"chai": "^4.1.2",
"cids": "~0.5.2",
"dirty-chai": "^2.0.1",
"electron-webrtc": "~0.3.0",
"libp2p-circuit": "~0.1.4",
"libp2p-kad-dht": "~0.8.0",
"libp2p-mdns": "~0.9.2",
"libp2p-multiplex": "~0.5.1",
"libp2p-mplex": "~0.6.0",
"libp2p-railing": "~0.7.1",
"libp2p-secio": "~0.9.2",
"libp2p-spdy": "~0.11.0",
Expand Down
20 changes: 10 additions & 10 deletions test/stream-muxing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ describe('stream muxing', () => {
], done)
})

it('multiplex only', (done) => {
it('mplex only', (done) => {
let nodeA
let nodeB

function setup (callback) {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
muxer: ['multiplex']
muxer: ['mplex']
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
muxer: ['multiplex']
muxer: ['mplex']
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
Expand All @@ -92,7 +92,7 @@ describe('stream muxing', () => {
], done)
})

it('spdy + multiplex', function (done) {
it('spdy + mplex', function (done) {
this.timeout(5000)

let nodeA
Expand All @@ -101,15 +101,15 @@ describe('stream muxing', () => {
function setup (callback) {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
muxer: ['spdy', 'multiplex']
muxer: ['spdy', 'mplex']
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
muxer: ['spdy', 'multiplex']
muxer: ['spdy', 'mplex']
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
Expand All @@ -126,7 +126,7 @@ describe('stream muxing', () => {
], done)
})

it('spdy + multiplex switched order', function (done) {
it('spdy + mplex switched order', function (done) {
this.timeout(5 * 1000)

let nodeA
Expand All @@ -135,15 +135,15 @@ describe('stream muxing', () => {
function setup (callback) {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
muxer: ['spdy', 'multiplex']
muxer: ['spdy', 'mplex']
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
muxer: ['multiplex', 'spdy']
muxer: ['mplex', 'spdy']
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('stream muxing', () => {
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
muxer: ['multiplex']
muxer: ['mplex']
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
Expand Down
6 changes: 3 additions & 3 deletions test/transports.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ describe('transports', () => {
})
})

it('create libp2pNode with multiplex only', (done) => {
it('create libp2pNode with mplex only', (done) => {
PeerInfo.create((err, peerInfo) => {
expect(err).to.not.exist()

const b = new Node(peerInfo, null, { muxer: ['multiplex'] })
expect(b.modules.connection.muxer).to.eql([require('libp2p-multiplex')])
const b = new Node(peerInfo, null, { muxer: ['mplex'] })
expect(b.modules.connection.muxer).to.eql([require('libp2p-mplex')])
done()
})
})
Expand Down
8 changes: 4 additions & 4 deletions test/utils/bundle.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const WS = require('libp2p-websockets')
const WebRTCStar = require('libp2p-webrtc-star')
const WebSocketStar = require('libp2p-websocket-star')
const spdy = require('libp2p-spdy')
const multiplex = require('libp2p-multiplex')
const mplex = require('libp2p-mplex')
const secio = require('libp2p-secio')
const Railing = require('libp2p-railing')
const libp2p = require('../..')
Expand All @@ -17,8 +17,8 @@ function mapMuxers (list) {
switch (pref.trim().toLowerCase()) {
case 'spdy':
return spdy
case 'multiplex':
return multiplex
case 'mplex':
return mplex
default:
throw new Error(pref + ' muxer not available')
}
Expand All @@ -29,7 +29,7 @@ function getMuxers (options) {
if (options) {
return mapMuxers(options)
} else {
return [multiplex, spdy]
return [mplex, spdy]
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/utils/bundle.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const WS = require('libp2p-websockets')
const Railing = require('libp2p-railing')
const spdy = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht')
const multiplex = require('libp2p-multiplex')
const mplex = require('libp2p-mplex')
const secio = require('libp2p-secio')
const libp2p = require('../..')

Expand All @@ -17,7 +17,7 @@ function mapMuxers (list) {
}
switch (pref.trim().toLowerCase()) {
case 'spdy': return spdy
case 'multiplex': return multiplex
case 'mplex': return mplex
default:
throw new Error(pref + ' muxer not available')
}
Expand All @@ -31,7 +31,7 @@ function getMuxers (muxers) {
} else if (muxers) {
return mapMuxers(muxers)
} else {
return [multiplex, spdy]
return [mplex, spdy]
}
}

Expand Down