| Crates.io | distributed-topic-tracker |
| lib.rs | distributed-topic-tracker |
| version | 0.2.0 |
| created_at | 2025-08-09 19:50:40.561465+00 |
| updated_at | 2025-09-21 15:26:45.870327+00 |
| description | automagically find peers interested in a topic + iroh-gossip integration |
| homepage | https://rustonbsd.github.io/2025/09/03/distributed-topic-tracker.html |
| repository | https://github.com/rustonbsd/distributed-topic-tracker |
| max_upload_size | |
| id | 1788195 |
| size | 222,028 |
Decentralized auto-bootstrapping for iroh-gossip topics using the mainline BitTorrent DHT.
Add dependencies to Cargo.toml:
[dependencies]
anyhow = "1"
tokio = "1"
iroh = "*"
iroh-gossip = "*"
distributed-topic-tracker = "0.2"
Basic iroh-gossip integration:
use anyhow::Result;
use iroh::{Endpoint, SecretKey};
use iroh_gossip::net::Gossip;
// Imports from distributed-topic-tracker
use distributed_topic_tracker::{TopicId, AutoDiscoveryGossip, RecordPublisher};
#[tokio::main]
async fn main() -> Result<()> {
// Generate a new random secret key
let secret_key = SecretKey::generate(rand::rngs::OsRng);
// Set up endpoint with discovery enabled
let endpoint = Endpoint::builder()
.secret_key(secret_key.clone())
.discovery_n0()
.bind()
.await?;
// Initialize gossip
let gossip = Gossip::builder().spawn(endpoint.clone());
// Set up protocol router
let _router = iroh::protocol::Router::builder(endpoint.clone())
.accept(iroh_gossip::ALPN, gossip.clone())
.spawn();
// Distributed Topic Tracker
let topic_id = TopicId::new("my-iroh-gossip-topic".to_string());
let initial_secret = b"my-initial-secret".to_vec();
let record_publisher = RecordPublisher::new(
topic_id.clone(),
endpoint.node_id().public(),
secret_key.secret().clone(),
None,
initial_secret,
);
// Use new `subscribe_and_join_with_auto_discovery` on Gossip
let topic = gossip
.subscribe_and_join_with_auto_discovery(record_publisher)
.await?;
println!("[joined topic]");
// Work with the topic (GossipSender/Receiver are clonable)
let (_gossip_sender, _gossip_receiver) = topic.split().await?;
Ok(())
}
Run core component tests:
cargo test
Verify peer discovery across Docker containers:
# Requires Docker and Docker Compose
./test-e2e.sh
The E2E test confirms multiple nodes discover each other via DHT and join the same gossip topic.
iroh-gossip integration a feature (repurposed for rustpatcher)Licensed under Apache-2.0 or MIT you choose.
Contributions are dual-licensed as above unless stated otherwise.