From 9cfaee595fbac25e26bd982bce66f376a895bd78 Mon Sep 17 00:00:00 2001 From: dozyio <37986489+dozyio@users.noreply.github.com> Date: Thu, 25 Jul 2024 15:13:02 +0100 Subject: [PATCH] feat: rust peer joins peer discovery topic (#174) * feat: rust peer discovery over gossipsub * chore: fmt --- rust-peer/src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust-peer/src/main.rs b/rust-peer/src/main.rs index 6bbf28e5..1f071931 100644 --- a/rust-peer/src/main.rs +++ b/rust-peer/src/main.rs @@ -42,6 +42,7 @@ const LOCAL_KEY_PATH: &str = "./local_key"; const LOCAL_CERT_PATH: &str = "./cert.pem"; const GOSSIPSUB_CHAT_TOPIC: &str = "universal-connectivity"; const GOSSIPSUB_CHAT_FILE_TOPIC: &str = "universal-connectivity-file"; +const GOSSIPSUB_PEER_DISCOVERY: &str = "universal-connectivity-browser-peer-discovery"; const BOOTSTRAP_NODES: [&str; 4] = [ "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", "/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa", @@ -113,6 +114,7 @@ async fn main() -> Result<()> { let chat_topic_hash = gossipsub::IdentTopic::new(GOSSIPSUB_CHAT_TOPIC).hash(); let file_topic_hash = gossipsub::IdentTopic::new(GOSSIPSUB_CHAT_FILE_TOPIC).hash(); + let peer_discovery_hash = gossipsub::IdentTopic::new(GOSSIPSUB_PEER_DISCOVERY).hash(); let mut tick = futures_timer::Delay::new(TICK_INTERVAL); @@ -181,6 +183,11 @@ async fn main() -> Result<()> { continue; } + if message.topic == peer_discovery_hash { + info!("Received peer discovery from {:?}", message.source); + continue; + } + error!("Unexpected gossipsub topic hash: {:?}", message.topic); } SwarmEvent::Behaviour(BehaviourEvent::Gossipsub( @@ -335,6 +342,7 @@ fn create_swarm( // Create/subscribe Gossipsub topics gossipsub.subscribe(&gossipsub::IdentTopic::new(GOSSIPSUB_CHAT_TOPIC))?; gossipsub.subscribe(&gossipsub::IdentTopic::new(GOSSIPSUB_CHAT_FILE_TOPIC))?; + gossipsub.subscribe(&gossipsub::IdentTopic::new(GOSSIPSUB_PEER_DISCOVERY))?; let transport = { let webrtc = webrtc::tokio::Transport::new(local_key.clone(), certificate);