From eec477828f62c1a7b71a4d8043895d9dcc40d9e5 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Wed, 12 Nov 2025 12:36:34 -0600 Subject: [PATCH 01/10] WIP - remove EndpointId type alias - add EndpointId enum - gradually reintroduce EndpointId to the public API --- iroh-base/src/endpoint_addr.rs | 14 ++++-- iroh-base/src/key.rs | 31 +++++++++++- iroh-base/src/lib.rs | 2 +- iroh-dns-server/examples/convert.rs | 6 +-- iroh-dns-server/examples/publish.rs | 4 +- iroh-dns-server/examples/resolve.rs | 4 +- iroh-relay/src/dns.rs | 6 +-- iroh-relay/src/endpoint_info.rs | 48 +++++++++---------- iroh-relay/src/main.rs | 10 ++-- iroh-relay/src/protos/relay.rs | 24 +++++----- iroh-relay/src/server.rs | 10 ++-- iroh-relay/src/server/client.rs | 28 +++++------ iroh-relay/src/server/clients.rs | 18 +++---- iroh/examples/0rtt.rs | 4 +- iroh/examples/connect-unreliable.rs | 2 +- iroh/examples/connect.rs | 2 +- iroh/examples/dht_discovery.rs | 4 +- iroh/examples/locally-discovered-nodes.rs | 4 +- iroh/examples/search.rs | 6 +-- iroh/examples/transfer.rs | 6 +-- iroh/src/discovery.rs | 32 ++++++------- iroh/src/discovery/dns.rs | 4 +- iroh/src/discovery/pkarr.rs | 8 ++-- iroh/src/discovery/static_provider.rs | 10 ++-- iroh/src/endpoint.rs | 18 +++---- iroh/src/endpoint/connection.rs | 22 ++++----- iroh/src/endpoint/rtt_actor.rs | 8 ++-- iroh/src/lib.rs | 2 +- iroh/src/magicsock.rs | 24 +++++----- iroh/src/magicsock/endpoint_map.rs | 32 ++++++------- .../magicsock/endpoint_map/endpoint_state.rs | 16 +++---- iroh/src/magicsock/endpoint_map/path_state.rs | 12 ++--- iroh/src/magicsock/transports.rs | 16 +++---- iroh/src/magicsock/transports/relay.rs | 18 +++---- iroh/src/magicsock/transports/relay/actor.rs | 18 +++---- iroh/src/protocol.rs | 6 +-- iroh/src/test_utils.rs | 24 +++++----- iroh/src/tls/name.rs | 8 ++-- 38 files changed, 273 insertions(+), 238 deletions(-) diff --git a/iroh-base/src/endpoint_addr.rs b/iroh-base/src/endpoint_addr.rs index 342f472ec41..004168b990d 100644 --- a/iroh-base/src/endpoint_addr.rs +++ b/iroh-base/src/endpoint_addr.rs @@ -59,17 +59,17 @@ impl EndpointAddr { /// /// This still is usable with e.g. a discovery service to establish a connection, /// depending on the situation. - pub fn new(id: PublicKey) -> Self { + pub fn new(id: impl Into) -> Self { EndpointAddr { - id, + id: id.into(), addrs: Default::default(), } } /// Creates a new [`EndpointAddr`] from its parts. - pub fn from_parts(id: PublicKey, addrs: impl IntoIterator) -> Self { + pub fn from_parts(id: impl Into, addrs: impl IntoIterator) -> Self { Self { - id, + id: id.into(), addrs: addrs.into_iter().collect(), } } @@ -118,6 +118,12 @@ impl EndpointAddr { } } +impl From for EndpointAddr { + fn from(endpoint_id: PublicKey) -> Self { + EndpointAddr::new(endpoint_id) + } +} + impl From for EndpointAddr { fn from(endpoint_id: EndpointId) -> Self { EndpointAddr::new(endpoint_id) diff --git a/iroh-base/src/key.rs b/iroh-base/src/key.rs index 9cb7b01bdd6..3207125d6c8 100644 --- a/iroh-base/src/key.rs +++ b/iroh-base/src/key.rs @@ -23,6 +23,36 @@ use serde::{Deserialize, Serialize, de, ser}; #[repr(transparent)] pub struct PublicKey(CompressedEdwardsY); +/// The identifier for an endpoint in the (iroh) network. +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +pub enum EndpointId { + /// An Ed25519 public key. + Ed25519(PublicKey), + /// Other types of endpoint identifiers. + Other([u8; 8]), +} + +impl EndpointId { + /// If this is an Ed25519 endpoint id, return the public key. + pub fn as_ed(self) -> Option { + match self { + EndpointId::Ed25519(key) => Some(key), + EndpointId::Other(_) => None, + } + } + + /// Expect this to be an Ed25519 endpoint id, panic if not. + pub fn expect_ed(self) -> PublicKey { + self.as_ed().expect("not an ed25519 endpoint id") + } +} + +impl From for EndpointId { + fn from(key: PublicKey) -> Self { + EndpointId::Ed25519(key) + } +} + impl Borrow<[u8; 32]> for PublicKey { fn borrow(&self) -> &[u8; 32] { self.as_bytes() @@ -61,7 +91,6 @@ impl Ord for PublicKey { /// /// - `encrypt(key: PublicKey)` /// - `send_to(endpoint: EndpointId)` -pub type EndpointId = PublicKey; impl Hash for PublicKey { fn hash(&self, state: &mut H) { diff --git a/iroh-base/src/lib.rs b/iroh-base/src/lib.rs index 4b513469626..be5c3e190b7 100644 --- a/iroh-base/src/lib.rs +++ b/iroh-base/src/lib.rs @@ -13,6 +13,6 @@ mod relay_url; #[cfg(feature = "key")] pub use self::endpoint_addr::{EndpointAddr, TransportAddr}; #[cfg(feature = "key")] -pub use self::key::{EndpointId, KeyParsingError, PublicKey, SecretKey, Signature, SignatureError}; +pub use self::key::{EndpointId, PublicKey, KeyParsingError, SecretKey, Signature, SignatureError}; #[cfg(feature = "relay")] pub use self::relay_url::{RelayUrl, RelayUrlParseError}; diff --git a/iroh-dns-server/examples/convert.rs b/iroh-dns-server/examples/convert.rs index 1f6a2eb88ed..816ceb47b29 100644 --- a/iroh-dns-server/examples/convert.rs +++ b/iroh-dns-server/examples/convert.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use clap::Parser; -use iroh::EndpointId; +use iroh::PublicKey; use n0_error::{Result, StdResultExt}; #[derive(Debug, Parser)] @@ -20,13 +20,13 @@ fn main() -> Result<()> { let args = Cli::parse(); match args.command { Command::EndpointToPkarr { endpoint_id } => { - let endpoint_id = EndpointId::from_str(&endpoint_id)?; + let endpoint_id = PublicKey::from_str(&endpoint_id)?; let public_key = pkarr::PublicKey::try_from(endpoint_id.as_bytes()).anyerr()?; println!("{}", public_key.to_z32()) } Command::PkarrToEndpoint { z32_pubkey } => { let public_key = pkarr::PublicKey::try_from(z32_pubkey.as_str()).anyerr()?; - let endpoint_id = EndpointId::from_bytes(public_key.as_bytes())?; + let endpoint_id = PublicKey::from_bytes(public_key.as_bytes())?; println!("{endpoint_id}") } } diff --git a/iroh-dns-server/examples/publish.rs b/iroh-dns-server/examples/publish.rs index d8fd5acffb2..ce1e1f72a2f 100644 --- a/iroh-dns-server/examples/publish.rs +++ b/iroh-dns-server/examples/publish.rs @@ -2,7 +2,7 @@ use std::{net::SocketAddr, str::FromStr}; use clap::{Parser, ValueEnum}; use iroh::{ - EndpointId, SecretKey, + PublicKey, SecretKey, discovery::{ UserData, dns::{N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}, @@ -140,6 +140,6 @@ async fn main() -> Result<()> { Ok(()) } -fn fmt_domain(endpoint_id: &EndpointId, origin: &str) -> String { +fn fmt_domain(endpoint_id: &PublicKey, origin: &str) -> String { format!("{IROH_TXT_NAME}.{}.{origin}", endpoint_id.to_z32()) } diff --git a/iroh-dns-server/examples/resolve.rs b/iroh-dns-server/examples/resolve.rs index e9c536bbcf2..ded96563f84 100644 --- a/iroh-dns-server/examples/resolve.rs +++ b/iroh-dns-server/examples/resolve.rs @@ -1,6 +1,6 @@ use clap::{Parser, ValueEnum}; use iroh::{ - EndpointId, + PublicKey, discovery::dns::{N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}, dns::DnsResolver, }; @@ -34,7 +34,7 @@ enum Command { /// Resolve endpoint info by endpoint id. Endpoint { /// The endpoint id to resolve. - endpoint_id: EndpointId, + endpoint_id: PublicKey, /// Use a custom domain when resolving endpoint info via DNS. #[clap(long)] dns_origin_domain: Option, diff --git a/iroh-relay/src/dns.rs b/iroh-relay/src/dns.rs index b9d1a1bc3fd..fe27a81c86f 100644 --- a/iroh-relay/src/dns.rs +++ b/iroh-relay/src/dns.rs @@ -12,7 +12,7 @@ use hickory_resolver::{ config::{ResolverConfig, ResolverOpts}, name_server::TokioConnectionProvider, }; -use iroh_base::EndpointId; +use iroh_base::PublicKey; use n0_error::{StackError, e, stack_error}; use n0_future::{ StreamExt, @@ -388,7 +388,7 @@ impl DnsResolver { /// pass [`N0_DNS_ENDPOINT_ORIGIN_PROD`] as `origin`. pub async fn lookup_endpoint_by_id( &self, - endpoint_id: &EndpointId, + endpoint_id: &PublicKey, origin: &str, ) -> Result { let name = endpoint_info::endpoint_domain(endpoint_id, origin); @@ -432,7 +432,7 @@ impl DnsResolver { /// summary of all errors otherwise. pub async fn lookup_endpoint_by_id_staggered( &self, - endpoint_id: &EndpointId, + endpoint_id: &PublicKey, origin: &str, delays_ms: &[u64], ) -> Result> { diff --git a/iroh-relay/src/endpoint_info.rs b/iroh-relay/src/endpoint_info.rs index 5cd582b5b73..640154ca6c8 100644 --- a/iroh-relay/src/endpoint_info.rs +++ b/iroh-relay/src/endpoint_info.rs @@ -40,7 +40,7 @@ use std::{ str::{FromStr, Utf8Error}, }; -use iroh_base::{EndpointAddr, EndpointId, KeyParsingError, RelayUrl, SecretKey, TransportAddr}; +use iroh_base::{EndpointAddr, EndpointId, KeyParsingError, PublicKey, RelayUrl, SecretKey, TransportAddr}; use n0_error::{e, ensure, stack_error}; use url::Url; @@ -89,22 +89,22 @@ pub trait EndpointIdExt { /// Parses a [`EndpointId`] from [`z-base-32`] encoding. /// /// [`z-base-32`]: https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt - fn from_z32(s: &str) -> Result; + fn from_z32(s: &str) -> Result; } -impl EndpointIdExt for EndpointId { +impl EndpointIdExt for PublicKey { fn to_z32(&self) -> String { z32::encode(self.as_bytes()) } - fn from_z32(s: &str) -> Result { + fn from_z32(s: &str) -> Result { let bytes = z32::decode(s.as_bytes()).map_err(|err| e!(DecodingError::InvalidEncodingZ32, err))?; let bytes: &[u8; 32] = &bytes .try_into() .map_err(|_| e!(DecodingError::InvalidLength { len: s.len() }))?; let endpoint_id = - EndpointId::from_bytes(bytes).map_err(|err| e!(DecodingError::InvalidKey, err))?; + PublicKey::from_bytes(bytes).map_err(|err| e!(DecodingError::InvalidKey, err))?; Ok(endpoint_id) } } @@ -321,7 +321,7 @@ impl From<&TxtAttrs> for EndpointInfo { data.set_user_data(user_data); data.add_addrs(relay_urls.chain(ip_addrs)); - Self { endpoint_id, data } + Self { endpoint_id: endpoint_id.into(), data } } } @@ -338,16 +338,16 @@ impl From for EndpointInfo { info } } - + impl EndpointInfo { /// Creates a new [`EndpointInfo`] with an empty [`EndpointData`]. - pub fn new(endpoint_id: EndpointId) -> Self { + pub fn new(endpoint_id: impl Into) -> Self { Self::from_parts(endpoint_id, Default::default()) } /// Creates a new [`EndpointInfo`] from its parts. - pub fn from_parts(endpoint_id: EndpointId, data: EndpointData) -> Self { - Self { endpoint_id, data } + pub fn from_parts(endpoint_id: impl Into, data: EndpointData) -> Self { + Self { endpoint_id: endpoint_id.into(), data } } /// Sets the relay URL and returns the updated endpoint info. @@ -462,7 +462,7 @@ impl std::ops::DerefMut for EndpointInfo { /// [`IROH_TXT_NAME`] and the second label to be a z32 encoded [`EndpointId`]. Ignores /// subsequent labels. #[cfg(not(wasm_browser))] -fn endpoint_id_from_txt_name(name: &str) -> Result { +fn endpoint_id_from_txt_name(name: &str) -> Result { let num_labels = name.split(".").count(); if num_labels < 2 { return Err(e!(ParseError::NumLabels { num_labels })); @@ -475,7 +475,7 @@ fn endpoint_id_from_txt_name(name: &str) -> Result { })); } let label = labels.next().expect("checked above"); - let endpoint_id = EndpointId::from_z32(label)?; + let endpoint_id = PublicKey::from_z32(label)?; Ok(endpoint_id) } @@ -502,7 +502,7 @@ pub(crate) enum IrohAttr { /// [`Display`]. #[derive(Debug)] pub(crate) struct TxtAttrs { - endpoint_id: EndpointId, + endpoint_id: PublicKey, attrs: BTreeMap>, } @@ -522,14 +522,14 @@ impl From<&EndpointInfo> for TxtAttrs { if let Some(user_data) = &info.data.user_data { attrs.push((IrohAttr::UserData, user_data.to_string())); } - Self::from_parts(info.endpoint_id, attrs.into_iter()) + Self::from_parts(info.endpoint_id.expect_ed(), attrs.into_iter()) } } impl TxtAttrs { /// Creates [`TxtAttrs`] from an endpoint id and an iterator of key-value pairs. pub(crate) fn from_parts( - endpoint_id: EndpointId, + endpoint_id: PublicKey, pairs: impl Iterator, ) -> Self { let mut attrs: BTreeMap> = BTreeMap::new(); @@ -541,7 +541,7 @@ impl TxtAttrs { /// Creates [`TxtAttrs`] from an endpoint id and an iterator of "{key}={value}" strings. pub(crate) fn from_strings( - endpoint_id: EndpointId, + endpoint_id: PublicKey, strings: impl Iterator, ) -> Result { let mut attrs: BTreeMap> = BTreeMap::new(); @@ -566,7 +566,7 @@ impl TxtAttrs { } /// Returns the endpoint id. - pub(crate) fn endpoint_id(&self) -> EndpointId { + pub(crate) fn endpoint_id(&self) -> PublicKey { self.endpoint_id } @@ -581,7 +581,7 @@ impl TxtAttrs { let pubkey = packet.public_key(); let pubkey_z32 = pubkey.to_z32(); let endpoint_id = - EndpointId::from_bytes(&pubkey.verifying_key().to_bytes()).expect("valid key"); + PublicKey::from_bytes(&pubkey.verifying_key().to_bytes()).expect("valid key"); let zone = dns::Name::new(&pubkey_z32).expect("z32 encoding is valid"); let txt_data = packet .all_resource_records() @@ -652,8 +652,8 @@ pub(crate) fn ensure_iroh_txt_label(name: String) -> String { } #[cfg(not(wasm_browser))] -pub(crate) fn endpoint_domain(endpoint_id: &EndpointId, origin: &str) -> String { - format!("{}.{}", EndpointId::to_z32(endpoint_id), origin) +pub(crate) fn endpoint_domain(endpoint_id: &PublicKey, origin: &str) -> String { + format!("{}.{}", PublicKey::to_z32(endpoint_id), origin) } #[cfg(test)] @@ -671,7 +671,7 @@ mod tests { }, }, }; - use iroh_base::{EndpointId, SecretKey, TransportAddr}; + use iroh_base::{PublicKey, SecretKey, TransportAddr}; use n0_error::{Result, StdResultExt}; use super::{EndpointData, EndpointIdExt, EndpointInfo}; @@ -684,7 +684,7 @@ mod tests { TransportAddr::Ip("127.0.0.1:1234".parse().unwrap()), ]) .with_user_data(Some("foobar".parse().unwrap())); - let endpoint_id = "vpnk377obfvzlipnsfbqba7ywkkenc4xlpmovt5tsfujoa75zqia" + let endpoint_id: PublicKey = "vpnk377obfvzlipnsfbqba7ywkkenc4xlpmovt5tsfujoa75zqia" .parse() .unwrap(); let expected = EndpointInfo::from_parts(endpoint_id, endpoint_data); @@ -738,7 +738,7 @@ mod tests { Record::from_rdata( Name::from_utf8(format!( "_iroh.{}.dns.iroh.link.", - EndpointId::from_str( + PublicKey::from_str( // Another EndpointId "a55f26132e5e43de834d534332f66a20d480c3e50a13a312a071adea6569981e" )? @@ -774,7 +774,7 @@ mod tests { let endpoint_info = EndpointInfo::from_txt_lookup(name.to_string(), lookup)?; - let expected_endpoint_info = EndpointInfo::new(EndpointId::from_str( + let expected_endpoint_info = EndpointInfo::new(PublicKey::from_str( "1992d53c02cdc04566e5c0edb1ce83305cd550297953a047a445ea3264b54b18", )?) .with_relay_url(Some("https://euw1-1.relay.iroh.network./".parse()?)) diff --git a/iroh-relay/src/main.rs b/iroh-relay/src/main.rs index 5f558dbaa15..bd7eda74337 100644 --- a/iroh-relay/src/main.rs +++ b/iroh-relay/src/main.rs @@ -12,7 +12,7 @@ use std::{ use clap::Parser; use http::StatusCode; -use iroh_base::EndpointId; +use iroh_base::PublicKey; use iroh_relay::{ defaults::{ DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT, DEFAULT_METRICS_PORT, DEFAULT_RELAY_QUIC_PORT, @@ -179,9 +179,9 @@ enum AccessConfig { #[default] Everyone, /// Allows only these endpoints. - Allowlist(Vec), + Allowlist(Vec), /// Allows everyone, except these endpoints. - Denylist(Vec), + Denylist(Vec), /// Performs a HTTP POST request to determine access for each endpoint that connects to the relay. /// /// The request will have a header `X-Iroh-Endpoint-Id` set to the hex-encoded endpoint id attempting @@ -261,7 +261,7 @@ impl From for iroh_relay::server::AccessConfig { async fn http_access_check( client: &reqwest::Client, config: &HttpAccessConfig, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> iroh_relay::server::Access { use iroh_relay::server::Access; debug!(url=%config.url, "Check relay access via HTTP POST"); @@ -281,7 +281,7 @@ async fn http_access_check( async fn http_access_check_inner( client: &reqwest::Client, config: &HttpAccessConfig, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Result<()> { let mut request = client .post(config.url.clone()) diff --git a/iroh-relay/src/protos/relay.rs b/iroh-relay/src/protos/relay.rs index 991f4472f54..919d1118b58 100644 --- a/iroh-relay/src/protos/relay.rs +++ b/iroh-relay/src/protos/relay.rs @@ -10,7 +10,7 @@ use std::num::NonZeroU16; use bytes::{Buf, BufMut, Bytes, BytesMut}; -use iroh_base::{EndpointId, KeyParsingError}; +use iroh_base::{PublicKey, KeyParsingError}; use n0_error::{e, ensure, stack_error}; use n0_future::time::Duration; @@ -76,13 +76,13 @@ pub enum RelayToClientMsg { /// Represents datagrams sent from relays (originally sent to them by another client). Datagrams { /// The [`EndpointId`] of the original sender. - remote_endpoint_id: EndpointId, + remote_endpoint_id: PublicKey, /// The datagrams and related metadata. datagrams: Datagrams, }, /// Indicates that the client identified by the underlying public key had previously sent you a /// packet but has now disconnected from the relay. - EndpointGone(EndpointId), + EndpointGone(PublicKey), /// A one-way message from relay to client, declaring the connection health state. Health { /// If set, is a description of why the connection is unhealthy. @@ -124,7 +124,7 @@ pub enum ClientToRelayMsg { /// Request from the client to relay datagrams to given remote endpoint. Datagrams { /// The remote endpoint to relay to. - dst_endpoint_id: EndpointId, + dst_endpoint_id: PublicKey, /// The datagrams and related metadata to relay. datagrams: Datagrams, }, @@ -336,11 +336,11 @@ impl RelayToClientMsg { let res = match frame_type { FrameType::RelayToClientDatagram | FrameType::RelayToClientDatagramBatch => { - ensure!(content.len() >= EndpointId::LENGTH, Error::InvalidFrame); + ensure!(content.len() >= PublicKey::LENGTH, Error::InvalidFrame); - let remote_endpoint_id = cache.key_from_slice(&content[..EndpointId::LENGTH])?; + let remote_endpoint_id = cache.key_from_slice(&content[..PublicKey::LENGTH])?; let datagrams = Datagrams::from_bytes( - content.slice(EndpointId::LENGTH..), + content.slice(PublicKey::LENGTH..), frame_type == FrameType::RelayToClientDatagramBatch, )?; Self::Datagrams { @@ -349,7 +349,7 @@ impl RelayToClientMsg { } } FrameType::EndpointGone => { - ensure!(content.len() == EndpointId::LENGTH, Error::InvalidFrame); + ensure!(content.len() == PublicKey::LENGTH, Error::InvalidFrame); let endpoint_id = cache.key_from_slice(content.as_ref())?; Self::EndpointGone(endpoint_id) } @@ -464,9 +464,9 @@ impl ClientToRelayMsg { let res = match frame_type { FrameType::ClientToRelayDatagram | FrameType::ClientToRelayDatagramBatch => { - let dst_endpoint_id = cache.key_from_slice(&content[..EndpointId::LENGTH])?; + let dst_endpoint_id = cache.key_from_slice(&content[..PublicKey::LENGTH])?; let datagrams = Datagrams::from_bytes( - content.slice(EndpointId::LENGTH..), + content.slice(PublicKey::LENGTH..), frame_type == FrameType::ClientToRelayDatagramBatch, )?; Self::Datagrams { @@ -678,7 +678,7 @@ mod proptests { prop::array::uniform32(any::()).prop_map(SecretKey::from) } - fn key() -> impl Strategy { + fn key() -> impl Strategy { secret_key().prop_map(|key| key.public()) } @@ -693,7 +693,7 @@ mod proptests { fn datagrams() -> impl Strategy { // The max payload size (conservatively, since with segment_size = 0 we'd have slightly more space) - const MAX_PAYLOAD_SIZE: usize = MAX_PACKET_SIZE - EndpointId::LENGTH - 1 /* ECN bytes */ - 2 /* segment size */; + const MAX_PAYLOAD_SIZE: usize = MAX_PACKET_SIZE - PublicKey::LENGTH - 1 /* ECN bytes */ - 2 /* segment size */; ( ecn(), prop::option::of(MAX_PAYLOAD_SIZE / 20..MAX_PAYLOAD_SIZE), diff --git a/iroh-relay/src/server.rs b/iroh-relay/src/server.rs index f3b470b8a3c..8a343f6378b 100644 --- a/iroh-relay/src/server.rs +++ b/iroh-relay/src/server.rs @@ -23,7 +23,7 @@ use http::{ response::Builder as ResponseBuilder, }; use hyper::body::Incoming; -use iroh_base::EndpointId; +use iroh_base::PublicKey; #[cfg(feature = "test-utils")] use iroh_base::RelayUrl; use n0_error::{e, stack_error}; @@ -134,12 +134,12 @@ pub enum AccessConfig { Everyone, /// Only endpoints for which the function returns `Access::Allow`. #[debug("restricted")] - Restricted(Box Boxed + Send + Sync + 'static>), + Restricted(Box Boxed + Send + Sync + 'static>), } impl AccessConfig { /// Is this endpoint allowed? - pub async fn is_allowed(&self, endpoint: EndpointId) -> bool { + pub async fn is_allowed(&self, endpoint: PublicKey) -> bool { match self { Self::Everyone => true, Self::Restricted(check) => { @@ -754,7 +754,7 @@ mod tests { use std::{net::Ipv4Addr, time::Duration}; use http::StatusCode; - use iroh_base::{EndpointId, RelayUrl, SecretKey}; + use iroh_base::{PublicKey, RelayUrl, SecretKey}; use n0_error::Result; use n0_future::{FutureExt, SinkExt, StreamExt}; use rand::SeedableRng; @@ -793,7 +793,7 @@ mod tests { async fn try_send_recv( client_a: &mut crate::client::Client, client_b: &mut crate::client::Client, - b_key: EndpointId, + b_key: PublicKey, msg: Datagrams, ) -> Result { // try resend 10 times diff --git a/iroh-relay/src/server/client.rs b/iroh-relay/src/server/client.rs index b1af242de8e..4055f213604 100644 --- a/iroh-relay/src/server/client.rs +++ b/iroh-relay/src/server/client.rs @@ -2,7 +2,7 @@ use std::{collections::HashSet, sync::Arc, time::Duration}; -use iroh_base::EndpointId; +use iroh_base::PublicKey; use n0_error::{e, stack_error}; use n0_future::{SinkExt, StreamExt}; use rand::Rng; @@ -31,7 +31,7 @@ use crate::{ #[derive(Debug, Clone)] pub(super) struct Packet { /// The sender of the packet - src: EndpointId, + src: PublicKey, /// The data packet bytes. data: Datagrams, } @@ -39,7 +39,7 @@ pub(super) struct Packet { /// Configuration for a [`Client`]. #[derive(Debug)] pub(super) struct Config { - pub(super) endpoint_id: EndpointId, + pub(super) endpoint_id: PublicKey, pub(super) stream: RelayedStream, pub(super) write_timeout: Duration, pub(super) channel_capacity: usize, @@ -52,7 +52,7 @@ pub(super) struct Config { #[derive(Debug)] pub(super) struct Client { /// Identity of the connected peer. - endpoint_id: EndpointId, + endpoint_id: PublicKey, /// Connection identifier. connection_id: u64, /// Used to close the connection loop. @@ -64,7 +64,7 @@ pub(super) struct Client { /// Queue of disco packets intended for the client. disco_send_queue: mpsc::Sender, /// Channel to notify the client that a previous sender has disconnected. - peer_gone: mpsc::Sender, + peer_gone: mpsc::Sender, } impl Client { @@ -147,7 +147,7 @@ impl Client { pub(super) fn try_send_packet( &self, - src: EndpointId, + src: PublicKey, data: Datagrams, ) -> Result<(), TrySendError> { self.send_queue.try_send(Packet { src, data }) @@ -155,7 +155,7 @@ impl Client { pub(super) fn try_send_disco_packet( &self, - src: EndpointId, + src: PublicKey, data: Datagrams, ) -> Result<(), TrySendError> { self.disco_send_queue.try_send(Packet { src, data }) @@ -163,8 +163,8 @@ impl Client { pub(super) fn try_send_peer_gone( &self, - key: EndpointId, - ) -> Result<(), TrySendError> { + key: PublicKey, + ) -> Result<(), TrySendError> { self.peer_gone.try_send(key) } } @@ -261,9 +261,9 @@ struct Actor { /// Important packets queued to send to the client disco_send_queue: mpsc::Receiver, /// Notify the client that a previous sender has disconnected - endpoint_gone: mpsc::Receiver, + endpoint_gone: mpsc::Receiver, /// [`EndpointId`] of this client - endpoint_id: EndpointId, + endpoint_id: PublicKey, /// Connection identifier. connection_id: u64, /// Reference to the other connected clients. @@ -464,7 +464,7 @@ impl Actor { fn handle_frame_send_packet( &self, - dst: EndpointId, + dst: PublicKey, data: Datagrams, ) -> Result<(), ForwardPacketError> { if disco::looks_like_disco_wrapper(&data.contents) { @@ -502,7 +502,7 @@ pub struct ForwardPacketError { /// Tracks how many unique endpoints have been seen during the last day. #[derive(Debug)] struct ClientCounter { - clients: HashSet, + clients: HashSet, last_clear_date: Date, } @@ -525,7 +525,7 @@ impl ClientCounter { } /// Marks this endpoint as seen, returns whether it is new today or not. - fn update(&mut self, client: EndpointId) -> bool { + fn update(&mut self, client: PublicKey) -> bool { self.check_and_clear(); self.clients.insert(client) } diff --git a/iroh-relay/src/server/clients.rs b/iroh-relay/src/server/clients.rs index 7fe77784e00..aa8393bc43b 100644 --- a/iroh-relay/src/server/clients.rs +++ b/iroh-relay/src/server/clients.rs @@ -10,7 +10,7 @@ use std::{ }; use dashmap::DashMap; -use iroh_base::EndpointId; +use iroh_base::PublicKey; use tokio::sync::mpsc::error::TrySendError; use tracing::{debug, trace}; @@ -30,9 +30,9 @@ pub(super) struct Clients(Arc); #[derive(Debug, Default)] struct Inner { /// The list of all currently connected clients. - clients: DashMap, + clients: DashMap, /// Map of which client has sent where - sent_to: DashMap>, + sent_to: DashMap>, /// Connection ID Counter next_connection_id: AtomicU64, } @@ -72,7 +72,7 @@ impl Clients { /// peer is gone from the network. /// /// Must be passed a matching connection_id. - pub(super) fn unregister(&self, connection_id: u64, endpoint_id: EndpointId) { + pub(super) fn unregister(&self, connection_id: u64, endpoint_id: PublicKey) { trace!( endpoint_id = %endpoint_id.fmt_short(), connection_id, "unregistering client" @@ -108,9 +108,9 @@ impl Clients { /// Attempt to send a packet to client with [`EndpointId`] `dst`. pub(super) fn send_packet( &self, - dst: EndpointId, + dst: PublicKey, data: Datagrams, - src: EndpointId, + src: PublicKey, metrics: &Metrics, ) -> Result<(), ForwardPacketError> { let Some(client) = self.0.clients.get(&dst) else { @@ -148,9 +148,9 @@ impl Clients { /// Attempt to send a disco packet to client with [`EndpointId`] `dst`. pub(super) fn send_disco_packet( &self, - dst: EndpointId, + dst: PublicKey, data: Datagrams, - src: EndpointId, + src: PublicKey, metrics: &Metrics, ) -> Result<(), ForwardPacketError> { let Some(client) = self.0.clients.get(&dst) else { @@ -228,7 +228,7 @@ mod tests { } } - fn test_client_builder(key: EndpointId) -> (Config, Conn) { + fn test_client_builder(key: PublicKey) -> (Config, Conn) { let (server, client) = tokio::io::duplex(1024); ( Config { diff --git a/iroh/examples/0rtt.rs b/iroh/examples/0rtt.rs index eb3fd564b64..efedbe8f92f 100644 --- a/iroh/examples/0rtt.rs +++ b/iroh/examples/0rtt.rs @@ -2,7 +2,7 @@ use std::{env, str::FromStr, time::Instant}; use clap::Parser; use data_encoding::HEXLOWER; -use iroh::{EndpointId, SecretKey, discovery::Discovery, endpoint::ZeroRttStatus}; +use iroh::{PublicKey, SecretKey, discovery::Discovery, endpoint::ZeroRttStatus}; use n0_error::{Result, StackResultExt, StdResultExt}; use n0_future::StreamExt; use quinn::{RecvStream, SendStream}; @@ -13,7 +13,7 @@ const PINGPONG_ALPN: &[u8] = b"0rtt-pingpong"; #[derive(Parser)] struct Args { /// The endpoint id to connect to. If not set, the program will start a server. - endpoint_id: Option, + endpoint_id: Option, /// Number of rounds to run. #[clap(long, default_value = "100")] rounds: u64, diff --git a/iroh/examples/connect-unreliable.rs b/iroh/examples/connect-unreliable.rs index 46a19bd8dc4..816740f21b2 100644 --- a/iroh/examples/connect-unreliable.rs +++ b/iroh/examples/connect-unreliable.rs @@ -20,7 +20,7 @@ const EXAMPLE_ALPN: &[u8] = b"n0/iroh/examples/magic/0"; struct Cli { /// The id of the remote endpoint. #[clap(long)] - endpoint_id: iroh::EndpointId, + endpoint_id: iroh::PublicKey, /// The list of direct UDP addresses for the remote endpoint. #[clap(long, value_parser, num_args = 1.., value_delimiter = ' ')] addrs: Vec, diff --git a/iroh/examples/connect.rs b/iroh/examples/connect.rs index 6ac6482519f..9e1125cf6fe 100644 --- a/iroh/examples/connect.rs +++ b/iroh/examples/connect.rs @@ -19,7 +19,7 @@ const EXAMPLE_ALPN: &[u8] = b"n0/iroh/examples/magic/0"; struct Cli { /// The id of the remote endpoint. #[clap(long)] - endpoint_id: iroh::EndpointId, + endpoint_id: iroh::PublicKey, /// The list of direct UDP addresses for the remote endpoint. #[clap(long, value_parser, num_args = 1.., value_delimiter = ' ')] addrs: Vec, diff --git a/iroh/examples/dht_discovery.rs b/iroh/examples/dht_discovery.rs index 7c85b01c6be..91ab0149694 100644 --- a/iroh/examples/dht_discovery.rs +++ b/iroh/examples/dht_discovery.rs @@ -11,7 +11,7 @@ use std::str::FromStr; use clap::Parser; -use iroh::{Endpoint, EndpointId}; +use iroh::{Endpoint, PublicKey}; use n0_error::{Result, StdResultExt}; use tracing::warn; use url::Url; @@ -21,7 +21,7 @@ const CHAT_ALPN: &[u8] = b"pkarr-discovery-demo-chat"; #[derive(Parser)] struct Args { /// The endpoint id to connect to. If not set, the program will start a server. - endpoint_id: Option, + endpoint_id: Option, /// Disable using the mainline DHT for discovery and publishing. #[clap(long)] disable_dht: bool, diff --git a/iroh/examples/locally-discovered-nodes.rs b/iroh/examples/locally-discovered-nodes.rs index eb7cd9783b2..9fe375fe28c 100644 --- a/iroh/examples/locally-discovered-nodes.rs +++ b/iroh/examples/locally-discovered-nodes.rs @@ -6,7 +6,7 @@ use std::time::Duration; use iroh::{ - Endpoint, EndpointId, + Endpoint, PublicKey, discovery::mdns::{DiscoveryEvent, MdnsDiscovery}, endpoint_info::UserData, }; @@ -32,7 +32,7 @@ async fn main() -> Result<()> { let ud = user_data.clone(); let discovery_stream_task = tokio::spawn(async move { let mut discovery_stream = mdns.subscribe().await; - let mut discovered_endpoints: Vec = vec![]; + let mut discovered_endpoints: Vec = vec![]; while let Some(event) = discovery_stream.next().await { match event { DiscoveryEvent::Discovered { endpoint_info, .. } => { diff --git a/iroh/examples/search.rs b/iroh/examples/search.rs index e4bc20b109a..f53b45ee9d9 100644 --- a/iroh/examples/search.rs +++ b/iroh/examples/search.rs @@ -33,7 +33,7 @@ use std::{collections::BTreeSet, sync::Arc}; use clap::Parser; use iroh::{ - Endpoint, EndpointId, + Endpoint, PublicKey, endpoint::Connection, protocol::{AcceptError, ProtocolHandler, Router}, }; @@ -57,7 +57,7 @@ pub enum Command { /// Query a remote endpoint for data and print the results. Query { /// The endpoint id of the endpoint we want to query. - endpoint_id: EndpointId, + endpoint_id: PublicKey, /// The text we want to match. query: String, }, @@ -171,7 +171,7 @@ impl BlobSearch { } /// Query a remote endpoint, download all matching blobs and print the results. - pub async fn query_remote(&self, endpoint_id: EndpointId, query: &str) -> Result { + pub async fn query_remote(&self, endpoint_id: PublicKey, query: &str) -> Result { // Establish a connection to our endpoint. // We use the default endpoint discovery in iroh, so we can connect by endpoint id without // providing further information. diff --git a/iroh/examples/transfer.rs b/iroh/examples/transfer.rs index 00cb52c9588..fcbc7407032 100644 --- a/iroh/examples/transfer.rs +++ b/iroh/examples/transfer.rs @@ -9,7 +9,7 @@ use clap::{Parser, Subcommand}; use data_encoding::HEXLOWER; use indicatif::HumanBytes; use iroh::{ - Endpoint, EndpointAddr, EndpointId, RelayMap, RelayMode, RelayUrl, SecretKey, TransportAddr, + Endpoint, EndpointAddr, PublicKey, RelayMap, RelayMode, RelayUrl, SecretKey, TransportAddr, discovery::{ dns::DnsDiscovery, pkarr::{N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING, PkarrPublisher}, @@ -146,7 +146,7 @@ enum Commands { }, /// Fetch data. Fetch { - remote_id: EndpointId, + remote_id: PublicKey, #[clap(long)] remote_relay_url: Option, #[clap(long)] @@ -521,7 +521,7 @@ fn parse_byte_size(s: &str) -> std::result::Result { cfg.parse_size(s) } -fn watch_conn_type(endpoint: &Endpoint, endpoint_id: EndpointId) -> AbortOnDropHandle<()> { +fn watch_conn_type(endpoint: &Endpoint, endpoint_id: PublicKey) -> AbortOnDropHandle<()> { let mut stream = endpoint.conn_type(endpoint_id).unwrap().stream(); let task = tokio::task::spawn(async move { while let Some(conn_type) = stream.next().await { diff --git a/iroh/src/discovery.rs b/iroh/src/discovery.rs index fb6b30ce5c7..7af006698db 100644 --- a/iroh/src/discovery.rs +++ b/iroh/src/discovery.rs @@ -112,7 +112,7 @@ use std::sync::{Arc, RwLock}; -use iroh_base::{EndpointAddr, EndpointId}; +use iroh_base::{EndpointAddr, PublicKey}; use n0_error::{AnyError, e, ensure, stack_error}; use n0_future::{ boxed::BoxStream, @@ -223,7 +223,7 @@ pub enum DiscoveryError { #[error("No discovery service configured")] NoServiceConfigured, #[error("Discovery produced no results for {}", endpoint_id.fmt_short())] - NoResults { endpoint_id: EndpointId }, + NoResults { endpoint_id: PublicKey }, #[error("Service '{provenance}' error")] User { provenance: &'static str, @@ -298,7 +298,7 @@ pub trait Discovery: std::fmt::Debug + Send + Sync + 'static { /// work. fn resolve( &self, - _endpoint_id: EndpointId, + _endpoint_id: PublicKey, ) -> Option>> { None } @@ -311,7 +311,7 @@ impl Discovery for Arc { fn resolve( &self, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Option>> { self.as_ref().resolve(endpoint_id) } @@ -355,7 +355,7 @@ impl DiscoveryItem { } /// Returns the endpoint id of the discovered endpoint. - pub fn endpoint_id(&self) -> EndpointId { + pub fn endpoint_id(&self) -> PublicKey { self.endpoint_info.endpoint_id } @@ -491,7 +491,7 @@ impl Discovery for ConcurrentDiscovery { fn resolve( &self, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Option>> { let services = self.services.read().expect("poisoned"); let streams = services @@ -515,7 +515,7 @@ pub(super) struct DiscoveryTask { impl DiscoveryTask { /// Starts a discovery task. - pub(super) fn start(ep: Endpoint, endpoint_id: EndpointId) -> Result { + pub(super) fn start(ep: Endpoint, endpoint_id: PublicKey) -> Result { ensure!( !ep.discovery().is_empty(), DiscoveryError::NoServiceConfigured @@ -543,7 +543,7 @@ impl DiscoveryTask { /// Otherwise, or if no `delay` is set, the discovery will be started. pub(super) fn maybe_start_after_delay( ep: &Endpoint, - endpoint_id: EndpointId, + endpoint_id: PublicKey, delay: Option, ) -> Result, DiscoveryError> { // If discovery is not needed, don't even spawn a task. @@ -589,7 +589,7 @@ impl DiscoveryTask { fn create_stream( ep: &Endpoint, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Result>, DiscoveryError> { ensure!( !ep.discovery().is_empty(), @@ -604,7 +604,7 @@ impl DiscoveryTask { async fn run( ep: Endpoint, - endpoint_id: EndpointId, + endpoint_id: PublicKey, on_first_tx: oneshot::Sender>, ) { let mut stream = match Self::create_stream(&ep, endpoint_id) { @@ -668,7 +668,7 @@ mod tests { use super::*; use crate::{Endpoint, RelayMode, endpoint::ConnectOptions}; - type InfoStore = HashMap; + type InfoStore = HashMap; #[derive(Debug, Clone, Default)] struct TestDiscoveryShared { @@ -676,7 +676,7 @@ mod tests { } impl TestDiscoveryShared { - pub fn create_discovery(&self, endpoint_id: EndpointId) -> TestDiscovery { + pub fn create_discovery(&self, endpoint_id: PublicKey) -> TestDiscovery { TestDiscovery { endpoint_id, shared: self.clone(), @@ -686,7 +686,7 @@ mod tests { } } - pub fn create_lying_discovery(&self, endpoint_id: EndpointId) -> TestDiscovery { + pub fn create_lying_discovery(&self, endpoint_id: PublicKey) -> TestDiscovery { TestDiscovery { endpoint_id, shared: self.clone(), @@ -699,7 +699,7 @@ mod tests { #[derive(Debug)] struct TestDiscovery { - endpoint_id: EndpointId, + endpoint_id: PublicKey, shared: TestDiscoveryShared, publish: bool, resolve_wrong: bool, @@ -721,7 +721,7 @@ mod tests { fn resolve( &self, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Option>> { let addr_info = if self.resolve_wrong { let ts = system_time_now() - 100_000; @@ -767,7 +767,7 @@ mod tests { fn resolve( &self, - _endpoint_id: EndpointId, + _endpoint_id: PublicKey, ) -> Option>> { Some(n0_future::stream::empty().boxed()) } diff --git a/iroh/src/discovery/dns.rs b/iroh/src/discovery/dns.rs index 52437dbd0ef..4d4014c921c 100644 --- a/iroh/src/discovery/dns.rs +++ b/iroh/src/discovery/dns.rs @@ -1,6 +1,6 @@ //! DNS endpoint discovery for iroh -use iroh_base::EndpointId; +use iroh_base::PublicKey; use iroh_relay::dns::DnsResolver; pub use iroh_relay::dns::{N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}; use n0_future::boxed::BoxStream; @@ -105,7 +105,7 @@ impl IntoDiscovery for DnsDiscoveryBuilder { impl Discovery for DnsDiscovery { fn resolve( &self, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Option>> { let resolver = self.dns_resolver.clone(); let origin_domain = self.origin_domain.clone(); diff --git a/iroh/src/discovery/pkarr.rs b/iroh/src/discovery/pkarr.rs index 67cecd0e4c3..43889b9e1f2 100644 --- a/iroh/src/discovery/pkarr.rs +++ b/iroh/src/discovery/pkarr.rs @@ -46,7 +46,7 @@ use std::sync::Arc; -use iroh_base::{EndpointId, RelayUrl, SecretKey}; +use iroh_base::{PublicKey, RelayUrl, SecretKey}; use iroh_relay::endpoint_info::{EncodingError, EndpointInfo}; use n0_error::{e, stack_error}; use n0_future::{ @@ -243,7 +243,7 @@ impl IntoDiscovery for PkarrPublisherBuilder { /// [`ConcurrentDiscovery`]: super::ConcurrentDiscovery #[derive(derive_more::Debug, Clone)] pub struct PkarrPublisher { - endpoint_id: EndpointId, + endpoint_id: PublicKey, watchable: Watchable>, _drop_guard: Arc>, } @@ -510,7 +510,7 @@ impl PkarrResolver { impl Discovery for PkarrResolver { fn resolve( &self, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Option>> { let pkarr_client = self.pkarr_client.clone(); let fut = async move { @@ -559,7 +559,7 @@ impl PkarrRelayClient { } /// Resolves a [`SignedPacket`] for the given [`EndpointId`]. - pub async fn resolve(&self, endpoint_id: EndpointId) -> Result { + pub async fn resolve(&self, endpoint_id: PublicKey) -> Result { // We map the error to string, as in browsers the error is !Send let public_key = pkarr::PublicKey::try_from(endpoint_id.as_bytes()) .map_err(|err| e!(PkarrError::PublicKey, err))?; diff --git a/iroh/src/discovery/static_provider.rs b/iroh/src/discovery/static_provider.rs index 05e16b85d69..8c63af20a5d 100644 --- a/iroh/src/discovery/static_provider.rs +++ b/iroh/src/discovery/static_provider.rs @@ -15,7 +15,7 @@ use std::{ sync::{Arc, RwLock}, }; -use iroh_base::EndpointId; +use iroh_base::PublicKey; use n0_future::{ boxed::BoxStream, stream::{self, StreamExt}, @@ -67,7 +67,7 @@ use super::{Discovery, DiscoveryError, DiscoveryItem, EndpointData, EndpointInfo /// [`EndpointTicket`]: https://docs.rs/iroh-base/latest/iroh_base/ticket/struct.EndpointTicket #[derive(Debug, Clone)] pub struct StaticProvider { - endpoints: Arc>>, + endpoints: Arc>>, provenance: &'static str, } @@ -186,7 +186,7 @@ impl StaticProvider { } /// Returns endpoint addressing information for the given endpoint ID. - pub fn get_endpoint_info(&self, endpoint_id: EndpointId) -> Option { + pub fn get_endpoint_info(&self, endpoint_id: PublicKey) -> Option { let guard = self.endpoints.read().expect("poisoned"); let info = guard.get(&endpoint_id)?; Some(EndpointInfo::from_parts(endpoint_id, info.data.clone())) @@ -195,7 +195,7 @@ impl StaticProvider { /// Removes all endpoint addressing information for the given endpoint ID. /// /// Any removed information is returned. - pub fn remove_endpoint_info(&self, endpoint_id: EndpointId) -> Option { + pub fn remove_endpoint_info(&self, endpoint_id: PublicKey) -> Option { let mut guard = self.endpoints.write().expect("poisoned"); let info = guard.remove(&endpoint_id)?; Some(EndpointInfo::from_parts(endpoint_id, info.data)) @@ -207,7 +207,7 @@ impl Discovery for StaticProvider { fn resolve( &self, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Option>> { let guard = self.endpoints.read().expect("poisoned"); let info = guard.get(&endpoint_id); diff --git a/iroh/src/endpoint.rs b/iroh/src/endpoint.rs index c5e49c7fb46..c699a16df67 100644 --- a/iroh/src/endpoint.rs +++ b/iroh/src/endpoint.rs @@ -16,7 +16,7 @@ use std::{ sync::Arc, }; -use iroh_base::{EndpointAddr, EndpointId, RelayUrl, SecretKey, TransportAddr}; +use iroh_base::{EndpointAddr, PublicKey, RelayUrl, SecretKey, TransportAddr}; use iroh_relay::{RelayConfig, RelayMap}; use n0_error::{e, ensure, stack_error}; use n0_future::time::Duration; @@ -793,7 +793,7 @@ impl Endpoint { /// /// This ID is the unique addressing information of this endpoint and other peers must know /// it to be able to connect to this endpoint. - pub fn id(&self) -> EndpointId { + pub fn id(&self) -> PublicKey { self.static_config.tls_config.secret_key.public() } @@ -975,14 +975,14 @@ impl Endpoint { /// become inaccessible. /// /// Will return `None` if we do not have any address information for the given `endpoint_id`. - pub fn conn_type(&self, endpoint_id: EndpointId) -> Option> { + pub fn conn_type(&self, endpoint_id: PublicKey) -> Option> { self.msock.conn_type(endpoint_id) } /// Returns the currently lowest latency for this endpoint. /// /// Will return `None` if we do not have any address information for the given `endpoint_id`. - pub fn latency(&self, endpoint_id: EndpointId) -> Option { + pub fn latency(&self, endpoint_id: PublicKey) -> Option { self.msock.latency(endpoint_id) } @@ -1200,7 +1200,7 @@ impl Endpoint { // # Remaining private methods /// Checks if the given `EndpointId` needs discovery. - pub(crate) fn needs_discovery(&self, endpoint_id: EndpointId, max_age: Duration) -> bool { + pub(crate) fn needs_discovery(&self, endpoint_id: PublicKey, max_age: Duration) -> bool { match self.msock.remote_info(endpoint_id) { // No info means no path to endpoint -> start discovery. None => true, @@ -1443,7 +1443,7 @@ fn is_cgi() -> bool { mod tests { use std::time::{Duration, Instant}; - use iroh_base::{EndpointAddr, EndpointId, SecretKey, TransportAddr}; + use iroh_base::{EndpointAddr, PublicKey, SecretKey, TransportAddr}; use n0_error::{AnyError as Error, Result, StdResultExt}; use n0_future::{BufferedStreamExt, StreamExt, stream, task::AbortOnDropHandle}; use n0_watcher::Watcher; @@ -1862,7 +1862,7 @@ mod tests { eprintln!("endpoint id 1 {ep1_endpointid}"); eprintln!("endpoint id 2 {ep2_endpointid}"); - async fn connect_hello(ep: Endpoint, dst: EndpointId) -> Result { + async fn connect_hello(ep: Endpoint, dst: PublicKey) -> Result { let conn = ep.connect(dst, TEST_ALPN).await?; let (mut send, mut recv) = conn.open_bi().await.anyerr()?; info!("sending hello"); @@ -1875,7 +1875,7 @@ mod tests { Ok(()) } - async fn accept_world(ep: Endpoint, src: EndpointId) -> Result { + async fn accept_world(ep: Endpoint, src: PublicKey) -> Result { let incoming = ep.accept().await.anyerr()?; let mut iconn = incoming.accept().anyerr()?; let alpn = iconn.alpn().await?; @@ -1957,7 +1957,7 @@ mod tests { .bind() .await?; - async fn wait_for_conn_type_direct(ep: &Endpoint, endpoint_id: EndpointId) -> Result { + async fn wait_for_conn_type_direct(ep: &Endpoint, endpoint_id: PublicKey) -> Result { let mut stream = ep .conn_type(endpoint_id) .expect("connection exists") diff --git a/iroh/src/endpoint/connection.rs b/iroh/src/endpoint/connection.rs index 48273ca9af4..266b617757d 100644 --- a/iroh/src/endpoint/connection.rs +++ b/iroh/src/endpoint/connection.rs @@ -27,7 +27,7 @@ use std::{ use ed25519_dalek::{VerifyingKey, pkcs8::DecodePublicKey}; use futures_util::{FutureExt, future::Shared}; -use iroh_base::EndpointId; +use iroh_base::PublicKey; use n0_error::{e, stack_error}; use n0_future::time::Duration; use n0_watcher::Watcher; @@ -246,7 +246,7 @@ fn conn_from_quinn_conn(conn: quinn::Connection) -> Result Result { +) -> Result { let data = conn.peer_identity(); match data { None => { @@ -263,7 +263,7 @@ fn remote_id_from_quinn_conn( return Err(RemoteEndpointIdError::new()); } - let peer_id = EndpointId::from_verifying_key( + let peer_id = PublicKey::from_verifying_key( VerifyingKey::from_public_key_der(&certs[0]) .map_err(|_| RemoteEndpointIdError::new())?, ); @@ -288,7 +288,7 @@ pub struct Connecting { inner: quinn::Connecting, ep: Endpoint, /// `Some(remote_id)` if this is an outgoing connection, `None` if this is an incoming conn - remote_endpoint_id: EndpointId, + remote_endpoint_id: PublicKey, /// We run discovery as long as we haven't established a connection yet. #[debug("Option")] _discovery_drop_guard: Option, @@ -335,7 +335,7 @@ impl Connecting { pub(crate) fn new( inner: quinn::Connecting, ep: Endpoint, - remote_endpoint_id: EndpointId, + remote_endpoint_id: PublicKey, _discovery_drop_guard: Option, ) -> Self { Self { @@ -421,7 +421,7 @@ impl Connecting { } /// Returns the [`EndpointId`] of the endpoint that this connection attempt tries to connect to. - pub fn remote_id(&self) -> EndpointId { + pub fn remote_id(&self) -> PublicKey { self.remote_endpoint_id } } @@ -824,7 +824,7 @@ impl OutgoingZeroRttConnection { /// connection. /// /// [`PublicKey`]: iroh_base::PublicKey - pub fn remote_id(&self) -> Result { + pub fn remote_id(&self) -> Result { remote_id_from_quinn_conn(&self.inner) } @@ -1135,7 +1135,7 @@ impl IncomingZeroRttConnection { /// connection. /// /// [`PublicKey`]: iroh_base::PublicKey - pub fn remote_id(&self) -> Result { + pub fn remote_id(&self) -> Result { remote_id_from_quinn_conn(&self.inner) } @@ -1207,7 +1207,7 @@ impl IncomingZeroRttConnection { #[derive(derive_more::Debug, Clone)] pub struct Connection { inner: quinn::Connection, - remote_id: EndpointId, + remote_id: PublicKey, alpn: Vec, } @@ -1434,7 +1434,7 @@ impl Connection { /// connection. /// /// [`PublicKey`]: iroh_base::PublicKey - pub fn remote_id(&self) -> EndpointId { + pub fn remote_id(&self) -> PublicKey { self.remote_id } @@ -1494,7 +1494,7 @@ impl Connection { /// /// If we can't notify the actor that will impact performance a little, but we can still /// function. -fn try_send_rtt_msg(conn: &quinn::Connection, ep: &Endpoint, remote_id: EndpointId) { +fn try_send_rtt_msg(conn: &quinn::Connection, ep: &Endpoint, remote_id: PublicKey) { let Some(conn_type_changes) = ep.conn_type(remote_id) else { warn!(?conn, "failed to create conn_type stream"); return; diff --git a/iroh/src/endpoint/rtt_actor.rs b/iroh/src/endpoint/rtt_actor.rs index 4dddc7955af..c9cb4f2eb70 100644 --- a/iroh/src/endpoint/rtt_actor.rs +++ b/iroh/src/endpoint/rtt_actor.rs @@ -2,7 +2,7 @@ use std::{pin::Pin, sync::Arc, task::Poll}; -use iroh_base::EndpointId; +use iroh_base::PublicKey; use n0_future::{ MergeUnbounded, Stream, StreamExt, task::{self, AbortOnDropHandle}, @@ -49,7 +49,7 @@ pub(super) enum RttMessage { /// Path changes for this connection from the magic socket. conn_type_changes: n0_watcher::Stream>, /// For reporting-only, the Endpoint ID of this connection. - endpoint_id: EndpointId, + endpoint_id: PublicKey, }, } @@ -68,7 +68,7 @@ struct RttActor { #[derive(Debug)] struct MappedStream { stream: n0_watcher::Stream>, - endpoint_id: EndpointId, + endpoint_id: PublicKey, /// Reference to the connection. connection: quinn::WeakConnectionHandle, /// This an indiciator of whether this connection was direct before. @@ -158,7 +158,7 @@ impl RttActor { &mut self, connection: quinn::WeakConnectionHandle, conn_type_changes: n0_watcher::Stream>, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) { self.connection_events.push(MappedStream { stream: conn_type_changes, diff --git a/iroh/src/lib.rs b/iroh/src/lib.rs index b6504381d6b..f290fd36ac1 100644 --- a/iroh/src/lib.rs +++ b/iroh/src/lib.rs @@ -273,7 +273,7 @@ pub mod protocol; pub use endpoint::{Endpoint, RelayMode}; pub use iroh_base::{ - EndpointAddr, EndpointId, KeyParsingError, PublicKey, RelayUrl, RelayUrlParseError, SecretKey, + EndpointAddr, PublicKey, KeyParsingError, RelayUrl, RelayUrlParseError, SecretKey, Signature, SignatureError, TransportAddr, }; pub use iroh_relay::{RelayConfig, RelayMap, endpoint_info}; diff --git a/iroh/src/magicsock.rs b/iroh/src/magicsock.rs index b135d317f68..281456935d0 100644 --- a/iroh/src/magicsock.rs +++ b/iroh/src/magicsock.rs @@ -30,7 +30,7 @@ use std::{ use bytes::Bytes; use data_encoding::HEXLOWER; -use iroh_base::{EndpointAddr, EndpointId, PublicKey, RelayUrl, SecretKey, TransportAddr}; +use iroh_base::{EndpointAddr, PublicKey, RelayUrl, SecretKey, TransportAddr}; use iroh_relay::{RelayConfig, RelayMap}; use n0_error::{e, stack_error}; use n0_future::{ @@ -281,7 +281,7 @@ impl MagicSock { } /// Return the [`RemoteInfo`] for a single endpoint in the endpoint map. - pub(crate) fn remote_info(&self, endpoint_id: EndpointId) -> Option { + pub(crate) fn remote_info(&self, endpoint_id: PublicKey) -> Option { self.endpoint_map.remote_info(endpoint_id) } @@ -375,17 +375,17 @@ impl MagicSock { /// given `endpoint_id`. pub(crate) fn conn_type( &self, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Option> { self.endpoint_map.conn_type(endpoint_id) } - pub(crate) fn latency(&self, endpoint_id: EndpointId) -> Option { + pub(crate) fn latency(&self, endpoint_id: PublicKey) -> Option { self.endpoint_map.latency(endpoint_id) } /// Returns the socket address which can be used by the QUIC layer to dial this endpoint. - pub(crate) fn get_mapping_addr(&self, endpoint_id: EndpointId) -> Option { + pub(crate) fn get_mapping_addr(&self, endpoint_id: PublicKey) -> Option { self.endpoint_map .get_quic_mapped_addr_for_endpoint_key(endpoint_id) } @@ -842,7 +842,7 @@ impl MagicSock { } /// Handle a ping message. - fn handle_ping(&self, dm: disco::Ping, sender: EndpointId, src: &transports::Addr) { + fn handle_ping(&self, dm: disco::Ping, sender: PublicKey, src: &transports::Addr) { // Insert the ping into the endpoint map, and return whether a ping with this tx_id was already // received. let addr: SendAddr = src.clone().into(); @@ -1661,8 +1661,8 @@ impl DiscoState { fn encode_and_seal( &self, - this_endpoint_id: EndpointId, - other_endpoint_id: EndpointId, + this_endpoint_id: PublicKey, + other_endpoint_id: PublicKey, msg: &disco::Message, ) -> Bytes { let mut seal = msg.as_bytes(); @@ -1769,7 +1769,7 @@ impl AsyncUdpSocket for MagicUdpSocket { enum ActorMessage { EndpointPingExpired(usize, TransactionId), NetworkChange, - ScheduleDirectAddrUpdate(UpdateReason, Option<(EndpointId, RelayUrl)>), + ScheduleDirectAddrUpdate(UpdateReason, Option<(PublicKey, RelayUrl)>), RelayMapChange, #[cfg(test)] ForceNetworkChange(bool), @@ -2522,7 +2522,7 @@ mod tests { use std::{collections::BTreeSet, net::SocketAddr, sync::Arc, time::Duration}; use data_encoding::HEXLOWER; - use iroh_base::{EndpointAddr, EndpointId, PublicKey, TransportAddr}; + use iroh_base::{EndpointAddr, PublicKey, TransportAddr}; use n0_error::{Result, StackResultExt, StdResultExt}; use n0_future::{StreamExt, time}; use n0_watcher::Watcher; @@ -3105,7 +3105,7 @@ mod tests { ep: &quinn::Endpoint, ep_secret_key: SecretKey, addr: EndpointIdMappedAddr, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Result { // Endpoint::connect sets this, do the same to have similar behaviour. let mut transport_config = quinn::TransportConfig::default(); @@ -3131,7 +3131,7 @@ mod tests { ep: &quinn::Endpoint, ep_secret_key: SecretKey, mapped_addr: EndpointIdMappedAddr, - endpoint_id: EndpointId, + endpoint_id: PublicKey, transport_config: Arc, ) -> Result { let alpns = vec![ALPN.to_vec()]; diff --git a/iroh/src/magicsock/endpoint_map.rs b/iroh/src/magicsock/endpoint_map.rs index e23da332321..85822489373 100644 --- a/iroh/src/magicsock/endpoint_map.rs +++ b/iroh/src/magicsock/endpoint_map.rs @@ -6,7 +6,7 @@ use std::{ time::Duration, }; -use iroh_base::{EndpointAddr, EndpointId, PublicKey, RelayUrl}; +use iroh_base::{EndpointAddr, PublicKey, RelayUrl}; use n0_future::time::Instant; use serde::{Deserialize, Serialize}; use tracing::{debug, info, instrument, trace, warn}; @@ -53,7 +53,7 @@ pub(super) struct EndpointMap { #[derive(Default, Debug)] pub(super) struct EndpointMapInner { - by_endpoint_key: HashMap, + by_endpoint_key: HashMap, by_ip_port: HashMap, by_quic_mapped_addr: HashMap, by_id: HashMap, @@ -69,7 +69,7 @@ pub(super) struct EndpointMapInner { #[derive(Debug, Clone)] enum EndpointStateKey { Idx(usize), - EndpointId(EndpointId), + EndpointId(PublicKey), EndpointIdMappedAddr(EndpointIdMappedAddr), IpPort(IpPort), } @@ -171,7 +171,7 @@ impl EndpointMap { pub(super) fn receive_relay( &self, relay_url: &RelayUrl, - src: EndpointId, + src: PublicKey, ) -> EndpointIdMappedAddr { self.inner .lock() @@ -210,7 +210,7 @@ impl EndpointMap { pub(super) fn get_quic_mapped_addr_for_endpoint_key( &self, - endpoint_key: EndpointId, + endpoint_key: PublicKey, ) -> Option { self.inner .lock() @@ -317,17 +317,17 @@ impl EndpointMap { /// the `endpoint_id` pub(super) fn conn_type( &self, - endpoint_id: EndpointId, + endpoint_id: PublicKey, ) -> Option> { self.inner.lock().expect("poisoned").conn_type(endpoint_id) } - pub(super) fn latency(&self, endpoint_id: EndpointId) -> Option { + pub(super) fn latency(&self, endpoint_id: PublicKey) -> Option { self.inner.lock().expect("poisoned").latency(endpoint_id) } /// Get the [`RemoteInfo`]s for the endpoint identified by [`EndpointId`]. - pub(super) fn remote_info(&self, endpoint_id: EndpointId) -> Option { + pub(super) fn remote_info(&self, endpoint_id: PublicKey) -> Option { self.inner .lock() .expect("poisoned") @@ -471,7 +471,7 @@ impl EndpointMapInner { /// Marks the endpoint we believe to be at `ipp` as recently used. #[cfg(not(wasm_browser))] - fn receive_udp(&mut self, udp_addr: SocketAddr) -> Option<(EndpointId, EndpointIdMappedAddr)> { + fn receive_udp(&mut self, udp_addr: SocketAddr) -> Option<(PublicKey, EndpointIdMappedAddr)> { let ip_port: IpPort = udp_addr.into(); let Some(endpoint_state) = self.get_mut(EndpointStateKey::IpPort(ip_port)) else { trace!(src=%udp_addr, "receive_udp: no endpoint_state found for addr, ignore"); @@ -485,7 +485,7 @@ impl EndpointMapInner { } #[instrument(skip_all, fields(src = %src.fmt_short()))] - fn receive_relay(&mut self, relay_url: &RelayUrl, src: EndpointId) -> EndpointIdMappedAddr { + fn receive_relay(&mut self, relay_url: &RelayUrl, src: PublicKey) -> EndpointIdMappedAddr { #[cfg(any(test, feature = "test-utils"))] let path_selection = self.path_selection; let endpoint_state = self.get_or_insert_with(EndpointStateKey::EndpointId(src), || { @@ -519,7 +519,7 @@ impl EndpointMapInner { } /// Get the [`RemoteInfo`]s for each endpoint. - fn remote_info(&self, endpoint_id: EndpointId) -> Option { + fn remote_info(&self, endpoint_id: PublicKey) -> Option { self.get(EndpointStateKey::EndpointId(endpoint_id)) .map(|ep| ep.info(Instant::now())) } @@ -533,19 +533,19 @@ impl EndpointMapInner { /// /// Will return `None` if there is not an entry in the [`EndpointMap`] for /// the `public_key` - fn conn_type(&self, endpoint_id: EndpointId) -> Option> { + fn conn_type(&self, endpoint_id: PublicKey) -> Option> { self.get(EndpointStateKey::EndpointId(endpoint_id)) .map(|ep| ep.conn_type()) } - fn latency(&self, endpoint_id: EndpointId) -> Option { + fn latency(&self, endpoint_id: PublicKey) -> Option { self.get(EndpointStateKey::EndpointId(endpoint_id)) .and_then(|ep| ep.latency()) } fn handle_pong( &mut self, - sender: EndpointId, + sender: PublicKey, src: &transports::Addr, pong: Pong, metrics: &Metrics, @@ -564,7 +564,7 @@ impl EndpointMapInner { #[must_use = "actions must be handled"] fn handle_call_me_maybe( &mut self, - sender: EndpointId, + sender: PublicKey, cm: CallMeMaybe, metrics: &Metrics, ) -> Vec { @@ -591,7 +591,7 @@ impl EndpointMapInner { fn handle_ping( &mut self, - sender: EndpointId, + sender: PublicKey, src: SendAddr, tx_id: TransactionId, ) -> PingHandled { diff --git a/iroh/src/magicsock/endpoint_map/endpoint_state.rs b/iroh/src/magicsock/endpoint_map/endpoint_state.rs index e4b1c2a2209..6c8807fe881 100644 --- a/iroh/src/magicsock/endpoint_map/endpoint_state.rs +++ b/iroh/src/magicsock/endpoint_map/endpoint_state.rs @@ -6,7 +6,7 @@ use std::{ }; use data_encoding::HEXLOWER; -use iroh_base::{EndpointAddr, EndpointId, PublicKey, RelayUrl, TransportAddr}; +use iroh_base::{EndpointAddr, PublicKey, RelayUrl, TransportAddr}; use n0_future::{ task::{self, AbortOnDropHandle}, time::{self, Duration, Instant}, @@ -59,7 +59,7 @@ const STAYIN_ALIVE_MIN_ELAPSED: Duration = Duration::from_secs(2); pub(in crate::magicsock) enum PingAction { SendCallMeMaybe { relay_url: RelayUrl, - dst_endpoint: EndpointId, + dst_endpoint: PublicKey, }, SendPing(SendPing), } @@ -68,7 +68,7 @@ pub(in crate::magicsock) enum PingAction { pub(in crate::magicsock) struct SendPing { pub id: usize, pub dst: SendAddr, - pub dst_endpoint: EndpointId, + pub dst_endpoint: PublicKey, pub tx_id: TransactionId, pub purpose: DiscoPingPurpose, } @@ -108,7 +108,7 @@ pub(super) struct EndpointState { /// The UDP address used on the QUIC-layer to address this endpoint. quic_mapped_addr: EndpointIdMappedAddr, /// The global identifier for this endpoint. - endpoint_id: EndpointId, + endpoint_id: PublicKey, /// The last time we pinged all endpoints. last_full_ping: Option, /// The url of relay endpoint that we can relay over to communicate. @@ -148,7 +148,7 @@ pub(super) struct EndpointState { /// Options for creating a new [`EndpointState`]. #[derive(Debug)] pub(super) struct Options { - pub(super) endpoint_id: EndpointId, + pub(super) endpoint_id: PublicKey, pub(super) relay_url: Option, /// Is this endpoint currently active (sending data)? pub(super) active: bool, @@ -1082,7 +1082,7 @@ impl EndpointState { self.last_used = Some(now); } - pub(super) fn receive_relay(&mut self, url: &RelayUrl, src: EndpointId, now: Instant) { + pub(super) fn receive_relay(&mut self, url: &RelayUrl, src: PublicKey, now: Instant) { match self.relay_url.as_mut() { Some((current_home, state)) if current_home == url => { // We received on the expected url. update state. @@ -1384,7 +1384,7 @@ impl From for RelayUrl { #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] pub(crate) struct RemoteInfo { /// The globally unique identifier for this endpoint. - pub endpoint_id: EndpointId, + pub endpoint_id: PublicKey, /// Relay server information, if available. pub relay_url: Option, /// The addresses at which this endpoint might be reachable. @@ -1463,7 +1463,7 @@ mod tests { let pong_src = SendAddr::Udp("0.0.0.0:1".parse().unwrap()); let latency = Duration::from_millis(50); - let relay_and_state = |endpoint_id: EndpointId, url: RelayUrl| { + let relay_and_state = |endpoint_id: PublicKey, url: RelayUrl| { let relay_state = PathState::with_pong_reply( endpoint_id, PongReply { diff --git a/iroh/src/magicsock/endpoint_map/path_state.rs b/iroh/src/magicsock/endpoint_map/path_state.rs index d78b67179f3..90e616164a4 100644 --- a/iroh/src/magicsock/endpoint_map/path_state.rs +++ b/iroh/src/magicsock/endpoint_map/path_state.rs @@ -2,7 +2,7 @@ use std::collections::{BTreeMap, HashMap}; -use iroh_base::EndpointId; +use iroh_base::PublicKey; use n0_future::time::{Duration, Instant}; use tracing::{Level, debug, event}; @@ -32,7 +32,7 @@ const DISCO_PING_INTERVAL: Duration = Duration::from_secs(5); #[derive(Debug, Clone)] pub(super) struct PathState { /// The endpoint for which this path exists. - endpoint_id: EndpointId, + endpoint_id: PublicKey, /// The path this applies for. path: SendAddr, /// The last (outgoing) ping time. @@ -66,7 +66,7 @@ pub(super) struct PathState { impl PathState { pub(super) fn new( - endpoint_id: EndpointId, + endpoint_id: PublicKey, path: SendAddr, source: Source, now: Instant, @@ -86,7 +86,7 @@ impl PathState { } pub(super) fn with_last_payload( - endpoint_id: EndpointId, + endpoint_id: PublicKey, path: SendAddr, source: Source, now: Instant, @@ -106,7 +106,7 @@ impl PathState { } pub(super) fn with_ping( - endpoint_id: EndpointId, + endpoint_id: PublicKey, path: SendAddr, tx_id: TransactionId, source: Source, @@ -142,7 +142,7 @@ impl PathState { } #[cfg(test)] - pub(super) fn with_pong_reply(endpoint_id: EndpointId, r: PongReply) -> Self { + pub(super) fn with_pong_reply(endpoint_id: PublicKey, r: PongReply) -> Self { PathState { endpoint_id, path: r.from.clone(), diff --git a/iroh/src/magicsock/transports.rs b/iroh/src/magicsock/transports.rs index b44eca505ae..d47ab8e854e 100644 --- a/iroh/src/magicsock/transports.rs +++ b/iroh/src/magicsock/transports.rs @@ -6,7 +6,7 @@ use std::{ task::{Context, Poll}, }; -use iroh_base::{EndpointId, RelayUrl}; +use iroh_base::{PublicKey, RelayUrl}; use n0_watcher::Watcher; use relay::{RelayNetworkChangeSender, RelaySender}; use smallvec::SmallVec; @@ -40,8 +40,8 @@ pub(crate) type LocalAddrsWatch = n0_watcher::Map< ( n0_watcher::Join>, n0_watcher::Join< - Option<(RelayUrl, EndpointId)>, - n0_watcher::Map>, Option<(RelayUrl, EndpointId)>>, + Option<(RelayUrl, PublicKey)>, + n0_watcher::Map>, Option<(RelayUrl, PublicKey)>>, >, ), Vec, @@ -50,8 +50,8 @@ pub(crate) type LocalAddrsWatch = n0_watcher::Map< #[cfg(wasm_browser)] pub(crate) type LocalAddrsWatch = n0_watcher::Map< n0_watcher::Join< - Option<(RelayUrl, EndpointId)>, - n0_watcher::Map>, Option<(RelayUrl, EndpointId)>>, + Option<(RelayUrl, PublicKey)>, + n0_watcher::Map>, Option<(RelayUrl, PublicKey)>>, >, Vec, >; @@ -304,7 +304,7 @@ pub(crate) struct Transmit<'a> { #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum Addr { Ip(SocketAddr), - Relay(RelayUrl, EndpointId), + Relay(RelayUrl, PublicKey), } impl Default for Addr { @@ -324,8 +324,8 @@ impl From for Addr { } } -impl From<(RelayUrl, EndpointId)> for Addr { - fn from(value: (RelayUrl, EndpointId)) -> Self { +impl From<(RelayUrl, PublicKey)> for Addr { + fn from(value: (RelayUrl, PublicKey)) -> Self { Self::Relay(value.0, value.1) } } diff --git a/iroh/src/magicsock/transports/relay.rs b/iroh/src/magicsock/transports/relay.rs index 7b3c8cf46a1..3085d4a9923 100644 --- a/iroh/src/magicsock/transports/relay.rs +++ b/iroh/src/magicsock/transports/relay.rs @@ -5,7 +5,7 @@ use std::{ }; use bytes::Bytes; -use iroh_base::{EndpointId, RelayUrl}; +use iroh_base::{PublicKey, RelayUrl}; use iroh_relay::protos::relay::Datagrams; use n0_future::{ ready, @@ -34,7 +34,7 @@ pub(crate) struct RelayTransport { actor_sender: mpsc::Sender, _actor_handle: AbortOnDropHandle<()>, my_relay: Watchable>, - my_endpoint_id: EndpointId, + my_endpoint_id: PublicKey, } impl RelayTransport { @@ -164,7 +164,7 @@ impl RelayTransport { pub(super) fn local_addr_watch( &self, - ) -> n0_watcher::Map>, Option<(RelayUrl, EndpointId)>> { + ) -> n0_watcher::Map>, Option<(RelayUrl, PublicKey)>> { let my_endpoint_id = self.my_endpoint_id; self.my_relay .watch() @@ -240,14 +240,14 @@ pub(crate) struct RelaySender { } impl RelaySender { - pub(super) fn is_valid_send_addr(&self, _url: &RelayUrl, _endpoint_id: &EndpointId) -> bool { + pub(super) fn is_valid_send_addr(&self, _url: &RelayUrl, _endpoint_id: &PublicKey) -> bool { true } pub(super) async fn send( &self, dest_url: RelayUrl, - dest_endpoint: EndpointId, + dest_endpoint: PublicKey, transmit: &Transmit<'_>, ) -> io::Result<()> { let contents = datagrams_from_transmit(transmit); @@ -284,7 +284,7 @@ impl RelaySender { &mut self, cx: &mut Context, dest_url: RelayUrl, - dest_endpoint: EndpointId, + dest_endpoint: PublicKey, transmit: &Transmit<'_>, ) -> Poll> { match ready!(self.sender.poll_reserve(cx)) { @@ -327,7 +327,7 @@ impl RelaySender { pub(super) fn try_send( &self, dest_url: RelayUrl, - dest_endpoint: EndpointId, + dest_endpoint: PublicKey, transmit: &Transmit<'_>, ) -> io::Result<()> { let contents = datagrams_from_transmit(transmit); @@ -388,7 +388,7 @@ fn datagrams_from_transmit(transmit: &Transmit<'_>) -> Datagrams { mod tests { use std::{collections::BTreeSet, time::Duration}; - use iroh_base::EndpointId; + use iroh_base::PublicKey; use tokio::task::JoinSet; use tracing::debug; @@ -427,7 +427,7 @@ mod tests { sender .try_send(RelayRecvDatagram { url, - src: EndpointId::from_bytes(&[0u8; 32]).unwrap(), + src: PublicKey::from_bytes(&[0u8; 32]).unwrap(), datagrams: Datagrams::from(&i.to_le_bytes()), }) .unwrap(); diff --git a/iroh/src/magicsock/transports/relay/actor.rs b/iroh/src/magicsock/transports/relay/actor.rs index 097b91ca80f..f07333dc64c 100644 --- a/iroh/src/magicsock/transports/relay/actor.rs +++ b/iroh/src/magicsock/transports/relay/actor.rs @@ -38,7 +38,7 @@ use std::{ }; use backon::{Backoff, BackoffBuilder, ExponentialBuilder}; -use iroh_base::{EndpointId, RelayUrl, SecretKey}; +use iroh_base::{PublicKey, RelayUrl, SecretKey}; use iroh_relay::{ self as relay, PingTracker, client::{Client, ConnectError, RecvError, SendError}, @@ -180,7 +180,7 @@ enum ActiveRelayMessage { #[derive(Debug)] enum ActiveRelayPrioMessage { /// Returns whether or not this relay can reach the EndpointId. - HasEndpointRoute(EndpointId, oneshot::Sender), + HasEndpointRoute(PublicKey, oneshot::Sender), } /// Configuration needed to start an [`ActiveRelayActor`]. @@ -781,12 +781,12 @@ struct ConnectedRelayState { /// Tracks pings we have sent, awaits pong replies. ping_tracker: PingTracker, /// Endpoints which are reachable via this relay server. - endpoints_present: BTreeSet, + endpoints_present: BTreeSet, /// The [`EndpointId`] from whom we received the last packet. /// /// This is to avoid a slower lookup in the [`ConnectedRelayState::endpoints_present`] map /// when we are only communicating to a single remote endpoint. - last_packet_src: Option, + last_packet_src: Option, /// A pong we need to send ASAP. pong_pending: Option<[u8; 8]>, /// Whether the connection is to be considered established. @@ -815,7 +815,7 @@ pub(super) enum RelayActorMessage { #[derive(Debug, Clone)] pub(crate) struct RelaySendItem { /// The destination for the datagrams. - pub(crate) remote_endpoint: EndpointId, + pub(crate) remote_endpoint: PublicKey, /// The home relay of the remote endpoint. pub(crate) url: RelayUrl, /// One or more datagrams to send. @@ -1019,7 +1019,7 @@ impl RelayActor { async fn active_relay_handle_for_endpoint( &mut self, url: &RelayUrl, - remote_endpoint: &EndpointId, + remote_endpoint: &PublicKey, ) -> ActiveRelayHandle { if let Some(handle) = self.active_relays.get(url) { return handle.clone(); @@ -1211,7 +1211,7 @@ struct ActiveRelayHandle { #[derive(Debug)] pub(crate) struct RelayRecvDatagram { pub(crate) url: RelayUrl, - pub(crate) src: EndpointId, + pub(crate) src: PublicKey, pub(crate) datagrams: Datagrams, } @@ -1222,7 +1222,7 @@ mod tests { time::Duration, }; - use iroh_base::{EndpointId, RelayUrl, SecretKey}; + use iroh_base::{PublicKey, RelayUrl, SecretKey}; use iroh_relay::{PingTracker, protos::relay::Datagrams}; use n0_error::{AnyError as Error, Result, StackResultExt, StdResultExt}; use tokio::sync::{mpsc, oneshot}; @@ -1274,7 +1274,7 @@ mod tests { /// This actor will connect to the relay server, pretending to be an iroh endpoint, and echo /// back any datagram it receives from the relay. This is used by the /// [`ActiveRelayActor`] under test to check connectivity works. - fn start_echo_endpoint(relay_url: RelayUrl) -> (EndpointId, AbortOnDropHandle<()>) { + fn start_echo_endpoint(relay_url: RelayUrl) -> (PublicKey, AbortOnDropHandle<()>) { let secret_key = SecretKey::from_bytes(&[8u8; 32]); let (recv_datagram_tx, mut recv_datagram_rx) = mpsc::channel(16); let (send_datagram_tx, send_datagram_rx) = mpsc::channel(16); diff --git a/iroh/src/protocol.rs b/iroh/src/protocol.rs index fcca2939fd5..c95eb005f81 100644 --- a/iroh/src/protocol.rs +++ b/iroh/src/protocol.rs @@ -42,7 +42,7 @@ use std::{ sync::{Arc, Mutex}, }; -use iroh_base::EndpointId; +use iroh_base::PublicKey; use n0_error::{AnyError, e, stack_error}; use n0_future::{ join_all, @@ -558,7 +558,7 @@ async fn handle_connection(incoming: crate::endpoint::Incoming, protocols: Arc

{ proto: P, #[debug("limiter")] - limiter: Arc bool + Send + Sync + 'static>, + limiter: Arc bool + Send + Sync + 'static>, } impl AccessLimit

{ @@ -568,7 +568,7 @@ impl AccessLimit

{ /// connect, and `false` otherwise. pub fn new(proto: P, limiter: F) -> Self where - F: Fn(EndpointId) -> bool + Send + Sync + 'static, + F: Fn(PublicKey) -> bool + Send + Sync + 'static, { Self { proto, diff --git a/iroh/src/test_utils.rs b/iroh/src/test_utils.rs index 99289aea032..1d9c34df5d8 100644 --- a/iroh/src/test_utils.rs +++ b/iroh/src/test_utils.rs @@ -83,7 +83,7 @@ pub async fn run_relay_server_with(quic: bool) -> Result<(RelayMap, RelayUrl, Se pub(crate) mod dns_and_pkarr_servers { use std::{net::SocketAddr, time::Duration}; - use iroh_base::{EndpointId, SecretKey}; + use iroh_base::{PublicKey, SecretKey}; use url::Url; use super::CleanupDropGuard; @@ -158,7 +158,7 @@ pub(crate) mod dns_and_pkarr_servers { /// If `timeout` elapses an error is returned. pub async fn on_endpoint( &self, - endpoint_id: &EndpointId, + endpoint_id: &PublicKey, timeout: Duration, ) -> std::io::Result<()> { self.state.on_endpoint(endpoint_id, timeout).await @@ -346,7 +346,7 @@ pub(crate) mod pkarr_dns_state { time::Duration, }; - use iroh_base::EndpointId; + use iroh_base::PublicKey; use iroh_relay::endpoint_info::{EndpointIdExt, EndpointInfo, IROH_TXT_NAME}; use pkarr::SignedPacket; use tracing::debug; @@ -355,7 +355,7 @@ pub(crate) mod pkarr_dns_state { #[derive(Debug, Clone)] pub struct State { - packets: Arc>>, + packets: Arc>>, origin: String, notify: Arc, } @@ -375,7 +375,7 @@ pub(crate) mod pkarr_dns_state { pub async fn on_endpoint( &self, - endpoint: &EndpointId, + endpoint: &PublicKey, timeout: Duration, ) -> std::io::Result<()> { let timeout = tokio::time::sleep(timeout); @@ -396,7 +396,7 @@ pub(crate) mod pkarr_dns_state { } pub fn upsert(&self, signed_packet: SignedPacket) -> std::io::Result { - let endpoint_id = EndpointId::from_bytes(&signed_packet.public_key().to_bytes()) + let endpoint_id = PublicKey::from_bytes(&signed_packet.public_key().to_bytes()) .map_err(std::io::Error::other)?; let mut map = self.packets.lock().expect("poisoned"); let updated = match map.entry(endpoint_id) { @@ -420,7 +420,7 @@ pub(crate) mod pkarr_dns_state { } /// Returns a mutex guard, do not hold over await points - pub fn get(&self, endpoint_id: &EndpointId, cb: F) -> T + pub fn get(&self, endpoint_id: &PublicKey, cb: F) -> T where F: FnOnce(Option<&mut SignedPacket>) -> T, { @@ -477,14 +477,14 @@ pub(crate) mod pkarr_dns_state { /// subsequent labels. /// /// Returns a [`EndpointId`] if parsed successfully, otherwise `None`. - fn endpoint_id_from_domain_name(name: &str) -> Option { + fn endpoint_id_from_domain_name(name: &str) -> Option { let mut labels = name.split("."); let label = labels.next()?; if label != IROH_TXT_NAME { return None; } let label = labels.next()?; - let endpoint_id = EndpointId::from_z32(label).ok()?; + let endpoint_id = PublicKey::from_z32(label).ok()?; Some(endpoint_id) } @@ -502,7 +502,7 @@ pub(crate) mod pkarr_dns_state { /// Converts to a list of [`hickory_resolver::proto::rr::Record`] resource records. fn to_hickory_records( txt_strings: Vec, - endpoint_id: EndpointId, + endpoint_id: PublicKey, origin: &str, ttl: u32, ) -> impl Iterator + '_ { @@ -518,14 +518,14 @@ pub(crate) mod pkarr_dns_state { #[cfg(test)] mod tests { - use iroh_base::EndpointId; + use iroh_base::PublicKey; use n0_error::Result; #[test] fn test_endpoint_id_from_domain_name() -> Result { let name = "_iroh.dgjpkxyn3zyrk3zfads5duwdgbqpkwbjxfj4yt7rezidr3fijccy.dns.iroh.link."; let endpoint_id = super::endpoint_id_from_domain_name(name); - let expected: EndpointId = + let expected: PublicKey = "1992d53c02cdc04566e5c0edb1ce83305cd550297953a047a445ea3264b54b18".parse()?; assert_eq!(endpoint_id, Some(expected)); Ok(()) diff --git a/iroh/src/tls/name.rs b/iroh/src/tls/name.rs index a9b64573639..a35a75b423b 100644 --- a/iroh/src/tls/name.rs +++ b/iroh/src/tls/name.rs @@ -12,20 +12,20 @@ //! We *could* decide to remove that indicator in the future likely without breakage. use data_encoding::BASE32_DNSSEC; -use iroh_base::EndpointId; +use iroh_base::PublicKey; -pub(crate) fn encode(endpoint_id: EndpointId) -> String { +pub(crate) fn encode(endpoint_id: PublicKey) -> String { format!( "{}.iroh.invalid", BASE32_DNSSEC.encode(endpoint_id.as_bytes()) ) } -pub(crate) fn decode(name: &str) -> Option { +pub(crate) fn decode(name: &str) -> Option { let [base32_endpoint_id, "iroh", "invalid"] = name.split(".").collect::>()[..] else { return None; }; - EndpointId::from_bytes( + PublicKey::from_bytes( &BASE32_DNSSEC .decode(base32_endpoint_id.as_bytes()) .ok()? From 94cc315acfb793488831783d27037eabe3d87e0b Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Wed, 12 Nov 2025 13:02:45 -0600 Subject: [PATCH 02/10] Make iroh build --- iroh-base/src/key.rs | 8 +++++ iroh/src/discovery.rs | 32 +++++++++---------- iroh/src/discovery/dns.rs | 7 ++-- iroh/src/discovery/pkarr.rs | 7 ++-- iroh/src/discovery/static_provider.rs | 10 +++--- iroh/src/endpoint.rs | 29 +++++++++++------ iroh/src/magicsock/endpoint_map.rs | 5 +-- .../magicsock/endpoint_map/endpoint_state.rs | 2 +- 8 files changed, 60 insertions(+), 40 deletions(-) diff --git a/iroh-base/src/key.rs b/iroh-base/src/key.rs index 3207125d6c8..84bc543e70f 100644 --- a/iroh-base/src/key.rs +++ b/iroh-base/src/key.rs @@ -45,6 +45,14 @@ impl EndpointId { pub fn expect_ed(self) -> PublicKey { self.as_ed().expect("not an ed25519 endpoint id") } + + /// Format a short representation of this endpoint id. + pub fn fmt_short(&self) -> String { + match self { + EndpointId::Ed25519(key) => key.fmt_short().to_string(), + EndpointId::Other(_) => "Other".to_string(), + } + } } impl From for EndpointId { diff --git a/iroh/src/discovery.rs b/iroh/src/discovery.rs index 7af006698db..fb6b30ce5c7 100644 --- a/iroh/src/discovery.rs +++ b/iroh/src/discovery.rs @@ -112,7 +112,7 @@ use std::sync::{Arc, RwLock}; -use iroh_base::{EndpointAddr, PublicKey}; +use iroh_base::{EndpointAddr, EndpointId}; use n0_error::{AnyError, e, ensure, stack_error}; use n0_future::{ boxed::BoxStream, @@ -223,7 +223,7 @@ pub enum DiscoveryError { #[error("No discovery service configured")] NoServiceConfigured, #[error("Discovery produced no results for {}", endpoint_id.fmt_short())] - NoResults { endpoint_id: PublicKey }, + NoResults { endpoint_id: EndpointId }, #[error("Service '{provenance}' error")] User { provenance: &'static str, @@ -298,7 +298,7 @@ pub trait Discovery: std::fmt::Debug + Send + Sync + 'static { /// work. fn resolve( &self, - _endpoint_id: PublicKey, + _endpoint_id: EndpointId, ) -> Option>> { None } @@ -311,7 +311,7 @@ impl Discovery for Arc { fn resolve( &self, - endpoint_id: PublicKey, + endpoint_id: EndpointId, ) -> Option>> { self.as_ref().resolve(endpoint_id) } @@ -355,7 +355,7 @@ impl DiscoveryItem { } /// Returns the endpoint id of the discovered endpoint. - pub fn endpoint_id(&self) -> PublicKey { + pub fn endpoint_id(&self) -> EndpointId { self.endpoint_info.endpoint_id } @@ -491,7 +491,7 @@ impl Discovery for ConcurrentDiscovery { fn resolve( &self, - endpoint_id: PublicKey, + endpoint_id: EndpointId, ) -> Option>> { let services = self.services.read().expect("poisoned"); let streams = services @@ -515,7 +515,7 @@ pub(super) struct DiscoveryTask { impl DiscoveryTask { /// Starts a discovery task. - pub(super) fn start(ep: Endpoint, endpoint_id: PublicKey) -> Result { + pub(super) fn start(ep: Endpoint, endpoint_id: EndpointId) -> Result { ensure!( !ep.discovery().is_empty(), DiscoveryError::NoServiceConfigured @@ -543,7 +543,7 @@ impl DiscoveryTask { /// Otherwise, or if no `delay` is set, the discovery will be started. pub(super) fn maybe_start_after_delay( ep: &Endpoint, - endpoint_id: PublicKey, + endpoint_id: EndpointId, delay: Option, ) -> Result, DiscoveryError> { // If discovery is not needed, don't even spawn a task. @@ -589,7 +589,7 @@ impl DiscoveryTask { fn create_stream( ep: &Endpoint, - endpoint_id: PublicKey, + endpoint_id: EndpointId, ) -> Result>, DiscoveryError> { ensure!( !ep.discovery().is_empty(), @@ -604,7 +604,7 @@ impl DiscoveryTask { async fn run( ep: Endpoint, - endpoint_id: PublicKey, + endpoint_id: EndpointId, on_first_tx: oneshot::Sender>, ) { let mut stream = match Self::create_stream(&ep, endpoint_id) { @@ -668,7 +668,7 @@ mod tests { use super::*; use crate::{Endpoint, RelayMode, endpoint::ConnectOptions}; - type InfoStore = HashMap; + type InfoStore = HashMap; #[derive(Debug, Clone, Default)] struct TestDiscoveryShared { @@ -676,7 +676,7 @@ mod tests { } impl TestDiscoveryShared { - pub fn create_discovery(&self, endpoint_id: PublicKey) -> TestDiscovery { + pub fn create_discovery(&self, endpoint_id: EndpointId) -> TestDiscovery { TestDiscovery { endpoint_id, shared: self.clone(), @@ -686,7 +686,7 @@ mod tests { } } - pub fn create_lying_discovery(&self, endpoint_id: PublicKey) -> TestDiscovery { + pub fn create_lying_discovery(&self, endpoint_id: EndpointId) -> TestDiscovery { TestDiscovery { endpoint_id, shared: self.clone(), @@ -699,7 +699,7 @@ mod tests { #[derive(Debug)] struct TestDiscovery { - endpoint_id: PublicKey, + endpoint_id: EndpointId, shared: TestDiscoveryShared, publish: bool, resolve_wrong: bool, @@ -721,7 +721,7 @@ mod tests { fn resolve( &self, - endpoint_id: PublicKey, + endpoint_id: EndpointId, ) -> Option>> { let addr_info = if self.resolve_wrong { let ts = system_time_now() - 100_000; @@ -767,7 +767,7 @@ mod tests { fn resolve( &self, - _endpoint_id: PublicKey, + _endpoint_id: EndpointId, ) -> Option>> { Some(n0_future::stream::empty().boxed()) } diff --git a/iroh/src/discovery/dns.rs b/iroh/src/discovery/dns.rs index 4d4014c921c..edfca093b9b 100644 --- a/iroh/src/discovery/dns.rs +++ b/iroh/src/discovery/dns.rs @@ -1,6 +1,6 @@ //! DNS endpoint discovery for iroh -use iroh_base::PublicKey; +use iroh_base::EndpointId; use iroh_relay::dns::DnsResolver; pub use iroh_relay::dns::{N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}; use n0_future::boxed::BoxStream; @@ -105,13 +105,14 @@ impl IntoDiscovery for DnsDiscoveryBuilder { impl Discovery for DnsDiscovery { fn resolve( &self, - endpoint_id: PublicKey, + endpoint_id: EndpointId, ) -> Option>> { + let public_key = endpoint_id.as_ed()?; let resolver = self.dns_resolver.clone(); let origin_domain = self.origin_domain.clone(); let fut = async move { let endpoint_info = resolver - .lookup_endpoint_by_id_staggered(&endpoint_id, &origin_domain, DNS_STAGGERING_MS) + .lookup_endpoint_by_id_staggered(&public_key, &origin_domain, DNS_STAGGERING_MS) .await .map_err(|e| DiscoveryError::from_err_any("dns", e))?; Ok(DiscoveryItem::new(endpoint_info, "dns", None)) diff --git a/iroh/src/discovery/pkarr.rs b/iroh/src/discovery/pkarr.rs index 43889b9e1f2..84a1a80f907 100644 --- a/iroh/src/discovery/pkarr.rs +++ b/iroh/src/discovery/pkarr.rs @@ -46,7 +46,7 @@ use std::sync::Arc; -use iroh_base::{PublicKey, RelayUrl, SecretKey}; +use iroh_base::{EndpointId, PublicKey, RelayUrl, SecretKey}; use iroh_relay::endpoint_info::{EncodingError, EndpointInfo}; use n0_error::{e, stack_error}; use n0_future::{ @@ -510,11 +510,12 @@ impl PkarrResolver { impl Discovery for PkarrResolver { fn resolve( &self, - endpoint_id: PublicKey, + endpoint_id: EndpointId, ) -> Option>> { + let public_key = endpoint_id.as_ed()?; let pkarr_client = self.pkarr_client.clone(); let fut = async move { - let signed_packet = pkarr_client.resolve(endpoint_id).await?; + let signed_packet = pkarr_client.resolve(public_key).await?; let info = EndpointInfo::from_pkarr_signed_packet(&signed_packet) .map_err(|err| DiscoveryError::from_err_any("pkarr", err))?; let item = DiscoveryItem::new(info, "pkarr", None); diff --git a/iroh/src/discovery/static_provider.rs b/iroh/src/discovery/static_provider.rs index 8c63af20a5d..05e16b85d69 100644 --- a/iroh/src/discovery/static_provider.rs +++ b/iroh/src/discovery/static_provider.rs @@ -15,7 +15,7 @@ use std::{ sync::{Arc, RwLock}, }; -use iroh_base::PublicKey; +use iroh_base::EndpointId; use n0_future::{ boxed::BoxStream, stream::{self, StreamExt}, @@ -67,7 +67,7 @@ use super::{Discovery, DiscoveryError, DiscoveryItem, EndpointData, EndpointInfo /// [`EndpointTicket`]: https://docs.rs/iroh-base/latest/iroh_base/ticket/struct.EndpointTicket #[derive(Debug, Clone)] pub struct StaticProvider { - endpoints: Arc>>, + endpoints: Arc>>, provenance: &'static str, } @@ -186,7 +186,7 @@ impl StaticProvider { } /// Returns endpoint addressing information for the given endpoint ID. - pub fn get_endpoint_info(&self, endpoint_id: PublicKey) -> Option { + pub fn get_endpoint_info(&self, endpoint_id: EndpointId) -> Option { let guard = self.endpoints.read().expect("poisoned"); let info = guard.get(&endpoint_id)?; Some(EndpointInfo::from_parts(endpoint_id, info.data.clone())) @@ -195,7 +195,7 @@ impl StaticProvider { /// Removes all endpoint addressing information for the given endpoint ID. /// /// Any removed information is returned. - pub fn remove_endpoint_info(&self, endpoint_id: PublicKey) -> Option { + pub fn remove_endpoint_info(&self, endpoint_id: EndpointId) -> Option { let mut guard = self.endpoints.write().expect("poisoned"); let info = guard.remove(&endpoint_id)?; Some(EndpointInfo::from_parts(endpoint_id, info.data)) @@ -207,7 +207,7 @@ impl Discovery for StaticProvider { fn resolve( &self, - endpoint_id: PublicKey, + endpoint_id: EndpointId, ) -> Option>> { let guard = self.endpoints.read().expect("poisoned"); let info = guard.get(&endpoint_id); diff --git a/iroh/src/endpoint.rs b/iroh/src/endpoint.rs index c699a16df67..a93971566f9 100644 --- a/iroh/src/endpoint.rs +++ b/iroh/src/endpoint.rs @@ -16,7 +16,7 @@ use std::{ sync::Arc, }; -use iroh_base::{EndpointAddr, PublicKey, RelayUrl, SecretKey, TransportAddr}; +use iroh_base::{EndpointAddr, EndpointId, PublicKey, RelayUrl, SecretKey, TransportAddr}; use iroh_relay::{RelayConfig, RelayMap}; use n0_error::{e, ensure, stack_error}; use n0_future::time::Duration; @@ -679,6 +679,9 @@ impl Endpoint { self.add_endpoint_addr(endpoint_addr.clone(), Source::App)?; } let endpoint_id = endpoint_addr.id; + let Some(public_key) = endpoint_id.as_ed() else { + panic!(); + }; let ip_addresses: Vec<_> = endpoint_addr.ip_addrs().cloned().collect(); let relay_url = endpoint_addr.relay_urls().next().cloned(); @@ -715,7 +718,7 @@ impl Endpoint { client_config }; - let server_name = &tls::name::encode(endpoint_id); + let server_name = &tls::name::encode(public_key); let connect = self.msock.endpoint().connect_with( client_config, mapped_addr.private_socket_addr(), @@ -725,7 +728,7 @@ impl Endpoint { Ok(Connecting::new( connect, self.clone(), - endpoint_id, + public_key, _discovery_drop_guard, )) } @@ -793,8 +796,8 @@ impl Endpoint { /// /// This ID is the unique addressing information of this endpoint and other peers must know /// it to be able to connect to this endpoint. - pub fn id(&self) -> PublicKey { - self.static_config.tls_config.secret_key.public() + pub fn id(&self) -> EndpointId { + self.static_config.tls_config.secret_key.public().into() } /// Returns the current [`EndpointAddr`]. @@ -1200,8 +1203,11 @@ impl Endpoint { // # Remaining private methods /// Checks if the given `EndpointId` needs discovery. - pub(crate) fn needs_discovery(&self, endpoint_id: PublicKey, max_age: Duration) -> bool { - match self.msock.remote_info(endpoint_id) { + pub(crate) fn needs_discovery(&self, endpoint_id: EndpointId, max_age: Duration) -> bool { + let Some(public_key) = endpoint_id.as_ed() else { + return false; + }; + match self.msock.remote_info(public_key) { // No info means no path to endpoint -> start discovery. None => true, Some(info) => { @@ -1240,11 +1246,14 @@ impl Endpoint { endpoint_addr: EndpointAddr, ) -> Result<(EndpointIdMappedAddr, Option), GetMappingAddressError> { let endpoint_id = endpoint_addr.id; + let Some(public_key) = endpoint_id.as_ed() else { + return Err(e!(GetMappingAddressError::NoAddress)) + }; // Only return a mapped addr if we have some way of dialing this endpoint, in other // words, we have either a relay URL or at least one direct address. - let addr = if self.msock.has_send_address(endpoint_id) { - self.msock.get_mapping_addr(endpoint_id) + let addr = if self.msock.has_send_address(public_key) { + self.msock.get_mapping_addr(public_key) } else { None }; @@ -1276,7 +1285,7 @@ impl Endpoint { .first_arrived() .await .map_err(|err| e!(GetMappingAddressError::Discover, err))?; - if let Some(addr) = self.msock.get_mapping_addr(endpoint_id) { + if let Some(addr) = self.msock.get_mapping_addr(public_key) { Ok((addr, Some(discovery))) } else { Err(e!(GetMappingAddressError::NoAddress)) diff --git a/iroh/src/magicsock/endpoint_map.rs b/iroh/src/magicsock/endpoint_map.rs index 85822489373..caa71fd27f1 100644 --- a/iroh/src/magicsock/endpoint_map.rs +++ b/iroh/src/magicsock/endpoint_map.rs @@ -377,12 +377,13 @@ impl EndpointMapInner { ) { let source0 = source.clone(); let endpoint_id = endpoint_addr.id; + let public_key = endpoint_id.expect_ed(); let relay_url = endpoint_addr.relay_urls().next().cloned(); #[cfg(any(test, feature = "test-utils"))] let path_selection = self.path_selection; let endpoint_state = - self.get_or_insert_with(EndpointStateKey::EndpointId(endpoint_id), || Options { - endpoint_id, + self.get_or_insert_with(EndpointStateKey::EndpointId(public_key), || Options { + endpoint_id: public_key, relay_url, active: false, source, diff --git a/iroh/src/magicsock/endpoint_map/endpoint_state.rs b/iroh/src/magicsock/endpoint_map/endpoint_state.rs index 6c8807fe881..238ac3d84b1 100644 --- a/iroh/src/magicsock/endpoint_map/endpoint_state.rs +++ b/iroh/src/magicsock/endpoint_map/endpoint_state.rs @@ -1233,7 +1233,7 @@ impl From for EndpointAddr { } EndpointAddr { - id: info.endpoint_id, + id: info.endpoint_id.into(), addrs, } } From e5452969ca984b386fa7c3d5752578ae2dadf381 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Wed, 12 Nov 2025 13:20:36 -0600 Subject: [PATCH 03/10] Tests seem to pass Still ugly .expect_ed() in tests. --- iroh-base/src/key.rs | 18 +++++++ iroh/examples/0rtt.rs | 2 +- iroh/examples/transfer.rs | 2 +- iroh/src/discovery.rs | 12 ++--- iroh/src/discovery/static_provider.rs | 36 ++++++-------- iroh/src/endpoint.rs | 12 ++--- iroh/src/magicsock.rs | 68 ++++++++++++--------------- iroh/src/test_utils.rs | 2 +- 8 files changed, 78 insertions(+), 74 deletions(-) diff --git a/iroh-base/src/key.rs b/iroh-base/src/key.rs index 84bc543e70f..9d58bbf4e84 100644 --- a/iroh-base/src/key.rs +++ b/iroh-base/src/key.rs @@ -32,6 +32,24 @@ pub enum EndpointId { Other([u8; 8]), } +impl PartialEq for EndpointId { + fn eq(&self, other: &PublicKey) -> bool { + match self { + EndpointId::Ed25519(key) => key == other, + EndpointId::Other(_) => false, + } + } +} + +impl Display for EndpointId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + EndpointId::Ed25519(key) => write!(f, "Ed25519({})", key), + EndpointId::Other(bytes) => write!(f, "Other({})", data_encoding::HEXLOWER.encode(bytes)), + } + } +} + impl EndpointId { /// If this is an Ed25519 endpoint id, return the public key. pub fn as_ed(self) -> Option { diff --git a/iroh/examples/0rtt.rs b/iroh/examples/0rtt.rs index efedbe8f92f..8634f226c30 100644 --- a/iroh/examples/0rtt.rs +++ b/iroh/examples/0rtt.rs @@ -60,7 +60,7 @@ async fn pong(mut recv: RecvStream, x: u64) -> Result<()> { } async fn connect(args: Args) -> Result<()> { - let remote_id = args.endpoint_id.unwrap(); + let remote_id = args.endpoint_id.unwrap().into(); let endpoint = iroh::Endpoint::builder() .relay_mode(iroh::RelayMode::Disabled) .keylog(true) diff --git a/iroh/examples/transfer.rs b/iroh/examples/transfer.rs index fcbc7407032..b5fae117dbf 100644 --- a/iroh/examples/transfer.rs +++ b/iroh/examples/transfer.rs @@ -404,7 +404,7 @@ async fn fetch(endpoint: Endpoint, remote_addr: EndpointAddr) -> Result<()> { let conn = endpoint.connect(remote_addr, TRANSFER_ALPN).await?; println!("Connected to {}", remote_id); // Spawn a background task that prints connection type changes. Will be aborted on drop. - let _guard = watch_conn_type(&endpoint, remote_id); + let _guard = watch_conn_type(&endpoint, remote_id.expect_ed()); // Use the Quinn API to send and recv content. let (mut send, mut recv) = conn.open_bi().await.anyerr()?; diff --git a/iroh/src/discovery.rs b/iroh/src/discovery.rs index fb6b30ce5c7..c5db499abd9 100644 --- a/iroh/src/discovery.rs +++ b/iroh/src/discovery.rs @@ -1017,7 +1017,7 @@ mod test_dns_pkarr { let resolver = DnsResolver::with_nameserver(nameserver); let resolved = resolver - .lookup_endpoint_by_id(&endpoint_info.endpoint_id, &origin) + .lookup_endpoint_by_id(&endpoint_info.endpoint_id.expect_ed(), &origin) .await?; assert_eq!(resolved, endpoint_info); @@ -1059,10 +1059,10 @@ mod test_dns_pkarr { .await?; println!("resolved {resolved:?}"); - let expected_addr = EndpointAddr { - id: endpoint_id, - addrs: relay_url.into_iter().collect(), - }; + let expected_addr = EndpointAddr::from_parts( + endpoint_id, + relay_url, + ); assert_eq!(resolved.to_endpoint_addr(), expected_addr); assert_eq!(resolved.user_data(), Some(&user_data)); @@ -1084,7 +1084,7 @@ mod test_dns_pkarr { // wait until our shared state received the update from pkarr publishing dns_pkarr_server - .on_endpoint(&ep1.id(), PUBLISH_TIMEOUT) + .on_endpoint(&ep1.id().expect_ed(), PUBLISH_TIMEOUT) .await .context("wait for on endpoint update")?; diff --git a/iroh/src/discovery/static_provider.rs b/iroh/src/discovery/static_provider.rs index 05e16b85d69..164c9075ef7 100644 --- a/iroh/src/discovery/static_provider.rs +++ b/iroh/src/discovery/static_provider.rs @@ -53,12 +53,10 @@ use super::{Discovery, DiscoveryError, DiscoveryItem, EndpointData, EndpointInfo /// // Sometime later add a RelayUrl for our endpoint. /// let id = SecretKey::generate(&mut rand::rng()).public(); /// // You can pass either `EndpointInfo` or `EndpointAddr` to `add_endpoint_info`. -/// discovery.add_endpoint_info(EndpointAddr { +/// discovery.add_endpoint_info(EndpointAddr::from_parts( /// id, -/// addrs: [TransportAddr::Relay("https://example.com".parse()?)] -/// .into_iter() -/// .collect(), -/// }); +/// [TransportAddr::Relay("https://example.com".parse()?)] +/// )); /// /// # Ok(()) /// # } @@ -248,18 +246,16 @@ mod tests { .await?; let key = SecretKey::from_bytes(&[0u8; 32]); - let addr = EndpointAddr { - id: key.public(), - addrs: [TransportAddr::Relay("https://example.com".parse()?)] - .into_iter() - .collect(), - }; + let addr = EndpointAddr::from_parts( + key.public(), + [TransportAddr::Relay("https://example.com".parse()?)] + ); let user_data = Some("foobar".parse().unwrap()); let endpoint_info = EndpointInfo::from(addr.clone()).with_user_data(user_data.clone()); discovery.add_endpoint_info(endpoint_info.clone()); let back = discovery - .get_endpoint_info(key.public()) + .get_endpoint_info(key.public().into()) .context("no addr")?; assert_eq!(back, endpoint_info); @@ -267,10 +263,10 @@ mod tests { assert_eq!(back.into_endpoint_addr(), addr); let removed = discovery - .remove_endpoint_info(key.public()) + .remove_endpoint_info(key.public().into()) .context("nothing removed")?; assert_eq!(removed, endpoint_info); - let res = discovery.get_endpoint_info(key.public()); + let res = discovery.get_endpoint_info(key.public().into()); assert!(res.is_none()); Ok(()) @@ -280,14 +276,12 @@ mod tests { async fn test_provenance() -> Result { let discovery = StaticProvider::with_provenance("foo"); let key = SecretKey::from_bytes(&[0u8; 32]); - let addr = EndpointAddr { - id: key.public(), - addrs: [TransportAddr::Relay("https://example.com".parse()?)] - .into_iter() - .collect(), - }; + let addr = EndpointAddr::from_parts( + key.public(), + [TransportAddr::Relay("https://example.com".parse()?)] + ); discovery.add_endpoint_info(addr); - let mut stream = discovery.resolve(key.public()).unwrap(); + let mut stream = discovery.resolve(key.public().into()).unwrap(); let item = stream.next().await.unwrap()?; assert_eq!(item.provenance(), "foo"); assert_eq!( diff --git a/iroh/src/endpoint.rs b/iroh/src/endpoint.rs index a93971566f9..f27ca0dfc56 100644 --- a/iroh/src/endpoint.rs +++ b/iroh/src/endpoint.rs @@ -1908,28 +1908,28 @@ mod tests { } } - let p1_accept = tokio::spawn(accept_world(ep1.clone(), ep2_endpointid).instrument( + let p1_accept = tokio::spawn(accept_world(ep1.clone(), ep2_endpointid.expect_ed()).instrument( info_span!( "p1_accept", ep1 = %ep1.id().fmt_short(), dst = %ep2_endpointid.fmt_short(), ), )); - let p2_accept = tokio::spawn(accept_world(ep2.clone(), ep1_endpointid).instrument( + let p2_accept = tokio::spawn(accept_world(ep2.clone(), ep1_endpointid.expect_ed()).instrument( info_span!( "p2_accept", ep2 = %ep2.id().fmt_short(), dst = %ep1_endpointid.fmt_short(), ), )); - let p1_connect = tokio::spawn(connect_hello(ep1.clone(), ep2_endpointid).instrument( + let p1_connect = tokio::spawn(connect_hello(ep1.clone(), ep2_endpointid.expect_ed()).instrument( info_span!( "p1_connect", ep1 = %ep1.id().fmt_short(), dst = %ep2_endpointid.fmt_short(), ), )); - let p2_connect = tokio::spawn(connect_hello(ep2.clone(), ep1_endpointid).instrument( + let p2_connect = tokio::spawn(connect_hello(ep2.clone(), ep1_endpointid.expect_ed()).instrument( info_span!( "p2_connect", ep2 = %ep2.id().fmt_short(), @@ -2003,7 +2003,7 @@ mod tests { let ep1_side = tokio::time::timeout(TIMEOUT, async move { let conn = accept(&ep1).await?; let mut send = conn.open_uni().await.anyerr()?; - wait_for_conn_type_direct(&ep1, ep2_endpointid).await?; + wait_for_conn_type_direct(&ep1, ep2_endpointid.expect_ed()).await?; send.write_all(b"Conn is direct").await.anyerr()?; send.finish().anyerr()?; conn.closed().await; @@ -2013,7 +2013,7 @@ mod tests { let ep2_side = tokio::time::timeout(TIMEOUT, async move { let conn = ep2.connect(ep1_endpointaddr, TEST_ALPN).await?; let mut recv = conn.accept_uni().await.anyerr()?; - wait_for_conn_type_direct(&ep2, ep1_endpointid).await?; + wait_for_conn_type_direct(&ep2, ep1_endpointid.expect_ed()).await?; let read = recv.read_to_end(100).await.anyerr()?; assert_eq!(read, b"Conn is direct".to_vec()); conn.close(0u32.into(), b"done"); diff --git a/iroh/src/magicsock.rs b/iroh/src/magicsock.rs index 281456935d0..ffe71679ba6 100644 --- a/iroh/src/magicsock.rs +++ b/iroh/src/magicsock.rs @@ -2651,10 +2651,10 @@ mod tests { continue; } - let addr = EndpointAddr { - id: me.public(), - addrs: new_addrs.iter().copied().map(TransportAddr::Ip).collect(), - }; + let addr = EndpointAddr::from_parts( + me.public(), + new_addrs.iter().copied().map(TransportAddr::Ip), + ); m.endpoint.magic_sock().add_test_addr(addr); } } @@ -2686,7 +2686,7 @@ mod tests { let all_endpoints_meshed = all_endpoint_ids .iter() .filter(|endpoint_id| **endpoint_id != my_endpoint_id) - .all(|endpoint_id| endpoints.contains(endpoint_id)); + .all(|endpoint_id| endpoints.contains(&endpoint_id.expect_ed())); ready.push(all_endpoints_meshed); } if ready.iter().all(|meshed| *meshed) { @@ -2812,7 +2812,7 @@ mod tests { info!("\nroundtrip: {send_endpoint_id:#} -> {recv_endpoint_id:#}"); let receiver_task = tokio::spawn(echo_receiver(receiver, loss)); - let sender_res = echo_sender(sender, recv_endpoint_id, payload, loss).await; + let sender_res = echo_sender(sender, recv_endpoint_id.expect_ed(), payload, loss).await; let sender_is_err = match sender_res { Ok(()) => false, Err(err) => { @@ -3216,12 +3216,11 @@ mod tests { .ip_addrs() .get() .into_iter() - .map(|x| TransportAddr::Ip(x.addr)) - .collect(); - let endpoint_addr_2 = EndpointAddr { - id: endpoint_id_2, + .map(|x| TransportAddr::Ip(x.addr)); + let endpoint_addr_2 = EndpointAddr::from_parts( + endpoint_id_2, addrs, - }; + ); msock_1 .add_endpoint_addr( endpoint_addr_2, @@ -3292,10 +3291,10 @@ mod tests { // Add an empty entry in the EndpointMap of ep_1 msock_1.endpoint_map.add_endpoint_addr( - EndpointAddr { - id: endpoint_id_2, - addrs: Default::default(), - }, + EndpointAddr::from_parts( + endpoint_id_2, + [], + ), Source::NamedApp { name: "test".into(), }, @@ -3332,13 +3331,12 @@ mod tests { .ip_addrs() .get() .into_iter() - .map(|x| TransportAddr::Ip(x.addr)) - .collect(); + .map(|x| TransportAddr::Ip(x.addr)); msock_1.endpoint_map.add_endpoint_addr( - EndpointAddr { - id: endpoint_id_2, + EndpointAddr::from_parts( + endpoint_id_2, addrs, - }, + ), Source::NamedApp { name: "test".into(), }, @@ -3393,12 +3391,10 @@ mod tests { ); // relay url only - let addr = EndpointAddr { - id: SecretKey::generate(&mut rng).public(), - addrs: [TransportAddr::Relay("http://my-relay.com".parse().unwrap())] - .into_iter() - .collect(), - }; + let addr = EndpointAddr::from_parts( + SecretKey::generate(&mut rng).public(), + [TransportAddr::Relay("http://my-relay.com".parse().unwrap())] + ); stack .endpoint .magic_sock() @@ -3406,12 +3402,10 @@ mod tests { assert_eq!(stack.endpoint.magic_sock().endpoint_map.endpoint_count(), 1); // addrs only - let addr = EndpointAddr { - id: SecretKey::generate(&mut rng).public(), - addrs: [TransportAddr::Ip("127.0.0.1:1234".parse().unwrap())] - .into_iter() - .collect(), - }; + let addr = EndpointAddr::from_parts( + SecretKey::generate(&mut rng).public(), + [TransportAddr::Ip("127.0.0.1:1234".parse().unwrap())] + ); stack .endpoint .magic_sock() @@ -3419,15 +3413,13 @@ mod tests { assert_eq!(stack.endpoint.magic_sock().endpoint_map.endpoint_count(), 2); // both - let addr = EndpointAddr { - id: SecretKey::generate(&mut rng).public(), - addrs: [ + let addr = EndpointAddr::from_parts( + SecretKey::generate(&mut rng).public(), + [ TransportAddr::Relay("http://my-relay.com".parse().unwrap()), TransportAddr::Ip("127.0.0.1:1234".parse().unwrap()), ] - .into_iter() - .collect(), - }; + ); stack .endpoint .magic_sock() diff --git a/iroh/src/test_utils.rs b/iroh/src/test_utils.rs index 1d9c34df5d8..005dade45a2 100644 --- a/iroh/src/test_utils.rs +++ b/iroh/src/test_utils.rs @@ -495,7 +495,7 @@ pub(crate) mod pkarr_dns_state { ttl: u32, ) -> impl Iterator + 'static { let txt_strings = endpoint_info.to_txt_strings(); - let records = to_hickory_records(txt_strings, endpoint_info.endpoint_id, origin, ttl); + let records = to_hickory_records(txt_strings, endpoint_info.endpoint_id.expect_ed(), origin, ttl); records.collect::>().into_iter() } From 7cc2d23972178b710fe85d0fe214c22c959d0e16 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Wed, 12 Nov 2025 13:33:33 -0600 Subject: [PATCH 04/10] fix docs --- iroh-relay/src/dns.rs | 4 ++-- iroh-relay/src/protos/relay.rs | 2 +- iroh/src/endpoint/connection.rs | 32 ++++++++++++++++---------------- iroh/src/lib.rs | 3 ++- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/iroh-relay/src/dns.rs b/iroh-relay/src/dns.rs index fe27a81c86f..77a9e8b2de4 100644 --- a/iroh-relay/src/dns.rs +++ b/iroh-relay/src/dns.rs @@ -382,7 +382,7 @@ impl DnsResolver { stagger_call(f, delays_ms).await } - /// Looks up endpoint info by [`EndpointId`] and origin domain name. + /// Looks up endpoint info by [`PublicKey`] and origin domain name. /// /// To lookup endpoints that published their endpoint info to the DNS servers run by n0, /// pass [`N0_DNS_ENDPOINT_ORIGIN_PROD`] as `origin`. @@ -424,7 +424,7 @@ impl DnsResolver { stagger_call(f, delays_ms).await } - /// Looks up endpoint info by [`EndpointId`] and origin domain name. + /// Looks up endpoint info by [`PublicKey`] and origin domain name. /// /// From the moment this function is called, each lookup is scheduled after the delays in /// `delays_ms` with the first call being done immediately. `[200ms, 300ms]` results in calls diff --git a/iroh-relay/src/protos/relay.rs b/iroh-relay/src/protos/relay.rs index 919d1118b58..9ccf3d7957b 100644 --- a/iroh-relay/src/protos/relay.rs +++ b/iroh-relay/src/protos/relay.rs @@ -75,7 +75,7 @@ pub enum Error { pub enum RelayToClientMsg { /// Represents datagrams sent from relays (originally sent to them by another client). Datagrams { - /// The [`EndpointId`] of the original sender. + /// The [`PublicKey`] of the original sender. remote_endpoint_id: PublicKey, /// The datagrams and related metadata. datagrams: Datagrams, diff --git a/iroh/src/endpoint/connection.rs b/iroh/src/endpoint/connection.rs index 266b617757d..89b1c92118a 100644 --- a/iroh/src/endpoint/connection.rs +++ b/iroh/src/endpoint/connection.rs @@ -27,7 +27,7 @@ use std::{ use ed25519_dalek::{VerifyingKey, pkcs8::DecodePublicKey}; use futures_util::{FutureExt, future::Shared}; -use iroh_base::PublicKey; +use iroh_base::{EndpointId, PublicKey}; use n0_error::{e, stack_error}; use n0_future::time::Duration; use n0_watcher::Watcher; @@ -236,11 +236,11 @@ fn conn_from_quinn_conn(conn: quinn::Connection) -> Result PublicKey { - self.remote_endpoint_id + pub fn remote_id(&self) -> EndpointId { + self.remote_endpoint_id.into() } } @@ -816,11 +816,11 @@ impl OutgoingZeroRttConnection { self.inner.peer_identity() } - /// Returns the [`EndpointId`] from the peer's TLS certificate. + /// Returns the [`PublicKey`] from the peer's TLS certificate. /// - /// The [`PublicKey`] of an endpoint is also known as an [`EndpointId`]. This [`PublicKey`] is + /// The [`PublicKey`] of an endpoint is also known as an [`PublicKey`]. This [`PublicKey`] is /// included in the TLS certificate presented during the handshake when connecting. - /// This function allows you to get the [`EndpointId`] of the remote endpoint of this + /// This function allows you to get the [`PublicKey`] of the remote endpoint of this /// connection. /// /// [`PublicKey`]: iroh_base::PublicKey @@ -897,7 +897,7 @@ impl OutgoingZeroRttConnection { /// Use the [`IncomingZeroRttConnection::handshake_completed`] method to get a [`Connection`] from a /// `IncomingZeroRttConnection`. This waits until 0-RTT connection has completed /// the handshake and can now confidently derive the ALPN and the -/// [`EndpointId`] of the remote endpoint. +/// [`PublicKey`] of the remote endpoint. #[derive(Debug)] pub struct IncomingZeroRttConnection { inner: quinn::Connection, @@ -1127,11 +1127,11 @@ impl IncomingZeroRttConnection { self.inner.peer_identity() } - /// Returns the [`EndpointId`] from the peer's TLS certificate. + /// Returns the [`PublicKey`] from the peer's TLS certificate. /// - /// The [`PublicKey`] of an endpoint is also known as an [`EndpointId`]. This [`PublicKey`] is + /// The [`PublicKey`] of an endpoint is also known as an [`PublicKey`]. This [`PublicKey`] is /// included in the TLS certificate presented during the handshake when connecting. - /// This function allows you to get the [`EndpointId`] of the remote endpoint of this + /// This function allows you to get the [`PublicKey`] of the remote endpoint of this /// connection. /// /// [`PublicKey`]: iroh_base::PublicKey @@ -1426,11 +1426,11 @@ impl Connection { self.inner.peer_identity() } - /// Returns the [`EndpointId`] from the peer's TLS certificate. + /// Returns the [`PublicKey`] from the peer's TLS certificate. /// - /// The [`PublicKey`] of an endpoint is also known as an [`EndpointId`]. This [`PublicKey`] is + /// The [`PublicKey`] of an endpoint is also known as an [`PublicKey`]. This [`PublicKey`] is /// included in the TLS certificate presented during the handshake when connecting. - /// This function allows you to get the [`EndpointId`] of the remote endpoint of this + /// This function allows you to get the [`PublicKey`] of the remote endpoint of this /// connection. /// /// [`PublicKey`]: iroh_base::PublicKey diff --git a/iroh/src/lib.rs b/iroh/src/lib.rs index f290fd36ac1..a00bc33c6c2 100644 --- a/iroh/src/lib.rs +++ b/iroh/src/lib.rs @@ -238,6 +238,7 @@ //! [HTTP3]: https://en.wikipedia.org/wiki/HTTP/3 //! [`SecretKey`]: crate::SecretKey //! [`PublicKey`]: crate::PublicKey +//! [`EndpointId`]: crate::EndpointId //! [`RelayUrl`]: crate::RelayUrl //! [`discovery`]: crate::endpoint::Builder::discovery //! [`DnsDiscovery`]: crate::discovery::dns::DnsDiscovery @@ -273,7 +274,7 @@ pub mod protocol; pub use endpoint::{Endpoint, RelayMode}; pub use iroh_base::{ - EndpointAddr, PublicKey, KeyParsingError, RelayUrl, RelayUrlParseError, SecretKey, + EndpointAddr, PublicKey, EndpointId, KeyParsingError, RelayUrl, RelayUrlParseError, SecretKey, Signature, SignatureError, TransportAddr, }; pub use iroh_relay::{RelayConfig, RelayMap, endpoint_info}; From cadee48400c64de814768941b33dd1335fa0dbf4 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 13 Nov 2025 08:54:39 -0600 Subject: [PATCH 05/10] Remove Other from EndpointId and make it non_exhaustive --- iroh-base/src/key.rs | 7 +------ iroh/examples/transfer.rs | 11 ++++------- iroh/src/endpoint.rs | 14 ++++++++------ iroh/src/endpoint/connection.rs | 20 ++++++++++---------- iroh/src/protocol.rs | 6 +++--- 5 files changed, 26 insertions(+), 32 deletions(-) diff --git a/iroh-base/src/key.rs b/iroh-base/src/key.rs index 9d58bbf4e84..40126de4d4a 100644 --- a/iroh-base/src/key.rs +++ b/iroh-base/src/key.rs @@ -25,18 +25,16 @@ pub struct PublicKey(CompressedEdwardsY); /// The identifier for an endpoint in the (iroh) network. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +#[non_exhaustive] pub enum EndpointId { /// An Ed25519 public key. Ed25519(PublicKey), - /// Other types of endpoint identifiers. - Other([u8; 8]), } impl PartialEq for EndpointId { fn eq(&self, other: &PublicKey) -> bool { match self { EndpointId::Ed25519(key) => key == other, - EndpointId::Other(_) => false, } } } @@ -45,7 +43,6 @@ impl Display for EndpointId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { EndpointId::Ed25519(key) => write!(f, "Ed25519({})", key), - EndpointId::Other(bytes) => write!(f, "Other({})", data_encoding::HEXLOWER.encode(bytes)), } } } @@ -55,7 +52,6 @@ impl EndpointId { pub fn as_ed(self) -> Option { match self { EndpointId::Ed25519(key) => Some(key), - EndpointId::Other(_) => None, } } @@ -68,7 +64,6 @@ impl EndpointId { pub fn fmt_short(&self) -> String { match self { EndpointId::Ed25519(key) => key.fmt_short().to_string(), - EndpointId::Other(_) => "Other".to_string(), } } } diff --git a/iroh/examples/transfer.rs b/iroh/examples/transfer.rs index b5fae117dbf..f8137ecf923 100644 --- a/iroh/examples/transfer.rs +++ b/iroh/examples/transfer.rs @@ -9,13 +9,10 @@ use clap::{Parser, Subcommand}; use data_encoding::HEXLOWER; use indicatif::HumanBytes; use iroh::{ - Endpoint, EndpointAddr, PublicKey, RelayMap, RelayMode, RelayUrl, SecretKey, TransportAddr, - discovery::{ + Endpoint, EndpointAddr, EndpointId, PublicKey, RelayMap, RelayMode, RelayUrl, SecretKey, TransportAddr, discovery::{ dns::DnsDiscovery, pkarr::{N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING, PkarrPublisher}, - }, - dns::{DnsResolver, N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}, - endpoint::ConnectionError, + }, dns::{DnsResolver, N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}, endpoint::ConnectionError }; use n0_error::{Result, StackResultExt, StdResultExt}; use n0_future::task::AbortOnDropHandle; @@ -404,7 +401,7 @@ async fn fetch(endpoint: Endpoint, remote_addr: EndpointAddr) -> Result<()> { let conn = endpoint.connect(remote_addr, TRANSFER_ALPN).await?; println!("Connected to {}", remote_id); // Spawn a background task that prints connection type changes. Will be aborted on drop. - let _guard = watch_conn_type(&endpoint, remote_id.expect_ed()); + let _guard = watch_conn_type(&endpoint, remote_id); // Use the Quinn API to send and recv content. let (mut send, mut recv) = conn.open_bi().await.anyerr()?; @@ -521,7 +518,7 @@ fn parse_byte_size(s: &str) -> std::result::Result { cfg.parse_size(s) } -fn watch_conn_type(endpoint: &Endpoint, endpoint_id: PublicKey) -> AbortOnDropHandle<()> { +fn watch_conn_type(endpoint: &Endpoint, endpoint_id: EndpointId) -> AbortOnDropHandle<()> { let mut stream = endpoint.conn_type(endpoint_id).unwrap().stream(); let task = tokio::task::spawn(async move { while let Some(conn_type) = stream.next().await { diff --git a/iroh/src/endpoint.rs b/iroh/src/endpoint.rs index f27ca0dfc56..4a4bfd9d431 100644 --- a/iroh/src/endpoint.rs +++ b/iroh/src/endpoint.rs @@ -16,7 +16,7 @@ use std::{ sync::Arc, }; -use iroh_base::{EndpointAddr, EndpointId, PublicKey, RelayUrl, SecretKey, TransportAddr}; +use iroh_base::{EndpointAddr, EndpointId, RelayUrl, SecretKey, TransportAddr}; use iroh_relay::{RelayConfig, RelayMap}; use n0_error::{e, ensure, stack_error}; use n0_future::time::Duration; @@ -978,15 +978,17 @@ impl Endpoint { /// become inaccessible. /// /// Will return `None` if we do not have any address information for the given `endpoint_id`. - pub fn conn_type(&self, endpoint_id: PublicKey) -> Option> { - self.msock.conn_type(endpoint_id) + pub fn conn_type(&self, endpoint_id: EndpointId) -> Option> { + let public_key = endpoint_id.as_ed()?; + self.msock.conn_type(public_key) } /// Returns the currently lowest latency for this endpoint. /// /// Will return `None` if we do not have any address information for the given `endpoint_id`. - pub fn latency(&self, endpoint_id: PublicKey) -> Option { - self.msock.latency(endpoint_id) + pub fn latency(&self, endpoint_id: EndpointId) -> Option { + let public_key = endpoint_id.as_ed()?; + self.msock.latency(public_key) } /// Returns the DNS resolver used in this [`Endpoint`]. @@ -1968,7 +1970,7 @@ mod tests { async fn wait_for_conn_type_direct(ep: &Endpoint, endpoint_id: PublicKey) -> Result { let mut stream = ep - .conn_type(endpoint_id) + .conn_type(endpoint_id.into()) .expect("connection exists") .stream(); let src = ep.id().fmt_short(); diff --git a/iroh/src/endpoint/connection.rs b/iroh/src/endpoint/connection.rs index 89b1c92118a..4da2d08c2d8 100644 --- a/iroh/src/endpoint/connection.rs +++ b/iroh/src/endpoint/connection.rs @@ -178,7 +178,7 @@ impl Future for IncomingFuture { Ok(conn) => conn, Err(err) => return Poll::Ready(Err(err.into())), }; - try_send_rtt_msg(conn.quinn_connection(), this.ep, conn.remote_id()); + try_send_rtt_msg(conn.quinn_connection(), this.ep, conn.remote_id); Poll::Ready(Ok(conn)) } } @@ -442,7 +442,7 @@ impl Future for Connecting { } }; - try_send_rtt_msg(conn.quinn_connection(), this.ep, conn.remote_id()); + try_send_rtt_msg(conn.quinn_connection(), this.ep, conn.remote_id); Poll::Ready(Ok(conn)) } } @@ -520,7 +520,7 @@ impl Future for Accepting { Err(err) => return Poll::Ready(Err(err.into())), }; - try_send_rtt_msg(conn.quinn_connection(), this.ep, conn.remote_id()); + try_send_rtt_msg(conn.quinn_connection(), this.ep, conn.remote_id); Poll::Ready(Ok(conn)) } } @@ -824,8 +824,8 @@ impl OutgoingZeroRttConnection { /// connection. /// /// [`PublicKey`]: iroh_base::PublicKey - pub fn remote_id(&self) -> Result { - remote_id_from_quinn_conn(&self.inner) + pub fn remote_id(&self) -> Result { + remote_id_from_quinn_conn(&self.inner).map(EndpointId::from) } /// A stable identifier for this connection. @@ -1135,8 +1135,8 @@ impl IncomingZeroRttConnection { /// connection. /// /// [`PublicKey`]: iroh_base::PublicKey - pub fn remote_id(&self) -> Result { - remote_id_from_quinn_conn(&self.inner) + pub fn remote_id(&self) -> Result { + remote_id_from_quinn_conn(&self.inner).map(EndpointId::from) } /// A stable identifier for this connection. @@ -1434,8 +1434,8 @@ impl Connection { /// connection. /// /// [`PublicKey`]: iroh_base::PublicKey - pub fn remote_id(&self) -> PublicKey { - self.remote_id + pub fn remote_id(&self) -> EndpointId { + self.remote_id.into() } /// A stable identifier for this connection. @@ -1495,7 +1495,7 @@ impl Connection { /// If we can't notify the actor that will impact performance a little, but we can still /// function. fn try_send_rtt_msg(conn: &quinn::Connection, ep: &Endpoint, remote_id: PublicKey) { - let Some(conn_type_changes) = ep.conn_type(remote_id) else { + let Some(conn_type_changes) = ep.conn_type(remote_id.into()) else { warn!(?conn, "failed to create conn_type stream"); return; }; diff --git a/iroh/src/protocol.rs b/iroh/src/protocol.rs index c95eb005f81..fcca2939fd5 100644 --- a/iroh/src/protocol.rs +++ b/iroh/src/protocol.rs @@ -42,7 +42,7 @@ use std::{ sync::{Arc, Mutex}, }; -use iroh_base::PublicKey; +use iroh_base::EndpointId; use n0_error::{AnyError, e, stack_error}; use n0_future::{ join_all, @@ -558,7 +558,7 @@ async fn handle_connection(incoming: crate::endpoint::Incoming, protocols: Arc

{ proto: P, #[debug("limiter")] - limiter: Arc bool + Send + Sync + 'static>, + limiter: Arc bool + Send + Sync + 'static>, } impl AccessLimit

{ @@ -568,7 +568,7 @@ impl AccessLimit

{ /// connect, and `false` otherwise. pub fn new(proto: P, limiter: F) -> Self where - F: Fn(PublicKey) -> bool + Send + Sync + 'static, + F: Fn(EndpointId) -> bool + Send + Sync + 'static, { Self { proto, From a1042adec1e5d210a41fe0a74ca67323fdba5587 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 13 Nov 2025 09:49:02 -0600 Subject: [PATCH 06/10] Some renaming, remove a panic! --- iroh-dns-server/examples/publish.rs | 2 +- iroh-relay/src/endpoint_info.rs | 24 ++++++++++++------------ iroh/src/discovery/pkarr.rs | 6 +++--- iroh/src/endpoint.rs | 4 +++- iroh/src/test_utils.rs | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/iroh-dns-server/examples/publish.rs b/iroh-dns-server/examples/publish.rs index ce1e1f72a2f..c5f4993c8ca 100644 --- a/iroh-dns-server/examples/publish.rs +++ b/iroh-dns-server/examples/publish.rs @@ -8,7 +8,7 @@ use iroh::{ dns::{N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}, pkarr::{N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING, PkarrRelayClient}, }, - endpoint_info::{EndpointIdExt, EndpointInfo, IROH_TXT_NAME}, + endpoint_info::{PublicKeyExt, EndpointInfo, IROH_TXT_NAME}, }; use n0_error::{Result, StackResultExt}; use url::Url; diff --git a/iroh-relay/src/endpoint_info.rs b/iroh-relay/src/endpoint_info.rs index 640154ca6c8..57b690b63e8 100644 --- a/iroh-relay/src/endpoint_info.rs +++ b/iroh-relay/src/endpoint_info.rs @@ -78,9 +78,9 @@ pub enum DecodingError { InvalidKey { source: KeyParsingError }, } -/// Extension methods for [`EndpointId`] to encode to and decode from [`z32`], +/// Extension methods for [`PublicKey`] to encode to and decode from [`z32`], /// which is the encoding used in [`pkarr`] domain names. -pub trait EndpointIdExt { +pub trait PublicKeyExt { /// Encodes a [`EndpointId`] in [`z-base-32`] encoding. /// /// [`z-base-32`]: https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt @@ -92,7 +92,7 @@ pub trait EndpointIdExt { fn from_z32(s: &str) -> Result; } -impl EndpointIdExt for PublicKey { +impl PublicKeyExt for PublicKey { fn to_z32(&self) -> String { z32::encode(self.as_bytes()) } @@ -462,7 +462,7 @@ impl std::ops::DerefMut for EndpointInfo { /// [`IROH_TXT_NAME`] and the second label to be a z32 encoded [`EndpointId`]. Ignores /// subsequent labels. #[cfg(not(wasm_browser))] -fn endpoint_id_from_txt_name(name: &str) -> Result { +fn public_key_from_txt_name(name: &str) -> Result { let num_labels = name.split(".").count(); if num_labels < 2 { return Err(e!(ParseError::NumLabels { num_labels })); @@ -502,7 +502,7 @@ pub(crate) enum IrohAttr { /// [`Display`]. #[derive(Debug)] pub(crate) struct TxtAttrs { - endpoint_id: PublicKey, + public_key: PublicKey, attrs: BTreeMap>, } @@ -529,19 +529,19 @@ impl From<&EndpointInfo> for TxtAttrs { impl TxtAttrs { /// Creates [`TxtAttrs`] from an endpoint id and an iterator of key-value pairs. pub(crate) fn from_parts( - endpoint_id: PublicKey, + public_key: PublicKey, pairs: impl Iterator, ) -> Self { let mut attrs: BTreeMap> = BTreeMap::new(); for (k, v) in pairs { attrs.entry(k).or_default().push(v); } - Self { attrs, endpoint_id } + Self { attrs, public_key } } /// Creates [`TxtAttrs`] from an endpoint id and an iterator of "{key}={value}" strings. pub(crate) fn from_strings( - endpoint_id: PublicKey, + public_key: PublicKey, strings: impl Iterator, ) -> Result { let mut attrs: BTreeMap> = BTreeMap::new(); @@ -557,7 +557,7 @@ impl TxtAttrs { })?; attrs.entry(attr).or_default().push(value.to_string()); } - Ok(Self { attrs, endpoint_id }) + Ok(Self { attrs, public_key }) } /// Returns the parsed attributes. @@ -567,7 +567,7 @@ impl TxtAttrs { /// Returns the endpoint id. pub(crate) fn endpoint_id(&self) -> PublicKey { - self.endpoint_id + self.public_key } /// Parses a [`pkarr::SignedPacket`]. @@ -603,7 +603,7 @@ impl TxtAttrs { name: String, lookup: impl Iterator, ) -> Result { - let queried_endpoint_id = endpoint_id_from_txt_name(&name)?; + let queried_endpoint_id = public_key_from_txt_name(&name)?; let strings = lookup.map(|record| record.to_string()); Self::from_strings(queried_endpoint_id, strings) @@ -674,7 +674,7 @@ mod tests { use iroh_base::{PublicKey, SecretKey, TransportAddr}; use n0_error::{Result, StdResultExt}; - use super::{EndpointData, EndpointIdExt, EndpointInfo}; + use super::{EndpointData, PublicKeyExt, EndpointInfo}; use crate::dns::TxtRecordData; #[test] diff --git a/iroh/src/discovery/pkarr.rs b/iroh/src/discovery/pkarr.rs index 84a1a80f907..c0d74cab471 100644 --- a/iroh/src/discovery/pkarr.rs +++ b/iroh/src/discovery/pkarr.rs @@ -559,10 +559,10 @@ impl PkarrRelayClient { } } - /// Resolves a [`SignedPacket`] for the given [`EndpointId`]. - pub async fn resolve(&self, endpoint_id: PublicKey) -> Result { + /// Resolves a [`SignedPacket`] for the given [`PublicKey`]. + pub async fn resolve(&self, public_key: PublicKey) -> Result { // We map the error to string, as in browsers the error is !Send - let public_key = pkarr::PublicKey::try_from(endpoint_id.as_bytes()) + let public_key = pkarr::PublicKey::try_from(public_key.as_bytes()) .map_err(|err| e!(PkarrError::PublicKey, err))?; let mut url = self.pkarr_relay_url.clone(); diff --git a/iroh/src/endpoint.rs b/iroh/src/endpoint.rs index 4a4bfd9d431..d6fcf91dfc5 100644 --- a/iroh/src/endpoint.rs +++ b/iroh/src/endpoint.rs @@ -494,6 +494,8 @@ pub enum ConnectWithOptsError { #[error(std_err)] source: quinn_proto::ConnectError, }, + #[error("Unsupported endpoint type")] + UnsupportedEndpointType, } #[allow(missing_docs)] @@ -680,7 +682,7 @@ impl Endpoint { } let endpoint_id = endpoint_addr.id; let Some(public_key) = endpoint_id.as_ed() else { - panic!(); + return Err(e!(ConnectWithOptsError::UnsupportedEndpointType)); }; let ip_addresses: Vec<_> = endpoint_addr.ip_addrs().cloned().collect(); let relay_url = endpoint_addr.relay_urls().next().cloned(); diff --git a/iroh/src/test_utils.rs b/iroh/src/test_utils.rs index 005dade45a2..64ec72251a7 100644 --- a/iroh/src/test_utils.rs +++ b/iroh/src/test_utils.rs @@ -347,7 +347,7 @@ pub(crate) mod pkarr_dns_state { }; use iroh_base::PublicKey; - use iroh_relay::endpoint_info::{EndpointIdExt, EndpointInfo, IROH_TXT_NAME}; + use iroh_relay::endpoint_info::{PublicKeyExt, EndpointInfo, IROH_TXT_NAME}; use pkarr::SignedPacket; use tracing::debug; From 9b0bfd930cd8390cade8f7854e9ada4d79b082fe Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 13 Nov 2025 10:24:27 -0600 Subject: [PATCH 07/10] adapt non-default discovery mechanisms --- iroh-base/src/endpoint_addr.rs | 5 ++- iroh-base/src/lib.rs | 2 +- iroh-dns-server/examples/publish.rs | 2 +- iroh-relay/src/endpoint_info.rs | 18 +++++--- iroh-relay/src/protos/relay.rs | 2 +- iroh-relay/src/server/client.rs | 5 +-- iroh/examples/locally-discovered-nodes.rs | 4 +- iroh/examples/transfer.rs | 8 +++- iroh/src/discovery.rs | 5 +-- iroh/src/discovery/mdns.rs | 51 ++++++++++++----------- iroh/src/discovery/pkarr/dht.rs | 5 ++- iroh/src/discovery/static_provider.rs | 6 +-- iroh/src/endpoint.rs | 34 +++++++-------- iroh/src/endpoint/connection.rs | 4 +- iroh/src/lib.rs | 2 +- iroh/src/magicsock.rs | 21 +++------- iroh/src/test_utils.rs | 9 +++- 17 files changed, 95 insertions(+), 88 deletions(-) diff --git a/iroh-base/src/endpoint_addr.rs b/iroh-base/src/endpoint_addr.rs index 004168b990d..d781fc74a94 100644 --- a/iroh-base/src/endpoint_addr.rs +++ b/iroh-base/src/endpoint_addr.rs @@ -67,7 +67,10 @@ impl EndpointAddr { } /// Creates a new [`EndpointAddr`] from its parts. - pub fn from_parts(id: impl Into, addrs: impl IntoIterator) -> Self { + pub fn from_parts( + id: impl Into, + addrs: impl IntoIterator, + ) -> Self { Self { id: id.into(), addrs: addrs.into_iter().collect(), diff --git a/iroh-base/src/lib.rs b/iroh-base/src/lib.rs index be5c3e190b7..4b513469626 100644 --- a/iroh-base/src/lib.rs +++ b/iroh-base/src/lib.rs @@ -13,6 +13,6 @@ mod relay_url; #[cfg(feature = "key")] pub use self::endpoint_addr::{EndpointAddr, TransportAddr}; #[cfg(feature = "key")] -pub use self::key::{EndpointId, PublicKey, KeyParsingError, SecretKey, Signature, SignatureError}; +pub use self::key::{EndpointId, KeyParsingError, PublicKey, SecretKey, Signature, SignatureError}; #[cfg(feature = "relay")] pub use self::relay_url::{RelayUrl, RelayUrlParseError}; diff --git a/iroh-dns-server/examples/publish.rs b/iroh-dns-server/examples/publish.rs index c5f4993c8ca..ee11beac03d 100644 --- a/iroh-dns-server/examples/publish.rs +++ b/iroh-dns-server/examples/publish.rs @@ -8,7 +8,7 @@ use iroh::{ dns::{N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}, pkarr::{N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING, PkarrRelayClient}, }, - endpoint_info::{PublicKeyExt, EndpointInfo, IROH_TXT_NAME}, + endpoint_info::{EndpointInfo, IROH_TXT_NAME, PublicKeyExt}, }; use n0_error::{Result, StackResultExt}; use url::Url; diff --git a/iroh-relay/src/endpoint_info.rs b/iroh-relay/src/endpoint_info.rs index 57b690b63e8..4948001bec8 100644 --- a/iroh-relay/src/endpoint_info.rs +++ b/iroh-relay/src/endpoint_info.rs @@ -40,7 +40,9 @@ use std::{ str::{FromStr, Utf8Error}, }; -use iroh_base::{EndpointAddr, EndpointId, KeyParsingError, PublicKey, RelayUrl, SecretKey, TransportAddr}; +use iroh_base::{ + EndpointAddr, EndpointId, KeyParsingError, PublicKey, RelayUrl, SecretKey, TransportAddr, +}; use n0_error::{e, ensure, stack_error}; use url::Url; @@ -321,7 +323,10 @@ impl From<&TxtAttrs> for EndpointInfo { data.set_user_data(user_data); data.add_addrs(relay_urls.chain(ip_addrs)); - Self { endpoint_id: endpoint_id.into(), data } + Self { + endpoint_id: endpoint_id.into(), + data, + } } } @@ -338,7 +343,7 @@ impl From for EndpointInfo { info } } - + impl EndpointInfo { /// Creates a new [`EndpointInfo`] with an empty [`EndpointData`]. pub fn new(endpoint_id: impl Into) -> Self { @@ -347,7 +352,10 @@ impl EndpointInfo { /// Creates a new [`EndpointInfo`] from its parts. pub fn from_parts(endpoint_id: impl Into, data: EndpointData) -> Self { - Self { endpoint_id: endpoint_id.into(), data } + Self { + endpoint_id: endpoint_id.into(), + data, + } } /// Sets the relay URL and returns the updated endpoint info. @@ -674,7 +682,7 @@ mod tests { use iroh_base::{PublicKey, SecretKey, TransportAddr}; use n0_error::{Result, StdResultExt}; - use super::{EndpointData, PublicKeyExt, EndpointInfo}; + use super::{EndpointData, EndpointInfo, PublicKeyExt}; use crate::dns::TxtRecordData; #[test] diff --git a/iroh-relay/src/protos/relay.rs b/iroh-relay/src/protos/relay.rs index 9ccf3d7957b..0cf19030df6 100644 --- a/iroh-relay/src/protos/relay.rs +++ b/iroh-relay/src/protos/relay.rs @@ -10,7 +10,7 @@ use std::num::NonZeroU16; use bytes::{Buf, BufMut, Bytes, BytesMut}; -use iroh_base::{PublicKey, KeyParsingError}; +use iroh_base::{KeyParsingError, PublicKey}; use n0_error::{e, ensure, stack_error}; use n0_future::time::Duration; diff --git a/iroh-relay/src/server/client.rs b/iroh-relay/src/server/client.rs index 4055f213604..1272d464bf4 100644 --- a/iroh-relay/src/server/client.rs +++ b/iroh-relay/src/server/client.rs @@ -161,10 +161,7 @@ impl Client { self.disco_send_queue.try_send(Packet { src, data }) } - pub(super) fn try_send_peer_gone( - &self, - key: PublicKey, - ) -> Result<(), TrySendError> { + pub(super) fn try_send_peer_gone(&self, key: PublicKey) -> Result<(), TrySendError> { self.peer_gone.try_send(key) } } diff --git a/iroh/examples/locally-discovered-nodes.rs b/iroh/examples/locally-discovered-nodes.rs index 9fe375fe28c..eb7cd9783b2 100644 --- a/iroh/examples/locally-discovered-nodes.rs +++ b/iroh/examples/locally-discovered-nodes.rs @@ -6,7 +6,7 @@ use std::time::Duration; use iroh::{ - Endpoint, PublicKey, + Endpoint, EndpointId, discovery::mdns::{DiscoveryEvent, MdnsDiscovery}, endpoint_info::UserData, }; @@ -32,7 +32,7 @@ async fn main() -> Result<()> { let ud = user_data.clone(); let discovery_stream_task = tokio::spawn(async move { let mut discovery_stream = mdns.subscribe().await; - let mut discovered_endpoints: Vec = vec![]; + let mut discovered_endpoints: Vec = vec![]; while let Some(event) = discovery_stream.next().await { match event { DiscoveryEvent::Discovered { endpoint_info, .. } => { diff --git a/iroh/examples/transfer.rs b/iroh/examples/transfer.rs index f8137ecf923..b63b72a429f 100644 --- a/iroh/examples/transfer.rs +++ b/iroh/examples/transfer.rs @@ -9,10 +9,14 @@ use clap::{Parser, Subcommand}; use data_encoding::HEXLOWER; use indicatif::HumanBytes; use iroh::{ - Endpoint, EndpointAddr, EndpointId, PublicKey, RelayMap, RelayMode, RelayUrl, SecretKey, TransportAddr, discovery::{ + Endpoint, EndpointAddr, EndpointId, PublicKey, RelayMap, RelayMode, RelayUrl, SecretKey, + TransportAddr, + discovery::{ dns::DnsDiscovery, pkarr::{N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING, PkarrPublisher}, - }, dns::{DnsResolver, N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}, endpoint::ConnectionError + }, + dns::{DnsResolver, N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING}, + endpoint::ConnectionError, }; use n0_error::{Result, StackResultExt, StdResultExt}; use n0_future::task::AbortOnDropHandle; diff --git a/iroh/src/discovery.rs b/iroh/src/discovery.rs index c5db499abd9..76fa32b93df 100644 --- a/iroh/src/discovery.rs +++ b/iroh/src/discovery.rs @@ -1059,10 +1059,7 @@ mod test_dns_pkarr { .await?; println!("resolved {resolved:?}"); - let expected_addr = EndpointAddr::from_parts( - endpoint_id, - relay_url, - ); + let expected_addr = EndpointAddr::from_parts(endpoint_id, relay_url); assert_eq!(resolved.to_endpoint_addr(), expected_addr); assert_eq!(resolved.user_data(), Some(&user_data)); diff --git a/iroh/src/discovery/mdns.rs b/iroh/src/discovery/mdns.rs index e5ea36575ca..968811891a9 100644 --- a/iroh/src/discovery/mdns.rs +++ b/iroh/src/discovery/mdns.rs @@ -98,10 +98,10 @@ pub struct MdnsDiscovery { enum Message { Discovery(String, Peer), Resolve( - EndpointId, + PublicKey, mpsc::Sender>, ), - Timeout(EndpointId, usize), + Timeout(PublicKey, usize), Subscribe(mpsc::Sender), } @@ -190,7 +190,7 @@ impl MdnsDiscoveryBuilder { /// # Panics /// This relies on [`tokio::runtime::Handle::current`] and will panic if called outside of the context of a tokio runtime. pub fn build(self, endpoint_id: EndpointId) -> Result { - MdnsDiscovery::new(endpoint_id, self.advertise, self.service_name) + MdnsDiscovery::new(endpoint_id.expect_ed(), self.advertise, self.service_name) } } @@ -241,7 +241,7 @@ impl MdnsDiscovery { /// # Panics /// This relies on [`tokio::runtime::Handle::current`] and will panic if called outside of the context of a tokio runtime. fn new( - endpoint_id: EndpointId, + endpoint_id: PublicKey, advertise: bool, service_name: String, ) -> Result { @@ -332,7 +332,7 @@ impl MdnsDiscovery { ); endpoint_addrs.remove(&discovered_endpoint_id); subscribers.send(DiscoveryEvent::Expired { - endpoint_id: discovered_endpoint_id, + endpoint_id: discovered_endpoint_id.into(), }); continue; } @@ -352,7 +352,8 @@ impl MdnsDiscovery { ); let mut resolved = false; - let item = peer_to_discovery_item(&peer_info, &discovered_endpoint_id); + let item = + peer_to_discovery_item(&peer_info, &discovered_endpoint_id.into()); if let Some(senders) = senders.get(&discovered_endpoint_id) { trace!(?item, senders = senders.len(), "sending DiscoveryItem"); resolved = true; @@ -372,21 +373,21 @@ impl MdnsDiscovery { }); } } - Message::Resolve(endpoint_id, sender) => { + Message::Resolve(public_key, sender) => { let id = last_id + 1; last_id = id; - trace!(?endpoint_id, "MdnsDiscovery Message::SendAddrs"); - if let Some(peer_info) = endpoint_addrs.get(&endpoint_id) { - let item = peer_to_discovery_item(peer_info, &endpoint_id); + trace!(?public_key, "MdnsDiscovery Message::SendAddrs"); + if let Some(peer_info) = endpoint_addrs.get(&public_key) { + let item = peer_to_discovery_item(peer_info, &public_key); debug!(?item, "sending DiscoveryItem"); sender.send(Ok(item)).await.ok(); } - if let Some(senders_for_endpoint_id) = senders.get_mut(&endpoint_id) { + if let Some(senders_for_endpoint_id) = senders.get_mut(&public_key) { senders_for_endpoint_id.insert(id, sender); } else { let mut senders_for_endpoint_id = HashMap::new(); senders_for_endpoint_id.insert(id, sender); - senders.insert(endpoint_id, senders_for_endpoint_id); + senders.insert(public_key, senders_for_endpoint_id); } let timeout_sender = task_sender.clone(); timeouts.spawn(async move { @@ -398,12 +399,12 @@ impl MdnsDiscovery { .ok(); }); } - Message::Timeout(endpoint_id, id) => { - trace!(?endpoint_id, "MdnsDiscovery Message::Timeout"); - if let Some(senders_for_endpoint_id) = senders.get_mut(&endpoint_id) { + Message::Timeout(public_key, id) => { + trace!(?public_key, "MdnsDiscovery Message::Timeout"); + if let Some(senders_for_endpoint_id) = senders.get_mut(&public_key) { senders_for_endpoint_id.remove(&id); if senders_for_endpoint_id.is_empty() { - senders.remove(&endpoint_id); + senders.remove(&public_key); } } } @@ -488,7 +489,7 @@ impl MdnsDiscovery { } } -fn peer_to_discovery_item(peer: &Peer, endpoint_id: &EndpointId) -> DiscoveryItem { +fn peer_to_discovery_item(peer: &Peer, public_key: &PublicKey) -> DiscoveryItem { let ip_addrs: BTreeSet = peer .addrs() .iter() @@ -507,7 +508,7 @@ fn peer_to_discovery_item(peer: &Peer, endpoint_id: &EndpointId) -> DiscoveryIte } else { None }; - let endpoint_info = EndpointInfo::new(*endpoint_id) + let endpoint_info = EndpointInfo::new(*public_key) .with_ip_addrs(ip_addrs) .with_user_data(user_data); DiscoveryItem::new(endpoint_info, NAME, None) @@ -520,11 +521,13 @@ impl Discovery for MdnsDiscovery { ) -> Option>> { use futures_util::FutureExt; + let public_key = endpoint_id.as_ed()?; + let (send, recv) = mpsc::channel(20); let discovery_sender = self.sender.clone(); let stream = async move { discovery_sender - .send(Message::Resolve(endpoint_id, send)) + .send(Message::Resolve(public_key, send)) .await .ok(); tokio_stream::wrappers::ReceiverStream::new(recv) @@ -762,19 +765,19 @@ mod tests { // Create a discovery service using the default // service name - let id_a = SecretKey::generate(&mut rng).public(); + let id_a = SecretKey::generate(&mut rng).public().into(); let discovery_a = MdnsDiscovery::builder().build(id_a)?; // Create a discovery service using a custom // service name - let id_b = SecretKey::generate(&mut rng).public(); + let id_b = SecretKey::generate(&mut rng).public().into(); let discovery_b = MdnsDiscovery::builder() .service_name("different.name") .build(id_b)?; // Create a discovery service using the same // custom service name - let id_c = SecretKey::generate(&mut rng).public(); + let id_c = SecretKey::generate(&mut rng).public().into(); let discovery_c = MdnsDiscovery::builder() .service_name("different.name") .build(id_c)?; @@ -818,8 +821,8 @@ mod tests { fn make_discoverer( rng: &mut R, advertise: bool, - ) -> Result<(PublicKey, MdnsDiscovery)> { - let endpoint_id = SecretKey::generate(rng).public(); + ) -> Result<(EndpointId, MdnsDiscovery)> { + let endpoint_id = SecretKey::generate(rng).public().into(); Ok(( endpoint_id, MdnsDiscovery::builder() diff --git a/iroh/src/discovery/pkarr/dht.rs b/iroh/src/discovery/pkarr/dht.rs index 720e66e5bf5..d8be879a631 100644 --- a/iroh/src/discovery/pkarr/dht.rs +++ b/iroh/src/discovery/pkarr/dht.rs @@ -315,8 +315,9 @@ impl Discovery for DhtDiscovery { &self, endpoint_id: EndpointId, ) -> Option>> { + let public_key = endpoint_id.as_ed()?; let pkarr_public_key = - pkarr::PublicKey::try_from(endpoint_id.as_bytes()).expect("valid public key"); + pkarr::PublicKey::try_from(public_key.as_bytes()).expect("valid public key"); tracing::info!("resolving {} as {}", endpoint_id, pkarr_public_key.to_z32()); let discovery = self.0.clone(); let stream = n0_future::stream::once_future(async move { @@ -364,7 +365,7 @@ mod tests { tokio::time::sleep(Duration::from_millis(200)).await; let mut found_relay_urls = BTreeSet::new(); let items = discovery - .resolve(secret.public()) + .resolve(secret.public().into()) .unwrap() .collect::>() .await; diff --git a/iroh/src/discovery/static_provider.rs b/iroh/src/discovery/static_provider.rs index 164c9075ef7..b55f32c6bc7 100644 --- a/iroh/src/discovery/static_provider.rs +++ b/iroh/src/discovery/static_provider.rs @@ -55,7 +55,7 @@ use super::{Discovery, DiscoveryError, DiscoveryItem, EndpointData, EndpointInfo /// // You can pass either `EndpointInfo` or `EndpointAddr` to `add_endpoint_info`. /// discovery.add_endpoint_info(EndpointAddr::from_parts( /// id, -/// [TransportAddr::Relay("https://example.com".parse()?)] +/// [TransportAddr::Relay("https://example.com".parse()?)], /// )); /// /// # Ok(()) @@ -248,7 +248,7 @@ mod tests { let key = SecretKey::from_bytes(&[0u8; 32]); let addr = EndpointAddr::from_parts( key.public(), - [TransportAddr::Relay("https://example.com".parse()?)] + [TransportAddr::Relay("https://example.com".parse()?)], ); let user_data = Some("foobar".parse().unwrap()); let endpoint_info = EndpointInfo::from(addr.clone()).with_user_data(user_data.clone()); @@ -278,7 +278,7 @@ mod tests { let key = SecretKey::from_bytes(&[0u8; 32]); let addr = EndpointAddr::from_parts( key.public(), - [TransportAddr::Relay("https://example.com".parse()?)] + [TransportAddr::Relay("https://example.com".parse()?)], ); discovery.add_endpoint_info(addr); let mut stream = discovery.resolve(key.public().into()).unwrap(); diff --git a/iroh/src/endpoint.rs b/iroh/src/endpoint.rs index d6fcf91dfc5..5aa506d6421 100644 --- a/iroh/src/endpoint.rs +++ b/iroh/src/endpoint.rs @@ -1251,7 +1251,7 @@ impl Endpoint { ) -> Result<(EndpointIdMappedAddr, Option), GetMappingAddressError> { let endpoint_id = endpoint_addr.id; let Some(public_key) = endpoint_id.as_ed() else { - return Err(e!(GetMappingAddressError::NoAddress)) + return Err(e!(GetMappingAddressError::NoAddress)); }; // Only return a mapped addr if we have some way of dialing this endpoint, in other @@ -1912,34 +1912,34 @@ mod tests { } } - let p1_accept = tokio::spawn(accept_world(ep1.clone(), ep2_endpointid.expect_ed()).instrument( - info_span!( + let p1_accept = tokio::spawn( + accept_world(ep1.clone(), ep2_endpointid.expect_ed()).instrument(info_span!( "p1_accept", ep1 = %ep1.id().fmt_short(), dst = %ep2_endpointid.fmt_short(), - ), - )); - let p2_accept = tokio::spawn(accept_world(ep2.clone(), ep1_endpointid.expect_ed()).instrument( - info_span!( + )), + ); + let p2_accept = tokio::spawn( + accept_world(ep2.clone(), ep1_endpointid.expect_ed()).instrument(info_span!( "p2_accept", ep2 = %ep2.id().fmt_short(), dst = %ep1_endpointid.fmt_short(), - ), - )); - let p1_connect = tokio::spawn(connect_hello(ep1.clone(), ep2_endpointid.expect_ed()).instrument( - info_span!( + )), + ); + let p1_connect = tokio::spawn( + connect_hello(ep1.clone(), ep2_endpointid.expect_ed()).instrument(info_span!( "p1_connect", ep1 = %ep1.id().fmt_short(), dst = %ep2_endpointid.fmt_short(), - ), - )); - let p2_connect = tokio::spawn(connect_hello(ep2.clone(), ep1_endpointid.expect_ed()).instrument( - info_span!( + )), + ); + let p2_connect = tokio::spawn( + connect_hello(ep2.clone(), ep1_endpointid.expect_ed()).instrument(info_span!( "p2_connect", ep2 = %ep2.id().fmt_short(), dst = %ep1_endpointid.fmt_short(), - ), - )); + )), + ); p1_accept.await.anyerr()??; p2_accept.await.anyerr()??; diff --git a/iroh/src/endpoint/connection.rs b/iroh/src/endpoint/connection.rs index 4da2d08c2d8..4de3003d2db 100644 --- a/iroh/src/endpoint/connection.rs +++ b/iroh/src/endpoint/connection.rs @@ -244,9 +244,7 @@ fn conn_from_quinn_conn(conn: quinn::Connection) -> Result Result { +fn remote_id_from_quinn_conn(conn: &quinn::Connection) -> Result { let data = conn.peer_identity(); match data { None => { diff --git a/iroh/src/lib.rs b/iroh/src/lib.rs index a00bc33c6c2..3ce76d911b7 100644 --- a/iroh/src/lib.rs +++ b/iroh/src/lib.rs @@ -274,7 +274,7 @@ pub mod protocol; pub use endpoint::{Endpoint, RelayMode}; pub use iroh_base::{ - EndpointAddr, PublicKey, EndpointId, KeyParsingError, RelayUrl, RelayUrlParseError, SecretKey, + EndpointAddr, EndpointId, KeyParsingError, PublicKey, RelayUrl, RelayUrlParseError, SecretKey, Signature, SignatureError, TransportAddr, }; pub use iroh_relay::{RelayConfig, RelayMap, endpoint_info}; diff --git a/iroh/src/magicsock.rs b/iroh/src/magicsock.rs index ffe71679ba6..61c9ff25e18 100644 --- a/iroh/src/magicsock.rs +++ b/iroh/src/magicsock.rs @@ -3217,10 +3217,7 @@ mod tests { .get() .into_iter() .map(|x| TransportAddr::Ip(x.addr)); - let endpoint_addr_2 = EndpointAddr::from_parts( - endpoint_id_2, - addrs, - ); + let endpoint_addr_2 = EndpointAddr::from_parts(endpoint_id_2, addrs); msock_1 .add_endpoint_addr( endpoint_addr_2, @@ -3291,10 +3288,7 @@ mod tests { // Add an empty entry in the EndpointMap of ep_1 msock_1.endpoint_map.add_endpoint_addr( - EndpointAddr::from_parts( - endpoint_id_2, - [], - ), + EndpointAddr::from_parts(endpoint_id_2, []), Source::NamedApp { name: "test".into(), }, @@ -3333,10 +3327,7 @@ mod tests { .into_iter() .map(|x| TransportAddr::Ip(x.addr)); msock_1.endpoint_map.add_endpoint_addr( - EndpointAddr::from_parts( - endpoint_id_2, - addrs, - ), + EndpointAddr::from_parts(endpoint_id_2, addrs), Source::NamedApp { name: "test".into(), }, @@ -3393,7 +3384,7 @@ mod tests { // relay url only let addr = EndpointAddr::from_parts( SecretKey::generate(&mut rng).public(), - [TransportAddr::Relay("http://my-relay.com".parse().unwrap())] + [TransportAddr::Relay("http://my-relay.com".parse().unwrap())], ); stack .endpoint @@ -3404,7 +3395,7 @@ mod tests { // addrs only let addr = EndpointAddr::from_parts( SecretKey::generate(&mut rng).public(), - [TransportAddr::Ip("127.0.0.1:1234".parse().unwrap())] + [TransportAddr::Ip("127.0.0.1:1234".parse().unwrap())], ); stack .endpoint @@ -3418,7 +3409,7 @@ mod tests { [ TransportAddr::Relay("http://my-relay.com".parse().unwrap()), TransportAddr::Ip("127.0.0.1:1234".parse().unwrap()), - ] + ], ); stack .endpoint diff --git a/iroh/src/test_utils.rs b/iroh/src/test_utils.rs index 64ec72251a7..e942da8b7a3 100644 --- a/iroh/src/test_utils.rs +++ b/iroh/src/test_utils.rs @@ -347,7 +347,7 @@ pub(crate) mod pkarr_dns_state { }; use iroh_base::PublicKey; - use iroh_relay::endpoint_info::{PublicKeyExt, EndpointInfo, IROH_TXT_NAME}; + use iroh_relay::endpoint_info::{EndpointInfo, IROH_TXT_NAME, PublicKeyExt}; use pkarr::SignedPacket; use tracing::debug; @@ -495,7 +495,12 @@ pub(crate) mod pkarr_dns_state { ttl: u32, ) -> impl Iterator + 'static { let txt_strings = endpoint_info.to_txt_strings(); - let records = to_hickory_records(txt_strings, endpoint_info.endpoint_id.expect_ed(), origin, ttl); + let records = to_hickory_records( + txt_strings, + endpoint_info.endpoint_id.expect_ed(), + origin, + ttl, + ); records.collect::>().into_iter() } From 3a9ddc13da4c042f506d26ee59a069443d70064d Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 13 Nov 2025 10:25:35 -0600 Subject: [PATCH 08/10] clippy --- iroh-base/src/key.rs | 1 - iroh/src/discovery/mdns.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/iroh-base/src/key.rs b/iroh-base/src/key.rs index 40126de4d4a..b5d6950ae32 100644 --- a/iroh-base/src/key.rs +++ b/iroh-base/src/key.rs @@ -112,7 +112,6 @@ impl Ord for PublicKey { /// /// - `encrypt(key: PublicKey)` /// - `send_to(endpoint: EndpointId)` - impl Hash for PublicKey { fn hash(&self, state: &mut H) { self.0.hash(state); diff --git a/iroh/src/discovery/mdns.rs b/iroh/src/discovery/mdns.rs index 968811891a9..13254dca6d1 100644 --- a/iroh/src/discovery/mdns.rs +++ b/iroh/src/discovery/mdns.rs @@ -353,7 +353,7 @@ impl MdnsDiscovery { let mut resolved = false; let item = - peer_to_discovery_item(&peer_info, &discovered_endpoint_id.into()); + peer_to_discovery_item(&peer_info, &discovered_endpoint_id); if let Some(senders) = senders.get(&discovered_endpoint_id) { trace!(?item, senders = senders.len(), "sending DiscoveryItem"); resolved = true; From e4549e53fdbbf0ef9b3d2f8e0166c4fd8a03b852 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 13 Nov 2025 10:28:51 -0600 Subject: [PATCH 09/10] docs fixes --- iroh-relay/src/server/client.rs | 2 +- iroh-relay/src/server/clients.rs | 4 ++-- iroh/src/magicsock/endpoint_map.rs | 2 +- iroh/src/magicsock/transports/relay/actor.rs | 2 +- iroh/src/test_utils.rs | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iroh-relay/src/server/client.rs b/iroh-relay/src/server/client.rs index 1272d464bf4..9feb40399d5 100644 --- a/iroh-relay/src/server/client.rs +++ b/iroh-relay/src/server/client.rs @@ -259,7 +259,7 @@ struct Actor { disco_send_queue: mpsc::Receiver, /// Notify the client that a previous sender has disconnected endpoint_gone: mpsc::Receiver, - /// [`EndpointId`] of this client + /// [`PublicKey`] of this client endpoint_id: PublicKey, /// Connection identifier. connection_id: u64, diff --git a/iroh-relay/src/server/clients.rs b/iroh-relay/src/server/clients.rs index aa8393bc43b..e843d82d57e 100644 --- a/iroh-relay/src/server/clients.rs +++ b/iroh-relay/src/server/clients.rs @@ -105,7 +105,7 @@ impl Clients { } } - /// Attempt to send a packet to client with [`EndpointId`] `dst`. + /// Attempt to send a packet to client with [`PublicKey`] `dst`. pub(super) fn send_packet( &self, dst: PublicKey, @@ -145,7 +145,7 @@ impl Clients { } } - /// Attempt to send a disco packet to client with [`EndpointId`] `dst`. + /// Attempt to send a disco packet to client with [`PublicKey`] `dst`. pub(super) fn send_disco_packet( &self, dst: PublicKey, diff --git a/iroh/src/magicsock/endpoint_map.rs b/iroh/src/magicsock/endpoint_map.rs index caa71fd27f1..30dae7879e1 100644 --- a/iroh/src/magicsock/endpoint_map.rs +++ b/iroh/src/magicsock/endpoint_map.rs @@ -326,7 +326,7 @@ impl EndpointMap { self.inner.lock().expect("poisoned").latency(endpoint_id) } - /// Get the [`RemoteInfo`]s for the endpoint identified by [`EndpointId`]. + /// Get the [`RemoteInfo`]s for the endpoint identified by [`PublicKey`]. pub(super) fn remote_info(&self, endpoint_id: PublicKey) -> Option { self.inner .lock() diff --git a/iroh/src/magicsock/transports/relay/actor.rs b/iroh/src/magicsock/transports/relay/actor.rs index f07333dc64c..88e94244930 100644 --- a/iroh/src/magicsock/transports/relay/actor.rs +++ b/iroh/src/magicsock/transports/relay/actor.rs @@ -782,7 +782,7 @@ struct ConnectedRelayState { ping_tracker: PingTracker, /// Endpoints which are reachable via this relay server. endpoints_present: BTreeSet, - /// The [`EndpointId`] from whom we received the last packet. + /// The [`PublicKey`] from whom we received the last packet. /// /// This is to avoid a slower lookup in the [`ConnectedRelayState::endpoints_present`] map /// when we are only communicating to a single remote endpoint. diff --git a/iroh/src/test_utils.rs b/iroh/src/test_utils.rs index e942da8b7a3..b0a95c5d5d3 100644 --- a/iroh/src/test_utils.rs +++ b/iroh/src/test_utils.rs @@ -470,13 +470,13 @@ pub(crate) mod pkarr_dns_state { } } - /// Parses a [`EndpointId`] from a DNS domain name. + /// Parses a [`PublicKey`] from a DNS domain name. /// /// Splits the domain name into labels on each dot. Expects the first label to be - /// [`IROH_TXT_NAME`] and the second label to be a z32 encoded [`EndpointId`]. Ignores + /// [`IROH_TXT_NAME`] and the second label to be a z32 encoded [`PublicKey`]. Ignores /// subsequent labels. /// - /// Returns a [`EndpointId`] if parsed successfully, otherwise `None`. + /// Returns a [`PublicKey`] if parsed successfully, otherwise `None`. fn endpoint_id_from_domain_name(name: &str) -> Option { let mut labels = name.split("."); let label = labels.next()?; From 921caa229cc45a545ddcb775a4e518c1f3494eb2 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 13 Nov 2025 10:34:46 -0600 Subject: [PATCH 10/10] fmt --- iroh/src/discovery/mdns.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iroh/src/discovery/mdns.rs b/iroh/src/discovery/mdns.rs index 13254dca6d1..3da898fc9c2 100644 --- a/iroh/src/discovery/mdns.rs +++ b/iroh/src/discovery/mdns.rs @@ -352,8 +352,7 @@ impl MdnsDiscovery { ); let mut resolved = false; - let item = - peer_to_discovery_item(&peer_info, &discovered_endpoint_id); + let item = peer_to_discovery_item(&peer_info, &discovered_endpoint_id); if let Some(senders) = senders.get(&discovered_endpoint_id) { trace!(?item, senders = senders.len(), "sending DiscoveryItem"); resolved = true;