-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use randomwalk to find circuit relay servers (#2563)
Instead of publishing provider records for a pre-shared CID to find circuit relay servers, perform a random walk and attempt to make a reservation on any relay peers discovered. Fixes #2545
- Loading branch information
1 parent
757fb26
commit 440c9b3
Showing
19 changed files
with
608 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/integration-tests/test/circuit-relay-discovery.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ['error', 6] */ | ||
|
||
import { noise } from '@chainsafe/libp2p-noise' | ||
import { yamux } from '@chainsafe/libp2p-yamux' | ||
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' | ||
import { identify } from '@libp2p/identify' | ||
import { stop } from '@libp2p/interface' | ||
import { mplex } from '@libp2p/mplex' | ||
import { plaintext } from '@libp2p/plaintext' | ||
import { webSockets } from '@libp2p/websockets' | ||
import * as filters from '@libp2p/websockets/filters' | ||
import { webTransport } from '@libp2p/webtransport' | ||
import { multiaddr } from '@multiformats/multiaddr' | ||
import { WebSockets, WebTransport } from '@multiformats/multiaddr-matcher' | ||
import { createLibp2p } from 'libp2p' | ||
import { hasRelay, isFirefox } from './fixtures/utils.js' | ||
import type { Libp2p } from '@libp2p/interface' | ||
|
||
describe('circuit-relay discovery', () => { | ||
let node: Libp2p | ||
|
||
beforeEach(async () => { | ||
node = await createLibp2p({ | ||
transports: [ | ||
webSockets({ | ||
filter: filters.all | ||
}), | ||
circuitRelayTransport({ | ||
discoverRelays: 1 | ||
}), | ||
webTransport() | ||
], | ||
streamMuxers: [ | ||
yamux(), | ||
mplex() | ||
], | ||
connectionEncryption: [ | ||
plaintext(), | ||
noise() | ||
], | ||
connectionGater: { | ||
denyDialMultiaddr: () => false | ||
}, | ||
services: { | ||
identify: identify() | ||
} | ||
}) | ||
}) | ||
|
||
afterEach(async () => { | ||
await stop(node) | ||
}) | ||
|
||
it('should reserve slot on go relay via WebSockets', async () => { | ||
const ma = (process.env.GO_RELAY_MULTIADDRS ?? '') | ||
.split(',') | ||
.map(ma => multiaddr(ma)) | ||
.filter(ma => WebSockets.matches(ma)) | ||
.pop() | ||
|
||
if (ma == null) { | ||
throw new Error('Could not detect go relay WebSocket address') | ||
} | ||
|
||
// dial the relay | ||
await node.dial(ma) | ||
|
||
// wait for a reservation to be made | ||
await hasRelay(node) | ||
}) | ||
|
||
it('should reserve slot on go relay via WebTransport', async function () { | ||
if (globalThis.WebTransport == null) { | ||
return this.skip() | ||
} | ||
|
||
if (isFirefox) { | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1899812 | ||
return this.skip() | ||
} | ||
|
||
const ma = (process.env.GO_RELAY_MULTIADDRS ?? '') | ||
.split(',') | ||
.map(ma => multiaddr(`${ma}/p2p/${process.env.GO_RELAY_PEER}`)) | ||
.filter(ma => WebTransport.matches(ma)) | ||
.pop() | ||
|
||
if (ma == null) { | ||
throw new Error('Could not detect go relay WebSocket address') | ||
} | ||
|
||
// dial the relay | ||
await node.dial(ma) | ||
|
||
// wait for a reservation to be made | ||
await hasRelay(node) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.