Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
feat: circuit relay v2
Browse files Browse the repository at this point in the history
Needed for:
ipfs/kubo#8522
  • Loading branch information
lidel committed Nov 29, 2021
1 parent 69ded0b commit 278e2a0
Show file tree
Hide file tree
Showing 15 changed files with 529 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ jobs:
type:
- browser
- webworker
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down Expand Up @@ -137,6 +138,7 @@ jobs:
type:
- electron-main
- electron-renderer
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
types
go-libp2p-relay-daemon
*.identity
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"
},
Expand All @@ -97,6 +101,7 @@
"Richard Littauer <richard.littauer@gmail.com>"
],
"devDependencies": {
"execa": "^5.1.1",
"go-ipfs": "^0.9.1",
"ipfs": "^0.59.0",
"ipfs-http-client": "^53.0.0"
Expand Down
15 changes: 15 additions & 0 deletions scripts/relayd_v1.config.json
Original file line number Diff line number Diff line change
@@ -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
}
}
15 changes: 15 additions & 0 deletions scripts/relayd_v2.config.json
Original file line number Diff line number Diff line change
@@ -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
}
}
14 changes: 14 additions & 0 deletions scripts/setup-relayd.sh
Original file line number Diff line number Diff line change
@@ -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
97 changes: 72 additions & 25 deletions test/circuit.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
})
})
})
Expand Down
65 changes: 0 additions & 65 deletions test/circuit/all.js

This file was deleted.

Loading

0 comments on commit 278e2a0

Please sign in to comment.