From c77458b5b4df4ed2c1f3d329ffd3807ae15cc97c Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Sun, 9 Feb 2020 18:43:23 +0100 Subject: [PATCH] feat: add support for specifying noise and secio --- package.json | 2 +- src/daemon.js | 4 ++ test/connect/js2js.js | 89 ++++++++++++++++++++++--------------------- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index 103fd58..360a8f9 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "cross-env": "^7.0.0", "dirty-chai": "^2.0.1", "go-libp2p-dep": "~0.5.0", - "libp2p-daemon": "^0.3.0", + "libp2p-daemon": "libp2p/js-libp2p-daemon#feat/noise", "libp2p-daemon-client": "^0.3.0", "multiaddr": "^7.2.1", "rimraf": "^3.0.0" diff --git a/src/daemon.js b/src/daemon.js index 37cdee0..a659abe 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -107,12 +107,16 @@ class Daemon { if (this._type === 'go') { execOptions = ['-listen', addr] + options.secio && execOptions.push('-secio') + options.noise && execOptions.push('-noise') options.dht && execOptions.push('-dht') options.pubsub && execOptions.push('-pubsub') options.pubsubRouter && execOptions.push('-pubsubRouter', options.pubsubRouter) } else { execOptions = ['--listen', addr] + options.secio && execOptions.push('--secio') + options.noise && execOptions.push('--noise') options.dht && execOptions.push('--dht') options.pubsub && execOptions.push('--pubsub') options.pubsubRouter && execOptions.push('--pubsubRouter', options.pubsubRouter) diff --git a/test/connect/js2js.js b/test/connect/js2js.js index 29aeaf2..c0ae6da 100644 --- a/test/connect/js2js.js +++ b/test/connect/js2js.js @@ -8,49 +8,50 @@ const expect = chai.expect const spawnDaemons = require('../utils/spawnDaemons') -describe('connect', () => { - let daemons - - // Start Daemons - before(async function () { - this.timeout(20 * 1000) - - daemons = await spawnDaemons(2, 'go') - }) - - // Stop daemons - after(async function () { - await Promise.all( - daemons.map((daemon) => daemon.stop()) - ) - }) - - it('js peer to js peer', async function () { - this.timeout(10 * 1000) - - const identify1 = await daemons[0].client.identify() - const identify2 = await daemons[1].client.identify() - - // verify connected peers - const knownPeersBeforeConnect1 = await daemons[0].client.listPeers() - expect(knownPeersBeforeConnect1).to.have.lengthOf(0) - - const knownPeersBeforeConnect2 = await daemons[1].client.listPeers() - expect(knownPeersBeforeConnect2).to.have.lengthOf(0) - - // connect peers - await daemons[1].client.connect(identify1.peerId, identify1.addrs) - - // daemons[0] will take some time to get the peers - await new Promise(resolve => setTimeout(resolve, 1000)) - - // verify connected peers - const knownPeersAfterConnect1 = await daemons[0].client.listPeers() - expect(knownPeersAfterConnect1).to.have.lengthOf(1) - expect(knownPeersAfterConnect1[0].toB58String()).to.equal(identify2.peerId.toB58String()) - - const knownPeersAfterConnect2 = await daemons[1].client.listPeers() - expect(knownPeersAfterConnect2).to.have.lengthOf(1) - expect(knownPeersAfterConnect2[0].toB58String()).to.equal(identify1.peerId.toB58String()) +;[{ secio: true, noise: false }, { secio: false, noise: true }].forEach(config => { + describe(`connect ${JSON.stringify(config)}`, () => { + let daemons + + // Start Daemons + before(async function () { + this.timeout(20 * 1000) + daemons = await spawnDaemons(2, 'js', config) + }) + + // Stop daemons + after(async function () { + await Promise.all( + daemons.map((daemon) => daemon.stop()) + ) + }) + + it('js peer to js peer', async function () { + this.timeout(10 * 1000) + + const identify1 = await daemons[0].client.identify() + const identify2 = await daemons[1].client.identify() + + // verify connected peers + const knownPeersBeforeConnect1 = await daemons[0].client.listPeers() + expect(knownPeersBeforeConnect1).to.have.lengthOf(0) + + const knownPeersBeforeConnect2 = await daemons[1].client.listPeers() + expect(knownPeersBeforeConnect2).to.have.lengthOf(0) + + // connect peers + await daemons[1].client.connect(identify1.peerId, identify1.addrs) + + // daemons[0] will take some time to get the peers + await new Promise(resolve => setTimeout(resolve, 1000)) + + // verify connected peers + const knownPeersAfterConnect1 = await daemons[0].client.listPeers() + expect(knownPeersAfterConnect1).to.have.lengthOf(1) + expect(knownPeersAfterConnect1[0].toB58String()).to.equal(identify2.peerId.toB58String()) + + const knownPeersAfterConnect2 = await daemons[1].client.listPeers() + expect(knownPeersAfterConnect2).to.have.lengthOf(1) + expect(knownPeersAfterConnect2[0].toB58String()).to.equal(identify1.peerId.toB58String()) + }) }) })