docs: update examples to use libp2p-mplex module

This commit is contained in:
David Dias 2018-02-19 09:46:11 +00:00
parent 14d3578eaf
commit b871bb0a1a
12 changed files with 24 additions and 24 deletions

View File

@ -6,7 +6,7 @@ const WS = require('libp2p-websockets')
const Railing = require('libp2p-railing') const Railing = require('libp2p-railing')
const spdy = require('libp2p-spdy') const spdy = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht') const KadDHT = require('libp2p-kad-dht')
const multiplex = require('libp2p-multiplex') const mplex = require('libp2p-mplex')
const secio = require('libp2p-secio') const secio = require('libp2p-secio')
const libp2p = require('../../..') const libp2p = require('../../..')
@ -17,7 +17,7 @@ function mapMuxers (list) {
} }
switch (pref.trim().toLowerCase()) { switch (pref.trim().toLowerCase()) {
case 'spdy': return spdy case 'spdy': return spdy
case 'multiplex': return multiplex case 'mplex': return mplex
default: default:
throw new Error(pref + ' muxer not available') throw new Error(pref + ' muxer not available')
} }
@ -31,7 +31,7 @@ function getMuxers (muxers) {
} else if (muxers) { } else if (muxers) {
return mapMuxers(muxers) return mapMuxers(muxers)
} else { } else {
return [multiplex, spdy] return [mplex, spdy]
} }
} }

View File

