@@ -2,10 +2,11 @@ use std::net::{SocketAddr, ToSocketAddrs};
2
2
use std:: num:: ParseIntError ;
3
3
use std:: str:: FromStr ;
4
4
use std:: path:: Path ;
5
- use std:: collections:: BTreeSet as Set ;
5
+ use std:: collections:: HashMap ;
6
6
7
7
use config:: { Config , File as CfgFile } ;
8
8
use serde:: de:: { self , Deserialize , Deserializer } ;
9
+ use serde_yaml:: Value ;
9
10
use clap:: { App , AppSettings , Arg , SubCommand , ArgMatches } ;
10
11
use hex:: FromHex ;
11
12
use itertools:: Itertools ;
@@ -135,10 +136,8 @@ pub struct NodeConfig {
135
136
#[ serde( skip_deserializing) ]
136
137
pub sk_passed_as_arg : bool ,
137
138
/// Path to the file where DHT keys are stored.
138
- /// When run with config, this field is required .
139
+ /// Required with config.
139
140
#[ serde( rename = "keys-file" ) ]
140
- pub keys_file_config : String ,
141
- #[ serde( skip_deserializing) ]
142
141
pub keys_file : Option < String > ,
143
142
/// List of bootstrap nodes.
144
143
#[ serde( rename = "bootstrap-nodes" ) ]
@@ -157,8 +156,8 @@ pub struct NodeConfig {
157
156
#[ serde( rename = "lan-discovery" ) ]
158
157
pub lan_discovery_enabled : bool ,
159
158
/// Unused fields while parsing config file
160
- #[ serde( skip_deserializing ) ]
161
- pub unused : Set < String > ,
159
+ #[ serde( flatten ) ]
160
+ pub unused : HashMap < String , Value > ,
162
161
}
163
162
164
163
/// Parse command line arguments.
@@ -276,15 +275,11 @@ fn parse_config(config_path: String) -> NodeConfig {
276
275
277
276
settings. merge ( config_file) . expect ( "Merging config file with default values failed" ) ;
278
277
279
- // Collect unrecognized fields to warn about them
280
- let mut unused = Set :: new ( ) ;
281
- let mut config: NodeConfig = serde_ignored:: deserialize ( settings, |path| {
282
- unused. insert ( path. to_string ( ) ) ;
283
- } ) . expect ( "Can't deserialize config" ) ;
278
+ let config: NodeConfig = settings. try_into ( ) . expect ( "Can't deserialize config" ) ;
284
279
285
- config. unused = unused ;
286
- config. sk_passed_as_arg = false ;
287
- config . keys_file = Some ( config . keys_file_config . clone ( ) ) ;
280
+ if config. keys_file . is_none ( ) {
281
+ panic ! ( "Can't deserialize config: 'keys-file' is not set" ) ;
282
+ }
288
283
289
284
config
290
285
}
@@ -343,20 +338,17 @@ fn run_args(matches: &ArgMatches) -> NodeConfig {
343
338
344
339
let lan_discovery_enabled = matches. is_present ( "lan-discovery" ) ;
345
340
346
- let keys_file_config = String :: new ( ) ;
347
-
348
341
NodeConfig {
349
342
udp_addr,
350
343
tcp_addrs,
351
344
sk,
352
345
sk_passed_as_arg,
353
346
keys_file,
354
- keys_file_config,
355
347
bootstrap_nodes,
356
348
threads,
357
349
log_type,
358
350
motd,
359
351
lan_discovery_enabled,
360
- unused : Set :: new ( ) ,
352
+ unused : HashMap :: new ( ) ,
361
353
}
362
354
}
0 commit comments