@@ -6,13 +6,13 @@ use hickory_proto::error::ProtoError;
6
6
use iroh_net:: { AddrInfo , NodeAddr , NodeId } ;
7
7
use url:: Url ;
8
8
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" ;
11
11
pub const DEFAULT_TTL : u32 = 30 ;
12
12
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" ;
16
16
17
17
#[ derive( derive_more:: Debug , Clone , Eq , PartialEq ) ]
18
18
pub struct NodeAnnounce {
@@ -51,12 +51,12 @@ impl NodeAnnounce {
51
51
52
52
pub fn to_attr_string ( & self ) -> String {
53
53
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 ) ) ;
55
55
if let Some ( derp) = & self . home_derp {
56
- attrs. push ( fmt_attr ( ATTR_DERP , & derp) ) ;
56
+ attrs. push ( fmt_attr ( ATTR_DERP , derp) ) ;
57
57
}
58
58
for dns in & self . home_dns {
59
- attrs. push ( fmt_attr ( ATTR_DNS , & dns) ) ;
59
+ attrs. push ( fmt_attr ( ATTR_DNS , dns) ) ;
60
60
}
61
61
attrs. join ( " " )
62
62
}
@@ -100,7 +100,7 @@ impl NodeAnnounce {
100
100
) -> Result < hickory_proto:: rr:: Record > {
101
101
use hickory_proto:: rr;
102
102
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) ?;
104
104
let name = rr:: Name :: parse ( IROH_NODE_TXT_LABEL , Some ( & zone) ) ?;
105
105
let txt_value = self . to_attr_string ( ) ;
106
106
let txt_data = rr:: rdata:: TXT :: new ( vec ! [ txt_value] ) ;
@@ -114,7 +114,7 @@ impl NodeAnnounce {
114
114
let mut packet = dns:: Packet :: new_reply ( 0 ) ;
115
115
// let name = format!("{}.{}", IROH_NODE_TXT_NAME, self.zone());
116
116
let name = IROH_NODE_TXT_LABEL ;
117
- let name = dns:: Name :: new ( & name) ?. into_owned ( ) ;
117
+ let name = dns:: Name :: new ( name) ?. into_owned ( ) ;
118
118
let txt_value = self . to_attr_string ( ) ;
119
119
let txt_data = rdata:: TXT :: new ( ) . with_string ( & txt_value) ?. into_owned ( ) ;
120
120
let rdata = rdata:: RData :: TXT ( txt_data) ;
@@ -150,7 +150,7 @@ impl NodeAnnounce {
150
150
. iter ( )
151
151
. find_map ( |rr| match & rr. rdata {
152
152
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) ,
154
154
Some ( _) | None => None ,
155
155
} ,
156
156
_ => None ,
@@ -180,11 +180,7 @@ impl NodeAnnounce {
180
180
. iter ( )
181
181
. find_map ( |rr| match rr. data ( ) {
182
182
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) )
188
184
}
189
185
_ => None ,
190
186
} )
@@ -205,7 +201,7 @@ impl NodeAnnounce {
205
201
if node. len ( ) != 1 {
206
202
bail ! ( "more than one node attr is not allowed" ) ;
207
203
}
208
- let node_id = NodeId :: from_str ( & node[ 0 ] ) ?;
204
+ let node_id = NodeId :: from_str ( node[ 0 ] ) ?;
209
205
let home_derp: Option < Url > = attrs
210
206
. get ( ATTR_DERP )
211
207
. into_iter ( )
@@ -214,8 +210,7 @@ impl NodeAnnounce {
214
210
let home_dns: Vec < String > = attrs
215
211
. get ( ATTR_DNS )
216
212
. into_iter ( )
217
- . map ( |x| x. into_iter ( ) )
218
- . flatten ( )
213
+ . flat_map ( |x| x. iter ( ) )
219
214
. map ( |s| s. to_string ( ) )
220
215
. collect ( ) ;
221
216
Ok ( Self {
@@ -242,9 +237,9 @@ fn is_hickory_node_info_name(name: &hickory_proto::rr::Name) -> Option<NodeId> {
242
237
243
238
fn parse_attrs < ' a > ( s : & ' a str ) -> HashMap < & ' a str , Vec < & ' a str > > {
244
239
let mut map: HashMap < & ' a str , Vec < & ' a str > > = HashMap :: new ( ) ;
245
- let parts = s. split ( " " ) ;
240
+ let parts = s. split ( ' ' ) ;
246
241
for part in parts {
247
- if let Some ( ( name, value) ) = part. split_once ( "=" ) {
242
+ if let Some ( ( name, value) ) = part. split_once ( '=' ) {
248
243
map. entry ( name) . or_default ( ) . push ( value) ;
249
244
}
250
245
}
0 commit comments