From c718f2ee0a808e714b8669b0f9229566e4c982f6 Mon Sep 17 00:00:00 2001 From: chad Date: Thu, 13 Apr 2023 20:15:13 -0500 Subject: [PATCH] fix: updated max reservations + removed ping (#35) --- packages/frontend/src/lib/libp2p.ts | 10 ++++------ packages/frontend/src/pages/index.tsx | 25 ------------------------- rust-peer/src/main.rs | 10 +++++++++- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/packages/frontend/src/lib/libp2p.ts b/packages/frontend/src/lib/libp2p.ts index 47d08848..413bd13c 100644 --- a/packages/frontend/src/lib/libp2p.ts +++ b/packages/frontend/src/lib/libp2p.ts @@ -14,7 +14,6 @@ import { webSockets } from '@libp2p/websockets' import { webTransport } from '@libp2p/webtransport' import { webRTC, webRTCDirect } from '@libp2p/webrtc' import { BOOTSTRAP_NODE, CHAT_TOPIC, CIRCUIT_RELAY_CODE } from './constants' -import * as filters from "@libp2p/websockets/filters" // @ts-ignore import { circuitRelayTransport } from 'libp2p/circuit-relay' @@ -27,9 +26,7 @@ export async function startLibp2p() { // libp2p is the networking layer that underpins Helia const libp2p = await createLibp2p({ dht: kadDHT({protocolPrefix: "/universal-connectivity"}), - transports: [webTransport(), webSockets({ - filter: filters.all, - }), webRTC({ + transports: [webTransport(), webSockets(), webRTC({ rtcConfiguration: { iceServers:[ { @@ -41,7 +38,7 @@ export async function startLibp2p() { ] } }), webRTCDirect(), circuitRelayTransport({ - discoverRelays: 1, + discoverRelays: 10, }),], connectionEncryption: [noise()], connectionManager: { @@ -52,7 +49,8 @@ export async function startLibp2p() { peerDiscovery: [ bootstrap({ list: [ - BOOTSTRAP_NODE, + // BOOTSTRAP_NODE, + '/ip4/127.0.0.1/udp/9090/webrtc-direct/certhash/uEiA2twAWww-g6fXsJe6JPlROwCHbRj6fNgr_WHxiQGEK3g/p2p/12D3KooWLTB1SrjyF8R5Z1MKErcV8abs26eo4LpadQKWsxMUcDBJ', ], }), ], diff --git a/packages/frontend/src/pages/index.tsx b/packages/frontend/src/pages/index.tsx index 210e91d7..886f6a98 100644 --- a/packages/frontend/src/pages/index.tsx +++ b/packages/frontend/src/pages/index.tsx @@ -13,26 +13,6 @@ export default function Home() { const { libp2p } = useLibp2pContext() const { peerStats, setPeerStats } = usePeerContext() - useInterval(() => { - - const ping = async () => { - const { peerIds } = peerStats - if (peerIds.length > 0) { - return libp2p.ping(peerIds[0]) - } - - return 0 - } - - ping() - .then((latency) => { - setPeerStats({ ...peerStats, latency }) - }) - .catch((e) => { - console.error(e, e?.error) - }) - }, 5000) - useEffect(() => { const peerConnectedCB = (evt: CustomEvent) => { const connection = evt.detail @@ -91,11 +71,6 @@ export default function Home() { ) : ( )} -

- {peerStats.latency > 0 - ? `Latency of nearest peer: ${peerStats.latency} ms` - : null} -

{peerStats.peerIds.length > 0 ? ( diff --git a/rust-peer/src/main.rs b/rust-peer/src/main.rs index 23a85732..563001a1 100644 --- a/rust-peer/src/main.rs +++ b/rust-peer/src/main.rs @@ -271,7 +271,15 @@ fn create_swarm( kademlia: kad_behaviour, keep_alive: keep_alive::Behaviour::default(), ping: ping::Behaviour::default(), - relay: relay::Behaviour::new(local_peer_id, Default::default()), + relay: relay::Behaviour::new( + local_peer_id, + relay::Config { + max_reservations: 400, + max_circuit_duration: Duration::from_secs(100 * 100), + max_reservations_per_peer: 10, + ..Default::default() + }, + ), }; Ok(SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build()) }