From 902e04547e8cd0aaee994193ef664f662ff07683 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 2 Sep 2019 22:39:17 +0200 Subject: [PATCH] feat: gossipsub as default pubsub (#2298) BREAKING CHANGE: The default pubsub implementation has changed from floodsub to [gossipsub](https://github.com/ChainSafe/gossipsub-js). Additionally, to enable pubsub programmatically set `pubsub.enabled: true` instead of `EXPERIMENTAL.pubsub: true` or via the CLI pass `--enable-pubsub` instead of `--enable-pubsub-experiment` to `jsipfs daemon`. --- README.md | 9 +- doc/config.md | 12 +++ examples/circuit-relaying/src/app.js | 4 +- examples/custom-libp2p/index.js | 4 +- examples/custom-libp2p/package.json | 2 +- .../exchange-files-in-browser/public/app.js | 4 +- package.json | 11 ++- src/cli/commands/daemon.js | 5 +- src/cli/daemon.js | 2 +- src/cli/utils.js | 4 +- src/core/components/libp2p.js | 19 ++++- src/core/components/pubsub.js | 29 +++---- src/core/config.js | 6 ++ src/core/index.js | 15 ++-- src/core/runtime/config-nodejs.js | 3 + src/core/runtime/libp2p-browser.js | 13 +-- src/core/runtime/libp2p-nodejs.js | 13 +-- .../runtime/libp2p-pubsub-routers-browser.js | 5 ++ .../runtime/libp2p-pubsub-routers-nodejs.js | 6 ++ test/cli/pubsub.js | 4 +- test/core/config.spec.js | 5 +- test/core/interface.spec.js | 51 +++++++++++- test/core/libp2p.spec.js | 82 ++++++++++++++++--- test/core/pubsub.spec.js | 4 +- test/http-api/interface.js | 2 +- test/http-api/routes.js | 4 +- 26 files changed, 241 insertions(+), 77 deletions(-) create mode 100644 src/core/runtime/libp2p-pubsub-routers-browser.js create mode 100644 src/core/runtime/libp2p-pubsub-routers-nodejs.js diff --git a/README.md b/README.md index 706eff4073..4cc262124c 100644 --- a/README.md +++ b/README.md @@ -324,7 +324,7 @@ Configure remote preload nodes. The remote will preload content added on this no | Type | Default | |------|---------| -| object | `{ pubsub: false, ipnsPubsub: false, sharding: false }` | +| object | `{ ipnsPubsub: false, sharding: false }` | Enable and configure experimental features. @@ -495,6 +495,8 @@ You can see the bundle in action in the [custom libp2p example](examples/custom- - `modules` (object): - `transport` (Array<[libp2p.Transport](https://github.com/libp2p/interface-transport)>): An array of Libp2p transport classes/instances to use _instead_ of the defaults. See [libp2p/interface-transport](https://github.com/libp2p/interface-transport) for details. - `peerDiscovery` (Array<[libp2p.PeerDiscovery](https://github.com/libp2p/interface-peer-discovery)>): An array of Libp2p peer discovery classes/instances to use _instead_ of the defaults. See [libp2p/peer-discovery](https://github.com/libp2p/interface-peer-discovery) for details. If passing a class, configuration can be passed using the config section below under the key corresponding to you module's unique `tag` (a static property on the class) + - `dht` (object): a DHT implementation that enables PeerRouting and ContentRouting. Example [libp2p/js-libp2p-kad-dht](https://github.com/libp2p/js-libp2p-kad-dht) + - `pubsub` (object): a Pubsub implementation on top of [libp2p/js-libp2p-pubsub](https://github.com/libp2p/js-libp2p-pubsub) - `config` (object): - `peerDiscovery` (object): - `autoDial` (boolean): Dial to discovered peers when under the Connection Manager min peer count watermark. (default `true`) @@ -506,6 +508,11 @@ You can see the bundle in action in the [custom libp2p example](examples/custom- - `kBucketSize` (number): bucket size (default `20`) - `randomWalk` (object): configuration for random walk - `enabled` (boolean): whether random DHT walking is enabled (default `false`) + - `pubsub` (object): Configuration options for Pubsub + - `enabled` (boolean): if pubbsub subsystem should be enabled (default: `false`) + - `emitSelf` (boolean): whether the node should emit to self on publish, in the event of the topic being subscribed (default: `true`) + - `signMessages` (boolean): if messages should be signed (default: `true`) + - `strictSigning` (boolean): if message signing should be required (default: `true`) ##### `options.connectionManager` diff --git a/doc/config.md b/doc/config.md index b1df05db22..08222f4a10 100644 --- a/doc/config.md +++ b/doc/config.md @@ -19,6 +19,8 @@ The js-ipfs config file is a JSON document located in the root directory of the - [`PeerID`](#peerid) - [`PrivKey`](#privkey) - [`Keychain`](#keychain) +- [`Pubsub`](#pubsub) + - [`Router`](#router) - [`Swarm`](#swarm) - [`ConnMgr`](#connmgr) @@ -168,6 +170,16 @@ Default: You can check the [parameter choice for pbkdf2](https://cryptosense.com/parameter-choice-for-pbkdf2/) for more information. +## `Pubsub` + +Options for configuring the pubsub subsystem. It is important pointing out that this is not supported in the browser. If you want to configure a different pubsub router in the browser you must configure `libp2p.modules.pubsub` options instead. + +### `Router` + +A string value for specifying which pubsub routing protocol to use. You can either use `gossipsub` in order to use the [ChainSafe/gossipsub-js](https://github.com/ChainSafe/gossipsub-js) implementation, or `floodsub` to use the [libp2p/js-libp2p-floodsub](https://github.com/libp2p/js-libp2p-floodsub) implementation. You can read more about these implementations on the [libp2p/specs/pubsub](https://github.com/libp2p/specs/tree/master/pubsub) document. + +Default: `gossipsub` + ## `Swarm` Options for configuring the swarm. diff --git a/examples/circuit-relaying/src/app.js b/examples/circuit-relaying/src/app.js index 290a57cf26..dd34347c1c 100644 --- a/examples/circuit-relaying/src/app.js +++ b/examples/circuit-relaying/src/app.js @@ -36,8 +36,8 @@ document.addEventListener('DOMContentLoaded', async () => { enabled: true // make this node a relay (HOP) } }, - EXPERIMENTAL: { - pubsub: true // enable pubsub + pubsub: { + enabled: true }, config: { Bootstrap: [] diff --git a/examples/custom-libp2p/index.js b/examples/custom-libp2p/index.js index 4b85fa2280..fa1a097b86 100644 --- a/examples/custom-libp2p/index.js +++ b/examples/custom-libp2p/index.js @@ -96,8 +96,8 @@ const libp2pBundle = (opts) => { timeout: 2e3 // End the query quickly since we're running so frequently } }, - EXPERIMENTAL: { - pubsub: true + pubsub: { + enabled: true } } }) diff --git a/examples/custom-libp2p/package.json b/examples/custom-libp2p/package.json index 81209e705b..944b8a2b7f 100644 --- a/examples/custom-libp2p/package.json +++ b/examples/custom-libp2p/package.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "ipfs": "file:../../", - "libp2p": "~0.25.0", + "libp2p": "~0.26.1", "libp2p-bootstrap": "~0.9.7", "libp2p-kad-dht": "~0.15.0", "libp2p-mdns": "~0.12.2", diff --git a/examples/exchange-files-in-browser/public/app.js b/examples/exchange-files-in-browser/public/app.js index 4578bc588d..d45f4c9b6e 100644 --- a/examples/exchange-files-in-browser/public/app.js +++ b/examples/exchange-files-in-browser/public/app.js @@ -44,8 +44,8 @@ let info async function start () { if (!node) { const options = { - EXPERIMENTAL: { - pubsub: true + pubsub: { + enabled: true }, repo: 'ipfs-' + Math.random(), config: { diff --git a/package.json b/package.json index a53177f21f..5102b9508d 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "./src/core/runtime/dns-nodejs.js": "./src/core/runtime/dns-browser.js", "./src/core/runtime/fetch-nodejs.js": "./src/core/runtime/fetch-browser.js", "./src/core/runtime/libp2p-nodejs.js": "./src/core/runtime/libp2p-browser.js", + "./src/core/runtime/libp2p-pubsub-routers-nodejs.js": "./src/core/runtime/libp2p-pubsub-routers-browser.js", "./src/core/runtime/preload-nodejs.js": "./src/core/runtime/preload-browser.js", "./src/core/runtime/repo-nodejs.js": "./src/core/runtime/repo-browser.js", "./src/core/runtime/ipld-nodejs.js": "./src/core/runtime/ipld-browser.js", @@ -96,7 +97,7 @@ "ipfs-bitswap": "~0.25.1", "ipfs-block": "~0.8.1", "ipfs-block-service": "~0.15.2", - "ipfs-http-client": "^33.1.1", + "ipfs-http-client": "^34.0.0", "ipfs-http-response": "~0.3.1", "ipfs-mfs": "~0.12.0", "ipfs-multipart": "~0.1.1", @@ -121,11 +122,13 @@ "iso-url": "~0.4.6", "just-safe-set": "^2.1.0", "kind-of": "^6.0.2", - "libp2p": "~0.25.4", + "libp2p": "~0.26.1", "libp2p-bootstrap": "~0.9.3", "libp2p-crypto": "~0.16.0", "libp2p-delegated-content-routing": "^0.2.4", "libp2p-delegated-peer-routing": "^0.2.4", + "libp2p-floodsub": "^0.17.0", + "libp2p-gossipsub": "~0.0.4", "libp2p-kad-dht": "~0.15.3", "libp2p-keychain": "~0.4.2", "libp2p-mdns": "~0.12.0", @@ -191,8 +194,8 @@ "execa": "^2.0.4", "form-data": "^2.5.1", "hat": "0.0.3", - "interface-ipfs-core": "^0.110.0", - "ipfsd-ctl": "^0.44.1", + "interface-ipfs-core": "^0.111.0", + "ipfsd-ctl": "~0.45.0", "libp2p-websocket-star": "~0.10.2", "ncp": "^2.0.0", "p-event": "^4.1.0", diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index 140ac2d224..f3f61f80e6 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -16,7 +16,8 @@ module.exports = { type: 'boolean', default: false }) - .option('enable-pubsub-experiment', { + .option('enable-pubsub', { + alias: 'enable-pubsub-experiment', type: 'boolean', default: false }) @@ -53,8 +54,8 @@ module.exports = { offline: argv.offline, pass: argv.pass, preload: { enabled: argv.enablePreload }, + pubsub: { enabled: argv.enablePubsub }, EXPERIMENTAL: { - pubsub: argv.enablePubsubExperiment, ipnsPubsub: argv.enableNamesysPubsub, dht: argv.enableDhtExperiment, sharding: argv.enableShardingExperiment diff --git a/src/cli/daemon.js b/src/cli/daemon.js index 879432018b..7181e8c1e7 100644 --- a/src/cli/daemon.js +++ b/src/cli/daemon.js @@ -30,7 +30,7 @@ class Daemon { async start () { this._log('starting') - const libp2p = { modules: {} } + const libp2p = { modules: {}, config: {} } // Attempt to use any of the WebRTC versions available globally let electronWebRTC diff --git a/src/cli/utils.js b/src/cli/utils.js index eed5cbdac6..0562ff6737 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -50,8 +50,8 @@ exports.getIPFS = (argv, callback) => { init: false, start: false, pass: argv.pass, - EXPERIMENTAL: { - pubsub: true + pubsub: { + enabled: true } }) diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 684bfe2714..ba420f120f 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -2,10 +2,12 @@ const get = require('dlv') const mergeOptions = require('merge-options') +const errCode = require('err-code') const ipnsUtils = require('../ipns/routing/utils') const multiaddr = require('multiaddr') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing') +const PubsubRouters = require('../runtime/libp2p-pubsub-routers-nodejs') module.exports = function libp2p (self, config) { const options = self._options || {} @@ -58,13 +60,24 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) { peerRouting = [new DelegatedPeerRouter(delegatedApiOptions)] } + const getPubsubRouter = () => { + const router = get(config, 'Pubsub.Router', 'gossipsub') + + if (!PubsubRouters[router]) { + throw errCode(new Error(`Router unavailable. Configure libp2p.modules.pubsub to use the ${router} router.`), 'ERR_NOT_SUPPORTED') + } + + return PubsubRouters[router] + } + const libp2pDefaults = { datastore, peerInfo, peerBook, modules: { contentRouting, - peerRouting + peerRouting, + pubsub: getPubsubRouter() }, config: { peerDiscovery: { @@ -105,8 +118,8 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) { ipns: ipnsUtils.selector } }, - EXPERIMENTAL: { - pubsub: get(options, 'EXPERIMENTAL.pubsub', false) + pubsub: { + enabled: get(options, 'pubsub.enabled', false) } }, connectionManager: get(options, 'connectionManager', diff --git a/src/core/components/pubsub.js b/src/core/components/pubsub.js index 0171eea179..ac6a0981cd 100644 --- a/src/core/components/pubsub.js +++ b/src/core/components/pubsub.js @@ -16,65 +16,56 @@ module.exports = function pubsub (self) { options = {} } - if (!self._options.EXPERIMENTAL.pubsub) { + if (!self.libp2p.pubsub) { return callback ? setImmediate(() => callback(errPubsubDisabled())) : Promise.reject(errPubsubDisabled()) } if (!callback) { - return new Promise((resolve, reject) => { - self.libp2p.pubsub.subscribe(topic, options, handler, (err) => { - if (err) { - return reject(err) - } - resolve() - }) - }) + return self.libp2p.pubsub.subscribe(topic, handler, options) } - self.libp2p.pubsub.subscribe(topic, options, handler, callback) + self.libp2p.pubsub.subscribe(topic, handler, options, callback) }, unsubscribe: (topic, handler, callback) => { - if (!self._options.EXPERIMENTAL.pubsub) { + if (!self.libp2p.pubsub) { return callback ? setImmediate(() => callback(errPubsubDisabled())) : Promise.reject(errPubsubDisabled()) } - self.libp2p.pubsub.unsubscribe(topic, handler) - if (!callback) { - return Promise.resolve() + return self.libp2p.pubsub.unsubscribe(topic, handler) } - setImmediate(() => callback()) + self.libp2p.pubsub.unsubscribe(topic, handler, callback) }, publish: promisify((topic, data, callback) => { - if (!self._options.EXPERIMENTAL.pubsub) { + if (!self.libp2p.pubsub) { return setImmediate(() => callback(errPubsubDisabled())) } self.libp2p.pubsub.publish(topic, data, callback) }), ls: promisify((callback) => { - if (!self._options.EXPERIMENTAL.pubsub) { + if (!self.libp2p.pubsub) { return setImmediate(() => callback(errPubsubDisabled())) } self.libp2p.pubsub.ls(callback) }), peers: promisify((topic, callback) => { - if (!self._options.EXPERIMENTAL.pubsub) { + if (!self.libp2p.pubsub) { return setImmediate(() => callback(errPubsubDisabled())) } self.libp2p.pubsub.peers(topic, callback) }), setMaxListeners (n) { - if (!self._options.EXPERIMENTAL.pubsub) { + if (!self.libp2p.pubsub) { throw errPubsubDisabled() } self.libp2p.pubsub.setMaxListeners(n) diff --git a/src/core/config.js b/src/core/config.js index 1d40e862c5..53231bcc73 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -32,6 +32,9 @@ const configSchema = s({ addresses: optional(s(['multiaddr'])), interval: 'number?' }, { enabled: true, interval: 30 * 1000 }), + pubsub: optional(s({ + enabled: 'boolean?' + })), init: optional(union(['boolean', s({ bits: 'number?', emptyRepo: 'boolean?', @@ -68,6 +71,9 @@ const configSchema = s({ })) })), Bootstrap: optional(s(['multiaddr-ipfs'])), + Pubsub: optional(s({ + Router: 'string?' + })), Swarm: optional(s({ ConnMgr: optional(s({ LowWater: 'number?', diff --git a/src/core/index.js b/src/core/index.js index 8b0b717716..4016aa47fc 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -15,6 +15,7 @@ const multihashing = require('multihashing-async') const CID = require('cids') const debug = require('debug') const mergeOptions = require('merge-options') +const get = require('dlv') const EventEmitter = require('events') const config = require('./config') @@ -46,6 +47,9 @@ class IPFS extends EventEmitter { init: true, start: true, EXPERIMENTAL: {}, + pubsub: { + enabled: false + }, preload: { enabled: true, addresses: [ @@ -131,13 +135,14 @@ class IPFS extends EventEmitter { this.stats = components.stats(this) this.resolve = components.resolve(this) - if (this._options.EXPERIMENTAL.pubsub) { - this.log('EXPERIMENTAL pubsub is enabled') + if (this._options.pubsub.enabled) { + this.log('pubsub is enabled') } if (this._options.EXPERIMENTAL.ipnsPubsub) { - if (!this._options.EXPERIMENTAL.pubsub) { - this.log('EXPERIMENTAL pubsub is enabled to use IPNS pubsub') - this._options.EXPERIMENTAL.pubsub = true + // if (!this._options.pubsub.enabled) { + if (!get(this._options, 'pubsub.enabled', false)) { + this.log('pubsub is enabled to use EXPERIMENTAL IPNS pubsub') + this._options.pubsub.enabled = true } this.log('EXPERIMENTAL IPNS pubsub is enabled') diff --git a/src/core/runtime/config-nodejs.js b/src/core/runtime/config-nodejs.js index 60169ef562..1a9598e515 100644 --- a/src/core/runtime/config-nodejs.js +++ b/src/core/runtime/config-nodejs.js @@ -40,6 +40,9 @@ module.exports = () => ({ '/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', '/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6' ], + Pubsub: { + Router: 'gossipsub' + }, Swarm: { ConnMgr: { LowWater: 200, diff --git a/src/core/runtime/libp2p-browser.js b/src/core/runtime/libp2p-browser.js index f05f87cebc..2054461afd 100644 --- a/src/core/runtime/libp2p-browser.js +++ b/src/core/runtime/libp2p-browser.js @@ -7,6 +7,7 @@ const Multiplex = require('pull-mplex') const SECIO = require('libp2p-secio') const Bootstrap = require('libp2p-bootstrap') const KadDHT = require('libp2p-kad-dht') +const GossipSub = require('libp2p-gossipsub') const libp2p = require('libp2p') const mergeOptions = require('merge-options') const multiaddr = require('multiaddr') @@ -23,8 +24,8 @@ class Node extends libp2p { const defaults = { switch: { - blacklistTTL: 2 * 60 * 1e3, // 2 minute base - blackListAttempts: 5, // back off 5 times + denyTTL: 2 * 60 * 1e3, // 2 minute base + denyAttempts: 5, // back off 5 times maxParallelDials: 100, maxColdCalls: 25, dialTimeout: 20e3 @@ -46,7 +47,8 @@ class Node extends libp2p { wsstar.discovery, Bootstrap ], - dht: KadDHT + dht: KadDHT, + pubsub: GossipSub }, config: { peerDiscovery: { @@ -64,8 +66,9 @@ class Node extends libp2p { dht: { enabled: false }, - EXPERIMENTAL: { - pubsub: false + pubsub: { + enabled: false, + emitSelf: true } } } diff --git a/src/core/runtime/libp2p-nodejs.js b/src/core/runtime/libp2p-nodejs.js index eb281a034a..744d0adb9a 100644 --- a/src/core/runtime/libp2p-nodejs.js +++ b/src/core/runtime/libp2p-nodejs.js @@ -6,6 +6,7 @@ const WS = require('libp2p-websockets') const WebSocketStarMulti = require('libp2p-websocket-star-multi') const Bootstrap = require('libp2p-bootstrap') const KadDHT = require('libp2p-kad-dht') +const GossipSub = require('libp2p-gossipsub') const Multiplex = require('pull-mplex') const SECIO = require('libp2p-secio') const libp2p = require('libp2p') @@ -22,8 +23,8 @@ class Node extends libp2p { const defaults = { switch: { - blacklistTTL: 2 * 60 * 1e3, // 2 minute base - blackListAttempts: 5, // back off 5 times + denyTTL: 2 * 60 * 1e3, // 2 minute base + denyAttempts: 5, // back off 5 times maxParallelDials: 150, maxColdCalls: 50, dialTimeout: 10e3 // Be strict with dial time @@ -45,7 +46,8 @@ class Node extends libp2p { Bootstrap, wsstar.discovery ], - dht: KadDHT + dht: KadDHT, + pubsub: GossipSub }, config: { peerDiscovery: { @@ -67,8 +69,9 @@ class Node extends libp2p { enabled: false } }, - EXPERIMENTAL: { - pubsub: false + pubsub: { + enabled: false, + emitSelf: true } } } diff --git a/src/core/runtime/libp2p-pubsub-routers-browser.js b/src/core/runtime/libp2p-pubsub-routers-browser.js new file mode 100644 index 0000000000..5b6aaedc0a --- /dev/null +++ b/src/core/runtime/libp2p-pubsub-routers-browser.js @@ -0,0 +1,5 @@ +'use strict' + +module.exports = { + gossipsub: require('libp2p-gossipsub') +} diff --git a/src/core/runtime/libp2p-pubsub-routers-nodejs.js b/src/core/runtime/libp2p-pubsub-routers-nodejs.js new file mode 100644 index 0000000000..0af111e881 --- /dev/null +++ b/src/core/runtime/libp2p-pubsub-routers-nodejs.js @@ -0,0 +1,6 @@ +'use strict' + +module.exports = { + gossipsub: require('libp2p-gossipsub'), + floodsub: require('libp2p-floodsub') +} diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js index 89ae432bcd..e4358e90f2 100644 --- a/test/cli/pubsub.js +++ b/test/cli/pubsub.js @@ -44,7 +44,7 @@ describe('pubsub', function () { exec: IPFS, initOptions: { bits: 512 }, config, - args: ['--enable-pubsub-experiment'] + args: ['--enable-pubsub'] }) node = ipfsdA.api }) @@ -59,7 +59,7 @@ describe('pubsub', function () { const df = DaemonFactory.create({ type: 'js' }) ipfsdB = await df.spawn({ initOptions: { bits: 512 }, - args: ['--enable-pubsub-experiment'], + args: ['--enable-pubsub'], exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), config }) diff --git a/test/core/config.spec.js b/test/core/config.spec.js index 8f2e643e1c..e67b077209 100644 --- a/test/core/config.spec.js +++ b/test/core/config.spec.js @@ -98,8 +98,8 @@ describe('config', () => { it('should validate valid EXPERIMENTAL', () => { const cfgs = [ - { EXPERIMENTAL: { pubsub: true, dht: true, sharding: true } }, - { EXPERIMENTAL: { pubsub: false, dht: false, sharding: false } }, + { EXPERIMENTAL: { dht: true, sharding: true } }, + { EXPERIMENTAL: { dht: false, sharding: false } }, { EXPERIMENTAL: undefined } ] @@ -108,7 +108,6 @@ describe('config', () => { it('should validate invalid EXPERIMENTAL', () => { const cfgs = [ - { EXPERIMENTAL: { pubsub: 138 } }, { EXPERIMENTAL: { dht: 138 } }, { EXPERIMENTAL: { sharding: 138 } } ] diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index f930641355..e650743875 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -102,6 +102,18 @@ describe('interface-ipfs-core tests', function () { { name: 'should resolve IPNS link recursively', reason: 'TODO: IPNS resolve not yet implemented https://github.com/ipfs/js-ipfs/issues/1918' + }, + { + name: 'should non-recursively resolve ipfs.io', + reasone: 'TODO: gateway issue on dns. To be enabled on a new PR' + }, + { + name: 'should recursively resolve ipfs.io', + reasone: 'TODO: gateway issue on dns. To be enabled on a new PR' + }, + { + name: 'should resolve subdomain docs.ipfs.io', + reasone: 'TODO: gateway issue on dns. To be enabled on a new PR' } ] }) @@ -110,7 +122,42 @@ describe('interface-ipfs-core tests', function () { spawnOptions: { args: ['--pass ipfs-is-awesome-software', '--offline'] } - })) + }), { + skip: [ + { + name: 'should resolve /ipns/ipfs.io', + reasones: 'TODO: gateway issue on dns. To be enabled on a new PR' + }, + { + name: 'should resolve /ipns/ipfs.io recursive === false', + reasones: 'TODO: gateway issue on dns. To be enabled on a new PR' + }, + { + name: 'should resolve /ipns/ipfs.io recursive === true', + reasones: 'TODO: gateway issue on dns. To be enabled on a new PR' + }, + { + name: 'should resolve /ipns/ipfs.io with remainder', + reasones: 'TODO: gateway issue on dns. To be enabled on a new PR' + }, + { + name: 'should resolve /ipns/ipfs.io with remainder recursive === false', + reasones: 'TODO: gateway issue on dns. To be enabled on a new PR' + }, + { + name: 'should resolve /ipns/ipfs.io with remainder recursive === true', + reasones: 'TODO: gateway issue on dns. To be enabled on a new PR' + }, + { + name: 'should fail to resolve /ipns/ipfs.a', + reasones: 'TODO: gateway issue on dns. To be enabled on a new PR' + }, + { + name: 'should resolve ipns path with hamt-shard recursive === true', + reasones: 'TODO: gateway issue on dns. To be enabled on a new PR' + } + ] + }) tests.namePubsub(CommonFactory.create({ spawnOptions: { @@ -149,7 +196,7 @@ describe('interface-ipfs-core tests', function () { tests.pubsub(CommonFactory.create({ spawnOptions: { - args: ['--enable-pubsub-experiment'], + args: ['--enable-pubsub'], initOptions: { bits: 512 } } }), { diff --git a/test/core/libp2p.spec.js b/test/core/libp2p.spec.js index 818902d523..b4f274996e 100644 --- a/test/core/libp2p.spec.js +++ b/test/core/libp2p.spec.js @@ -15,6 +15,7 @@ const Multiplex = require('pull-mplex') const SECIO = require('libp2p-secio') const KadDHT = require('libp2p-kad-dht') const Libp2p = require('libp2p') +const isNode = require('detect-node') const libp2pComponent = require('../../src/core/components/libp2p') @@ -44,9 +45,6 @@ describe('libp2p customization', function () { webRTCStar: { Enabled: false } - }, - EXPERIMENTAL: { - pubsub: false } } datastore = new MemoryStore() @@ -149,8 +147,11 @@ describe('libp2p customization', function () { enabled: true } }, - EXPERIMENTAL: { - pubsub: false + pubsub: { + enabled: false, + emitSelf: true, + signMessages: true, + strictSigning: true } }) expect(_libp2p._transport).to.have.length(3) @@ -177,8 +178,8 @@ describe('libp2p customization', function () { } } }, - EXPERIMENTAL: { - pubsub: true + pubsub: { + enabled: true }, libp2p: { modules: { @@ -213,9 +214,6 @@ describe('libp2p customization', function () { websocketStar: { enabled: true } - }, - EXPERIMENTAL: { - pubsub: true } }) expect(_libp2p._transport).to.have.length(1) @@ -293,4 +291,68 @@ describe('libp2p customization', function () { }) }) }) + + describe('bundle via custom config for pubsub', () => { + it('select gossipsub as pubsub router', (done) => { + const ipfs = { + _repo: { + datastore + }, + _peerInfo: peerInfo, + _peerBook: peerBook, + // eslint-disable-next-line no-console + _print: console.log, + _options: {} + } + const customConfig = { + ...testConfig, + Pubsub: { + Router: 'gossipsub' + } + } + + _libp2p = libp2pComponent(ipfs, customConfig) + + _libp2p.start((err) => { + expect(err).to.not.exist() + expect(_libp2p._modules.pubsub).to.eql(require('libp2p-gossipsub')) + done() + }) + }) + + it('select floodsub as pubsub router if node', (done) => { + const ipfs = { + _repo: { + datastore + }, + _peerInfo: peerInfo, + _peerBook: peerBook, + // eslint-disable-next-line no-console + _print: console.log, + _options: {} + } + const customConfig = { + ...testConfig, + Pubsub: { + Router: 'floodsub' + } + } + + try { + _libp2p = libp2pComponent(ipfs, customConfig) + } catch (err) { + if (!isNode) { + expect(err).to.exist() + expect(err.code).to.eql('ERR_NOT_SUPPORTED') + done() + } + } + + _libp2p.start((err) => { + expect(err).to.not.exist() + expect(_libp2p._modules.pubsub).to.eql(require('libp2p-floodsub')) + done() + }) + }) + }) }) diff --git a/test/core/pubsub.spec.js b/test/core/pubsub.spec.js index c1a8ec9092..de0f4404c6 100644 --- a/test/core/pubsub.spec.js +++ b/test/core/pubsub.spec.js @@ -29,8 +29,8 @@ describe('pubsub disabled', () => { preload: { enabled: false }, - EXPERIMENTAL: { - pubsub: false + pubsub: { + enabled: false } }) diff --git a/test/http-api/interface.js b/test/http-api/interface.js index 8cbc2423ef..23b5916624 100644 --- a/test/http-api/interface.js +++ b/test/http-api/interface.js @@ -148,7 +148,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => { tests.pubsub(CommonFactory.create({ spawnOptions: { - args: ['--enable-pubsub-experiment'], + args: ['--enable-pubsub'], initOptions: { bits: 512 } } })) diff --git a/test/http-api/routes.js b/test/http-api/routes.js index ded737cc6a..8c090727a5 100644 --- a/test/http-api/routes.js +++ b/test/http-api/routes.js @@ -26,9 +26,7 @@ describe('HTTP API', () => { repo: repoTests, pass: hat(), config, - EXPERIMENTAL: { - pubsub: true - }, + pubsub: { enabled: true }, preload: { enabled: false } }) await ncp(repoExample, repoTests)