Skip to content

Commit

Permalink
fix: updated max reservations + removed ping (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Apr 14, 2023
1 parent 9ab2b5c commit c718f2e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
10 changes: 4 additions & 6 deletions packages/frontend/src/lib/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:[
{
Expand All @@ -41,7 +38,7 @@ export async function startLibp2p() {
]
}
}), webRTCDirect(), circuitRelayTransport({
discoverRelays: 1,
discoverRelays: 10,
}),],
connectionEncryption: [noise()],
connectionManager: {
Expand All @@ -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',
],
}),
],
Expand Down
25 changes: 0 additions & 25 deletions packages/frontend/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection>) => {
const connection = evt.detail
Expand Down Expand Up @@ -91,11 +71,6 @@ export default function Home() {
) : (
<XCircleIcon className="w-6 h-6 text-red-500" />
)}
<p className='mx-auto max-w-7xl px-2 sm:px-6 lg:px-8'>
{peerStats.latency > 0
? `Latency of nearest peer: ${peerStats.latency} ms`
: null}
</p>
</div>
<div>
{peerStats.peerIds.length > 0 ? (
Expand Down
10 changes: 9 additions & 1 deletion rust-peer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down

0 comments on commit c718f2e

Please sign in to comment.