From 3099a1e7e2299a0a5d0fd9d2033b88868bb346e4 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 10 Apr 2019 11:16:46 +0200 Subject: [PATCH 1/7] fix: use libp2p autodial --- src/core/components/libp2p.js | 20 -------------------- src/core/runtime/libp2p-browser.js | 1 + src/core/runtime/libp2p-nodejs.js | 1 + 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 05cb693ba5..447205a147 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -17,15 +17,6 @@ module.exports = function libp2p (self, config) { const peerInfo = self._peerInfo const peerBook = self._peerInfoBook const libp2p = createBundle({ options, config, datastore, peerInfo, peerBook }) - let discoveredPeers = [] - - const noop = () => {} - const putAndDial = peerInfo => { - peerInfo = peerBook.put(peerInfo) - if (!peerInfo.isConnected()) { - libp2p.dial(peerInfo, noop) - } - } libp2p.on('stop', () => { // Clear our addresses so we can start clean @@ -36,16 +27,6 @@ module.exports = function libp2p (self, config) { peerInfo.multiaddrs.forEach((ma) => { self._print('Swarm listening on', ma.toString()) }) - discoveredPeers.forEach(putAndDial) - discoveredPeers = [] - }) - - libp2p.on('peer:discovery', (peerInfo) => { - if (self.isOnline()) { - putAndDial(peerInfo) - } else { - discoveredPeers.push(peerInfo) - } }) libp2p.on('peer:connect', peerInfo => peerBook.put(peerInfo)) @@ -108,7 +89,6 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) { } const libp2pOptions = mergeOptions(libp2pDefaults, get(options, 'libp2p', {})) - // Required inline to reduce startup time // Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified const Node = require('../runtime/libp2p-nodejs') diff --git a/src/core/runtime/libp2p-browser.js b/src/core/runtime/libp2p-browser.js index 19fe27398b..8dfdd0dfcb 100644 --- a/src/core/runtime/libp2p-browser.js +++ b/src/core/runtime/libp2p-browser.js @@ -43,6 +43,7 @@ class Node extends libp2p { }, config: { peerDiscovery: { + autoDial: true, bootstrap: { enabled: true }, diff --git a/src/core/runtime/libp2p-nodejs.js b/src/core/runtime/libp2p-nodejs.js index 4f11036a86..19f214a8a0 100644 --- a/src/core/runtime/libp2p-nodejs.js +++ b/src/core/runtime/libp2p-nodejs.js @@ -42,6 +42,7 @@ class Node extends libp2p { }, config: { peerDiscovery: { + autoDial: true, mdns: { enabled: true }, From 086b4df6aff09c7690833bf115203f0544aa2aa9 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 10 Apr 2019 11:17:37 +0200 Subject: [PATCH 2/7] chore: use libp2p autodial branch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 242fff2c13..f3a0722360 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,7 @@ "joi": "^14.3.0", "just-flatten-it": "^2.1.0", "just-safe-set": "^2.1.0", - "libp2p": "~0.25.0-rc.5", + "libp2p": "github:libp2p/js-libp2p#feat/disco-strategies", "libp2p-bootstrap": "~0.9.3", "libp2p-crypto": "~0.16.0", "libp2p-kad-dht": "~0.14.12", From dfd8022bbd40886bbda93194904ac9c07bf6ebf3 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 10 Apr 2019 19:00:45 +0200 Subject: [PATCH 3/7] test: fix libp2p config test --- test/core/libp2p.spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/core/libp2p.spec.js b/test/core/libp2p.spec.js index c77709c9ee..1fa19cf3f5 100644 --- a/test/core/libp2p.spec.js +++ b/test/core/libp2p.spec.js @@ -106,7 +106,9 @@ describe('libp2p customization', function () { _libp2p.start((err) => { expect(err).to.not.exist() - expect(_libp2p._config).to.not.have.property('peerDiscovery') + expect(_libp2p._config.peerDiscovery).to.eql({ + autoDial: true + }) expect(_libp2p._transport).to.have.length(1) done() }) @@ -130,6 +132,7 @@ describe('libp2p customization', function () { expect(err).to.not.exist() expect(_libp2p._config).to.deep.include({ peerDiscovery: { + autoDial: true, bootstrap: { enabled: true, list: [] @@ -193,6 +196,7 @@ describe('libp2p customization', function () { expect(err).to.not.exist() expect(_libp2p._config).to.deep.include({ peerDiscovery: { + autoDial: true, bootstrap: { enabled: true, list: [] From d6f12128397863bfc52fedccb24de4718967159f Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Thu, 11 Apr 2019 13:56:44 +0200 Subject: [PATCH 4/7] chore: bump libp2p version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3a0722360..64fecd1c65 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,7 @@ "joi": "^14.3.0", "just-flatten-it": "^2.1.0", "just-safe-set": "^2.1.0", - "libp2p": "github:libp2p/js-libp2p#feat/disco-strategies", + "libp2p": "~0.25.0-rc.6", "libp2p-bootstrap": "~0.9.3", "libp2p-crypto": "~0.16.0", "libp2p-kad-dht": "~0.14.12", From 196b374fdbd12a3c9002a0da4e6bf902adf8940f Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 11 Apr 2019 13:32:32 +0100 Subject: [PATCH 5/7] fix: flakey windows test License: MIT Signed-off-by: Alan Shaw --- test/cli/daemon.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index afebfbbc41..d444134531 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -109,7 +109,7 @@ describe('daemon', () => { await ipfs('config', 'Addresses.API', JSON.stringify(apiAddrs), '--json') await ipfs('config', 'Addresses.Gateway', JSON.stringify(gatewayAddrs), '--json') - const out = await new Promise(resolve => { + const out = await new Promise((resolve, reject) => { const res = ipfs('daemon') let out = '' @@ -117,8 +117,8 @@ describe('daemon', () => { out += data if (out.includes('Daemon is ready')) { res.stdout.removeListener('data', onData) + res.then(() => resolve(out)).catch(reject) res.kill() - resolve(out) } }) }) @@ -134,7 +134,7 @@ describe('daemon', () => { await ipfs('config', 'Addresses.API', '[]', '--json') await ipfs('config', 'Addresses.Gateway', '[]', '--json') - const out = await new Promise(resolve => { + const out = await new Promise((resolve, reject) => { const res = ipfs('daemon') let out = '' @@ -142,8 +142,8 @@ describe('daemon', () => { out += data if (out.includes('Daemon is ready')) { res.stdout.removeListener('data', onData) + res.then(() => resolve(out)).catch(reject) res.kill() - resolve(out) } }) }) From 3f9e903e85885aa42d19ddf870349d375b986f29 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Thu, 11 Apr 2019 15:00:12 +0200 Subject: [PATCH 6/7] docs: add autoDial config to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9d003aacd3..ccaefe0b0a 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,7 @@ You can see the bundle in action in the [custom libp2p example](examples/custom- - `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) - `config` (object): - `peerDiscovery` (object): + - `autoDial` (boolean): Dial to discovered peers when under the Connection Manager min peer count watermark. (default `true`) - `[PeerDiscovery.tag]` (object): configuration for a peer discovery module - `enabled` (boolean): whether this module is enabled or disabled - `[custom config]` (any): other keys are specific to the module From 8f2fea41aa9bb9a70765c23d76e8712055d4cc60 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 11 Apr 2019 15:15:36 +0100 Subject: [PATCH 7/7] fix: windows exits with error License: MIT Signed-off-by: Alan Shaw --- test/cli/daemon.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index d444134531..c7639b21ab 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -117,7 +117,8 @@ describe('daemon', () => { out += data if (out.includes('Daemon is ready')) { res.stdout.removeListener('data', onData) - res.then(() => resolve(out)).catch(reject) + const onKilled = () => resolve(out) + res.then(onKilled).catch(onKilled) res.kill() } }) @@ -142,7 +143,8 @@ describe('daemon', () => { out += data if (out.includes('Daemon is ready')) { res.stdout.removeListener('data', onData) - res.then(() => resolve(out)).catch(reject) + const onKilled = () => resolve(out) + res.then(onKilled).catch(onKilled) res.kill() } })