Skip to content

Commit a1042ad

Browse files
committed
Some renaming, remove a panic!
1 parent cadee48 commit a1042ad

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

iroh-dns-server/examples/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use iroh::{
88
dns::{N0_DNS_ENDPOINT_ORIGIN_PROD, N0_DNS_ENDPOINT_ORIGIN_STAGING},
99
pkarr::{N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING, PkarrRelayClient},
1010
},
11-
endpoint_info::{EndpointIdExt, EndpointInfo, IROH_TXT_NAME},
11+
endpoint_info::{PublicKeyExt, EndpointInfo, IROH_TXT_NAME},
1212
};
1313
use n0_error::{Result, StackResultExt};
1414
use url::Url;

iroh-relay/src/endpoint_info.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ pub enum DecodingError {
7878
InvalidKey { source: KeyParsingError },
7979
}
8080

81-
/// Extension methods for [`EndpointId`] to encode to and decode from [`z32`],
81+
/// Extension methods for [`PublicKey`] to encode to and decode from [`z32`],
8282
/// which is the encoding used in [`pkarr`] domain names.
83-
pub trait EndpointIdExt {
83+
pub trait PublicKeyExt {
8484
/// Encodes a [`EndpointId`] in [`z-base-32`] encoding.
8585
///
8686
/// [`z-base-32`]: https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt
@@ -92,7 +92,7 @@ pub trait EndpointIdExt {
9292
fn from_z32(s: &str) -> Result<PublicKey, DecodingError>;
9393
}
9494

95-
impl EndpointIdExt for PublicKey {
95+
impl PublicKeyExt for PublicKey {
9696
fn to_z32(&self) -> String {
9797
z32::encode(self.as_bytes())
9898
}
@@ -462,7 +462,7 @@ impl std::ops::DerefMut for EndpointInfo {
462462
/// [`IROH_TXT_NAME`] and the second label to be a z32 encoded [`EndpointId`]. Ignores
463463
/// subsequent labels.
464464
#[cfg(not(wasm_browser))]
465-
fn endpoint_id_from_txt_name(name: &str) -> Result<PublicKey, ParseError> {
465+
fn public_key_from_txt_name(name: &str) -> Result<PublicKey, ParseError> {
466466
let num_labels = name.split(".").count();
467467
if num_labels < 2 {
468468
return Err(e!(ParseError::NumLabels { num_labels }));
@@ -502,7 +502,7 @@ pub(crate) enum IrohAttr {
502502
/// [`Display`].
503503
#[derive(Debug)]
504504
pub(crate) struct TxtAttrs<T> {
505-
endpoint_id: PublicKey,
505+
public_key: PublicKey,
506506
attrs: BTreeMap<T, Vec<String>>,
507507
}
508508

@@ -529,19 +529,19 @@ impl From<&EndpointInfo> for TxtAttrs<IrohAttr> {
529529
impl<T: FromStr + Display + Hash + Ord> TxtAttrs<T> {
530530
/// Creates [`TxtAttrs`] from an endpoint id and an iterator of key-value pairs.
531531
pub(crate) fn from_parts(
532-
endpoint_id: PublicKey,
532+
public_key: PublicKey,
533533
pairs: impl Iterator<Item = (T, String)>,
534534
) -> Self {
535535
let mut attrs: BTreeMap<T, Vec<String>> = BTreeMap::new();
536536
for (k, v) in pairs {
537537
attrs.entry(k).or_default().push(v);
538538
}
539-
Self { attrs, endpoint_id }
539+
Self { attrs, public_key }
540540
}
541541

542542
/// Creates [`TxtAttrs`] from an endpoint id and an iterator of "{key}={value}" strings.
543543
pub(crate) fn from_strings(
544-
endpoint_id: PublicKey,
544+
public_key: PublicKey,
545545
strings: impl Iterator<Item = String>,
546546
) -> Result<Self, ParseError> {
547547
let mut attrs: BTreeMap<T, Vec<String>> = BTreeMap::new();
@@ -557,7 +557,7 @@ impl<T: FromStr + Display + Hash + Ord> TxtAttrs<T> {
557557
})?;
558558
attrs.entry(attr).or_default().push(value.to_string());
559559
}
560-
Ok(Self { attrs, endpoint_id })
560+
Ok(Self { attrs, public_key })
561561
}
562562

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

568568
/// Returns the endpoint id.
569569
pub(crate) fn endpoint_id(&self) -> PublicKey {
570-
self.endpoint_id
570+
self.public_key
571571
}
572572

573573
/// Parses a [`pkarr::SignedPacket`].
@@ -603,7 +603,7 @@ impl<T: FromStr + Display + Hash + Ord> TxtAttrs<T> {
603603
name: String,
604604
lookup: impl Iterator<Item = crate::dns::TxtRecordData>,
605605
) -> Result<Self, ParseError> {
606-
let queried_endpoint_id = endpoint_id_from_txt_name(&name)?;
606+
let queried_endpoint_id = public_key_from_txt_name(&name)?;
607607

608608
let strings = lookup.map(|record| record.to_string());
609609
Self::from_strings(queried_endpoint_id, strings)
@@ -674,7 +674,7 @@ mod tests {
674674
use iroh_base::{PublicKey, SecretKey, TransportAddr};
675675
use n0_error::{Result, StdResultExt};
676676

677-
use super::{EndpointData, EndpointIdExt, EndpointInfo};
677+
use super::{EndpointData, PublicKeyExt, EndpointInfo};
678678
use crate::dns::TxtRecordData;
679679

680680
#[test]

iroh/src/discovery/pkarr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,10 @@ impl PkarrRelayClient {
559559
}
560560
}
561561

562-
/// Resolves a [`SignedPacket`] for the given [`EndpointId`].
563-
pub async fn resolve(&self, endpoint_id: PublicKey) -> Result<SignedPacket, DiscoveryError> {
562+
/// Resolves a [`SignedPacket`] for the given [`PublicKey`].
563+
pub async fn resolve(&self, public_key: PublicKey) -> Result<SignedPacket, DiscoveryError> {
564564
// We map the error to string, as in browsers the error is !Send
565-
let public_key = pkarr::PublicKey::try_from(endpoint_id.as_bytes())
565+
let public_key = pkarr::PublicKey::try_from(public_key.as_bytes())
566566
.map_err(|err| e!(PkarrError::PublicKey, err))?;
567567

568568
let mut url = self.pkarr_relay_url.clone();

iroh/src/endpoint.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ pub enum ConnectWithOptsError {
494494
#[error(std_err)]
495495
source: quinn_proto::ConnectError,
496496
},
497+
#[error("Unsupported endpoint type")]
498+
UnsupportedEndpointType,
497499
}
498500

499501
#[allow(missing_docs)]
@@ -680,7 +682,7 @@ impl Endpoint {
680682
}
681683
let endpoint_id = endpoint_addr.id;
682684
let Some(public_key) = endpoint_id.as_ed() else {
683-
panic!();
685+
return Err(e!(ConnectWithOptsError::UnsupportedEndpointType));
684686
};
685687
let ip_addresses: Vec<_> = endpoint_addr.ip_addrs().cloned().collect();
686688
let relay_url = endpoint_addr.relay_urls().next().cloned();

iroh/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub(crate) mod pkarr_dns_state {
347347
};
348348

349349
use iroh_base::PublicKey;
350-
use iroh_relay::endpoint_info::{EndpointIdExt, EndpointInfo, IROH_TXT_NAME};
350+
use iroh_relay::endpoint_info::{PublicKeyExt, EndpointInfo, IROH_TXT_NAME};
351351
use pkarr::SignedPacket;
352352
use tracing::debug;
353353

0 commit comments

Comments
 (0)