From 87f23a103cc8fc2ddfc44c2854a765dc47ff19e6 Mon Sep 17 00:00:00 2001 From: rklaehn Date: Wed, 8 Apr 2026 12:12:56 +0000 Subject: [PATCH] deploy: 7074a83684132201c5d218798f5b42f62bbadb73 --- .../iroh/address_lookup/pkarr/dht/index.html | 2 +- .../pkarr/dht/struct.DhtAddressLookup.html | 4 +- .../address_lookup/trait.AddressLookup.html | 2 +- .../attrs/fn.endpoint_id_from_txt_name.html | 4 +- pr/4026/docs/iroh_dns/attrs/index.html | 4 +- .../docs/iroh_dns/attrs/struct.TxtAttrs.html | 10 +- pr/4026/docs/iroh_dns/enum.DecodingError.html | 4 +- pr/4026/docs/iroh_dns/index.html | 2 +- .../iroh_dns/pkarr/struct.SignedPacket.html | 8 +- .../docs/iroh_dns/trait.EndpointIdExt.html | 10 +- .../src/iroh/address_lookup/pkarr/dht.rs.html | 247 +++++++++--------- 11 files changed, 147 insertions(+), 150 deletions(-) diff --git a/pr/4026/docs/iroh/address_lookup/pkarr/dht/index.html b/pr/4026/docs/iroh/address_lookup/pkarr/dht/index.html index 7465f95209..47c974dfd9 100644 --- a/pr/4026/docs/iroh/address_lookup/pkarr/dht/index.html +++ b/pr/4026/docs/iroh/address_lookup/pkarr/dht/index.html @@ -1,4 +1,4 @@ -iroh::address_lookup::pkarr::dht - Rust

Module dht

Module dht 

Source
Available on crate feature address-lookup-pkarr-dht only.
Expand description

Pkarr based address lookup for iroh, supporting both relay servers and the DHT.

+iroh::address_lookup::pkarr::dht - Rust

Module dht

Module dht 

Source
Available on crate feature address-lookup-pkarr-dht only.
Expand description

Pkarr based address lookup for iroh, supporting both relay servers and the DHT.

This module contains pkarr-based address lookup for iroh which can use both pkarr relay servers as well as the Mainline DHT directly. See the pkarr module for an overview of pkarr.

diff --git a/pr/4026/docs/iroh/address_lookup/pkarr/dht/struct.DhtAddressLookup.html b/pr/4026/docs/iroh/address_lookup/pkarr/dht/struct.DhtAddressLookup.html index 23c5105122..9342238ae6 100644 --- a/pr/4026/docs/iroh/address_lookup/pkarr/dht/struct.DhtAddressLookup.html +++ b/pr/4026/docs/iroh/address_lookup/pkarr/dht/struct.DhtAddressLookup.html @@ -8,8 +8,8 @@ a background task that periodically publishes the endpoint address.

To change this behavior, use Builder::addr_filter and set it to e.g. AddrFilter::unfiltered. This can be useful to enable publishing IP addresses if the iroh endpoint is reachable via public IP addresses.

-

Implementations§

Source§

impl DhtAddressLookup

Source

pub fn builder() -> Builder

Creates a new builder for DhtAddressLookup.

-

Trait Implementations§

Source§

impl AddressLookup for DhtAddressLookup

Source§

fn publish(&self, data: &EndpointData)

Publishes the given EndpointData to the Address Lookup mechanism. Read more
Source§

fn resolve( +

Implementations§

Source§

impl DhtAddressLookup

Source

pub fn builder() -> Builder

Creates a new builder for DhtAddressLookup.

+

Trait Implementations§

Source§

impl AddressLookup for DhtAddressLookup

Source§

fn publish(&self, data: &EndpointData)

Publishes the given EndpointData to the Address Lookup mechanism. Read more
Source§

fn resolve( &self, endpoint_id: EndpointId, ) -> Option<BoxStream<Result<AddressLookupItem, AddressLookupError>>>

Resolves the Item for the given EndpointId. Read more
Source§

impl Clone for DhtAddressLookup

Source§

fn clone(&self) -> DhtAddressLookup

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DhtAddressLookup

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AddressLookupBuilder for T
where diff --git a/pr/4026/docs/iroh/address_lookup/trait.AddressLookup.html b/pr/4026/docs/iroh/address_lookup/trait.AddressLookup.html index 02dd598301..c83427903d 100644 --- a/pr/4026/docs/iroh/address_lookup/trait.AddressLookup.html +++ b/pr/4026/docs/iroh/address_lookup/trait.AddressLookup.html @@ -34,4 +34,4 @@ work.

Implementations on Foreign Types§

Source§

impl<T: AddressLookup> AddressLookup for Arc<T>

Source§

fn publish(&self, data: &EndpointData)

Source§

fn resolve( &self, endpoint_id: EndpointId, -) -> Option<BoxStream<Result<Item, Error>>>

Implementors§

Source§

impl AddressLookup for DnsAddressLookup

Available on non-wasm_browser only.
Source§

impl AddressLookup for MdnsAddressLookup

Available on crate feature address-lookup-mdns only.
Source§

impl AddressLookup for MemoryLookup

Source§

impl AddressLookup for DhtAddressLookup

Available on crate feature address-lookup-pkarr-dht only.
Source§

impl AddressLookup for PkarrPublisher

Source§

impl AddressLookup for PkarrResolver

Source§

impl AddressLookup for ConcurrentAddressLookup

Source§

impl<T: AddressLookup> AddressLookup for FilteredAddressLookup<T>

\ No newline at end of file +) -> Option<BoxStream<Result<Item, Error>>>

Implementors§

Source§

impl AddressLookup for DnsAddressLookup

Available on non-wasm_browser only.
Source§

impl AddressLookup for MdnsAddressLookup

Available on crate feature address-lookup-mdns only.
Source§

impl AddressLookup for MemoryLookup

Source§

impl AddressLookup for DhtAddressLookup

Available on crate feature address-lookup-pkarr-dht only.
Source§

impl AddressLookup for PkarrPublisher

Source§

impl AddressLookup for PkarrResolver

Source§

impl AddressLookup for ConcurrentAddressLookup

Source§

impl<T: AddressLookup> AddressLookup for FilteredAddressLookup<T>

\ No newline at end of file diff --git a/pr/4026/docs/iroh_dns/attrs/fn.endpoint_id_from_txt_name.html b/pr/4026/docs/iroh_dns/attrs/fn.endpoint_id_from_txt_name.html index b7124318a2..fcd6248304 100644 --- a/pr/4026/docs/iroh_dns/attrs/fn.endpoint_id_from_txt_name.html +++ b/pr/4026/docs/iroh_dns/attrs/fn.endpoint_id_from_txt_name.html @@ -1,4 +1,4 @@ -endpoint_id_from_txt_name in iroh_dns::attrs - Rust

endpoint_id_from_txt_name

Function endpoint_id_from_txt_name 

Source
pub fn endpoint_id_from_txt_name(name: &str) -> Result<EndpointId, ParseError>
Expand description

Parses a [EndpointId] from iroh DNS name.

+endpoint_id_from_txt_name in iroh_dns::attrs - Rust

endpoint_id_from_txt_name

Function endpoint_id_from_txt_name 

Source
pub fn endpoint_id_from_txt_name(name: &str) -> Result<EndpointId, ParseError>
Expand description

Parses a EndpointId from iroh DNS name.

Takes a DNS name and expects the first label to be IROH_TXT_NAME and the second -label to be a z32 encoded [EndpointId]. Ignores subsequent labels.

+label to be a z32 encoded EndpointId. Ignores subsequent labels.

\ No newline at end of file diff --git a/pr/4026/docs/iroh_dns/attrs/index.html b/pr/4026/docs/iroh_dns/attrs/index.html index 782856a669..f1cbdabb73 100644 --- a/pr/4026/docs/iroh_dns/attrs/index.html +++ b/pr/4026/docs/iroh_dns/attrs/index.html @@ -1,6 +1,6 @@ -iroh_dns::attrs - Rust

