From 2b6f0e9116da773dbca6a6523a3811e1a2552c55 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Jan 2020 20:38:37 +0000 Subject: [PATCH] fix: start webrtc sigserve during tests so browsers can dial things --- .aegir.js | 7 +++++++ src/core/components/id.js | 12 +++++++++++- test/core/interface.spec.js | 13 +++++++++++-- test/utils/factory.js | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.aegir.js b/.aegir.js index 93a928004c..4ae4b45c83 100644 --- a/.aegir.js +++ b/.aegir.js @@ -3,10 +3,12 @@ const IPFSFactory = require('ipfsd-ctl') const MockPreloadNode = require('./test/utils/mock-preload-node') const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server') +const webRTCStarSigServer = require('libp2p-webrtc-star/src/sig-server') const ipfsdServer = IPFSFactory.createServer() const preloadNode = MockPreloadNode.createNode() const echoServer = EchoServer.createServer() +let sigServer module.exports = { bundlesize: { maxSize: '652kB' }, @@ -42,11 +44,16 @@ module.exports = { await ipfsdServer.start() await preloadNode.start() await echoServer.start() + sigServer = await webRTCStarSigServer.start({ + host: '127.0.0.1', + port: 14579 + }) }, post: async () => { await ipfsdServer.stop() await preloadNode.stop() await echoServer.stop() + await sigServer.stop() } } } diff --git a/src/core/components/id.js b/src/core/components/id.js index 1b25d25c71..ecc6843b8c 100644 --- a/src/core/components/id.js +++ b/src/core/components/id.js @@ -12,7 +12,17 @@ module.exports = ({ peerInfo }) => { publicKey: peerInfo.id.pubKey.bytes.toString('base64'), addresses: peerInfo.multiaddrs .toArray() - .map(ma => `${ma}/p2p/${id}`) + .map(ma => { + const str = ma.toString() + + // some relay-style transports add our peer id to the ma for us + // so don't double-add + if (str.endsWith(`/p2p/${id}`)) { + return str + } + + return `${str}/p2p/${id}` + }) .sort() .map(ma => multiaddr(ma)), agentVersion: `js-ipfs/${pkgversion}`, diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 19ce074cea..4b4815cdde 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -4,7 +4,7 @@ const tests = require('interface-ipfs-core') const merge = require('merge-options') const { createFactory } = require('ipfsd-ctl') -const { isNode } = require('ipfs-utils/src/env') +const { isNode, isBrowser } = require('ipfs-utils/src/env') const IPFS = require('../../src') /** @typedef { import("ipfsd-ctl").ControllerOptions } ControllerOptions */ @@ -23,7 +23,16 @@ describe('interface-ipfs-core tests', function () { ref: require('ipfs-http-client') }, ipfsOptions: { - pass: 'ipfs-is-awesome-software' + pass: 'ipfs-is-awesome-software', + ...(isBrowser ? { + config: { + Addresses: { + Swarm: [ + '/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star' + ] + } + } + } : {}) } } const overrides = { diff --git a/test/utils/factory.js b/test/utils/factory.js index e8152175e9..dd2884369e 100644 --- a/test/utils/factory.js +++ b/test/utils/factory.js @@ -1,6 +1,7 @@ 'use strict' const { createFactory } = require('ipfsd-ctl') const merge = require('merge-options') +const { isBrowser } = require('ipfs-utils/src/env') const factory = (options, overrides) => createFactory( merge({ @@ -18,6 +19,19 @@ const factory = (options, overrides) => createFactory( merge({ js: { ipfsBin: './src/cli/bin.js' + }, + proc: { + ...(isBrowser ? { + ipfsOptions: { + config: { + Addresses: { + Swarm: [ + '/ip4/127.0.0.1/tcp/14579/wss/p2p-webrtc-star' + ] + } + } + } + } : {}) } }, overrides) )