Skip to content

Commit 4afed36

Browse files
committed
Update relay code to new version
1 parent 49cda90 commit 4afed36

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

hole-punch-interop/rust-relay/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# syntax=docker/dockerfile:1.5-labs
2-
FROM rust:1.72.0 as builder
2+
FROM rust:1.75.0 as builder
33

44
# Run with access to the target cache to speed up builds
55
WORKDIR /workspace

hole-punch-interop/rust-relay/src/main.rs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ use libp2p::{
66
transport::Transport,
77
upgrade,
88
},
9-
futures::future::Either,
10-
futures::StreamExt,
11-
identify, identity, noise, ping, quic, relay,
12-
swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent},
13-
tcp, yamux, PeerId, Swarm,
9+
futures::{future::Either, StreamExt},
10+
identify,
11+
identity::{self, Keypair},
12+
noise, ping, quic, relay,
13+
swarm::{NetworkBehaviour, SwarmEvent},
14+
tcp, yamux, PeerId, Swarm, SwarmBuilder,
1415
};
1516
use redis::AsyncCommands;
1617
use std::net::{IpAddr, Ipv4Addr};
@@ -90,34 +91,26 @@ fn quic_addr(addr: IpAddr) -> Multiaddr {
9091
}
9192

9293
fn make_swarm() -> Result<Swarm<Behaviour>> {
93-
let local_key = identity::Keypair::generate_ed25519();
94-
let local_peer_id = PeerId::from(local_key.public());
95-
log::info!("Local peer id: {local_peer_id}");
96-
97-
let transport = tcp::tokio::Transport::new(tcp::Config::default().nodelay(true))
98-
.upgrade(upgrade::Version::V1Lazy)
99-
.authenticate(noise::Config::new(&local_key)?)
100-
.multiplex(yamux::Config::default())
101-
.or_transport(quic::tokio::Transport::new(quic::Config::new(&local_key)))
102-
.map(|either_output, _| match either_output {
103-
Either::Left((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
104-
Either::Right((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
105-
})
106-
.boxed();
107-
let behaviour = Behaviour {
108-
relay: relay::Behaviour::new(local_peer_id, relay::Config::default()),
109-
identify: identify::Behaviour::new(identify::Config::new(
110-
"/hole-punch-tests/1".to_owned(),
111-
local_key.public(),
112-
)),
113-
ping: ping::Behaviour::default(),
114-
};
115-
116-
Ok(
117-
SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id)
118-
.substream_upgrade_protocol_override(upgrade::Version::V1Lazy)
119-
.build(),
120-
)
94+
Ok(SwarmBuilder::with_new_identity()
95+
.with_tokio()
96+
.with_tcp(
97+
tcp::Config::default().nodelay(true),
98+
|k: &Keypair| noise::Config::new(k),
99+
|| yamux::Config::default(),
100+
)?
101+
.with_quic()
102+
.with_behaviour(|local_key| {
103+
let local_peer_id = PeerId::from(local_key.public());
104+
Behaviour {
105+
relay: relay::Behaviour::new(local_peer_id, relay::Config::default()),
106+
identify: identify::Behaviour::new(identify::Config::new(
107+
"/hole-punch-tests/1".to_owned(),
108+
local_key.public(),
109+
)),
110+
ping: ping::Behaviour::default(),
111+
}
112+
})?
113+
.build())
121114
}
122115

123116
struct RedisClient {

0 commit comments

Comments
 (0)