diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..96244478 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,49 @@ +name: ci +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: npm install + - run: npx aegir lint + - run: npx aegir dep-check -- -i wrtc -i electron-webrtc + - run: npx aegir build --no-types + test-node: + needs: check + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + node: [14, 15] + fail-fast: true + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - run: npm install @mapbox/node-pre-gyp -g + - run: npm install + - run: npx aegir test -t node --cov --bail + - uses: codecov/codecov-action@v1 + test-chrome: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: npm install + - run: npx aegir test -t browser --bail + test-firefox: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: npm install + - run: npx aegir test -t browser --bail -- --browser firefox diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6041472a..00000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: node_js -cache: npm -stages: - - check - - test - - cov - -node_js: - - 'lts/*' - - '14' - -os: - - linux - - osx - -script: npx nyc -s npm run test:node -- --bail -after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov - -jobs: - include: - - stage: check - script: - - npx aegir dep-check -- -i wrtc -i electron-webrtc - - npm run lint - - - stage: test - name: chrome - addons: - chrome: stable - script: - - npx aegir test -t browser - - - stage: test - name: firefox - addons: - firefox: latest - script: - - npx aegir test -t browser -- --browsers FirefoxHeadless - -notifications: - email: false diff --git a/package.json b/package.json index 139f32a9..5e593be6 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,7 @@ "lint" ], "engines": { - "node": ">=10.0.0", - "npm": ">=6.0.0" + "node": ">=14.0.0" }, "repository": { "type": "git", @@ -49,13 +48,13 @@ }, "homepage": "https://github.com/libp2p/js-libp2p-webrtc-star#readme", "devDependencies": { - "aegir": "^30.2.0", - "chai": "^4.2.0", + "aegir": "^30.3.0", + "chai": "^4.3.4", "dirty-chai": "^2.0.1", "electron-webrtc": "~0.3.0", - "libp2p-interfaces": "^0.8.1", + "libp2p-interfaces": "^0.9.0", "p-wait-for": "^3.1.0", - "sinon": "^9.2.0", + "sinon": "^10.0.1", "socket.io-client": "^2.3.0", "uint8arrays": "^2.0.5", "wrtc": "^0.4.6" @@ -69,18 +68,18 @@ "err-code": "^3.0.1", "ipfs-utils": "^6.0.0", "it-pipe": "^1.1.0", - "libp2p-utils": "^0.2.1", + "libp2p-utils": "^0.3.0", "libp2p-webrtc-peer": "^10.0.1", - "mafmt": "^8.0.0", + "mafmt": "^9.0.0", "menoetius": "0.0.2", "minimist": "^1.2.5", - "multiaddr": "^8.0.0", + "multiaddr": "^9.0.1", "p-defer": "^3.0.0", "peer-id": "^0.14.2", "prom-client": "^13.0.0", "socket.io": "^2.3.0", - "socket.io-next": "npm:socket.io@^3.0.4", - "socket.io-client-next": "npm:socket.io-client@^3.0.4", + "socket.io-next": "npm:socket.io@^3.1.2", + "socket.io-client-next": "npm:socket.io-client@^3.1.2", "stream-to-it": "^0.2.2", "streaming-iterables": "^5.0.3" }, diff --git a/src/index.js b/src/index.js index 1d46d942..d16f6593 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,7 @@ const { AbortError } = require('abortable-iterator') const SimplePeer = require('libp2p-webrtc-peer') const { supportsWebRTCDataChannels: webrtcSupport } = require('ipfs-utils/src/supports') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const mafmt = require('mafmt') const PeerId = require('peer-id') @@ -232,7 +232,7 @@ class WebRTCStar { log('Peer Discovered:', maStr) maStr = cleanMultiaddr(maStr) - const ma = multiaddr(maStr) + const ma = new Multiaddr(maStr) const peerId = PeerId.createFromB58String(ma.getPeerId()) this.discovery.emit('peer', { diff --git a/src/listener.js b/src/listener.js index 7f3e95d2..6730df9e 100644 --- a/src/listener.js +++ b/src/listener.js @@ -5,8 +5,7 @@ const debug = require('debug') const log = debug('libp2p:webrtc-star:listener') log.error = debug('libp2p:webrtc-star:listener:error') -const multiaddr = require('multiaddr') - +const { Multiaddr } = require('multiaddr') const io = require('socket.io-client-next') const SimplePeer = require('libp2p-webrtc-peer') const pDefer = require('p-defer') @@ -149,16 +148,23 @@ module.exports = ({ handler, upgrader }, WebRTCStar, options = {}) => { } listener.close = async () => { - listener.io && listener.io.emit('ss-leave') + if (listener.io) { + listener.io.emit('ss-leave') + listener.io.close() + } + await Promise.all(listener.__connections.map(maConn => maConn.close())) listener.emit('close') + + listener.removeAllListeners() } listener.getAddrs = () => { return [listeningAddr] } - WebRTCStar.listenersRefs[multiaddr.toString()] = listener + WebRTCStar.listenersRefs[Multiaddr.toString()] = listener + return listener } diff --git a/src/sig-server/index.js b/src/sig-server/index.js index fc183de2..30d469a3 100644 --- a/src/sig-server/index.js +++ b/src/sig-server/index.js @@ -27,11 +27,11 @@ module.exports = { log('signaling server has started on: ' + http.info.uri) const peers = require('./routes-ws')(http, options.metrics).peers - const next = require('./routes-ws/next')(http, options.metrics).peers + const nextPeers = require('./routes-ws/next')(http, options.metrics).peers http.peers = () => ({ ...peers(), - ...next() + ...nextPeers() }) http.route({ diff --git a/src/sig-server/routes-ws/index.js b/src/sig-server/routes-ws/index.js index cb89c28a..8e021fe8 100644 --- a/src/sig-server/routes-ws/index.js +++ b/src/sig-server/routes-ws/index.js @@ -18,6 +18,8 @@ module.exports = (http, hasMetrics) => { const io = new SocketIO(http.listener) io.on('connection', handle) + http.events.on('stop', () => io.close()) + const peers = {} const peersMetric = hasMetrics ? new client.Gauge({ name: 'webrtc_star_peers', help: 'peers online now' }) : fake.gauge @@ -30,6 +32,10 @@ module.exports = (http, hasMetrics) => { const refreshMetrics = () => peersMetric.set(Object.keys(peers).length) + this.io = () => { + return io + } + this.peers = () => { return peers } diff --git a/src/sig-server/routes-ws/next.js b/src/sig-server/routes-ws/next.js index df1618bc..e6fb4b9d 100644 --- a/src/sig-server/routes-ws/next.js +++ b/src/sig-server/routes-ws/next.js @@ -19,6 +19,8 @@ module.exports = (http, hasMetrics) => { path: '/socket.io-next/' // This should be removed when socket.io@2 support is removed }) + http.events.on('stop', () => io.close()) + io.on('connection', handle) const peers = {} @@ -33,6 +35,10 @@ module.exports = (http, hasMetrics) => { const refreshMetrics = () => peersMetric.set(Object.keys(peers).length) + this.io = () => { + return io + } + this.peers = () => { return peers } diff --git a/src/utils.js b/src/utils.js index 7e079b2a..42278459 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,6 @@ 'use strict' -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') function cleanUrlSIO (ma) { const maStrSplit = ma.toString().split('/') @@ -12,16 +12,16 @@ function cleanUrlSIO (ma) { throw new Error('invalid multiaddr: ' + ma.toString()) } - if (!multiaddr.isName(ma)) { + if (!Multiaddr.isName(ma)) { return 'http://' + maStrSplit[2] + ':' + maStrSplit[4] } if (wsProto === 'ws') { - return 'http://' + maStrSplit[2] + (tcpPort === 80 ? '' : ':' + tcpPort) + return 'http://' + maStrSplit[2] + (tcpPort === '80' ? '' : ':' + tcpPort) } if (wsProto === 'wss') { - return 'https://' + maStrSplit[2] + (tcpPort === 443 ? '' : ':' + tcpPort) + return 'https://' + maStrSplit[2] + (tcpPort === '443' ? '' : ':' + tcpPort) } } @@ -30,7 +30,7 @@ function cleanMultiaddr (maStr) { if (maStr.indexOf(legacy) !== -1) { maStr = maStr.substring(legacy.length, maStr.length) - let ma = multiaddr(maStr) + let ma = new Multiaddr(maStr) const tuppleIPFS = ma.stringTuples().filter((tupple) => { return tupple[0] === 421 // ipfs code })[0] diff --git a/test/compliance.spec.js b/test/compliance.spec.js index 9f67eee2..be0ba449 100644 --- a/test/compliance.spec.js +++ b/test/compliance.spec.js @@ -6,7 +6,7 @@ const wrtc = require('wrtc') const sinon = require('sinon') const testsTransport = require('libp2p-interfaces/src/transport/tests') const testsDiscovery = require('libp2p-interfaces/src/peer-discovery/tests') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const WStar = require('../src') @@ -21,9 +21,9 @@ describe('interface-transport compliance', function () { } const addrs = [ - multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2a')), - multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2b')), - multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2c')) + new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2a')), + new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2b')), + new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2c')) ] // Used by the dial tests to simulate a delayed connect diff --git a/test/sig-server-next.js b/test/sig-server-next.js index 84bb331e..7b6be8cc 100644 --- a/test/sig-server-next.js +++ b/test/sig-server-next.js @@ -3,7 +3,7 @@ const { expect } = require('aegir/utils/chai') const io = require('socket.io-client-next') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const sigServer = require('../src/sig-server') @@ -25,10 +25,10 @@ describe('signalling', () => { return `/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/ipfs/${id}` } - const c1mh = multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1')) - const c2mh = multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo2')) - const c3mh = multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo3')) - const c4mh = multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4')) + const c1mh = new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1')) + const c2mh = new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo2')) + const c3mh = new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo3')) + const c4mh = new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4')) it('start and stop signalling server (default port)', async () => { const server = await sigServer.start() @@ -56,6 +56,9 @@ describe('signalling', () => { await server.stop() }) + cl.on('disconnect', () => { + cl.close() + }) }) it('start and stop signalling server (custom port)', async () => { diff --git a/test/sig-server.js b/test/sig-server.js index 17947589..de100892 100644 --- a/test/sig-server.js +++ b/test/sig-server.js @@ -3,7 +3,7 @@ const { expect } = require('aegir/utils/chai') const io = require('socket.io-client') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const sigServer = require('../src/sig-server') @@ -24,10 +24,10 @@ describe('signalling', () => { return `/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/ipfs/${id}` } - const c1mh = multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1')) - const c2mh = multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo2')) - const c3mh = multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo3')) - const c4mh = multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4')) + const c1mh = new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1')) + const c2mh = new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo2')) + const c3mh = new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo3')) + const c4mh = new Multiaddr(base('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4')) it('start and stop signalling server (default port)', async () => { const server = await sigServer.start() @@ -55,6 +55,9 @@ describe('signalling', () => { await server.stop() }) + cl.on('disconnect', () => { + cl.close() + }) }) it('start and stop signalling server (custom port)', async () => { diff --git a/test/transport/dial.js b/test/transport/dial.js index cb429fbb..2f32fad8 100644 --- a/test/transport/dial.js +++ b/test/transport/dial.js @@ -4,7 +4,7 @@ 'use strict' const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const pipe = require('it-pipe') const { collect } = require('streaming-iterables') const uint8ArrayFromString = require('uint8arrays/from-string') @@ -26,11 +26,12 @@ module.exports = (create) => { let ws2 let ma1 let ma2 + let listener1 let listener2 - const maHSDNS = multiaddr('/dns/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star') - const maHSIP = multiaddr('/ip4/188.166.203.82/tcp/20000/wss/p2p-webrtc-star') - const maLS = multiaddr('/ip4/127.0.0.1/tcp/15555/wss/p2p-webrtc-star') + const maHSDNS = new Multiaddr('/dns/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star') + const maHSIP = new Multiaddr('/ip4/188.166.203.82/tcp/20000/wss/p2p-webrtc-star') + const maLS = new Multiaddr('/ip4/127.0.0.1/tcp/15555/wss/p2p-webrtc-star') if (process.env.WEBRTC_STAR_REMOTE_SIGNAL_DNS) { // test with deployed signalling server using DNS @@ -50,7 +51,7 @@ module.exports = (create) => { beforeEach(async () => { // first ws1 = await create() - const listener1 = ws1.createListener((conn) => { + listener1 = ws1.createListener((conn) => { expect(conn.remoteAddr).to.exist() pipe(conn, conn) }) @@ -62,6 +63,10 @@ module.exports = (create) => { await Promise.all([listener1.listen(ma1), listener2.listen(ma2)]) }) + afterEach(async () => { + await Promise.all([listener1, listener2].map(l => l.close())) + }) + it('dial on IPv4, check promise', async function () { this.timeout(20 * 1000) @@ -78,7 +83,7 @@ module.exports = (create) => { it('dial offline / non-exist()ent node on IPv4, check promise rejected', async function () { this.timeout(20 * 1000) - const maOffline = multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2f') + const maOffline = new Multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2f') try { await ws1.dial(maOffline) diff --git a/test/transport/discovery.js b/test/transport/discovery.js index ec2967f0..8a3486e2 100644 --- a/test/transport/discovery.js +++ b/test/transport/discovery.js @@ -3,7 +3,7 @@ 'use strict' const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') module.exports = (create) => { describe('peer discovery', () => { @@ -12,7 +12,7 @@ module.exports = (create) => { let ws3 let ws4 let ws1Listener - const signallerAddr = multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star') + const signallerAddr = new Multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star') it('listen on the first', async () => { ws1 = await create() diff --git a/test/transport/filter.js b/test/transport/filter.js index 84c4249f..316faa47 100644 --- a/test/transport/filter.js +++ b/test/transport/filter.js @@ -3,7 +3,7 @@ const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') module.exports = (create) => { describe('filter', () => { @@ -11,17 +11,17 @@ module.exports = (create) => { const ws = await create() const maArr = [ - multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'), - multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star'), - multiaddr('/dnsaddr/libp2p.io/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'), - multiaddr('/dnsaddr/signal.libp2p.io/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'), - multiaddr('/dnsaddr/signal.libp2p.io/wss/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'), - multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo2'), - multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo3'), - multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4'), - multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4'), - multiaddr('/ip4/127.0.0.1/tcp/9090/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4'), - multiaddr('/ip4/127.0.0.1/tcp/9090/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + + new Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'), + new Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star'), + new Multiaddr('/dnsaddr/libp2p.io/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'), + new Multiaddr('/dnsaddr/signal.libp2p.io/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'), + new Multiaddr('/dnsaddr/signal.libp2p.io/wss/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1'), + new Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo2'), + new Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo3'), + new Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4'), + new Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4'), + new Multiaddr('/ip4/127.0.0.1/tcp/9090/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4'), + new Multiaddr('/ip4/127.0.0.1/tcp/9090/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + '/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1') ] @@ -31,7 +31,7 @@ module.exports = (create) => { it('filter a single addr for this transport', async () => { const ws = await create() - const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1') + const ma = new Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo1') const filtered = ws.filter(ma) expect(filtered.length).to.equal(1) diff --git a/test/transport/listen.js b/test/transport/listen.js index 5d45fc26..f273c869 100644 --- a/test/transport/listen.js +++ b/test/transport/listen.js @@ -3,13 +3,13 @@ 'use strict' const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') module.exports = (create) => { describe('listen', () => { let ws - const ma = multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star') + const ma = new Multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star') before(async () => { ws = await create() @@ -54,7 +54,7 @@ module.exports = (create) => { it('should throw an error if it cannot listen on the given multiaddr', async () => { const listener = ws.createListener(() => { }) - const ma = multiaddr('/ip4/127.0.0.1/tcp/15554/ws/p2p-webrtc-star') + const ma = new Multiaddr('/ip4/127.0.0.1/tcp/15554/ws/p2p-webrtc-star') await expect(listener.listen(ma)) .to.eventually.be.rejected() @@ -62,7 +62,7 @@ module.exports = (create) => { it('getAddrs', async () => { const listener = ws.createListener(() => {}) - const ma = multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star') + const ma = new Multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star') await listener.listen(ma) @@ -74,7 +74,7 @@ module.exports = (create) => { it('getAddrs with peer id', async () => { const listener = ws.createListener(() => {}) - const ma = multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooooA') + const ma = new Multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooooA') await listener.listen(ma) diff --git a/test/transport/reconnect.node.js b/test/transport/reconnect.node.js index 5fb9ce8c..1d3c0917 100644 --- a/test/transport/reconnect.node.js +++ b/test/transport/reconnect.node.js @@ -3,7 +3,7 @@ 'use strict' const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const sigServer = require('../../src/sig-server') const SERVER_PORT = 13580 @@ -14,7 +14,7 @@ module.exports = (create) => { let ws1 let ws2 let ws3 - const signallerAddr = multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star') + const signallerAddr = new Multiaddr('/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star') before(async () => { sigS = await sigServer.start({ port: SERVER_PORT }) diff --git a/test/transport/track.js b/test/transport/track.js index a7f52c95..88622b49 100644 --- a/test/transport/track.js +++ b/test/transport/track.js @@ -4,7 +4,7 @@ 'use strict' const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const pipe = require('it-pipe') const pWaitFor = require('p-wait-for') @@ -16,9 +16,9 @@ module.exports = (create) => { let listener let remoteListener - const maHSDNS = multiaddr('/dns/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star') - const maHSIP = multiaddr('/ip4/188.166.203.82/tcp/20000/wss/p2p-webrtc-star') - const maLS = multiaddr('/ip4/127.0.0.1/tcp/15555/wss/p2p-webrtc-star') + const maHSDNS = new Multiaddr('/dns/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star') + const maHSIP = new Multiaddr('/ip4/188.166.203.82/tcp/20000/wss/p2p-webrtc-star') + const maLS = new Multiaddr('/ip4/127.0.0.1/tcp/15555/wss/p2p-webrtc-star') if (process.env.WEBRTC_STAR_REMOTE_SIGNAL_DNS) { // test with deployed signalling server using DNS @@ -44,6 +44,10 @@ module.exports = (create) => { await Promise.all([listener.listen(ma), remoteListener.listen(ma)]) }) + afterEach(async () => { + await Promise.all([listener, remoteListener].map(l => l.close())) + }) + it('should untrack conn after being closed', async function () { this.timeout(20e3) expect(listener.__connections).to.have.lengthOf(0) diff --git a/test/utils.spec.js b/test/utils.spec.js index 73ce9537..2b1db8b7 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -3,7 +3,7 @@ 'use strict' const { expect } = require('aegir/utils/chai') -const multiaddr = require('multiaddr') +const { Multiaddr } = require('multiaddr') const { cleanMultiaddr } = require('../src/utils') const { cleanUrlSIO } = require('../src/utils') @@ -23,14 +23,14 @@ describe('utils', () => { const invalidMultiaddrStringDNS3 = '/dns4/star-signal.cloud.ipfs.team/ws/p2p-webrtc-star/p2p/QmWxLfixekyv6GAzvDEtXfXjj7gb1z3G8i5aQNHLhw1zA1' // Create actual multiaddrs - const modernMultiaddrDNS = multiaddr(modernMultiaddrStringDNS) - const modernMultiaddrDNS2 = multiaddr(modernMultiaddrStringDNS2) - const modernMultiaddrDNS3 = multiaddr(modernMultiaddrStringDNS3) - const modernMultiaddrDNS4 = multiaddr(modernMultiaddrStringDNS4) + const modernMultiaddrDNS = new Multiaddr(modernMultiaddrStringDNS) + const modernMultiaddrDNS2 = new Multiaddr(modernMultiaddrStringDNS2) + const modernMultiaddrDNS3 = new Multiaddr(modernMultiaddrStringDNS3) + const modernMultiaddrDNS4 = new Multiaddr(modernMultiaddrStringDNS4) - const invalidMultiaddrDNS = multiaddr(invalidMultiaddrStringDNS) - const invalidMultiaddrDNS2 = multiaddr(invalidMultiaddrStringDNS2) - const invalidMultiaddrDNS3 = multiaddr(invalidMultiaddrStringDNS3) + const invalidMultiaddrDNS = new Multiaddr(invalidMultiaddrStringDNS) + const invalidMultiaddrDNS2 = new Multiaddr(invalidMultiaddrStringDNS2) + const invalidMultiaddrDNS3 = new Multiaddr(invalidMultiaddrStringDNS3) it('cleanUrlSIO webrtc-star modern', () => { const newUrlSIOStringDNS = cleanUrlSIO(modernMultiaddrDNS)