Skip to content

Commit 513f0ad

Browse files
committed
wip: added circuit-relay dialing
1 parent 53c0d1b commit 513f0ad

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

packages/frontend/src/lib/libp2p.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function startLibp2p(options: {} = {}) {
6262
]
6363
}
6464
}), webRTCDirect(), circuitRelayTransport({
65-
discoverRelays: 1,
65+
discoverRelays: 10,
6666
}),],
6767
// transports: [webRTC()],
6868
connectionEncryption: [noise()],

packages/frontend/src/pages/index.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ export default function Home() {
3838
return await libp2p.getConnections()
3939
}
4040

41-
const ping = async () => {
42-
if (maddr) {
43-
return libp2p.ping(multiaddr(maddr))
44-
}
45-
}
41+
// const ping = async () => {
42+
// if (maddr) {
43+
// return libp2p.ping(multiaddr(maddr))
44+
// }
45+
// }
4646

47-
ping()
48-
.then((lat) => {
49-
setLatency(lat)
50-
})
51-
.catch((e) => {
52-
console.error(e, e?.error)
53-
})
47+
// ping()
48+
// .then((lat) => {
49+
// setLatency(lat)
50+
// })
51+
// .catch((e) => {
52+
// console.error(e, e?.error)
53+
// })
5454

5555
getConnectedPeers().then((peers) => {
5656
// If one of the connected peers matches the one in input we're connected

rust-peer/src/main.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use libp2p::{
88
kad::{Kademlia, KademliaConfig},
99
multiaddr::Protocol,
1010
ping, relay,
11-
swarm::{keep_alive, AddressScore, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent},
11+
swarm::{
12+
keep_alive, AddressRecord, AddressScore, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent,
13+
},
1214
Multiaddr, PeerId, Transport,
1315
};
1416
use libp2p_webrtc as webrtc;
@@ -70,7 +72,8 @@ async fn main() -> Result<()> {
7072
futures::future::Either::Left((event, _)) => match event.unwrap() {
7173
SwarmEvent::NewListenAddr { address, .. } => {
7274
let p2p_address = address.with(Protocol::P2p((*swarm.local_peer_id()).into()));
73-
info!("Listen p2p address: {p2p_address:?}")
75+
info!("Listen p2p address: {p2p_address:?}");
76+
swarm.add_external_address(p2p_address, AddressScore::Infinite);
7477
}
7578
SwarmEvent::ConnectionEstablished { peer_id, .. } => {
7679
info!("Connected to {peer_id}");
@@ -109,6 +112,11 @@ async fn main() -> Result<()> {
109112
futures::future::Either::Right(_) => {
110113
tick = futures_timer::Delay::new(TICK_INTERVAL);
111114

115+
info!(
116+
"external addrs: {:?}",
117+
swarm.external_addresses().collect::<Vec<&AddressRecord>>()
118+
);
119+
112120
let message = format!("Hello world! Sent at: {:4}s", now.elapsed().as_secs_f64());
113121

114122
if let Err(err) = swarm.behaviour_mut().gossipsub.publish(

0 commit comments

Comments
 (0)