chore: clean up bootstrap connection code (#136)

* feat: create circuit relay reservations on bootstrappers

* feat: persistent peer id in js-peer

* fix: pass relay listen addrs to libp2p

* Revert "feat: persistent peer id in js-peer"

Turns out this is a bad idea in a browser that can have multiple tabs
open and you don't want them to share the same peer ID

This reverts commit 50175a2fc9aff0668c399f88dc3f16636a39ee57.

* fix: import missing type

* chore: clean up bootstrap connection code

---------

Co-authored-by: Daniel N <2color@users.noreply.github.com>
This commit is contained in:
Daniel Norman
2024-05-03 16:17:16 +02:00
committed by GitHub
parent 6354a4abb2
commit eef2cf4fe9
2 changed files with 8 additions and 16 deletions

View File

@@ -4,9 +4,10 @@ export const FILE_EXCHANGE_PROTOCOL = "/universal-connectivity-file/1"
export const CIRCUIT_RELAY_CODE = 290
// 👇 The multiaddrs below are ephemeral and not recommended for use as they expire after a couple of weeks. Instead PeerIDs with peer routing is used
// export const WEBRTC_BOOTSTRAP_MULTIADDR = "/ip4/147.28.186.157/udp/9090/webrtc-direct/certhash/uEiBbC9bbdvraVWDvcvCEdJAWDymmUqiJQ964FuyEq0hELw/p2p/12D3KooWGahRw3ZnM4gAyd9FK75v4Bp5keFYTvkcAwhpEm28wbV3"
// export const WEBTRANSPORT_BOOTSTRAP_MULTIADDR = "/ip4/147.28.186.157/udp/9095/quic-v1/webtransport/certhash/uEiCmLPMgXJ1F1wQ-OgOWJEVa_SYB_jLSf5IkQ_d3V98GBQ/certhash/uEiB-ti6URtr64LV8HYDMvZzzzrb1iNEIT-vGY0yd6UYk2g/p2p/12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr"
// 👇 App specific dedicated bootstrap PeerIDs
// Their multiaddrs are ephemeral so peer routing is used to resolve multiaddr
export const WEBRTC_BOOTSTRAP_PEER_ID = "12D3KooWGahRw3ZnM4gAyd9FK75v4Bp5keFYTvkcAwhpEm28wbV3"
export const WEBTRANSPORT_BOOTSTRAP_PEER_ID = "12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr"
export const WEBTRANSPORT_BOOTSTRAP_PEER_ID = "12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr"
export const BOOTSTRAP_PEER_IDS = [WEBTRANSPORT_BOOTSTRAP_PEER_ID, WEBRTC_BOOTSTRAP_PEER_ID]

View File

@@ -16,14 +16,7 @@ import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { webSockets } from '@libp2p/websockets'
import { webTransport } from '@libp2p/webtransport'
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
import {
CHAT_FILE_TOPIC,
CHAT_TOPIC,
WEBRTC_BOOTSTRAP_PEER_ID,
WEBTRANSPORT_BOOTSTRAP_PEER_ID,
} from './constants'
import * as filters from '@libp2p/websockets/filters'
import { BOOTSTRAP_PEER_IDS, CHAT_FILE_TOPIC, CHAT_TOPIC } from './constants'
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import first from 'it-first'
@@ -140,10 +133,8 @@ export const connectToMultiaddr = (libp2p: Libp2p) => async (multiaddr: Multiadd
async function getBootstrapMultiaddrs(
client: DelegatedRoutingV1HttpApiClient,
): Promise<BootstrapsMultiaddrs> {
const peers = await Promise.all([
first(client.getPeers(peerIdFromString(WEBTRANSPORT_BOOTSTRAP_PEER_ID))),
first(client.getPeers(peerIdFromString(WEBRTC_BOOTSTRAP_PEER_ID))),
])
const peers = await Promise.all(BOOTSTRAP_PEER_IDS.map(peerId => first(client.getPeers(peerIdFromString(peerId)))))
const bootstrapAddrs = []
const relayListenAddrs = []
for (const p of peers) {