From f4f3f0f03aa3735a3a6d4b2baff33a7255fe47cf Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 31 Jul 2019 18:47:30 +0200 Subject: [PATCH] fix: pubsub default config (#393) * docs: update browser example pubsub * docs: fix pubsub example config * fix: make pubsub default to enabled This allows for only adding the module to have it enabled. Previously you would have to supply and enable the module which is unncessary for users --- examples/libp2p-in-the-browser/1/package.json | 1 + examples/libp2p-in-the-browser/1/src/browser-bundle.js | 8 +++++--- examples/pubsub/1.js | 8 +++----- src/config.js | 4 ++-- test/config.spec.js | 6 +++--- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/examples/libp2p-in-the-browser/1/package.json b/examples/libp2p-in-the-browser/1/package.json index b19e7226..75010eb3 100644 --- a/examples/libp2p-in-the-browser/1/package.json +++ b/examples/libp2p-in-the-browser/1/package.json @@ -19,6 +19,7 @@ "detect-dom-ready": "^1.0.2", "libp2p": "../../../", "libp2p-bootstrap": "~0.9.7", + "libp2p-gossipsub": "~0.0.4", "libp2p-kad-dht": "^0.15.3", "libp2p-mplex": "~0.8.5", "libp2p-secio": "~0.11.1", diff --git a/examples/libp2p-in-the-browser/1/src/browser-bundle.js b/examples/libp2p-in-the-browser/1/src/browser-bundle.js index e6109d28..b9ddfd22 100644 --- a/examples/libp2p-in-the-browser/1/src/browser-bundle.js +++ b/examples/libp2p-in-the-browser/1/src/browser-bundle.js @@ -8,6 +8,7 @@ const SPDY = require('libp2p-spdy') const SECIO = require('libp2p-secio') const Bootstrap = require('libp2p-bootstrap') const DHT = require('libp2p-kad-dht') +const Gossipsub = require('libp2p-gossipsub') const libp2p = require('libp2p') // Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-browser.json @@ -48,7 +49,8 @@ class Node extends libp2p { wsstar.discovery, Bootstrap ], - dht: DHT + dht: DHT, + pubsub: Gossipsub }, config: { peerDiscovery: { @@ -75,8 +77,8 @@ class Node extends libp2p { dht: { enabled: false }, - EXPERIMENTAL: { - pubsub: false + pubsub: { + enabled: false } }, connectionManager: { diff --git a/examples/pubsub/1.js b/examples/pubsub/1.js index e80315a2..6757ca68 100644 --- a/examples/pubsub/1.js +++ b/examples/pubsub/1.js @@ -7,10 +7,10 @@ const Mplex = require('libp2p-mplex') const SECIO = require('libp2p-secio') const PeerInfo = require('peer-info') const MulticastDNS = require('libp2p-mdns') +const Gossipsub = require('libp2p-gossipsub') const defaultsDeep = require('@nodeutils/defaults-deep') const waterfall = require('async/waterfall') const parallel = require('async/parallel') -const series = require('async/series') class MyBundle extends libp2p { constructor (_options) { @@ -19,7 +19,8 @@ class MyBundle extends libp2p { transport: [ TCP ], streamMuxer: [ Mplex ], connEncryption: [ SECIO ], - peerDiscovery: [ MulticastDNS ] + peerDiscovery: [ MulticastDNS ], + pubsub: Gossipsub }, config: { peerDiscovery: { @@ -27,9 +28,6 @@ class MyBundle extends libp2p { interval: 2000, enabled: true } - }, - EXPERIMENTAL: { - pubsub: true } } } diff --git a/src/config.js b/src/config.js index f3fef2e8..94a6164b 100644 --- a/src/config.js +++ b/src/config.js @@ -62,8 +62,8 @@ const configSchema = s({ }), // Pubsub config pubsub: s('object?', { - // DHT defaults - enabled: false + // Pubsub defaults + enabled: true }) }, {}) diff --git a/test/config.spec.js b/test/config.spec.js index 329ac2f7..9d65ed3a 100644 --- a/test/config.spec.js +++ b/test/config.spec.js @@ -83,7 +83,7 @@ describe('configuration', () => { autoDial: true }, pubsub: { - enabled: false + enabled: true }, dht: { kBucketSize: 20, @@ -145,7 +145,7 @@ describe('configuration', () => { } }, pubsub: { - enabled: false + enabled: true }, dht: { kBucketSize: 20, @@ -270,7 +270,7 @@ describe('configuration', () => { }, config: { pubsub: { - enabled: false + enabled: true }, peerDiscovery: { autoDial: true