@@ -282,29 +282,33 @@ fn make_neighborhood_mode(
282282 }
283283 }
284284 Some ( ref s) if s == "zero-hop" => {
285- if value_m ! ( multi_config, "ip" , IpAddr ) . is_some ( ) {
286- Err ( ConfiguratorError :: required (
287- "neighborhood-mode" ,
288- "Node cannot run as --neighborhood-mode zero-hop if --ip is specified" ,
289- ) )
290- } else {
291- if !neighbor_configs. is_empty ( ) {
292- let password_opt = value_m ! ( multi_config, "db-password" , String ) ;
293- zero_hop_neighbors_configuration (
294- password_opt,
295- neighbor_configs,
296- persistent_config,
297- ) ?
298- }
299- Ok ( NeighborhoodMode :: ZeroHop )
300- }
285+ process_zero_hop_mode ( multi_config, neighbor_configs, persistent_config)
301286 }
302287 // These two cases are untestable
303288 Some ( ref s) => panic ! (
304289 "--neighborhood-mode {} has not been properly provided for in the code" ,
305290 s
306291 ) ,
307- None => Ok ( NeighborhoodMode :: ZeroHop ) ,
292+ None => process_zero_hop_mode ( multi_config, neighbor_configs, persistent_config) ,
293+ }
294+ }
295+
296+ fn process_zero_hop_mode (
297+ multi_config : & MultiConfig ,
298+ neighbor_configs : Vec < NodeDescriptor > ,
299+ persistent_config : & mut dyn PersistentConfiguration ,
300+ ) -> Result < NeighborhoodMode , ConfiguratorError > {
301+ if value_m ! ( multi_config, "ip" , IpAddr ) . is_some ( ) {
302+ Err ( ConfiguratorError :: required (
303+ "neighborhood-mode" ,
304+ "Node cannot run as --neighborhood-mode zero-hop if --ip is specified" ,
305+ ) )
306+ } else {
307+ if !neighbor_configs. is_empty ( ) {
308+ let password_opt = value_m ! ( multi_config, "db-password" , String ) ;
309+ zero_hop_neighbors_configuration ( password_opt, neighbor_configs, persistent_config) ?
310+ }
311+ Ok ( NeighborhoodMode :: ZeroHop )
308312 }
309313}
310314
@@ -614,15 +618,14 @@ mod tests {
614618 use super :: * ;
615619 use crate :: accountant:: db_access_objects:: utils:: ThresholdUtils ;
616620 use crate :: apps:: app_node;
617- use crate :: blockchain:: bip32:: Bip32EncryptionKeyProvider ;
618621 use crate :: bootstrapper:: CryptDEPair ;
619622 use crate :: database:: db_initializer:: DbInitializationConfig ;
620623 use crate :: database:: db_initializer:: { DbInitializer , DbInitializerReal } ;
621624 use crate :: db_config:: config_dao:: { ConfigDao , ConfigDaoReal } ;
622625 use crate :: db_config:: persistent_configuration:: PersistentConfigError :: NotPresent ;
623626 use crate :: db_config:: persistent_configuration:: PersistentConfigurationReal ;
624627 use crate :: sub_lib:: accountant:: DEFAULT_PAYMENT_THRESHOLDS ;
625- use crate :: sub_lib:: cryptde:: { PlainData , PublicKey } ;
628+ use crate :: sub_lib:: cryptde:: PublicKey ;
626629 use crate :: sub_lib:: neighborhood:: { Hops , DEFAULT_RATE_PACK } ;
627630 use crate :: sub_lib:: utils:: make_new_multi_config;
628631 use crate :: sub_lib:: wallet:: Wallet ;
@@ -1436,30 +1439,30 @@ mod tests {
14361439 }
14371440
14381441 #[ test]
1439- fn unprivileged_parse_args_dao_real_creates_configurations ( ) {
1442+ fn unprivileged_parse_args_dao_real_creates_configurations_in_standard_mode ( ) {
14401443 let home_dir = ensure_node_home_directory_exists (
14411444 "unprivileged_parse_args_configuration" ,
1442- "unprivileged_parse_args_dao_real_creates_configurations " ,
1445+ "unprivileged_parse_args_dao_real_creates_configurations_in_standard_mode " ,
14431446 ) ;
1444- assert_unprivileged_parse_args_creates_configurations (
1447+ assert_unprivileged_parse_args_creates_configurations_in_standard_mode (
14451448 home_dir,
14461449 & UnprivilegedParseArgsConfigurationDaoReal { } ,
14471450 )
14481451 }
14491452
14501453 #[ test]
1451- fn unprivileged_parse_args_dao_null_creates_configurations ( ) {
1454+ fn unprivileged_parse_args_dao_null_creates_configurations_in_standard_mode ( ) {
14521455 let home_dir = ensure_node_home_directory_exists (
14531456 "unprivileged_parse_args_configuration" ,
1454- "unprivileged_parse_args_dao_null_creates_configurations " ,
1457+ "unprivileged_parse_args_dao_null_creates_configurations_in_standard_mode " ,
14551458 ) ;
1456- assert_unprivileged_parse_args_creates_configurations (
1459+ assert_unprivileged_parse_args_creates_configurations_in_standard_mode (
14571460 home_dir,
14581461 & UnprivilegedParseArgsConfigurationDaoNull { } ,
14591462 )
14601463 }
14611464
1462- fn assert_unprivileged_parse_args_creates_configurations (
1465+ fn assert_unprivileged_parse_args_creates_configurations_in_standard_mode (
14631466 home_dir : PathBuf ,
14641467 subject : & dyn UnprivilegedParseArgsConfiguration ,
14651468 ) {
@@ -1471,7 +1474,6 @@ mod tests {
14711474 ) ) ;
14721475 let consuming_private_key_text =
14731476 "ABCDEF01ABCDEF01ABCDEF01ABCDEF01ABCDEF01ABCDEF01ABCDEF01ABCDEF01" ;
1474- let consuming_private_key = PlainData :: from_str ( consuming_private_key_text) . unwrap ( ) ;
14751477 let mut persistent_config = PersistentConfigurationReal :: new ( config_dao) ;
14761478 let password = "secret-db-password" ;
14771479 let args = ArgsBuilder :: new ( )
@@ -1488,6 +1490,7 @@ mod tests {
14881490 . param ( "--blockchain-service-url" , "http://127.0.0.1:8545" )
14891491 . param ( "--log-level" , "trace" )
14901492 . param ( "--fake-public-key" , "AQIDBA" )
1493+ . param ( "--neighborhood-mode" , "standard" )
14911494 . param ( "--db-password" , password)
14921495 . param (
14931496 "--earning-wallet" ,
@@ -1511,32 +1514,32 @@ mod tests {
15111514 . unwrap ( ) ;
15121515
15131516 assert_eq ! (
1514- value_m!( multi_config, "config-file" , PathBuf ) ,
1515- Some ( PathBuf :: from( "specified_config.toml" ) ) ,
1516- ) ;
1517- assert_eq ! (
1518- config. blockchain_bridge_config. blockchain_service_url_opt,
1519- Some ( "http://127.0.0.1:8545" . to_string( ) )
1520- ) ;
1521- assert_eq ! (
1522- config. earning_wallet,
1523- Wallet :: from_str( "0x0123456789012345678901234567890123456789" ) . unwrap( )
1524- ) ;
1525- assert_eq ! ( Some ( 1234u16 ) , config. clandestine_port_opt) ;
1526- assert_eq ! (
1527- config. earning_wallet,
1528- Wallet :: from_str( "0x0123456789012345678901234567890123456789" ) . unwrap( )
1529- ) ;
1530- assert_eq ! (
1531- config. consuming_wallet_opt,
1532- Some ( Wallet :: from(
1533- Bip32EncryptionKeyProvider :: from_raw_secret( consuming_private_key. as_slice( ) )
1534- . unwrap( )
1535- ) ) ,
1517+ config. neighborhood_config. mode,
1518+ NeighborhoodMode :: Standard (
1519+ NodeAddr :: new( & IpAddr :: from_str( "34.56.78.90" ) . unwrap( ) , & [ ] ) ,
1520+ vec![
1521+ NodeDescriptor :: try_from( (
1522+ CRYPTDE_PAIR . main. as_ref( ) ,
1523+ format!(
1524+ "masq://{}:[email protected] :1234/2345" , 1525+ DEFAULT_CHAIN . rec( ) . literal_identifier
1526+ )
1527+ . as_str( )
1528+ ) )
1529+ . unwrap( ) ,
1530+ NodeDescriptor :: try_from( (
1531+ CRYPTDE_PAIR . main. as_ref( ) ,
1532+ format!(
1533+ "masq://{}:[email protected] :3456/4567" , 1534+ DEFAULT_CHAIN . rec( ) . literal_identifier
1535+ )
1536+ . as_str( )
1537+ ) )
1538+ . unwrap( ) ,
1539+ ] ,
1540+ DEFAULT_RATE_PACK . clone( )
1541+ )
15361542 ) ;
1537- assert_eq ! ( config. neighborhood_config. mode, NeighborhoodMode :: ZeroHop ) ;
1538- assert_eq ! ( config. db_password_opt, Some ( password. to_string( ) ) ) ;
1539- assert_eq ! ( config. mapping_protocol_opt, Some ( AutomapProtocol :: Pcp ) ) ;
15401543 }
15411544
15421545 #[ test]
@@ -1581,6 +1584,7 @@ mod tests {
15811584 let args = ArgsBuilder :: new ( )
15821585 . param ( "--ip" , "1.2.3.4" )
15831586 . param ( "--fake-public-key" , "BORSCHT" )
1587+ . param ( "--neighborhood-mode" , "standard" )
15841588 . param ( "--db-password" , "password" ) ;
15851589 let mut config = BootstrapperConfig :: new ( ) ;
15861590 config. db_password_opt = Some ( "password" . to_string ( ) ) ;
@@ -1618,7 +1622,21 @@ mod tests {
16181622 )
16191623 . unwrap ( ) ;
16201624
1621- assert_eq ! ( config. neighborhood_config. mode. neighbor_configs( ) , & [ ] ) ;
1625+ assert_eq ! (
1626+ config. neighborhood_config. mode. neighbor_configs( ) ,
1627+ & [
1628+ NodeDescriptor :: try_from( (
1629+ CRYPTDE_PAIR . main. as_ref( ) ,
1630+ "masq://eth-ropsten:[email protected] :1234" 1631+ ) )
1632+ . unwrap( ) ,
1633+ NodeDescriptor :: try_from( (
1634+ CRYPTDE_PAIR . main. as_ref( ) ,
1635+ "masq://eth-ropsten:[email protected] :2345" 1636+ ) )
1637+ . unwrap( ) ,
1638+ ]
1639+ ) ;
16221640 let past_neighbors_params = past_neighbors_params_arc. lock ( ) . unwrap ( ) ;
16231641 assert_eq ! ( past_neighbors_params[ 0 ] , "password" . to_string( ) ) ;
16241642 assert_eq ! ( config. mapping_protocol_opt, Some ( AutomapProtocol :: Pcp ) ) ;
@@ -1700,6 +1718,7 @@ mod tests {
17001718
17011719 let args = ArgsBuilder :: new ( )
17021720 . param ( "--blockchain-service-url" , "booga.com" )
1721+ . param ( "--neighborhood-mode" , "standard" )
17031722 . param ( "--ip" , "1.2.3.4" )
17041723 . param ( "--data-directory" , home_directory. to_str ( ) . unwrap ( ) )
17051724 . opt ( "--db-password" ) ;
@@ -1748,6 +1767,8 @@ mod tests {
17481767 "booga.com" ,
17491768 "--ip" ,
17501769 "1.2.3.4" ,
1770+ "--neighborhood-mode" ,
1771+ "standard" ,
17511772 "--scan-intervals" ,
17521773 "180|150|130" ,
17531774 "--payment-thresholds" ,
@@ -1826,6 +1847,8 @@ mod tests {
18261847 "booga.com" ,
18271848 "--ip" ,
18281849 "1.2.3.4" ,
1850+ "--neighborhood-mode" ,
1851+ "standard" ,
18291852 "--scan-intervals" ,
18301853 "180|150|130" ,
18311854 "--payment-thresholds" ,
@@ -2508,6 +2531,8 @@ mod tests {
25082531 "booga.com" ,
25092532 "--ip" ,
25102533 "1.2.3.4" ,
2534+ "--neighborhood-mode" ,
2535+ "standard" ,
25112536 "--scans" ,
25122537 "off" ,
25132538 ] ;
@@ -2536,6 +2561,8 @@ mod tests {
25362561 "booga.com" ,
25372562 "--ip" ,
25382563 "1.2.3.4" ,
2564+ "--neighborhood-mode" ,
2565+ "standard" ,
25392566 "--scans" ,
25402567 "on" ,
25412568 ] ;
@@ -2559,7 +2586,14 @@ mod tests {
25592586 fn unprivileged_configuration_defaults_scans ( ) {
25602587 running_test ( ) ;
25612588 let subject = UnprivilegedParseArgsConfigurationDaoReal { } ;
2562- let args = [ "--blockchain-service-url" , "booga.com" , "--ip" , "1.2.3.4" ] ;
2589+ let args = [
2590+ "--blockchain-service-url" ,
2591+ "booga.com" ,
2592+ "--ip" ,
2593+ "1.2.3.4" ,
2594+ "--neighborhood-mode" ,
2595+ "standard" ,
2596+ ] ;
25632597 let mut bootstrapper_config = BootstrapperConfig :: new ( ) ;
25642598
25652599 subject
0 commit comments