Skip to content

Commit 6cf9973

Browse files
committed
fix: updated UI + increased outbound streams (#49)
1 parent 5617525 commit 6cf9973

File tree

3 files changed

+70
-58
lines changed

3 files changed

+70
-58
lines changed

packages/frontend/src/lib/libp2p.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { BOOTSTRAP_NODE, CHAT_TOPIC, CIRCUIT_RELAY_CODE } from './constants'
1717
import * as filters from "@libp2p/websockets/filters"
1818

1919
// @ts-ignore
20-
import { circuitRelayTransport } from 'libp2p/circuit-relay'
20+
import { circuitRelayTransport, circuitRelayServer } from 'libp2p/circuit-relay'
2121

2222

2323
export async function startLibp2p() {
@@ -43,6 +43,10 @@ export async function startLibp2p() {
4343
}), webRTCDirect(), circuitRelayTransport({
4444
discoverRelays: 10,
4545
}),],
46+
relay: circuitRelayServer({
47+
maxInboundHopStreams: 100,
48+
maxOutboundHopStreams: 100,
49+
}),
4650
connectionEncryption: [noise()],
4751
connectionManager: {
4852
maxConnections: 200,
@@ -53,7 +57,8 @@ export async function startLibp2p() {
5357
bootstrap({
5458
list: [
5559
// BOOTSTRAP_NODE,
56-
"/ip4/127.0.0.1/udp/9090/webrtc-direct/certhash/uEiA2twAWww-g6fXsJe6JPlROwCHbRj6fNgr_WHxiQGEK3g/p2p/12D3KooWLTB1SrjyF8R5Z1MKErcV8abs26eo4LpadQKWsxMUcDBJ"
60+
// Local Rust Peer Bootstrap node
61+
"/ip4/127.0.0.1/udp/9090/webrtc-direct/certhash/uEiA2twAWww-g6fXsJe6JPlROwCHbRj6fNgr_WHxiQGEK3g/p2p/12D3KooWLTB1SrjyF8R5Z1MKErcV8abs26eo4LpadQKWsxMUcDBJ"
5762
],
5863
}),
5964
],
@@ -65,6 +70,7 @@ export async function startLibp2p() {
6570
identify: {
6671
maxPushOutgoingStreams: 100,
6772
maxInboundStreams: 100,
73+
maxOutboundStreams: 100,
6874
},
6975
autonat: {
7076
startupDelay: 60 * 60 *24 * 1000,

packages/frontend/src/pages/index.tsx

+60-55
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ export default function Home() {
4040
const exists = protoNames.get(conn.remotePeer.toString())
4141
const dedupedProtonames = [...new Set(conn.remoteAddr.protoNames())]
4242

43-
if (exists) {
44-
const namesToAdd = exists.filter(
45-
(name) => !dedupedProtonames.includes(name),
46-
)
43+
if (exists?.length) {
44+
const namesToAdd = dedupedProtonames.filter((name) => !exists.includes(name))
45+
console.log('namesToAdd: ', namesToAdd)
4746
protoNames.set(conn.remotePeer.toString(), [...exists, ...namesToAdd])
47+
4848
} else {
4949
protoNames.set(conn.remotePeer.toString(), dedupedProtonames)
5050
}
@@ -109,60 +109,65 @@ export default function Home() {
109109
</div>
110110
</header>
111111
<main>
112-
<div className="my-6 w-1/2">
113-
<label
114-
htmlFor="peer-id"
115-
className="block text-sm font-medium leading-6 text-gray-900"
116-
>
117-
multiaddr to connect to
118-
</label>
119-
<div className="mt-2">
120-
<input
121-
value={maddr}
122-
type="text"
123-
name="peer-id"
124-
id="peer-id"
125-
className="block w-full rounded-md border-0 py-1.5 px-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
126-
placeholder="12D3Koo..."
127-
aria-describedby="multiaddr-id-description"
128-
onChange={handleMultiaddrChange}
129-
/>
112+
<div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
113+
<ul className="my-2 space-y-2 break-all">
114+
<li className="">This PeerID: {libp2p.peerId.toString()}</li>
115+
</ul>
116+
<div className="my-6 w-1/2">
117+
<label
118+
htmlFor="peer-id"
119+
className="block text-sm font-medium leading-6 text-gray-900"
120+
>
121+
multiaddr to connect to
122+
</label>
123+
<div className="mt-2">
124+
<input
125+
value={maddr}
126+
type="text"
127+
name="peer-id"
128+
id="peer-id"
129+
className="block w-full rounded-md border-0 py-1.5 px-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
130+
placeholder="12D3Koo..."
131+
aria-describedby="multiaddr-id-description"
132+
onChange={handleMultiaddrChange}
133+
/>
134+
</div>
135+
<button
136+
type="button"
137+
className="rounded-md bg-indigo-600 my-2 py-2 px-3 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
138+
onClick={handleConnectToMultiaddr}
139+
>
140+
Connect to multiaddr
141+
</button>
130142
</div>
131-
<button
132-
type="button"
133-
className="rounded-md bg-indigo-600 my-2 py-2 px-3 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
134-
onClick={handleConnectToMultiaddr}
135-
>
136-
Connect to multiaddr
137-
</button>
138-
</div>
139143

140144

141-
<div className="my-4 inline-flex items-center text-xl">
142-
Connected:{' '}
143-
{peerStats.connected ? (
144-
<CheckCircleIcon className="inline w-6 h-6 text-green-500" />
145-
) : (
146-
<XCircleIcon className="w-6 h-6 text-red-500" />
147-
)}
148-
</div>
149-
<div>
150-
{peerStats.peerIds.length > 0 ? (
151-
<>
152-
<h3 className="text-xl">
153-
{' '}
154-
Connected peers ({getFormattedConnections(peerStats.connections).length}) 👇
155-
</h3>
156-
<pre className="px-2">
157-
{getFormattedConnections(peerStats.connections)
158-
.map(
159-
(pair) =>
160-
`${pair.peerId} (${pair.protocols.join(', ')})`,
161-
)
162-
.join('\n')}
163-
</pre>
164-
</>
165-
) : null}
145+
<div className="my-4 inline-flex items-center text-xl">
146+
Connected:{' '}
147+
{peerStats.connected ? (
148+
<CheckCircleIcon className="inline w-6 h-6 text-green-500" />
149+
) : (
150+
<XCircleIcon className="w-6 h-6 text-red-500" />
151+
)}
152+
</div>
153+
<div>
154+
{peerStats.peerIds.length > 0 ? (
155+
<>
156+
<h3 className="text-xl">
157+
{' '}
158+
Connected peers ({getFormattedConnections(peerStats.connections).length}) 👇
159+
</h3>
160+
<pre className="px-2">
161+
{getFormattedConnections(peerStats.connections)
162+
.map(
163+
(pair) =>
164+
`${pair.peerId} (${pair.protocols.join(', ')})`,
165+
)
166+
.join('\n')}
167+
</pre>
168+
</>
169+
) : null}
170+
</div>
166171
</div>
167172
</main>
168173
</div>

rust-peer/src/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ fn create_swarm(
288288
relay: relay::Behaviour::new(
289289
local_peer_id,
290290
relay::Config {
291-
max_reservations: 400,
291+
max_reservations: 200,
292292
max_reservations_per_peer: 10,
293+
reservation_duration: Duration::from_secs(60),
293294
..Default::default()
294295
},
295296
),

0 commit comments

Comments
 (0)