Skip to content

Commit

Permalink
feat: rust peer joins peer discovery topic (#174)
Browse files Browse the repository at this point in the history
* feat: rust peer discovery over gossipsub

* chore: fmt
  • Loading branch information
dozyio authored Jul 25, 2024
1 parent 4760d9b commit 9cfaee5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rust-peer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9cfaee5

Please sign in to comment.