@@ -54,6 +54,31 @@ arg_enum! {
54
54
}
55
55
}
56
56
57
+ /// Bootstrap node with generic string address which might be either IP address
58
+ /// or DNS name.
59
+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
60
+ pub struct BootstrapNode {
61
+ /// `PublicKey` of the node.
62
+ pk : PublicKey ,
63
+ /// Generic string address which might be either IP address or DNS name.
64
+ addr : String ,
65
+ }
66
+
67
+ impl BootstrapNode {
68
+ /// Resolve string address of the node to possible multiple `SocketAddr`s.
69
+ pub fn resolve ( & self ) -> impl Iterator < Item = PackedNode > {
70
+ let pk = self . pk ;
71
+ let addrs = match self . addr . to_socket_addrs ( ) {
72
+ Ok ( addrs) => addrs,
73
+ Err ( e) => {
74
+ warn ! ( "Failed to resolve bootstrap node address '{}': {}" , self . addr, e) ;
75
+ Vec :: new ( ) . into_iter ( )
76
+ } ,
77
+ } ;
78
+ addrs. map ( move |addr| PackedNode :: new ( addr, & pk) )
79
+ }
80
+ }
81
+
57
82
/// Config parsed from command line arguments.
58
83
#[ derive( Clone , PartialEq , Eq , Debug ) ]
59
84
pub struct CliConfig {
@@ -70,7 +95,7 @@ pub struct CliConfig {
70
95
/// Path to the file where DHT keys are stored.
71
96
pub keys_file : Option < String > ,
72
97
/// List of bootstrap nodes.
73
- pub bootstrap_nodes : Vec < PackedNode > ,
98
+ pub bootstrap_nodes : Vec < BootstrapNode > ,
74
99
/// Number of threads for execution.
75
100
pub threads_config : ThreadsConfig ,
76
101
/// Specifies where to write logs.
@@ -192,18 +217,16 @@ pub fn cli_parse() -> CliConfig {
192
217
. into_iter ( )
193
218
. flat_map ( |values| values)
194
219
. tuples ( )
195
- . map ( |( pk, saddr ) | {
220
+ . map ( |( pk, addr ) | {
196
221
// get PK bytes of the bootstrap node
197
222
let bootstrap_pk_bytes: [ u8 ; 32 ] = FromHex :: from_hex ( pk) . expect ( "Invalid node key" ) ;
198
223
// create PK from bytes
199
224
let bootstrap_pk = PublicKey :: from_slice ( & bootstrap_pk_bytes) . expect ( "Invalid node key" ) ;
200
225
201
- let saddr = saddr
202
- . to_socket_addrs ( )
203
- . expect ( "Invalid node address" )
204
- . next ( )
205
- . expect ( "Invalid node address" ) ;
206
- PackedNode :: new ( saddr, & bootstrap_pk)
226
+ BootstrapNode {
227
+ pk : bootstrap_pk,
228
+ addr : addr. to_owned ( ) ,
229
+ }
207
230
} )
208
231
. collect ( ) ;
209
232
0 commit comments