Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some renaming, remove a panic!
  • Loading branch information
rklaehn committed Nov 13, 2025
commit a1042adec1e5d210a41fe0a74ca67323fdba5587
2 changes: 1 addition & 1 deletion iroh-dns-server/examples/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions iroh-relay/src/endpoint_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -92,7 +92,7 @@ pub trait EndpointIdExt {
fn from_z32(s: &str) -> Result<PublicKey, DecodingError>;
}

impl EndpointIdExt for PublicKey {
impl PublicKeyExt for PublicKey {
fn to_z32(&self) -> String {
z32::encode(self.as_bytes())
}
Expand Down Expand Up @@ -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<PublicKey, ParseError> {
fn public_key_from_txt_name(name: &str) -> Result<PublicKey, ParseError> {
let num_labels = name.split(".").count();
if num_labels < 2 {
return Err(e!(ParseError::NumLabels { num_labels }));
Expand Down Expand Up @@ -502,7 +502,7 @@ pub(crate) enum IrohAttr {
/// [`Display`].
#[derive(Debug)]
pub(crate) struct TxtAttrs<T> {
endpoint_id: PublicKey,
public_key: PublicKey,
attrs: BTreeMap<T, Vec<String>>,
}

Expand All @@ -529,19 +529,19 @@ impl From<&EndpointInfo> for TxtAttrs<IrohAttr> {
impl<T: FromStr + Display + Hash + Ord> TxtAttrs<T> {
/// 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<Item = (T, String)>,
) -> Self {
let mut attrs: BTreeMap<T, Vec<String>> = 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<Item = String>,
) -> Result<Self, ParseError> {
let mut attrs: BTreeMap<T, Vec<String>> = BTreeMap::new();
Expand All @@ -557,7 +557,7 @@ impl<T: FromStr + Display + Hash + Ord> TxtAttrs<T> {
})?;
attrs.entry(attr).or_default().push(value.to_string());
}
Ok(Self { attrs, endpoint_id })
Ok(Self { attrs, public_key })
}

/// Returns the parsed attributes.
Expand All @@ -567,7 +567,7 @@ impl<T: FromStr + Display + Hash + Ord> TxtAttrs<T> {

/// Returns the endpoint id.
pub(crate) fn endpoint_id(&self) -> PublicKey {
self.endpoint_id
self.public_key
}

/// Parses a [`pkarr::SignedPacket`].
Expand Down Expand Up @@ -603,7 +603,7 @@ impl<T: FromStr + Display + Hash + Ord> TxtAttrs<T> {
name: String,
lookup: impl Iterator<Item = crate::dns::TxtRecordData>,
) -> Result<Self, ParseError> {
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)
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions iroh/src/discovery/pkarr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,10 @@ impl PkarrRelayClient {
}
}

/// Resolves a [`SignedPacket`] for the given [`EndpointId`].
pub async fn resolve(&self, endpoint_id: PublicKey) -> Result<SignedPacket, DiscoveryError> {
/// Resolves a [`SignedPacket`] for the given [`PublicKey`].
pub async fn resolve(&self, public_key: PublicKey) -> Result<SignedPacket, DiscoveryError> {
// 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();
Expand Down
4 changes: 3 additions & 1 deletion iroh/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ pub enum ConnectWithOptsError {
#[error(std_err)]
source: quinn_proto::ConnectError,
},
#[error("Unsupported endpoint type")]
UnsupportedEndpointType,
}

#[allow(missing_docs)]
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading