diff --git a/Cargo.lock b/Cargo.lock index 6951a19c47..762ac74866 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2652,7 +2652,7 @@ dependencies = [ "iroh-metrics", "nix 0.27.1", "parking_lot", - "pkarr 1.1.5", + "pkarr", "portable-atomic", "postcard", "quic-rpc", @@ -2705,7 +2705,7 @@ dependencies = [ "lru", "mainline", "parking_lot", - "pkarr 2.1.0", + "pkarr", "rcgen 0.12.1", "redb 2.1.1", "regex", @@ -2882,7 +2882,7 @@ dependencies = [ "once_cell", "parking_lot", "pin-project", - "pkarr 2.1.0", + "pkarr", "postcard", "pretty_assertions", "proptest", @@ -3825,25 +3825,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkarr" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "242ae92dfb9d2ba3aaa9caf4723e72043bc50729ad05a763771771ba03196ffb" -dependencies = [ - "bytes", - "ed25519-dalek", - "rand", - "self_cell", - "simple-dns", - "thiserror", - "url", - "z32", -] - -[[package]] -name = "pkarr" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4548c673cbf8c91b69f7a17d3a042710aa73cffe5e82351db5378f26c3be64d8" +checksum = "a8ffdac8b4b7ea5240c46b28f88de799e0efaa2b93ccb08eaae6e50835dfe137" dependencies = [ "bytes", "document-features", diff --git a/iroh-cli/Cargo.toml b/iroh-cli/Cargo.toml index 7a330dcf6c..1927897bd1 100644 --- a/iroh-cli/Cargo.toml +++ b/iroh-cli/Cargo.toml @@ -44,7 +44,7 @@ iroh = { version = "0.22.0", path = "../iroh", features = ["metrics"] } iroh-gossip = { version = "0.22.0", path = "../iroh-gossip" } iroh-metrics = { version = "0.22.0", path = "../iroh-metrics" } parking_lot = "0.12.1" -pkarr = { version = "1.1.5", default-features = false } +pkarr = { version = "2.0.0", default-features = false } portable-atomic = "1" postcard = "1.0.8" quic-rpc = { version = "0.11", features = ["flume-transport", "quinn-transport"] } diff --git a/iroh-cli/src/commands/doctor.rs b/iroh-cli/src/commands/doctor.rs index 3b2a8348c6..78c014a3e6 100644 --- a/iroh-cli/src/commands/doctor.rs +++ b/iroh-cli/src/commands/doctor.rs @@ -1015,7 +1015,7 @@ fn bold(x: T) -> String { } fn to_z32(node_id: NodeId) -> String { - pkarr::PublicKey::try_from(*node_id.as_bytes()) + pkarr::PublicKey::try_from(node_id.as_bytes()) .unwrap() .to_z32() } diff --git a/iroh-net/src/discovery/pkarr/dht.rs b/iroh-net/src/discovery/pkarr/dht.rs index 4b4d0e5ae1..cc79aafda2 100644 --- a/iroh-net/src/discovery/pkarr/dht.rs +++ b/iroh-net/src/discovery/pkarr/dht.rs @@ -73,6 +73,10 @@ struct Inner { ttl: u32, /// True to include the direct addresses in the DNS packet. include_direct_addresses: bool, + /// Initial delay before the first publish. + initial_publish_delay: Duration, + /// Republish delay for the DHT. + republish_delay: Duration, } /// Builder for PkarrNodeDiscovery. @@ -86,6 +90,8 @@ pub struct Builder { pkarr_relay: Option, dht: bool, include_direct_addresses: bool, + initial_publish_delay: Duration, + republish_delay: Duration, } impl Default for Builder { @@ -97,6 +103,8 @@ impl Default for Builder { pkarr_relay: None, dht: true, include_direct_addresses: false, + initial_publish_delay: INITIAL_PUBLISH_DELAY, + republish_delay: REPUBLISH_DELAY, } } } @@ -146,6 +154,18 @@ impl Builder { self } + /// Set the initial delay before the first publish. + pub fn initial_publish_delay(mut self, initial_publish_delay: Duration) -> Self { + self.initial_publish_delay = initial_publish_delay; + self + } + + /// Set the republish delay for the DHT. + pub fn republish_delay(mut self, republish_delay: Duration) -> Self { + self.republish_delay = republish_delay; + self + } + /// Build the discovery mechanism. pub fn build(self) -> anyhow::Result { let pkarr = self @@ -175,11 +195,13 @@ impl Builder { Ok(DhtDiscovery(Arc::new(Inner { pkarr, pkarr_relay, - secret_key: self.secret_key, ttl, relay_url, dht, include_direct_addresses, + secret_key: self.secret_key, + initial_publish_delay: self.initial_publish_delay, + republish_delay: self.republish_delay, task: Default::default(), }))) } @@ -199,7 +221,7 @@ impl DhtDiscovery { .to_z32(); // initial delay. If the task gets aborted before this delay is over, // we have not published anything to the DHT yet. - tokio::time::sleep(INITIAL_PUBLISH_DELAY).await; + tokio::time::sleep(this.0.initial_publish_delay).await; loop { // publish to the DHT if enabled let dht_publish = async { @@ -240,7 +262,7 @@ impl DhtDiscovery { }; // do both at the same time tokio::join!(relay_publish, dht_publish); - tokio::time::sleep(REPUBLISH_DELAY).await; + tokio::time::sleep(this.0.republish_delay).await; } } @@ -378,7 +400,7 @@ mod tests { let _ = tracing_subscriber::fmt::try_init(); let ep = crate::Endpoint::builder().bind(0).await?; let secret = ep.secret_key().clone(); - let testnet = mainline::dht::Testnet::new(5); + let testnet = mainline::dht::Testnet::new(2); let settings = pkarr::Settings { dht: DhtSettings { bootstrap: Some(testnet.bootstrap.clone()), @@ -389,6 +411,7 @@ mod tests { let client = PkarrClient::new(settings)?; let discovery = DhtDiscovery::builder() .secret_key(secret.clone()) + .initial_publish_delay(Duration::ZERO) .client(client) .build()?; let relay_url: RelayUrl = Url::parse("https://example.com")?.into();