Module attrs

Module attrs 

Source
Expand description

Support for handling DNS resource records for dialing by [EndpointId].

+iroh_dns::attrs - Rust

Module attrs

Module attrs 

Source
Expand description

Support for handling DNS resource records for dialing by EndpointId.

DNS records are published under the following names:

_iroh.<z32-endpoint-id>.<origin-domain> TXT

The returned TXT records must contain a string value of the form key=value as defined in RFC1464.

-

Structs§

TxtAttrs
Attributes parsed from IROH_TXT_NAME TXT records.

Enums§

EncodingError
IrohAttr
The attributes supported by iroh for IROH_TXT_NAME DNS resource records.
ParseError

Constants§

IROH_TXT_NAME
The DNS name for the iroh TXT record.

Functions§

endpoint_id_from_txt_name
Parses a [EndpointId] from iroh DNS name.
\ No newline at end of file +

Structs§

TxtAttrs
Attributes parsed from IROH_TXT_NAME TXT records.

Enums§

EncodingError
IrohAttr
The attributes supported by iroh for IROH_TXT_NAME DNS resource records.
ParseError

Constants§

IROH_TXT_NAME
The DNS name for the iroh TXT record.

Functions§

endpoint_id_from_txt_name
Parses a EndpointId from iroh DNS name.
\ No newline at end of file diff --git a/pr/4026/docs/iroh_dns/attrs/struct.TxtAttrs.html b/pr/4026/docs/iroh_dns/attrs/struct.TxtAttrs.html index cbc7f0e8c8..dc4ca7ca41 100644 --- a/pr/4026/docs/iroh_dns/attrs/struct.TxtAttrs.html +++ b/pr/4026/docs/iroh_dns/attrs/struct.TxtAttrs.html @@ -3,15 +3,15 @@ all attributes. Can also be used with an enum, if it implements FromStr and Display.

Implementations§

Source§

impl<T: FromStr + Display + Hash + Ord> TxtAttrs<T>

Source

pub fn from_parts( - endpoint_id: EndpointId, + endpoint_id: EndpointId, pairs: impl Iterator<Item = (T, String)>, ) -> Self

Creates TxtAttrs from an endpoint id and an iterator of key-value pairs.

Source

pub fn from_strings( - endpoint_id: EndpointId, + endpoint_id: EndpointId, strings: impl Iterator<Item = String>, ) -> Result<Self, ParseError>

Creates TxtAttrs from an endpoint id and an iterator of “{key}={value}” strings.

Source

pub fn attrs(&self) -> &BTreeMap<T, Vec<String>>

Returns the parsed attributes.

-
Source

pub fn endpoint_id(&self) -> EndpointId

Returns the endpoint id.

+
Source

pub fn endpoint_id(&self) -> EndpointId

Returns the endpoint id.

Source

pub fn from_txt_lookup( name: String, lookup: impl Iterator<Item = impl Display>, @@ -24,10 +24,10 @@ values that implement
Source

pub fn to_txt_strings(&self) -> impl Iterator<Item = String> + '_

Converts to {key}={value} strings.

Source

pub fn to_pkarr_signed_packet( &self, - secret_key: &SecretKey, + secret_key: &SecretKey, ttl: u32, ) -> Result<SignedPacket, EncodingError>

Creates a pkarr::SignedPacket

-

This constructs a DNS packet and signs it with a [SecretKey].

+

This constructs a DNS packet and signs it with a SecretKey.

Trait Implementations§

Source§

impl<T: Debug> Debug for TxtAttrs<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for TxtAttrs<T>

§

impl<T> RefUnwindSafe for TxtAttrs<T>
where T: RefUnwindSafe,

§

impl<T> Send for TxtAttrs<T>
where T: Send,

§

impl<T> Sync for TxtAttrs<T>
where diff --git a/pr/4026/docs/iroh_dns/enum.DecodingError.html b/pr/4026/docs/iroh_dns/enum.DecodingError.html index ba55e0c71f..43b41092d1 100644 --- a/pr/4026/docs/iroh_dns/enum.DecodingError.html +++ b/pr/4026/docs/iroh_dns/enum.DecodingError.html @@ -8,12 +8,12 @@ meta: Meta, }, InvalidKey { - source: KeyParsingError, + source: KeyParsingError, meta: Meta, }, }

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

