Skip to content

Commit c718f2e

Browse files
committed
fix: updated max reservations + removed ping (#35)
1 parent 9ab2b5c commit c718f2e

File tree

3 files changed

+13
-32
lines changed

3 files changed

+13
-32
lines changed

packages/frontend/src/lib/libp2p.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { webSockets } from '@libp2p/websockets'
1414
import { webTransport } from '@libp2p/webtransport'
1515
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
1616
import { BOOTSTRAP_NODE, CHAT_TOPIC, CIRCUIT_RELAY_CODE } from './constants'
17-
import * as filters from "@libp2p/websockets/filters"
1817

1918
// @ts-ignore
2019
import { circuitRelayTransport } from 'libp2p/circuit-relay'
@@ -27,9 +26,7 @@ export async function startLibp2p() {
2726
// libp2p is the networking layer that underpins Helia
2827
const libp2p = await createLibp2p({
2928
dht: kadDHT({protocolPrefix: "/universal-connectivity"}),
30-
transports: [webTransport(), webSockets({
31-
filter: filters.all,
32-
}), webRTC({
29+
transports: [webTransport(), webSockets(), webRTC({
3330
rtcConfiguration: {
3431
iceServers:[
3532
{
@@ -41,7 +38,7 @@ export async function startLibp2p() {
4138
]
4239
}
4340
}), webRTCDirect(), circuitRelayTransport({
44-
discoverRelays: 1,
41+
discoverRelays: 10,
4542
}),],
4643
connectionEncryption: [noise()],
4744
connectionManager: {
@@ -52,7 +49,8 @@ export async function startLibp2p() {
5249
peerDiscovery: [
5350
bootstrap({
5451
list: [
55-
BOOTSTRAP_NODE,
52+
// BOOTSTRAP_NODE,
53+
'/ip4/127.0.0.1/udp/9090/webrtc-direct/certhash/uEiA2twAWww-g6fXsJe6JPlROwCHbRj6fNgr_WHxiQGEK3g/p2p/12D3KooWLTB1SrjyF8R5Z1MKErcV8abs26eo4LpadQKWsxMUcDBJ',
5654
],
5755
}),
5856
],

packages/frontend/src/pages/index.tsx

-25
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,6 @@ export default function Home() {
1313
const { libp2p } = useLibp2pContext()
1414
const { peerStats, setPeerStats } = usePeerContext()
1515

16-
useInterval(() => {
17-
18-
const ping = async () => {
19-
const { peerIds } = peerStats
20-
if (peerIds.length > 0) {
21-
return libp2p.ping(peerIds[0])
22-
}
23-
24-
return 0
25-
}
26-
27-
ping()
28-
.then((latency) => {
29-
setPeerStats({ ...peerStats, latency })
30-
})
31-
.catch((e) => {
32-
console.error(e, e?.error)
33-
})
34-
}, 5000)
35-
3616
useEffect(() => {
3717
const peerConnectedCB = (evt: CustomEvent<Connection>) => {
3818
const connection = evt.detail
@@ -91,11 +71,6 @@ export default function Home() {
9171
) : (
9272
<XCircleIcon className="w-6 h-6 text-red-500" />
9373
)}
94-
<p className='mx-auto max-w-7xl px-2 sm:px-6 lg:px-8'>
95-
{peerStats.latency > 0
96-
? `Latency of nearest peer: ${peerStats.latency} ms`
97-
: null}
98-
</p>
9974
</div>
10075
<div>
10176
{peerStats.peerIds.length > 0 ? (

rust-peer/src/main.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,15 @@ fn create_swarm(
271271
kademlia: kad_behaviour,
272272
keep_alive: keep_alive::Behaviour::default(),
273273
ping: ping::Behaviour::default(),
274-
relay: relay::Behaviour::new(local_peer_id, Default::default()),
274+
relay: relay::Behaviour::new(
275+
local_peer_id,
276+
relay::Config {
277+
max_reservations: 400,
278+
max_circuit_duration: Duration::from_secs(100 * 100),
279+
max_reservations_per_peer: 10,
280+
..Default::default()
281+
},
282+
),
275283
};
276284
Ok(SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build())
277285
}

0 commit comments

Comments
 (0)