From 5ccca1740a7d46632ac2f9d700f56242fb217851 Mon Sep 17 00:00:00 2001 From: mkg20001 Date: Sun, 19 Nov 2017 13:42:05 +0100 Subject: [PATCH] feat: WebSocketStar --- package.json | 1 + src/core/runtime/libp2p-browser.js | 6 ++++-- src/core/runtime/libp2p-nodejs.js | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index afc9b633a9..ecdf611f6a 100644 --- a/package.json +++ b/package.json @@ -129,6 +129,7 @@ "libp2p-secio": "~0.8.1", "libp2p-tcp": "~0.11.1", "libp2p-webrtc-star": "~0.13.2", + "libp2p-websocket-star": "^0.5.1", "libp2p-websockets": "~0.10.4", "lodash.flatmap": "^4.5.0", "lodash.get": "^4.4.2", diff --git a/src/core/runtime/libp2p-browser.js b/src/core/runtime/libp2p-browser.js index d50fdc3f22..4994f74617 100644 --- a/src/core/runtime/libp2p-browser.js +++ b/src/core/runtime/libp2p-browser.js @@ -2,6 +2,7 @@ const WS = require('libp2p-websockets') const WebRTCStar = require('libp2p-webrtc-star') +const WebSocketStar = require('libp2p-websocket-star') const Multiplex = require('libp2p-multiplex') const SECIO = require('libp2p-secio') const Railing = require('libp2p-railing') @@ -11,14 +12,15 @@ class Node extends libp2p { constructor (peerInfo, peerBook, options) { options = options || {} const wstar = new WebRTCStar() + const wsstar = new WebSocketStar({id: peerInfo.id}) const modules = { - transport: [new WS(), wstar], + transport: [new WS(), wstar, wsstar], connection: { muxer: [Multiplex], crypto: [SECIO] }, - discovery: [wstar.discovery] + discovery: [wstar.discovery, wsstar.discovery] } if (options.bootstrap) { diff --git a/src/core/runtime/libp2p-nodejs.js b/src/core/runtime/libp2p-nodejs.js index 5533a96399..0ada60e15b 100644 --- a/src/core/runtime/libp2p-nodejs.js +++ b/src/core/runtime/libp2p-nodejs.js @@ -3,6 +3,7 @@ const TCP = require('libp2p-tcp') const MulticastDNS = require('libp2p-mdns') const WS = require('libp2p-websockets') +const WebSocketStar = require('libp2p-websocket-star') const Railing = require('libp2p-railing') const KadDHT = require('libp2p-kad-dht') const Multiplex = require('libp2p-multiplex') @@ -12,14 +13,15 @@ const libp2p = require('libp2p') class Node extends libp2p { constructor (peerInfo, peerBook, options) { options = options || {} + const wsstar = new WebSocketStar({id: peerInfo.id}) const modules = { - transport: [new TCP(), new WS()], + transport: [new TCP(), new WS(), wsstar], connection: { muxer: [Multiplex], crypto: [SECIO] }, - discovery: [] + discovery: [wsstar.discovery] } if (options.dht) {