InvalidEncodingZ32

Fields

§source: DecodeError
§meta: Meta

Captured call-site metadata

§

InvalidLength

Fields

§len: usize
§meta: Meta

Captured call-site metadata

-
§

InvalidKey

Fields

§source: KeyParsingError
§meta: Meta

Captured call-site metadata

+
§

InvalidKey

Fields

§meta: Meta

Captured call-site metadata

Trait Implementations§

Source§

impl Debug for DecodingError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DecodingError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for DecodingError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DecodingError> for AnyError

Source§

fn from(value: DecodingError) -> AnyError

Converts to this type from the input type.
Source§

impl From<DecodingError> for ParseError

Source§

fn from(source: DecodingError) -> Self

Converts to this type from the input type.
Source§

impl StackError for DecodingError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where diff --git a/pr/4026/docs/iroh_dns/index.html b/pr/4026/docs/iroh_dns/index.html index e276c05581..f8d2fcb8a6 100644 --- a/pr/4026/docs/iroh_dns/index.html +++ b/pr/4026/docs/iroh_dns/index.html @@ -1,5 +1,5 @@ iroh_dns - Rust

Crate iroh_dns

Crate iroh_dns 

Source
Expand description

DNS-based endpoint discovery for iroh.

This crate contains the core types for publishing and resolving iroh endpoint information via DNS, using the pkarr signed packet format.

-

Modules§

attrs
Support for handling DNS resource records for dialing by [EndpointId].
pkarr
Pkarr signed packet encoding.

Enums§

DecodingError

Traits§

EndpointIdExt
Extension methods for [EndpointId] to encode to and decode from z-base-32, +

Modules§

attrs
Support for handling DNS resource records for dialing by EndpointId.
pkarr
Pkarr signed packet encoding.

Enums§

DecodingError

Traits§

EndpointIdExt
Extension methods for EndpointId to encode to and decode from z-base-32, which is the encoding used by pkarr domain names.

\ No newline at end of file diff --git a/pr/4026/docs/iroh_dns/pkarr/struct.SignedPacket.html b/pr/4026/docs/iroh_dns/pkarr/struct.SignedPacket.html index 4d719bcc57..651c5a897c 100644 --- a/pr/4026/docs/iroh_dns/pkarr/struct.SignedPacket.html +++ b/pr/4026/docs/iroh_dns/pkarr/struct.SignedPacket.html @@ -3,7 +3,7 @@

The DNS packet must be at most 1000 bytes. Total max size is 1104 bytes.

Implementations§

Source§

impl SignedPacket

Source

pub const MAX_BYTES: usize = 1_104usize

Maximum total byte size of a signed packet.

Source

