From b0acc71447e874a987408cfedf6ecec089519725 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 29 Jan 2019 11:19:32 +0000 Subject: [PATCH] fix: code review --- package.json | 4 ++-- src/cli/commands/daemon.js | 4 ---- src/core/components/dht.js | 9 +++++---- src/core/components/libp2p.js | 2 +- src/core/runtime/libp2p-browser.js | 2 +- src/core/runtime/libp2p-nodejs.js | 2 +- src/http/api/resources/dht.js | 4 ++-- test/core/interface.spec.js | 2 +- test/core/libp2p.spec.js | 8 +++----- test/core/name.js | 6 +++--- test/core/ping.spec.js | 2 +- 11 files changed, 20 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 1acc4db534..2e6c47af15 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "form-data": "^2.3.3", "hat": "0.0.3", "interface-ipfs-core": "~0.96.0", - "ipfsd-ctl": "~0.40.2", + "ipfsd-ctl": "~0.41.0", "ncp": "^2.0.0", "qs": "^6.5.2", "rimraf": "^2.6.2", @@ -128,7 +128,7 @@ "joi": "^14.3.0", "joi-browser": "^13.4.0", "joi-multiaddr": "^4.0.0", - "libp2p": "~0.24.3", + "libp2p": "libp2p/js-libp2p#master", "libp2p-bootstrap": "~0.9.3", "libp2p-crypto": "~0.16.0", "libp2p-kad-dht": "~0.14.4", diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index 71024150de..11f27f0932 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -22,10 +22,6 @@ module.exports = { type: 'boolean', default: false }) - .option('enable-dht-experiment', { - type: 'boolean', - default: false - }) .option('offline', { desc: 'Run offline. Do not connect to the rest of the network but provide local API.', default: false diff --git a/src/core/components/dht.js b/src/core/components/dht.js index e969367d54..e5fc62dbec 100644 --- a/src/core/components/dht.js +++ b/src/core/components/dht.js @@ -6,7 +6,8 @@ const PeerId = require('peer-id') const PeerInfo = require('peer-info') const CID = require('cids') const each = require('async/each') -const setImmediate = require('async/setImmediate') +const nextTick = require('async/nextTick') + const errcode = require('err-code') const debug = require('debug') @@ -38,7 +39,7 @@ module.exports = (self) => { } catch (err) { log.error(err) - return setImmediate(() => callback(errcode(err, 'ERR_INVALID_CID'))) + return nextTick(() => callback(errcode(err, 'ERR_INVALID_CID'))) } } @@ -64,7 +65,7 @@ module.exports = (self) => { } catch (err) { log.error(err) - return setImmediate(() => callback(errcode(err, 'ERR_INVALID_CID'))) + return nextTick(() => callback(errcode(err, 'ERR_INVALID_CID'))) } } @@ -95,7 +96,7 @@ module.exports = (self) => { } catch (err) { log.error(err) - return setImmediate(() => callback(errcode(err, 'ERR_INVALID_CID'))) + return nextTick(() => callback(errcode(err, 'ERR_INVALID_CID'))) } } diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 8f73abaf25..ace170f591 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -77,6 +77,7 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) { }, dht: { kBucketSize: get(options, 'dht.kBucketSize', 20), + enabled: get(options, 'dht.enabled', true) && !(get(options, 'local', false)), enabledDiscovery: get(options, 'dht.enabledDiscovery', true), validators: { ipns: ipnsUtils.validator @@ -86,7 +87,6 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) { } }, EXPERIMENTAL: { - dht: !(get(options, 'local', false)), pubsub: get(options, 'EXPERIMENTAL.pubsub', false) } }, diff --git a/src/core/runtime/libp2p-browser.js b/src/core/runtime/libp2p-browser.js index 19eb7fd848..97d22b833b 100644 --- a/src/core/runtime/libp2p-browser.js +++ b/src/core/runtime/libp2p-browser.js @@ -55,10 +55,10 @@ class Node extends libp2p { }, dht: { kBucketSize: 20, + enabled: false, enabledDiscovery: true }, EXPERIMENTAL: { - dht: true, pubsub: false } } diff --git a/src/core/runtime/libp2p-nodejs.js b/src/core/runtime/libp2p-nodejs.js index acf3f2af8c..729ee43146 100644 --- a/src/core/runtime/libp2p-nodejs.js +++ b/src/core/runtime/libp2p-nodejs.js @@ -54,10 +54,10 @@ class Node extends libp2p { }, dht: { kBucketSize: 20, + enabled: true, enabledDiscovery: true }, EXPERIMENTAL: { - dht: true, pubsub: false } } diff --git a/src/http/api/resources/dht.js b/src/http/api/resources/dht.js index 48755716d1..962a1cd99b 100644 --- a/src/http/api/resources/dht.js +++ b/src/http/api/resources/dht.js @@ -144,7 +144,7 @@ exports.provide = { }).code(500) } - reply({}) + reply() }) } } @@ -176,7 +176,7 @@ exports.put = { }).code(500) } - reply({}) + reply() }) } } diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 261bbf3f54..b7aaace791 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -102,7 +102,7 @@ describe('interface-ipfs-core tests', function () { tests.name(CommonFactory.create({ spawnOptions: { - args: ['--pass ipfs-is-awesome-software', '--local'], + args: ['--pass ipfs-is-awesome-software', '--offline'], initOptions: { bits: 512 }, config: { Bootstrap: [], diff --git a/test/core/libp2p.spec.js b/test/core/libp2p.spec.js index cd360f057d..c77709c9ee 100644 --- a/test/core/libp2p.spec.js +++ b/test/core/libp2p.spec.js @@ -13,6 +13,7 @@ const PeerBook = require('peer-book') const WebSocketStar = require('libp2p-websocket-star') const Multiplex = require('libp2p-mplex') const SECIO = require('libp2p-secio') +const KadDHT = require('libp2p-kad-dht') const Libp2p = require('libp2p') const libp2pComponent = require('../../src/core/components/libp2p') @@ -45,7 +46,6 @@ describe('libp2p customization', function () { } }, EXPERIMENTAL: { - dht: false, pubsub: false } } @@ -94,7 +94,8 @@ describe('libp2p customization', function () { ], peerDiscovery: [ wsstar.discovery - ] + ], + dht: KadDHT } }) } @@ -144,7 +145,6 @@ describe('libp2p customization', function () { } }, EXPERIMENTAL: { - dht: true, pubsub: false } }) @@ -172,7 +172,6 @@ describe('libp2p customization', function () { } }, EXPERIMENTAL: { - dht: false, pubsub: true }, libp2p: { @@ -209,7 +208,6 @@ describe('libp2p customization', function () { } }, EXPERIMENTAL: { - dht: true, pubsub: true } }) diff --git a/test/core/name.js b/test/core/name.js index 972d5c25ed..ed73592d28 100644 --- a/test/core/name.js +++ b/test/core/name.js @@ -50,7 +50,7 @@ describe('name', function () { this.timeout(50 * 1000) df.spawn({ exec: IPFS, - args: [`--pass ${hat()}`, '--local'], + args: [`--pass ${hat()}`, '--offline'], config: { Bootstrap: [] } }, (err, _ipfsd) => { expect(err).to.not.exist() @@ -152,7 +152,7 @@ describe('name', function () { this.timeout(40 * 1000) df.spawn({ exec: IPFS, - args: [`--pass ${hat()}`, '--local'], + args: [`--pass ${hat()}`, '--offline'], config: { Bootstrap: [] } }, (err, _ipfsd) => { expect(err).to.not.exist() @@ -474,7 +474,7 @@ describe('name', function () { this.timeout(40 * 1000) df.spawn({ exec: IPFS, - args: [`--pass ${hat()}`, '--local'], + args: [`--pass ${hat()}`, '--offline'], config: { Bootstrap: [], Discovery: { diff --git a/test/core/ping.spec.js b/test/core/ping.spec.js index a3f220f2d9..5b784c5428 100644 --- a/test/core/ping.spec.js +++ b/test/core/ping.spec.js @@ -29,7 +29,7 @@ const config = { } function spawnNode ({ dht = false, type = 'js' }, cb) { - const args = dht ? [] : ['--local'] + const args = dht ? [] : ['--offline'] const factory = type === 'js' ? df : dfProc factory.spawn({ args,