8 releases
new 0.1.7 | Jan 17, 2025 |
---|---|
0.1.6 | Jan 16, 2025 |
#532 in Network programming
319 downloads per month
36KB
281 lines
Iroh Topic Tracker
An easy-to-use tracker for Iroh NodeId's in GossipSub topics. This library includes a hosted iroh-topic-tracker
BOOTSTRAP_NODE to facilitate seamless tracking.
Getting Started
Automatic Discovery with iroh-gossip
This crate comes with an iroh-gossip integration, available via the feature flag:
feature = ["iroh-gossip-auto-discovery"]
use iroh_topic_tracker::integrations::iroh_gossip::*;
let endpoint = Endpoint::builder().bind().await?;
// Setup Gossip with auto discovery
let gossip = Gossip::new(endpoint.clone()).await?;
// ::new() or ::builder().spawn_with_auto_discovery()
let gossip = Gossip::builder()
.spawn_with_auto_discovery(endpoint.clone())
.await?;
let router = iroh::protocol::Router::builder(endpoint.clone())
.accept(iroh_gossip::ALPN, gossip.gossip.clone())
.spawn().await?;
// Gossip Topic
let topic = Topic::from_passphrase("my-iroh-gossip-topic");
// Subscribe and join with automatic peer discovery
let (sink, mut stream) = gossip.subscribe_and_join(topic.into()).await?.split();
Try It Out
-
Get the last connected NodeId's for a given gossip topic:
cargo run --example client
-
Run your own dedicated topic tracker node:
cargo run --example server
Note: Adjust the
secret.rs
SecretKey to ensure secure communication, and update theBOOTSTRAP_NODES
public key intopic_tracker.rs
(around line 33) to correctly point to the desired bootstrap node for discovery.
Build Server for Release
To build the server in release mode:
cargo build --release --example server
Library Usage
Refer to the examples below for quick guidance:
Basic Example
use iroh_topic_tracker::topic_tracker::TopicTracker;
let topic = Topic::from_passphrase("my topic name");
let topic_tracker = TopicTracker::new(&endpoint);
topic_tracker.get_topic_nodes(&topic).await?;
Expanded Example
use iroh_topic_tracker::topic_tracker::TopicTracker;
let topic = Topic::from_passphrase("my test topic");
let endpoint = Endpoint::builder()
.secret_key(SecretKey::generate(rand::rngs::OsRng))
.discovery_n0()
.discovery_dht()
.bind()
.await?;
let topic_tracker = TopicTracker::new(&endpoint);
let router = Router::builder(endpoint.clone())
.accept(TopicTracker::ALPN, topic_tracker.clone())
.spawn()
.await?;
topic_tracker.get_topic_nodes(&topic).await?;
Dependencies
~45–82MB
~1.5M SLoC