@ -2,7 +2,7 @@
const libp2p = require('libp2p') const libp2p = require('libp2p')
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex') const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info') const PeerInfo = require('peer-info')
const Railing = require('libp2p-railing') const Railing = require('libp2p-railing')
@ -26,7 +26,7 @@ class MyBundle extends libp2p {
const modules = { const modules = {
transport: [new TCP()], transport: [new TCP()],
connection: { connection: {
muxer: [Multiplex], muxer: [Mplex],
crypto: [SECIO] crypto: [SECIO]
}, },
discovery: [new Railing(bootstrapers)] discovery: [new Railing(bootstrapers)]

View File

@ -2,7 +2,7 @@
const libp2p = require('libp2p') const libp2p = require('libp2p')
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex') const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info') const PeerInfo = require('peer-info')
const MulticastDNS = require('libp2p-mdns') const MulticastDNS = require('libp2p-mdns')
@ -14,7 +14,7 @@ class MyBundle extends libp2p {
const modules = { const modules = {
transport: [new TCP()], transport: [new TCP()],
connection: { connection: {
muxer: [Multiplex], muxer: [Mplex],
crypto: [SECIO] crypto: [SECIO]
}, },
discovery: [new MulticastDNS(peerInfo, { interval: 1000 })] discovery: [new MulticastDNS(peerInfo, { interval: 1000 })]

View File

@ -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 ## 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. First, we create our libp2p bundle.
@ -18,7 +18,7 @@ class MyBundle extends libp2p {
const modules = { const modules = {
transport: [new TCP()], transport: [new TCP()],
connection: { connection: {
muxer: [Multiplex], muxer: [Mplex],
crypto: [SECIO] crypto: [SECIO]
}, },
discovery: [new Railing(bootstrapers)] discovery: [new Railing(bootstrapers)]
@ -111,7 +111,7 @@ class MyBundle extends libp2p {
const modules = { const modules = {
transport: [new TCP()], transport: [new TCP()],
connection: { connection: {
muxer: [Multiplex], muxer: [Mplex],
crypto: [SECIO] crypto: [SECIO]
}, },
// We set the interval here to 1 second so that is faster to observe. The // We set the interval here to 1 second so that is faster to observe. The

View File

@ -6,7 +6,7 @@ const WS = require('libp2p-websockets')
const Railing = require('libp2p-railing') const Railing = require('libp2p-railing')
const spdy = require('libp2p-spdy') const spdy = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht') const KadDHT = require('libp2p-kad-dht')
const multiplex = require('libp2p-multiplex') const mplex = require('libp2p-mplex')
const secio = require('libp2p-secio') const secio = require('libp2p-secio')
const libp2p = require('../../..') const libp2p = require('../../..')
@ -17,7 +17,7 @@ function mapMuxers (list) {
} }
switch (pref.trim().toLowerCase()) { switch (pref.trim().toLowerCase()) {
case 'spdy': return spdy case 'spdy': return spdy
case 'multiplex': return multiplex case 'mplex': return mplex
default: default:
throw new Error(pref + ' muxer not available') throw new Error(pref + ' muxer not available')
} }
@ -31,7 +31,7 @@ function getMuxers (muxers) {
} else if (muxers) { } else if (muxers) {
return mapMuxers(muxers) return mapMuxers(muxers)
} else { } else {
return [multiplex, spdy] return [mplex, spdy]
} }
} }

View File

@ -18,7 +18,7 @@
"dependencies": { "dependencies": {
"detect-dom-ready": "^1.0.2", "detect-dom-ready": "^1.0.2",
"libp2p": "^0.13.0", "libp2p": "^0.13.0",
"libp2p-multiplex": "^0.5.0", "libp2p-mplex": "^0.6.0",
"libp2p-railing": "^0.7.1", "libp2p-railing": "^0.7.1",
"libp2p-secio": "^0.8.1", "libp2p-secio": "^0.8.1",
"libp2p-spdy": "^0.11.0", "libp2p-spdy": "^0.11.0",

View File

@ -3,7 +3,7 @@
const WebRTCStar = require('libp2p-webrtc-star') const WebRTCStar = require('libp2p-webrtc-star')
const WebSockets = require('libp2p-websockets') const WebSockets = require('libp2p-websockets')
const Multiplex = require('libp2p-multiplex') const Mplex = require('libp2p-mplex')
const SPDY = require('libp2p-spdy') const SPDY = require('libp2p-spdy')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
@ -37,7 +37,7 @@ class Node extends libp2p {
], ],
connection: { connection: {
muxer: [ muxer: [
Multiplex, Mplex,
SPDY SPDY
], ],
crypto: [SECIO] crypto: [SECIO]

View File

@ -2,7 +2,7 @@
const libp2p = require('libp2p') const libp2p = require('libp2p')
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex') const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info') const PeerInfo = require('peer-info')
const KadDHT = require('libp2p-kad-dht') const KadDHT = require('libp2p-kad-dht')
@ -15,7 +15,7 @@ class MyBundle extends libp2p {
const modules = { const modules = {
transport: [new TCP()], transport: [new TCP()],
connection: { connection: {
muxer: [Multiplex], muxer: [Mplex],
crypto: [SECIO] crypto: [SECIO]
}, },
// we add the DHT module that will enable Peer and Content Routing // we add the DHT module that will enable Peer and Content Routing

View File

@ -2,7 +2,7 @@
const libp2p = require('libp2p') const libp2p = require('libp2p')
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex') const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info') const PeerInfo = require('peer-info')
const CID = require('cids') const CID = require('cids')
@ -16,7 +16,7 @@ class MyBundle extends libp2p {
const modules = { const modules = {
transport: [new TCP()], transport: [new TCP()],
connection: { connection: {
muxer: [Multiplex], muxer: [Mplex],
crypto: [SECIO] crypto: [SECIO]
}, },
// we add the DHT module that will enable Peer and Content Routing // we add the DHT module that will enable Peer and Content Routing

View File

@ -18,7 +18,7 @@ class MyBundle extends libp2p {
const modules = { const modules = {
transport: [new TCP()], transport: [new TCP()],
connection: { connection: {
muxer: [Multiplex], muxer: [Mplex],
crypto: [SECIO] crypto: [SECIO]
}, },
// we add the DHT module that will enable Peer and Content Routing // we add the DHT module that will enable Peer and Content Routing

View File

@ -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. 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 ```JavaScript
const SPDY = require('libp2p-spdy') const SPDY = require('libp2p-spdy')

View File

@ -2,7 +2,7 @@
const libp2p = require('libp2p') const libp2p = require('libp2p')
const TCP = require('libp2p-tcp') const TCP = require('libp2p-tcp')
const Multiplex = require('libp2p-multiplex') const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio') const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info') const PeerInfo = require('peer-info')
const MulticastDNS = require('libp2p-mdns') const MulticastDNS = require('libp2p-mdns')
@ -15,7 +15,7 @@ class MyBundle extends libp2p {
const modules = { const modules = {
transport: [new TCP()], transport: [new TCP()],
connection: { connection: {
muxer: [Multiplex], muxer: [Mplex],
crypto: [SECIO] crypto: [SECIO]
}, },
discovery: [ discovery: [