Skip to content

Commit d8d94d3

Browse files
committed
feat: add relay capabilities to rust server (#12)
1 parent fe12566 commit d8d94d3

File tree

3 files changed

+176
-4
lines changed

3 files changed

+176
-4
lines changed

rust-server/Cargo.lock

+154
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-server/Cargo.toml

+16-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@ clap = { version = "4.1.11", features = ["derive"] }
1111
env_logger = "0.10.0"
1212
futures = "0.3.27"
1313
futures-timer = "3.0.2"
14-
libp2p = {git = "https://github.com/vnermolaev/rust-libp2p.git", branch = "deprecate/gossipsub-close-event", version="0.51.2", features = ["identify", "ping", "tokio", "gossipsub", "webrtc", "macros", "kad", "rsa", "ed25519"]}
15-
libp2p-webrtc = {git = "https://github.com/vnermolaev/rust-libp2p.git", branch = "deprecate/gossipsub-close-event", version="0.4.0-alpha.4", features = ["tokio"] }
14+
libp2p = { git = "https://github.com/vnermolaev/rust-libp2p.git", branch = "deprecate/gossipsub-close-event", version = "0.51.2", features = [
15+
"identify",
16+
"ping",
17+
"tokio",
18+
"gossipsub",
19+
"webrtc",
20+
"macros",
21+
"relay",
22+
"kad",
23+
"rsa",
24+
"ed25519",
25+
] }
26+
libp2p-webrtc = { git = "https://github.com/vnermolaev/rust-libp2p.git", branch = "deprecate/gossipsub-close-event", version = "0.4.0-alpha.4", features = [
27+
"tokio",
28+
] }
1629
log = "0.4.17"
1730
rand = "0.8.5"
18-
tokio = { version= "1.26.0", features=["full"] }
31+
tokio = { version = "1.26.0", features = ["full"] }
1932
tokio-util = { version = "0.7", features = ["full"] }
2033
webrtc = { version = "0.6.0", optional = true }

rust-server/src/main.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use libp2p::{
55
core::muxing::StreamMuxerBox,
66
gossipsub, identify, identity,
77
multiaddr::Protocol,
8-
ping,
8+
ping, relay,
99
swarm::{keep_alive, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent},
1010
Multiaddr, PeerId, Transport,
1111
};
@@ -59,6 +59,9 @@ async fn main() -> Result<()> {
5959
SwarmEvent::ConnectionClosed { peer_id, cause, .. } => {
6060
warn!("Connection to {peer_id} closed: {cause:?}");
6161
}
62+
SwarmEvent::Behaviour(BehaviourEvent::Relay(e)) => {
63+
info!("{:?}", e);
64+
}
6265
SwarmEvent::Behaviour(BehaviourEvent::Gossipsub(
6366
libp2p::gossipsub::Event::Message {
6467
message_id: _,
@@ -104,6 +107,7 @@ struct Behaviour {
104107
// kademlia: Kademlia<MemoryStore>,
105108
keep_alive: keep_alive::Behaviour,
106109
ping: ping::Behaviour,
110+
relay: relay::Behaviour,
107111
}
108112

109113
fn create_swarm() -> Result<Swarm<Behaviour>> {
@@ -160,6 +164,7 @@ fn create_swarm() -> Result<Swarm<Behaviour>> {
160164
identify: identify_config,
161165
keep_alive: keep_alive::Behaviour::default(),
162166
ping: ping::Behaviour::default(),
167+
relay: relay::Behaviour::new(local_peer_id, Default::default()),
163168
};
164169
Ok(SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build())
165170
}

0 commit comments

Comments
 (0)