From 69ded0b7d9924068edf2416b20276b3f219fe5f9 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 18 Nov 2021 00:38:12 +0100 Subject: [PATCH 1/5] chore: switch CI to go-ipfs/pull/8522 --- .github/workflows/test.yml | 4 ++-- scripts/custom-runtime.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9e144310..81998506 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,8 +7,8 @@ on: # To run CI against unrelased go-ipfs or js-ipfs-* code (eg. wip PR), # uncomment env below and define git revisions in ./scripts/custom-runtime.sh -#env: - #IPFS_GO_EXEC: /tmp/go-ipfs/cmd/ipfs/ipfs +env: + IPFS_GO_EXEC: /tmp/go-ipfs/cmd/ipfs/ipfs #IPFS_JS_EXEC: /tmp/js-ipfs/packages/ipfs/src/cli.js #IPFS_JS_MODULE: /tmp/js-ipfs/packages/ipfs/dist/cjs/src/index.js #IPFS_JS_HTTP_MODULE: /tmp/js-ipfs/packages/ipfs-http-client/dist/cjs/src/index.js diff --git a/scripts/custom-runtime.sh b/scripts/custom-runtime.sh index c68d75f6..58196ebc 100755 --- a/scripts/custom-runtime.sh +++ b/scripts/custom-runtime.sh @@ -25,7 +25,7 @@ if [ ! -d /tmp/go-ipfs ]; then git clone https://github.com/ipfs/go-ipfs.git cd go-ipfs # set implementation to specific commit - git checkout CHANGEME_GO + git checkout b526b280cd773755abce0628d2a2f4eea4199673 make build fi fi From 278e2a0901010575ddfda10d5bd6432dec8d07d0 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 18 Nov 2021 01:38:04 +0100 Subject: [PATCH 2/5] feat: circuit relay v2 Needed for: https://github.com/ipfs/go-ipfs/pull/8522 --- .github/workflows/test.yml | 2 + .gitignore | 4 +- package-lock.json | 6 +- package.json | 11 +++- scripts/relayd_v1.config.json | 15 +++++ scripts/relayd_v2.config.json | 15 +++++ scripts/setup-relayd.sh | 14 +++++ test/circuit.js | 97 +++++++++++++++++++++++-------- test/circuit/all.js | 65 --------------------- test/circuit/v1/all.js | 93 ++++++++++++++++++++++++++++++ test/circuit/{ => v1}/browser.js | 86 ++++++++++++++++----------- test/circuit/v2/all.js | 72 +++++++++++++++++++++++ test/circuit/v2/browser.js | 42 ++++++++++++++ test/utils/circuit.js | 99 +++++++++++++++++++++++++++++--- test/utils/relayd.js | 46 +++++++++++++++ 15 files changed, 529 insertions(+), 138 deletions(-) create mode 100644 scripts/relayd_v1.config.json create mode 100644 scripts/relayd_v2.config.json create mode 100755 scripts/setup-relayd.sh delete mode 100644 test/circuit/all.js create mode 100644 test/circuit/v1/all.js rename test/circuit/{ => v1}/browser.js (69%) create mode 100644 test/circuit/v2/all.js create mode 100644 test/circuit/v2/browser.js create mode 100644 test/utils/relayd.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 81998506..ddd99dd7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -106,6 +106,7 @@ jobs: type: - browser - webworker + fail-fast: false steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 @@ -137,6 +138,7 @@ jobs: type: - electron-main - electron-renderer + fail-fast: false steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 diff --git a/.gitignore b/.gitignore index 729bf0ce..badb10b3 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,6 @@ dist test/test-data/go-ipfs-repo/LOCK test/test-data/go-ipfs-repo/LOG test/test-data/go-ipfs-repo/LOG.old -types \ No newline at end of file +types +go-libp2p-relay-daemon +*.identity diff --git a/package-lock.json b/package-lock.json index 166641b6..7409ef89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "ipfs-interop", "version": "7.0.5", + "hasInstallScript": true, "license": "MIT", "dependencies": { "aegir": "^35.0.2", @@ -36,7 +37,7 @@ "promisify-es6": "^1.0.3", "random-fs": "^1.0.3", "readable-stream-buffer-stream": "^1.0.0", - "rimraf": "^3.0.0", + "rimraf": "^3.0.2", "uint8arrays": "^3.0.0", "wherearewe": "^1.0.0" }, @@ -44,12 +45,13 @@ "ipfs-interop": "bin/ipfs-interop.js" }, "devDependencies": { + "execa": "^5.1.1", "go-ipfs": "^0.9.1", "ipfs": "^0.59.0", "ipfs-http-client": "^53.0.0" }, "engines": { - "node": ">=12.0.0", + "node": ">=16.0.0", "npm": ">6.0.0" } }, diff --git a/package.json b/package.json index 05c102bf..3d6ebf65 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,8 @@ "npm": ">6.0.0" }, "scripts": { + "postinstall": "./scripts/setup-relayd.sh", + "clean": "rimraf /tmp/js-ipfs /tmp/go-ipfs ./go-libp2p-relay-daemon", "lint": "aegir lint", "build": "aegir build", "pretest": "aegir build --esm-tests", @@ -45,7 +47,9 @@ }, "homepage": "https://github.com/ipfs/interop#readme", "browser": { - "go-ipfs": false + "go-ipfs": false, + "fs": false, + "execa": false }, "dependencies": { "aegir": "^35.0.2", @@ -55,8 +59,8 @@ "delay": "^5.0.0", "detect-node": "^2.0.4", "ipfs-unixfs": "^6.0.3", - "ipfsd-ctl": "^10.0.3", "ipfs-utils": "^9.0.1", + "ipfsd-ctl": "^10.0.3", "ipns": "^0.15.0", "is-ci": "^3.0.0", "is-os": "^1.0.1", @@ -75,7 +79,7 @@ "promisify-es6": "^1.0.3", "random-fs": "^1.0.3", "readable-stream-buffer-stream": "^1.0.0", - "rimraf": "^3.0.0", + "rimraf": "^3.0.2", "uint8arrays": "^3.0.0", "wherearewe": "^1.0.0" }, @@ -97,6 +101,7 @@ "Richard Littauer " ], "devDependencies": { + "execa": "^5.1.1", "go-ipfs": "^0.9.1", "ipfs": "^0.59.0", "ipfs-http-client": "^53.0.0" diff --git a/scripts/relayd_v1.config.json b/scripts/relayd_v1.config.json new file mode 100644 index 00000000..f057058b --- /dev/null +++ b/scripts/relayd_v1.config.json @@ -0,0 +1,15 @@ +{ + "RelayV1": { + "Enabled": true + }, + "RelayV2": { + "Enabled": false + }, + "Network": { + "ListenAddrs": ["/ip4/127.0.0.1/tcp/14111/ws"], + "AnnounceAddrs": ["/ip4/127.0.0.1/tcp/14111/ws"] + }, + "Daemon": { + "PprofPort": -1 + } +} diff --git a/scripts/relayd_v2.config.json b/scripts/relayd_v2.config.json new file mode 100644 index 00000000..38af707f --- /dev/null +++ b/scripts/relayd_v2.config.json @@ -0,0 +1,15 @@ +{ + "RelayV1": { + "Enabled": false + }, + "RelayV2": { + "Enabled": true + }, + "Network": { + "ListenAddrs": ["/ip4/127.0.0.1/tcp/24222/ws"], + "AnnounceAddrs": ["/ip4/127.0.0.1/tcp/24222/ws"] + }, + "Daemon": { + "PprofPort": -1 + } +} diff --git a/scripts/setup-relayd.sh b/scripts/setup-relayd.sh new file mode 100755 index 00000000..cdc61f6f --- /dev/null +++ b/scripts/setup-relayd.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# This script ensures go-libp2p-relay-daemon is available +# for use in circuit v1 and v2 tests. + +set -eo pipefail + +if ! type relayd; then + git clone https://github.com/libp2p/go-libp2p-relay-daemon.git + cd go-libp2p-relay-daemon + # no releases atm, so we pin implementation to specific commit + git checkout 65211a0b6d881086feb7c386d780f55c37dff101 # 2021-11-19 + go install ./... +fi diff --git a/test/circuit.js b/test/circuit.js index 809f42ce..ee7c333d 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -1,10 +1,13 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import all from './circuit/all.js' -import browser from './circuit/browser.js' +import allV1 from './circuit/v1/all.js' +import allV2 from './circuit/v2/all.js' +import browserV1 from './circuit/v1/browser.js' +import browserV2 from './circuit/v2/browser.js' import isNode from 'detect-node' import { connect, send, clean } from './utils/circuit.js' +import { closeRelays } from './utils/relayd.js' import { daemonFactory } from './utils/daemon-factory.js' const timeout = 80 * 1000 @@ -15,40 +18,84 @@ const baseTest = { } describe('circuit', () => { - let factory + after(closeRelays) - before(async () => { - factory = await daemonFactory() - }) + // Legacy v1 (unlimited relay) + describe('v1', () => { + let factory - const tests = isNode ? all : browser + before(async () => { + factory = await daemonFactory() + }) - Object.keys(tests).forEach((test) => { - let nodeA - let relay - let nodeB + const tests = isNode ? allV1 : browserV1 - tests[test] = Object.assign({}, baseTest, tests[test]) + Object.keys(tests).forEach((test) => { + let nodeA + let relay + let nodeB - const dsc = tests[test].skip && tests[test].skip() - ? describe.skip - : describe + tests[test] = Object.assign({}, baseTest, tests[test]) - dsc(test, function () { - this.timeout(tests[test].timeout) + const dsc = tests[test].skip && tests[test].skip() + ? describe.skip + : describe - before(async () => { - [nodeA, relay, nodeB] = await tests[test].create(factory) - }) + dsc(test, function () { + this.timeout(tests[test].timeout) + + before(async () => { + [nodeA, relay, nodeB] = await tests[test].create(factory) + }) + + after(() => clean(factory)) - after(() => clean(factory)) + it('connect', () => { + return tests[test].connect(nodeA, nodeB, relay) + }) - it('connect', () => { - return tests[test].connect(nodeA, nodeB, relay) + it('send', () => { + return tests[test].send(nodeA, nodeB) + }) }) + }) + }) + + // Modern v2 (limited relay) + // https://github.com/libp2p/specs/blob/master/relay/circuit-v2.md + describe('v2', () => { + let factory + + before(async () => { + factory = await daemonFactory() + }) + + const tests = isNode ? allV2 : browserV2 + + Object.keys(tests).forEach((test) => { + let nodeA + let relay + let nodeB + + tests[test] = Object.assign({}, baseTest, tests[test]) + + const dsc = tests[test].skip && tests[test].skip() + ? describe.skip + : describe + + dsc(test, function () { + this.timeout(tests[test].timeout) + + before(async () => { + [nodeA, relay, nodeB] = await tests[test].create(factory) + }) + + after(() => clean(factory)) - it('send', () => { - return tests[test].send(nodeA, nodeB) + it('connect', () => { + return tests[test].connect(nodeA, nodeB, relay) + }) + // Note: v2 provides a limited relay for things like hole punching – no send test }) }) }) diff --git a/test/circuit/all.js b/test/circuit/all.js deleted file mode 100644 index e4c76ef6..00000000 --- a/test/circuit/all.js +++ /dev/null @@ -1,65 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-env mocha */ - -import { createJs, createGo } from '../utils/circuit.js' - -const base = '/ip4/127.0.0.1/tcp/0' - -export default { - 'go-go-go': { - create: (factory) => Promise.all([ - createGo([`${base}/ws`], factory), - createGo([`${base}/ws`], factory), - createGo([`${base}/ws`], factory) - ]) - }, - 'js-go-go': { - create: (factory) => Promise.all([ - createJs([`${base}/ws`], factory), - createGo([`${base}/ws`], factory), - createGo([`${base}/ws`], factory) - ]) - }, - 'go-go-js': { - create: (factory) => Promise.all([ - createGo([`${base}/ws`], factory), - createGo([`${base}/ws`], factory), - createJs([`${base}/ws`], factory) - ]) - }, - 'js-go-js': { - create: (factory) => Promise.all([ - createJs([`${base}/ws`], factory), - createGo([`${base}/ws`], factory), - createJs([`${base}/ws`], factory) - ]) - }, - 'go-js-go': { - create: (factory) => Promise.all([ - createGo([`${base}/ws`], factory), - createJs([`${base}/ws`], factory), - createGo([`${base}/ws`], factory) - ]) - }, - 'js-js-go': { - create: (factory) => Promise.all([ - createJs([`${base}/ws`], factory), - createJs([`${base}/ws`], factory), - createGo([`${base}/ws`], factory) - ]) - }, - 'go-js-js': { - create: (factory) => Promise.all([ - createGo([`${base}/ws`], factory), - createJs([`${base}/ws`], factory), - createJs([`${base}/ws`], factory) - ]) - }, - 'js-js-js': { - create: (factory) => Promise.all([ - createJs([`${base}/ws`], factory), - createJs([`${base}/ws`], factory), - createJs([`${base}/ws`], factory) - ]) - } -} diff --git a/test/circuit/v1/all.js b/test/circuit/v1/all.js new file mode 100644 index 00000000..35abea40 --- /dev/null +++ b/test/circuit/v1/all.js @@ -0,0 +1,93 @@ +/* eslint max-nested-callbacks: ["error", 8] */ +/* eslint-env mocha */ + +import { createJs, createGo, randomWsAddr } from '../../utils/circuit.js' +import { getRelayV } from '../../utils/relayd.js' + +export default { + + // rv1 is a standalone, reference implementation of circuit relay v1 + // (https://github.com/libp2p/go-libp2p-relay-daemon) + + 'go-rv1-go': { + create: async (factory) => { + const relay = await getRelayV(1) + return Promise.all([ + createGo([randomWsAddr], factory), + relay, + createGo([randomWsAddr], factory) + ]) + } + }, + + 'js-rv1-js': { + create: async (factory) => { + const relay = await getRelayV(1) + return Promise.all([ + createJs([randomWsAddr], factory), + relay, + createJs([randomWsAddr], factory) + ]) + } + }, + + 'js-rv1-go': { + create: async (factory) => { + const relay = await getRelayV(1) + return Promise.all([ + createJs([randomWsAddr], factory), + relay, + createGo([randomWsAddr], factory) + ]) + } + }, + + 'go-rv1-js': { + create: async (factory) => { + const relay = await getRelayV(1) + return Promise.all([ + createGo([randomWsAddr], factory), + relay, + createJs([randomWsAddr], factory) + ]) + } + }, + + // Below are legacy tests that use js-ipfs as v1 relay + // (no tests for go-ipfs as relay v1, because since 0.11 it only supports v2) + // FIXME: remove after js-ipfs migrates to v2 + + 'go-js-go': { + create: async (factory) => { + return Promise.all([ + createGo([randomWsAddr], factory), + createJs([randomWsAddr], factory), + createGo([randomWsAddr], factory) + ]) + } + }, + 'js-js-go': { + create: async (factory) => { + return Promise.all([ + createJs([randomWsAddr], factory), + createJs([randomWsAddr], factory), + createGo([randomWsAddr], factory) + ]) + } + }, + 'go-js-js': { + create: (factory) => Promise.all([ + createGo([randomWsAddr], factory), + createJs([randomWsAddr], factory), + createJs([randomWsAddr], factory) + ]) + }, + 'js-js-js': { + create: (factory) => Promise.all([ + createJs([randomWsAddr], factory), + createJs([randomWsAddr], factory), + createJs([randomWsAddr], factory) + ]) + } + +} diff --git a/test/circuit/browser.js b/test/circuit/v1/browser.js similarity index 69% rename from test/circuit/browser.js rename to test/circuit/v1/browser.js index f72aa18d..b29ef32c 100644 --- a/test/circuit/browser.js +++ b/test/circuit/v1/browser.js @@ -6,82 +6,98 @@ import { isWebWorker } from 'wherearewe' import { createJs, createGo, + createGoRelay, createProc, connWithTimeout, + randomWsAddr, getWsAddr, getWrtcStarAddr -} from '../utils/circuit.js' - -const base = '/ip4/127.0.0.1/tcp/0' +} from '../../utils/circuit.js' export default { 'browser-go-js': { - create: (factory) => Promise.all([ - createProc([], factory), - createGo([`${base}/ws`], factory), - createJs([`${base}/ws`], factory) - ]), + skip: () => true, // FIXME when we have circuit v2 in js-ipfs and webrtc signaling + create: async (factory) => { + const relay = await createGoRelay([randomWsAddr], factory) + return Promise.all([ + createProc([], factory), + relay, + createJs([randomWsAddr], factory, relay) + ]) + }, connect: connWithTimeout(1500) }, 'browser-go-go': { - create: (factory) => Promise.all([ - createProc([], factory), - createGo([`${base}/ws`], factory), - createGo([`${base}/ws`], factory) - ]), + skip: () => true, // FIXME when we have circuit v2 in js-ipfs and webrtc signaling + create: async (factory) => { + const relay = await createGoRelay([randomWsAddr], factory) + return Promise.all([ + createProc([], factory), + relay, + createGo([randomWsAddr], factory, relay) + ]) + }, connect: connWithTimeout(1500) }, 'browser-js-js': { create: (factory) => Promise.all([ createProc([], factory), - createJs([`${base}/ws`], factory), - createJs([`${base}/ws`], factory) + createJs([randomWsAddr], factory), + createJs([randomWsAddr], factory) ]), connect: connWithTimeout(1500) }, 'browser-js-go': { create: (factory) => Promise.all([ createProc([], factory), - createJs([`${base}/ws`], factory), - createGo([`${base}/ws`], factory) + createJs([randomWsAddr], factory), + createGo([randomWsAddr], factory) ]), connect: connWithTimeout(1500) }, 'js-go-browser': { - create: (factory) => Promise.all([ - createJs([`${base}/ws`], factory), - createGo([`${base}/ws`], factory), - createProc([], factory) - ]), + skip: () => true, // FIXME when we have circuit v2 in js-ipfs and webrtc signaling + create: async (factory) => { + const relay = await createGoRelay([randomWsAddr], factory) + return Promise.all([ + createJs([randomWsAddr], factory), + relay, + createProc([], factory, relay) + ]) + }, connect: connWithTimeout(1500) }, 'go-go-browser': { - create: (factory) => Promise.all([ - createGo([`${base}/ws`], factory), - createGo([`${base}/ws`], factory), - createProc([], factory) - ]), + skip: () => true, // FIXME when we have circuit v2 in js-ipfs and webrtc signaling + create: async (factory) => { + const relay = await createGoRelay([randomWsAddr], factory) + return Promise.all([ + createGo([randomWsAddr], factory), + relay, + createProc([], factory) + ]) + }, connect: connWithTimeout(1500) }, 'js-js-browser': { create: (factory) => Promise.all([ - createJs([`${base}/ws`], factory), - createJs([`${base}/ws`], factory), + createJs([randomWsAddr], factory), + createJs([randomWsAddr], factory), createProc([], factory) ]), connect: connWithTimeout(1500) }, 'go-js-browser': { create: (factory) => Promise.all([ - createGo([`${base}/ws`], factory), - createJs([`${base}/ws`], factory), + createGo([randomWsAddr], factory), + createJs([randomWsAddr], factory), createProc([], factory) ]), connect: connWithTimeout(1500) }, 'go-browser-browser': { create: (factory) => Promise.all([ - createGo([`${base}/ws`], factory), + createGo([randomWsAddr], factory), createProc(['/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'], factory), createProc(['/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'], factory) ]), @@ -97,7 +113,7 @@ export default { }, 'js-browser-browser': { create: (factory) => Promise.all([ - createJs([`${base}/ws`], factory), + createJs([randomWsAddr], factory), createProc(['/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'], factory), createProc(['/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'], factory) ]), @@ -115,7 +131,7 @@ export default { create: (factory) => Promise.all([ createProc(['/ip4/127.0.0.1/tcp/24642/wss/p2p-webrtc-star'], factory), createProc(['/ip4/127.0.0.1/tcp/24642/wss/p2p-webrtc-star'], factory), - createGo([`${base}/ws`], factory) + createGo([randomWsAddr], factory) ]), connect: async (nodeA, nodeB, relay) => { await relay.api.swarm.connect(getWrtcStarAddr(nodeA.api.peerId.addresses)) @@ -131,7 +147,7 @@ export default { create: (factory) => Promise.all([ createProc(['/ip4/127.0.0.1/tcp/24642/wss/p2p-webrtc-star'], factory), createProc(['/ip4/127.0.0.1/tcp/24642/wss/p2p-webrtc-star'], factory), - createJs([`${base}/ws`], factory) + createJs([randomWsAddr], factory) ]), connect: async (nodeA, nodeB, relay) => { await relay.api.swarm.connect(getWrtcStarAddr(nodeA.api.peerId.addresses)) diff --git a/test/circuit/v2/all.js b/test/circuit/v2/all.js new file mode 100644 index 00000000..9425f441 --- /dev/null +++ b/test/circuit/v2/all.js @@ -0,0 +1,72 @@ +/* eslint max-nested-callbacks: ["error", 8] */ +/* eslint-env mocha */ + +import { createGo, createGoRelay, randomWsAddr } from '../../utils/circuit.js' +import { getRelayV } from '../../utils/relayd.js' + +export default { + + // rv2 is a standalone, reference implementation of circuit relay v2 + // (https://github.com/libp2p/go-libp2p-relay-daemon) + + 'go-rv2-go': { + create: async (factory) => { + const relay = await getRelayV(2) + return Promise.all([ + createGo([randomWsAddr], factory), + relay, + createGo([randomWsAddr], factory, relay) + ]) + } + }, + + 'js-rv2-js': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + }, + + 'js-rv2-go': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + }, + + 'go-rv2-js': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + }, + + // relay v2 implementation in go-ipfs 0.11+ + + 'go-go-go': { + create: async (factory) => { + const relay = await createGoRelay([randomWsAddr], factory) + return Promise.all([ + createGo([randomWsAddr], factory), + relay, + createGo([randomWsAddr], factory, relay) + ]) + } + }, + 'js-go-go': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + }, + 'go-go-js': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + }, + 'js-go-js': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + }, + + // relay v2 implementation in js-ipfs + + 'go-js-go': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + }, + 'js-js-go': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + }, + 'go-js-js': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + }, + 'js-js-js': { + skip: () => true // FIXME when we have circuit v2 in js-ipfs + } + +} diff --git a/test/circuit/v2/browser.js b/test/circuit/v2/browser.js new file mode 100644 index 00000000..df6b310f --- /dev/null +++ b/test/circuit/v2/browser.js @@ -0,0 +1,42 @@ +/* eslint max-nested-callbacks: ["error", 8] */ +/* eslint-env mocha */ + +// TODO when we have circuit v2 in js-ipfs and webrtc signaling +export default { + 'browser-go-js': { + skip: () => true + }, + 'browser-go-go': { + skip: () => true + }, + 'browser-js-js': { + skip: () => true + }, + 'browser-js-go': { + skip: () => true + }, + 'js-go-browser': { + skip: () => true + }, + 'go-go-browser': { + skip: () => true + }, + 'js-js-browser': { + skip: () => true + }, + 'go-js-browser': { + skip: () => true + }, + 'go-browser-browser': { + skip: () => true + }, + 'js-browser-browser': { + skip: () => true + }, + 'browser-browser-go': { + skip: () => true + }, + 'browser-browser-js': { + skip: () => true + } +} diff --git a/test/utils/circuit.js b/test/utils/circuit.js index 2d28252e..c0fdcaa9 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -1,3 +1,4 @@ +/* eslint no-console: ["error", { allow: ["log"] }] */ import delay from 'delay' import randomBytes from 'iso-random-stream/src/random.js' import concat from 'it-concat' @@ -7,7 +8,12 @@ import { expect } from 'aegir/utils/chai.js' const transportKey = WS.prototype[Symbol.toStringTag] -export function createProc (addrs, factory) { +export const randomWsAddr = '/ip4/127.0.0.1/tcp/0/ws' + +export function createProc (addrs, factory, relay) { + if (relay) { + throw new Error('createProc missing support for static relay v2') + } return factory.spawn({ type: 'proc', ipfsOptions: { @@ -15,7 +21,7 @@ export function createProc (addrs, factory) { Addresses: { Swarm: addrs }, - relay: { + relay: { // FIXME: this is circuit v1, needs support of v2 enabled: true, hop: { enabled: true @@ -35,7 +41,10 @@ export function createProc (addrs, factory) { }) } -export function createJs (addrs, factory) { +export function createJs (addrs, factory, relay) { + if (relay) { + throw new Error('createJs missing support for static relay v2') + } return factory.spawn({ type: 'js', ipfsOptions: { @@ -43,7 +52,7 @@ export function createJs (addrs, factory) { Addresses: { Swarm: addrs }, - relay: { + relay: { // FIXME: this is circuit v1, needs support of v2 enabled: true, hop: { enabled: true @@ -54,7 +63,48 @@ export function createJs (addrs, factory) { }) } -export function createGo (addrs, factory) { +// creates "private" go-ipfs node which is uses static relay if specified +export function createGo (addrs, factory, relay) { + let StaticRelays + if (relay) { + StaticRelays = [getWsAddr(relay.api.peerId.addresses)] + } + return factory.spawn({ + type: 'go', + ipfsOptions: { + config: { + Addresses: { + Swarm: addrs + }, + Swarm: { + // go uses circuit v2 + RelayClient: { + Enabled: true, + StaticRelays + }, + RelayService: { + Enabled: false + } + }, + Bootstraps: [], + Discovery: { + MDNS: { + Enabled: false + } + }, + Routing: { + Type: 'none' + }, + Internal: { + Libp2pForceReachability: 'private' + } + } + } + }) +} + +// creates "publicly diallable" go-ipfs running a relay service +export function createGoRelay (addrs, factory) { return factory.spawn({ type: 'go', ipfsOptions: { @@ -63,8 +113,25 @@ export function createGo (addrs, factory) { Swarm: addrs }, Swarm: { - DisableRelay: false, - EnableRelayHop: true + // go uses circuit v2 + RelayClient: { + Enabled: false + }, + RelayService: { + Enabled: true + } + }, + Bootstraps: [], + Discovery: { + MDNS: { + Enabled: false + } + }, + Routing: { + Type: 'none' + }, + Internal: { + Libp2pForceReachability: 'public' } } } @@ -136,12 +203,30 @@ export function getTcpAddr (addrs) { export async function connect (nodeA, nodeB, relay, timeout = 1000) { const relayWsAddr = getWsAddr(relay.api.peerId.addresses) + const nodeAId = nodeA.api.peerId.id + const nodeBId = nodeB.api.peerId.id + + if (process.env.DEBUG) console.log(`connect A (${nodeAId}) to relay at`, relayWsAddr) await nodeA.api.swarm.connect(relayWsAddr) + + if (process.env.DEBUG) console.log(`connect B (${nodeBId}) to relay at`, relayWsAddr) await nodeB.api.swarm.connect(relayWsAddr) + // TODO: needed until https://github.com/ipfs/interop/issues/17 is resolved await delay(timeout) const nodeBCircuitAddr = `${relayWsAddr}/p2p-circuit/p2p/${nodeB.api.peerId.id}` + if (process.env.DEBUG) console.log('connect A to B over circuit', nodeBCircuitAddr) await nodeA.api.swarm.connect(nodeBCircuitAddr) + + if (process.env.DEBUG) { + console.log('done!') + const listConnections = async (name, node) => { + const peers = await node.api.swarm.peers() + console.log(`${name} has connections`, peers.map(p => `${p.addr.toString()}/p2p/${p.peer}`)) + } + await listConnections('nodeA', nodeA) + await listConnections('nodeB', nodeB) + } } export function connWithTimeout (timeout) { diff --git a/test/utils/relayd.js b/test/utils/relayd.js new file mode 100644 index 00000000..55cc41cc --- /dev/null +++ b/test/utils/relayd.js @@ -0,0 +1,46 @@ +import isNode from 'detect-node' +import fs from 'fs' +import { command } from 'execa' + +// augumentWithRelayd is the glue code that makes running relayd-based relay +// possible without changing too much in existing tests. We keep one instance +// per circuit relay version. +const relays = new Map() + +export async function getRelayV (version, factory) { + if (!isNode) return + if (relays.has(version)) return relays.get(version) + if (process.env.DEBUG) console.log(`Starting relayd_v${version}..`) // eslint-disable-line no-console + if (version < 1 || version > 2) throw new Error('Unsupported circuit relay version') + const relayd = command(`relayd -config scripts/relayd_v${version}.config.json -id scripts/relayd_v${version}.identity`) + let id + for await (const line of relayd.stdout) { + const text = line.toString() + if (process.env.DEBUG) console.log(text) // eslint-disable-line no-console + if (text.includes(`RelayV${version} is running!`)) break + if (text.includes('I am')) { + id = text.split('I am')[1].split('\n')[0].trim() + } + } + const config = JSON.parse(fs.readFileSync(`scripts/relayd_v${version}.config.json`)) + const result = { + relayd, + // Mock: make it look like other things returned by ipfsd-ctl to reuse existing code. + api: { + peerId: { + id, + addresses: [ + `${config.Network.ListenAddrs[0]}/p2p/${id}` + ] + } + } + } + relays.set(version, result) + return result +} + +export async function closeRelays () { + for (const r of relays.values()) { + r.relayd.cancel() + } +} From 360deb971990a818d080428391d27ee5c53ac20f Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 10 Nov 2021 16:46:47 -0500 Subject: [PATCH 3/5] fix: use new go-ipfs sharding option to lower the threshold to the minimum for compatibility with existing tests --- test/files.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/files.js b/test/files.js index 38e96071..ada4b896 100644 --- a/test/files.js +++ b/test/files.js @@ -18,9 +18,9 @@ class ExpectedError extends Error { const goOptions = { ipfsOptions: { config: { - // enabled sharding for go - Experimental: { - ShardingEnabled: true + // enabled sharding for go with automatic threshold dropped to the minimum + Internal: { + UnixFSShardingSizeThreshold: "1B" } } } From e1f111a6c1a855951dc67846e4a0c15f86985a62 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Tue, 23 Nov 2021 13:37:10 -0500 Subject: [PATCH 4/5] chore: switch CI to go-ipfs/pull/8563 --- scripts/custom-runtime.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/custom-runtime.sh b/scripts/custom-runtime.sh index 58196ebc..d177a7e8 100755 --- a/scripts/custom-runtime.sh +++ b/scripts/custom-runtime.sh @@ -25,7 +25,7 @@ if [ ! -d /tmp/go-ipfs ]; then git clone https://github.com/ipfs/go-ipfs.git cd go-ipfs # set implementation to specific commit - git checkout b526b280cd773755abce0628d2a2f4eea4199673 + git checkout f13fa35a68723b5702312bed4575911f7f0f2185 make build fi fi From 3004b52120a4f655c01a70cad36363a8b3ddb2f1 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 23 Nov 2021 21:37:09 +0100 Subject: [PATCH 5/5] fix: go-libp2p-relay-daemon caching on ci --- .github/workflows/test.yml | 5 +++++ scripts/custom-runtime.sh | 2 +- scripts/setup-relayd.sh | 7 +++++-- test/files.js | 2 +- test/utils/relayd.js | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ddd99dd7..5b1a34ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,6 +31,7 @@ jobs: with: path: | /tmp/*-ipfs/** + ./go-libp2p-relay-daemon ~/.npm ./node_modules key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }} @@ -56,6 +57,7 @@ jobs: with: path: | /tmp/*-ipfs/** + ./go-libp2p-relay-daemon ~/.npm ./node_modules key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }} @@ -84,6 +86,7 @@ jobs: with: path: | /tmp/*-ipfs/** + ./go-libp2p-relay-daemon ~/.npm ./node_modules key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }} @@ -119,6 +122,7 @@ jobs: with: path: | /tmp/*-ipfs/** + ./go-libp2p-relay-daemon ~/.npm ./node_modules key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }} @@ -151,6 +155,7 @@ jobs: with: path: | /tmp/*-ipfs/** + ./go-libp2p-relay-daemon ~/.npm ./node_modules key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }} diff --git a/scripts/custom-runtime.sh b/scripts/custom-runtime.sh index d177a7e8..cde8943a 100755 --- a/scripts/custom-runtime.sh +++ b/scripts/custom-runtime.sh @@ -25,7 +25,7 @@ if [ ! -d /tmp/go-ipfs ]; then git clone https://github.com/ipfs/go-ipfs.git cd go-ipfs # set implementation to specific commit - git checkout f13fa35a68723b5702312bed4575911f7f0f2185 + git checkout 8c902b156b1c35d17ce45de2525c80bf71c77b5b # https://github.com/ipfs/go-ipfs/pull/8563 make build fi fi diff --git a/scripts/setup-relayd.sh b/scripts/setup-relayd.sh index cdc61f6f..e23466d0 100755 --- a/scripts/setup-relayd.sh +++ b/scripts/setup-relayd.sh @@ -5,10 +5,13 @@ set -eo pipefail -if ! type relayd; then +if ! test -e ./go-libp2p-relay-daemon/relayd; then + echo "Building ./go-libp2p-relay-daemon/relayd binary.." + rm -rf ./go-libp2p-relay-daemon git clone https://github.com/libp2p/go-libp2p-relay-daemon.git cd go-libp2p-relay-daemon # no releases atm, so we pin implementation to specific commit git checkout 65211a0b6d881086feb7c386d780f55c37dff101 # 2021-11-19 - go install ./... + go build ./... + echo "./go-libp2p-relay-daemon/relayd is ready" fi diff --git a/test/files.js b/test/files.js index ada4b896..e1a3f4c2 100644 --- a/test/files.js +++ b/test/files.js @@ -20,7 +20,7 @@ const goOptions = { config: { // enabled sharding for go with automatic threshold dropped to the minimum Internal: { - UnixFSShardingSizeThreshold: "1B" + UnixFSShardingSizeThreshold: '1B' } } } diff --git a/test/utils/relayd.js b/test/utils/relayd.js index 55cc41cc..7af38078 100644 --- a/test/utils/relayd.js +++ b/test/utils/relayd.js @@ -12,7 +12,7 @@ export async function getRelayV (version, factory) { if (relays.has(version)) return relays.get(version) if (process.env.DEBUG) console.log(`Starting relayd_v${version}..`) // eslint-disable-line no-console if (version < 1 || version > 2) throw new Error('Unsupported circuit relay version') - const relayd = command(`relayd -config scripts/relayd_v${version}.config.json -id scripts/relayd_v${version}.identity`) + const relayd = command(`go-libp2p-relay-daemon/relayd -config scripts/relayd_v${version}.config.json -id scripts/relayd_v${version}.identity`) let id for await (const line of relayd.stdout) { const text = line.toString()