Skip to content

Commit b0eb625

Browse files
committed
More docs
1 parent 47d5579 commit b0eb625

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

iroh-pkarr-node-discovery/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
name = "iroh-pkarr-node-discovery"
33
version = "0.1.0"
44
edition = "2021"
5+
authors = ["Rüdiger Klaehn <rklaehn@protonmail.com>", "n0 team"]
6+
keywords = ["network", "p2p"]
7+
categories = ["network-programming"]
8+
license = "Apache-2.0/MIT"
9+
repository = "https://github.com/n0-computer/iroh-examples"
10+
description = "A discovery mechanism for iroh-net that uses the bittorrent mainline DHT via pkarr"
511

612
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
713

iroh-pkarr-node-discovery/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! # Pkarr based node discovery for iroh-net
22
//!
3-
//! Node discovery is being able to find information about an iroh node based on just its node id.
3+
//! Node discovery is being able to find connecting information about an iroh node based on just its node id.
44
//!
55
//! This crate implements a discovery mechanism for iroh-net based on https://https://pkarr.org/.
66
//!
7-
//! Each node publishes its address to the mainline DHT as a DNS packet, signed with its private key.
7+
//! TLDR: Each node publishes its address to the mainline DHT as a DNS packet, signed with its private key.
88
//! The DNS packet contains the node's direct addresses and optionally a DERP URL.
99
use std::{
1010
collections::BTreeSet,
@@ -25,26 +25,39 @@ use pkarr::{
2525
Keypair, PkarrClient, SignedPacket,
2626
};
2727

28+
/// The key for the DERP URL TXT record.
2829
const DERP_URL_KEY: &str = "_derp_url.iroh.";
30+
/// Republish delay for the DHT. This is only for when the info does not change.
31+
/// If the info changes, it will be published immediately.
2932
const REPUBLISH_DELAY: Duration = Duration::from_secs(60 * 60);
3033

3134
/// A discovery mechanism for iroh-net based on https://https://pkarr.org/
3235
///
3336
/// TLDR: it stores node addresses in DNS records, signed by the node's private key,
3437
/// and publishes them to the bittorrent mainline DHT.
3538
///
36-
/// Calling publish will start a background task that periodically publishes the node address
39+
/// Calling publish will start a background task that periodically publishes the node address.
3740
#[derive(Debug, Clone)]
3841
pub struct PkarrNodeDiscovery(Arc<Inner>);
3942

4043
#[derive(Debug)]
4144
struct Inner {
42-
keypair: Option<pkarr::Keypair>,
45+
/// Pkarr client for interacting with the DHT.
4346
pkarr: PkarrClient,
47+
/// The background task that periodically publishes the node address.
48+
/// Due to AbortingJoinHandle, this will be aborted when the discovery is dropped.
4449
task: Mutex<Option<AbortingJoinHandle<()>>>,
50+
/// Optional keypair for signing the DNS packets.
51+
///
52+
/// If this is None, the node will not publish its address to the DHT.
53+
keypair: Option<pkarr::Keypair>,
4554
}
4655

4756
impl PkarrNodeDiscovery {
57+
/// Create a new discovery mechanism.
58+
///
59+
/// If a secret key is provided, the node will publish its address to the DHT.
60+
/// If no secret key is provided, publish will be a no-op, but resolving other nodes will still work.
4861
pub fn new(pkarr: PkarrClient, secret_key: Option<&SecretKey>) -> Self {
4962
let keypair =
5063
secret_key.map(|secret_key| pkarr::Keypair::from_secret_key(&secret_key.to_bytes()));

0 commit comments

Comments
 (0)