pub fn from_txt_strings( - secret_key: &SecretKey, + secret_key: &SecretKey, name: &str, values: impl IntoIterator<Item = impl AsRef<str>>, ttl: u32, @@ -11,7 +11,7 @@

This is the common case: multiple TXT values under the same DNS name (e.g. "_iroh").

Source

pub fn from_bytes(bytes: &[u8]) -> Result<SignedPacket, SignedPacketVerifyError>

Parse and verify a signed packet from its wire representation.

Source

pub fn from_relay_payload( - public_key: &PublicKey, + public_key: &PublicKey, payload: &[u8], ) -> Result<SignedPacket, SignedPacketVerifyError>

Create from a public key and relay payload (signature + timestamp + dns).

Source

pub fn from_bytes_unchecked( @@ -20,8 +20,8 @@

Still validates minimum length and DNS parsing.

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Return the full serialized bytes.

Source

pub fn to_relay_payload(&self) -> Vec<u8> ⓘ

Return the relay payload (everything after the public key).

-
Source

pub fn public_key(&self) -> PublicKey

Return the public key.

-
Source

pub fn signature(&self) -> Signature

Return the signature.

+
Source

pub fn public_key(&self) -> PublicKey

Return the public key.

+
Source

pub fn signature(&self) -> Signature

Return the signature.

Source

pub fn timestamp(&self) -> u64

Return the timestamp in microseconds since UNIX epoch.

Source

pub fn encoded_packet(&self) -> &[u8] ⓘ

Return the encoded DNS packet bytes.

Source

pub fn txt_records(&self, name: &str) -> Vec<String>

Iterate over TXT records under a specific DNS name.

diff --git a/pr/4026/docs/iroh_dns/trait.EndpointIdExt.html b/pr/4026/docs/iroh_dns/trait.EndpointIdExt.html index bdd3ab70e4..4ee78decb2 100644 --- a/pr/4026/docs/iroh_dns/trait.EndpointIdExt.html +++ b/pr/4026/docs/iroh_dns/trait.EndpointIdExt.html @@ -1,9 +1,9 @@ EndpointIdExt in iroh_dns - Rust

EndpointIdExt

Trait EndpointIdExt 

Source
pub trait EndpointIdExt {
     // Required methods
     fn to_z32(&self) -> String;
-    fn from_z32(s: &str) -> Result<EndpointId, DecodingError>;
-}
Expand description

Extension methods for [EndpointId] to encode to and decode from z-base-32, + fn from_z32(s: &str) -> Result<EndpointId, DecodingError>; +}

Expand description

Extension methods for EndpointId to encode to and decode from z-base-32, which is the encoding used by pkarr domain names.

-

Required Methods§

Source

fn to_z32(&self) -> String

Encodes a [EndpointId] in z-base-32 encoding.

-
Source

fn from_z32(s: &str) -> Result<EndpointId, DecodingError>

Parses a [EndpointId] from z-base-32 encoding.

-

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl EndpointIdExt for EndpointId

Source§

fn to_z32(&self) -> String

Source§

fn from_z32(s: &str) -> Result<EndpointId, DecodingError>

Implementors§

\ No newline at end of file +

Required Methods§

Source

fn to_z32(&self) -> String

Encodes a EndpointId in z-base-32 encoding.

+
Source

fn from_z32(s: &str) -> Result<EndpointId, DecodingError>

Parses a EndpointId from z-base-32 encoding.

+

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl EndpointIdExt for EndpointId

Implementors§

\ No newline at end of file diff --git a/pr/4026/docs/src/iroh/address_lookup/pkarr/dht.rs.html b/pr/4026/docs/src/iroh/address_lookup/pkarr/dht.rs.html index d8f61d7a24..60ec9fd9e8 100644 --- a/pr/4026/docs/src/iroh/address_lookup/pkarr/dht.rs.html +++ b/pr/4026/docs/src/iroh/address_lookup/pkarr/dht.rs.html @@ -242,131 +242,128 @@ 242 } 243 244 /// Periodically publishes the endpoint address to the DHT. -245 async fn publish_loop(self, public_key_bytes: [u8; 32], item: MutableItem) { +245 async fn publish_loop(self, signed_packet: SignedPacket) { 246 let this = self; -247 let z32 = iroh_base::PublicKey::try_from(public_key_bytes.as_slice()) -248 .expect("valid key") -249 .to_z32(); -250 loop { -251 let res = this -252 .0 -253 .dht -254 .clone() -255 .as_async() -256 .put_mutable(item.clone(), None) -257 .await; -258 match res { -259 Ok(_) => { -260 tracing::debug!("pkarr publish success. published under {z32}"); -261 } -262 Err(e) => { -263 tracing::warn!("pkarr publish error: {}", e); -264 } -265 } -266 time::sleep(this.0.republish_delay).await; -267 } -268 } -269} -270 -271impl AddressLookup for DhtAddressLookup { -272 fn publish(&self, data: &EndpointData) { -273 let Some(keypair) = &self.0.secret_key else { -274 tracing::debug!("no keypair set, not publishing"); -275 return; -276 }; -277 -278 // apply user-supplied filter -279 let data = data.apply_filter(&self.0.filter).into_owned(); -280 -281 if !data.has_addrs() { -282 tracing::debug!("no relay url or direct addresses in endpoint data, not publishing"); -283 return; -284 } -285 -286 tracing::debug!("publishing {data:?}"); -287 let info = EndpointInfo::from_parts(keypair.public(), data); -288 let Ok(signed_packet) = info.to_pkarr_signed_packet(keypair, self.0.ttl) else { -289 tracing::warn!("failed to create signed packet"); -290 return; -291 }; -292 let item = signed_packet_to_mutable_item(&signed_packet); -293 let public_key_bytes = *keypair.public().as_bytes(); -294 let this = self.clone(); -295 let curr = task::spawn(this.publish_loop(public_key_bytes, item)); -296 let mut task = self.0.task.lock().expect("poisoned"); -297 *task = Some(AbortOnDropHandle::new(curr)); -298 } -299 -300 fn resolve( -301 &self, -302 endpoint_id: EndpointId, -303 ) -> Option<BoxStream<Result<AddressLookupItem, AddressLookupError>>> { -304 let z32 = endpoint_id.to_z32(); -305 tracing::info!("resolving {} as {}", endpoint_id, z32); -306 let address_lookup = self.0.clone(); -307 let public_key_bytes = *endpoint_id.as_bytes(); -308 let stream = n0_future::stream::once_future(async move { -309 address_lookup.resolve_dht(&public_key_bytes).await -310 }) -311 .filter_map(|x| x) -312 .boxed(); -313 Some(stream) -314 } -315} -316 -317#[cfg(test)] -318mod tests { -319 use std::collections::BTreeSet; -320 -321 use iroh_base::{RelayUrl, TransportAddr}; -322 use mainline::Testnet; -323 use n0_error::{Result, StdResultExt}; -324 use n0_tracing_test::traced_test; -325 use url::Url; -326 -327 use super::*; -328 -329 #[tokio::test] -330 #[ignore = "flaky"] -331 #[traced_test] -332 async fn dht_address_lookup_smoke() -> Result { -333 let secret = SecretKey::generate(); -334 let testnet = Testnet::new_async(3).await.anyerr()?; -335 let mut dht_builder = DhtBuilder::default(); -336 dht_builder.bootstrap(&testnet.bootstrap); -337 let address_lookup = DhtAddressLookup::builder() -338 .secret_key(secret.clone()) -339 .dht_builder(dht_builder) -340 .addr_filter(AddrFilter::unfiltered()) -341 .build()?; -342 -343 let relay_url: RelayUrl = Url::parse("https://example.com").anyerr()?.into(); +247 let z32 = signed_packet.public_key().to_z32(); +248 let item = signed_packet_to_mutable_item(&signed_packet); +249 loop { +250 let res = this +251 .0 +252 .dht +253 .clone() +254 .as_async() +255 .put_mutable(item.clone(), None) +256 .await; +257 match res { +258 Ok(_) => { +259 tracing::debug!("pkarr publish success. published under {z32}"); +260 } +261 Err(e) => { +262 tracing::warn!("pkarr publish error: {}", e); +263 } +264 } +265 time::sleep(this.0.republish_delay).await; +266 } +267 } +268} +269 +270impl AddressLookup for DhtAddressLookup { +271 fn publish(&self, data: &EndpointData) { +272 let Some(keypair) = &self.0.secret_key else { +273 tracing::debug!("no keypair set, not publishing"); +274 return; +275 }; +276 +277 // apply user-supplied filter +278 let data = data.apply_filter(&self.0.filter).into_owned(); +279 +280 if !data.has_addrs() { +281 tracing::debug!("no relay url or direct addresses in endpoint data, not publishing"); +282 return; +283 } +284 +285 tracing::debug!("publishing {data:?}"); +286 let info = EndpointInfo::from_parts(keypair.public(), data); +287 let Ok(signed_packet) = info.to_pkarr_signed_packet(keypair, self.0.ttl) else { +288 tracing::warn!("failed to create signed packet"); +289 return; +290 }; +291 let this = self.clone(); +292 let curr = task::spawn(this.publish_loop(signed_packet)); +293 let mut task = self.0.task.lock().expect("poisoned"); +294 *task = Some(AbortOnDropHandle::new(curr)); +295 } +296 +297 fn resolve( +298 &self, +299 endpoint_id: EndpointId, +300 ) -> Option<BoxStream<Result<AddressLookupItem, AddressLookupError>>> { +301 let z32 = endpoint_id.to_z32(); +302 tracing::info!("resolving {} as {}", endpoint_id, z32); +303 let address_lookup = self.0.clone(); +304 let public_key_bytes = *endpoint_id.as_bytes(); +305 let stream = n0_future::stream::once_future(async move { +306 address_lookup.resolve_dht(&public_key_bytes).await +307 }) +308 .filter_map(|x| x) +309 .boxed(); +310 Some(stream) +311 } +312} +313 +314#[cfg(test)] +315mod tests { +316 use std::collections::BTreeSet; +317 +318 use iroh_base::{RelayUrl, TransportAddr}; +319 use mainline::Testnet; +320 use n0_error::{Result, StdResultExt}; +321 use n0_tracing_test::traced_test; +322 use url::Url; +323 +324 use super::*; +325 +326 #[tokio::test] +327 #[ignore = "flaky"] +328 #[traced_test] +329 async fn dht_address_lookup_smoke() -> Result { +330 let secret = SecretKey::generate(); +331 let testnet = Testnet::new_async(3).await.anyerr()?; +332 let mut dht_builder = DhtBuilder::default(); +333 dht_builder.bootstrap(&testnet.bootstrap); +334 let address_lookup = DhtAddressLookup::builder() +335 .secret_key(secret.clone()) +336 .dht_builder(dht_builder) +337 .addr_filter(AddrFilter::unfiltered()) +338 .build()?; +339 +340 let relay_url: RelayUrl = Url::parse("https://example.com").anyerr()?.into(); +341 +342 let data = EndpointData::from_iter([TransportAddr::Relay(relay_url.clone())]); +343 address_lookup.publish(&data); 344 -345 let data = EndpointData::from_iter([TransportAddr::Relay(relay_url.clone())]); -346 address_lookup.publish(&data); -347 -348 // publish is fire and forget, so we have no way to wait until it is done. -349 tokio::time::timeout(Duration::from_secs(30), async move { -350 loop { -351 tokio::time::sleep(Duration::from_millis(200)).await; -352 let mut found_relay_urls = BTreeSet::new(); -353 let items = address_lookup -354 .resolve(secret.public()) -355 .unwrap() -356 .collect::<Vec<_>>() -357 .await; -358 for item in items.into_iter().flatten() { -359 for url in item.relay_urls() { -360 found_relay_urls.insert(url.clone()); -361 } +345 // publish is fire and forget, so we have no way to wait until it is done. +346 tokio::time::timeout(Duration::from_secs(30), async move { +347 loop { +348 tokio::time::sleep(Duration::from_millis(200)).await; +349 let mut found_relay_urls = BTreeSet::new(); +350 let items = address_lookup +351 .resolve(secret.public()) +352 .unwrap() +353 .collect::<Vec<_>>() +354 .await; +355 for item in items.into_iter().flatten() { +356 for url in item.relay_urls() { +357 found_relay_urls.insert(url.clone()); +358 } +359 } +360 if found_relay_urls.contains(&relay_url) { +361 break; 362 } -363 if found_relay_urls.contains(&relay_url) { -364 break; -365 } -366 } -367 }) -368 .await -369 .expect("timeout, relay_url not found on DHT"); -370 Ok(()) -371 } -372} \ No newline at end of file +363 } +364 }) +365 .await +366 .expect("timeout, relay_url not found on DHT"); +367 Ok(()) +368 } +369} \ No newline at end of file