Skip to content

Commit 510c616

Browse files
committed
chore: fmt and clippy
1 parent 576e52c commit 510c616

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

iroh-dns/examples/publish.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async fn main() -> Result<()> {
6666
let publisher = Publisher::new(config);
6767

6868
let info = AddrInfo {
69-
derp_url: Some(args.derp_url),
69+
derp_url: Some(args.derp_url.into()),
7070
direct_addresses: Default::default(),
7171
};
7272
// let an = NodeAnnounce::new(node_id, Some(args.home_derp), vec![]);

iroh-dns/src/packet.rs

+16-21
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use hickory_proto::error::ProtoError;
66
use iroh_net::{AddrInfo, NodeAddr, NodeId};
77
use url::Url;
88

9-
pub const IROH_ROOT_ZONE: &'static str = "iroh";
10-
pub const IROH_NODE_TXT_LABEL: &'static str = "_iroh_node";
9+
pub const IROH_ROOT_ZONE: &str = "iroh";
10+
pub const IROH_NODE_TXT_LABEL: &str = "_iroh_node";
1111
pub const DEFAULT_TTL: u32 = 30;
1212

13-
pub const ATTR_DERP: &'static str = "derp";
14-
pub const ATTR_NODE_ID: &'static str = "node";
15-
pub const ATTR_DNS: &'static str = "dns";
13+
pub const ATTR_DERP: &str = "derp";
14+
pub const ATTR_NODE_ID: &str = "node";
15+
pub const ATTR_DNS: &str = "dns";
1616

1717
#[derive(derive_more::Debug, Clone, Eq, PartialEq)]
1818
pub struct NodeAnnounce {
@@ -51,12 +51,12 @@ impl NodeAnnounce {
5151

5252
pub fn to_attr_string(&self) -> String {
5353
let mut attrs = vec![];
54-
attrs.push(fmt_attr(ATTR_NODE_ID, &self.node_id));
54+
attrs.push(fmt_attr(ATTR_NODE_ID, self.node_id));
5555
if let Some(derp) = &self.home_derp {
56-
attrs.push(fmt_attr(ATTR_DERP, &derp));
56+
attrs.push(fmt_attr(ATTR_DERP, derp));
5757
}
5858
for dns in &self.home_dns {
59-
attrs.push(fmt_attr(ATTR_DNS, &dns));
59+
attrs.push(fmt_attr(ATTR_DNS, dns));
6060
}
6161
attrs.join(" ")
6262
}
@@ -100,7 +100,7 @@ impl NodeAnnounce {
100100
) -> Result<hickory_proto::rr::Record> {
101101
use hickory_proto::rr;
102102
let zone = rr::Name::from_str(&self.node_id.to_string())?;
103-
let zone = zone.append_domain(&origin)?;
103+
let zone = zone.append_domain(origin)?;
104104
let name = rr::Name::parse(IROH_NODE_TXT_LABEL, Some(&zone))?;
105105
let txt_value = self.to_attr_string();
106106
let txt_data = rr::rdata::TXT::new(vec![txt_value]);
@@ -114,7 +114,7 @@ impl NodeAnnounce {
114114
let mut packet = dns::Packet::new_reply(0);
115115
// let name = format!("{}.{}", IROH_NODE_TXT_NAME, self.zone());
116116
let name = IROH_NODE_TXT_LABEL;
117-
let name = dns::Name::new(&name)?.into_owned();
117+
let name = dns::Name::new(name)?.into_owned();
118118
let txt_value = self.to_attr_string();
119119
let txt_data = rdata::TXT::new().with_string(&txt_value)?.into_owned();
120120
let rdata = rdata::RData::TXT(txt_data);
@@ -150,7 +150,7 @@ impl NodeAnnounce {
150150
.iter()
151151
.find_map(|rr| match &rr.rdata {
152152
RData::TXT(txt) => match rr.name.without(&zone) {
153-
Some(name) if &name.to_string() == IROH_NODE_TXT_LABEL => Some(txt),
153+
Some(name) if name.to_string() == IROH_NODE_TXT_LABEL => Some(txt),
154154
Some(_) | None => None,
155155
},
156156
_ => None,
@@ -180,11 +180,7 @@ impl NodeAnnounce {
180180
.iter()
181181
.find_map(|rr| match rr.data() {
182182
Some(rr::RData::TXT(txt)) => {
183-
if let Some(node_id) = is_hickory_node_info_name(rr.name()) {
184-
Some((node_id, txt))
185-
} else {
186-
None
187-
}
183+
is_hickory_node_info_name(rr.name()).map(|node_id| (node_id, txt))
188184
}
189185
_ => None,
190186
})
@@ -205,7 +201,7 @@ impl NodeAnnounce {
205201
if node.len() != 1 {
206202
bail!("more than one node attr is not allowed");
207203
}
208-
let node_id = NodeId::from_str(&node[0])?;
204+
let node_id = NodeId::from_str(node[0])?;
209205
let home_derp: Option<Url> = attrs
210206
.get(ATTR_DERP)
211207
.into_iter()
@@ -214,8 +210,7 @@ impl NodeAnnounce {
214210
let home_dns: Vec<String> = attrs
215211
.get(ATTR_DNS)
216212
.into_iter()
217-
.map(|x| x.into_iter())
218-
.flatten()
213+
.flat_map(|x| x.iter())
219214
.map(|s| s.to_string())
220215
.collect();
221216
Ok(Self {
@@ -242,9 +237,9 @@ fn is_hickory_node_info_name(name: &hickory_proto::rr::Name) -> Option<NodeId> {
242237

243238
fn parse_attrs<'a>(s: &'a str) -> HashMap<&'a str, Vec<&'a str>> {
244239
let mut map: HashMap<&'a str, Vec<&'a str>> = HashMap::new();
245-
let parts = s.split(" ");
240+
let parts = s.split(' ');
246241
for part in parts {
247-
if let Some((name, value)) = part.split_once("=") {
242+
if let Some((name, value)) = part.split_once('=') {
248243
map.entry(name).or_default().push(value);
249244
}
250245
}

iroh-dns/src/publish.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use url::Url;
77

88
use crate::packet::NodeAnnounce;
99

10-
pub const IROH_TEST_PKARR_RELAY: &'static str = "https://testdns.iroh.link/pkarr";
11-
pub const LOCALHOST_PKARR_RELAY: &'static str = "http://localhost:8080/pkarr";
10+
pub const IROH_TEST_PKARR_RELAY: &str = "https://testdns.iroh.link/pkarr";
11+
pub const LOCALHOST_PKARR_RELAY: &str = "http://localhost:8080/pkarr";
1212

1313
/// Publisher config
1414
pub struct Config {

iroh-dns/src/resolve.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use tracing::debug;
1313
use crate::packet::{NodeAnnounce, IROH_NODE_TXT_LABEL};
1414

1515
pub const IROH_TEST_DNS_IPV4: Ipv4Addr = Ipv4Addr::new(5, 75, 181, 3);
16-
pub const IROH_TEST_DOMAIN: &'static str = "testdns.iroh.link.";
17-
pub const EXAMPLE_DOMAIN: &'static str = "irohdns.example.";
16+
pub const IROH_TEST_DOMAIN: &str = "testdns.iroh.link.";
17+
pub const EXAMPLE_DOMAIN: &str = "irohdns.example.";
1818

1919
pub type HickoryResolver = AsyncResolver<GenericConnector<TokioRuntimeProvider>>;
2020

@@ -87,7 +87,7 @@ impl Resolver {
8787
}
8888

8989
pub async fn resolve_node_by_domain(&self, domain: &str) -> Result<NodeAddr> {
90-
let name = Name::from_str(&domain)?;
90+
let name = Name::from_str(domain)?;
9191
self.resolve_node(name).await
9292
}
9393

0 commit comments

Comments
 (0)