From 86e373f786b42ae6e09aeeaa2222f3d221956b55 Mon Sep 17 00:00:00 2001 From: dozyio Date: Wed, 17 Jul 2024 12:29:01 +0100 Subject: [PATCH 1/2] feat: rust peer discovery over gossipsub --- rust-peer/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rust-peer/src/main.rs b/rust-peer/src/main.rs index 6bbf28e5..af6c3822 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,14 @@ 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 +345,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); From e6ad7844cfe7d514e3a48e38073a4363ce85e7c0 Mon Sep 17 00:00:00 2001 From: dozyio Date: Wed, 17 Jul 2024 13:43:05 +0100 Subject: [PATCH 2/2] chore: fmt --- rust-peer/src/main.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rust-peer/src/main.rs b/rust-peer/src/main.rs index af6c3822..1f071931 100644 --- a/rust-peer/src/main.rs +++ b/rust-peer/src/main.rs @@ -184,10 +184,7 @@ async fn main() -> Result<()> { } if message.topic == peer_discovery_hash { - info!( - "Received peer discovery from {:?}", - message.source - ); + info!("Received peer discovery from {:?}", message.source); continue; }