diff --git a/iroh-dns/examples/publish.rs b/iroh-dns/examples/publish.rs index 01d6892f16b..5602fb3e3f4 100644 --- a/iroh-dns/examples/publish.rs +++ b/iroh-dns/examples/publish.rs @@ -66,7 +66,7 @@ async fn main() -> Result<()> { let publisher = Publisher::new(config); let info = AddrInfo { - derp_url: Some(args.derp_url), + derp_url: Some(args.derp_url.into()), direct_addresses: Default::default(), }; // let an = NodeAnnounce::new(node_id, Some(args.home_derp), vec![]); diff --git a/iroh-dns/src/packet.rs b/iroh-dns/src/packet.rs index 60d03edf653..af95db509c7 100644 --- a/iroh-dns/src/packet.rs +++ b/iroh-dns/src/packet.rs @@ -6,13 +6,13 @@ use hickory_proto::error::ProtoError; use iroh_net::{AddrInfo, NodeAddr, NodeId}; use url::Url; -pub const IROH_ROOT_ZONE: &'static str = "iroh"; -pub const IROH_NODE_TXT_LABEL: &'static str = "_iroh_node"; +pub const IROH_ROOT_ZONE: &str = "iroh"; +pub const IROH_NODE_TXT_LABEL: &str = "_iroh_node"; pub const DEFAULT_TTL: u32 = 30; -pub const ATTR_DERP: &'static str = "derp"; -pub const ATTR_NODE_ID: &'static str = "node"; -pub const ATTR_DNS: &'static str = "dns"; +pub const ATTR_DERP: &str = "derp"; +pub const ATTR_NODE_ID: &str = "node"; +pub const ATTR_DNS: &str = "dns"; #[derive(derive_more::Debug, Clone, Eq, PartialEq)] pub struct NodeAnnounce { @@ -51,12 +51,12 @@ impl NodeAnnounce { pub fn to_attr_string(&self) -> String { let mut attrs = vec![]; - attrs.push(fmt_attr(ATTR_NODE_ID, &self.node_id)); + attrs.push(fmt_attr(ATTR_NODE_ID, self.node_id)); if let Some(derp) = &self.home_derp { - attrs.push(fmt_attr(ATTR_DERP, &derp)); + attrs.push(fmt_attr(ATTR_DERP, derp)); } for dns in &self.home_dns { - attrs.push(fmt_attr(ATTR_DNS, &dns)); + attrs.push(fmt_attr(ATTR_DNS, dns)); } attrs.join(" ") } @@ -100,7 +100,7 @@ impl NodeAnnounce { ) -> Result { use hickory_proto::rr; let zone = rr::Name::from_str(&self.node_id.to_string())?; - let zone = zone.append_domain(&origin)?; + let zone = zone.append_domain(origin)?; let name = rr::Name::parse(IROH_NODE_TXT_LABEL, Some(&zone))?; let txt_value = self.to_attr_string(); let txt_data = rr::rdata::TXT::new(vec![txt_value]); @@ -114,7 +114,7 @@ impl NodeAnnounce { let mut packet = dns::Packet::new_reply(0); // let name = format!("{}.{}", IROH_NODE_TXT_NAME, self.zone()); let name = IROH_NODE_TXT_LABEL; - let name = dns::Name::new(&name)?.into_owned(); + let name = dns::Name::new(name)?.into_owned(); let txt_value = self.to_attr_string(); let txt_data = rdata::TXT::new().with_string(&txt_value)?.into_owned(); let rdata = rdata::RData::TXT(txt_data); @@ -150,7 +150,7 @@ impl NodeAnnounce { .iter() .find_map(|rr| match &rr.rdata { RData::TXT(txt) => match rr.name.without(&zone) { - Some(name) if &name.to_string() == IROH_NODE_TXT_LABEL => Some(txt), + Some(name) if name.to_string() == IROH_NODE_TXT_LABEL => Some(txt), Some(_) | None => None, }, _ => None, @@ -180,11 +180,7 @@ impl NodeAnnounce { .iter() .find_map(|rr| match rr.data() { Some(rr::RData::TXT(txt)) => { - if let Some(node_id) = is_hickory_node_info_name(rr.name()) { - Some((node_id, txt)) - } else { - None - } + is_hickory_node_info_name(rr.name()).map(|node_id| (node_id, txt)) } _ => None, }) @@ -205,7 +201,7 @@ impl NodeAnnounce { if node.len() != 1 { bail!("more than one node attr is not allowed"); } - let node_id = NodeId::from_str(&node[0])?; + let node_id = NodeId::from_str(node[0])?; let home_derp: Option = attrs .get(ATTR_DERP) .into_iter() @@ -214,8 +210,7 @@ impl NodeAnnounce { let home_dns: Vec = attrs .get(ATTR_DNS) .into_iter() - .map(|x| x.into_iter()) - .flatten() + .flat_map(|x| x.iter()) .map(|s| s.to_string()) .collect(); Ok(Self { @@ -242,9 +237,9 @@ fn is_hickory_node_info_name(name: &hickory_proto::rr::Name) -> Option { fn parse_attrs<'a>(s: &'a str) -> HashMap<&'a str, Vec<&'a str>> { let mut map: HashMap<&'a str, Vec<&'a str>> = HashMap::new(); - let parts = s.split(" "); + let parts = s.split(' '); for part in parts { - if let Some((name, value)) = part.split_once("=") { + if let Some((name, value)) = part.split_once('=') { map.entry(name).or_default().push(value); } } diff --git a/iroh-dns/src/publish.rs b/iroh-dns/src/publish.rs index 91aa71c7a08..3e19b7cb1e3 100644 --- a/iroh-dns/src/publish.rs +++ b/iroh-dns/src/publish.rs @@ -7,8 +7,8 @@ use url::Url; use crate::packet::NodeAnnounce; -pub const IROH_TEST_PKARR_RELAY: &'static str = "https://testdns.iroh.link/pkarr"; -pub const LOCALHOST_PKARR_RELAY: &'static str = "http://localhost:8080/pkarr"; +pub const IROH_TEST_PKARR_RELAY: &str = "https://testdns.iroh.link/pkarr"; +pub const LOCALHOST_PKARR_RELAY: &str = "http://localhost:8080/pkarr"; /// Publisher config pub struct Config { diff --git a/iroh-dns/src/resolve.rs b/iroh-dns/src/resolve.rs index 973dadd805c..739005aaee6 100644 --- a/iroh-dns/src/resolve.rs +++ b/iroh-dns/src/resolve.rs @@ -13,8 +13,8 @@ use tracing::debug; use crate::packet::{NodeAnnounce, IROH_NODE_TXT_LABEL}; pub const IROH_TEST_DNS_IPV4: Ipv4Addr = Ipv4Addr::new(5, 75, 181, 3); -pub const IROH_TEST_DOMAIN: &'static str = "testdns.iroh.link."; -pub const EXAMPLE_DOMAIN: &'static str = "irohdns.example."; +pub const IROH_TEST_DOMAIN: &str = "testdns.iroh.link."; +pub const EXAMPLE_DOMAIN: &str = "irohdns.example."; pub type HickoryResolver = AsyncResolver>; @@ -87,7 +87,7 @@ impl Resolver { } pub async fn resolve_node_by_domain(&self, domain: &str) -> Result { - let name = Name::from_str(&domain)?; + let name = Name::from_str(domain)?; self.resolve_node(name).await }