@@ -37,8 +37,12 @@ pub const DEFAULT_RANDOM_PEER_CONN_THRESHOLD: usize = 7;
37
37
/// Default maximum number of hops to live for any operation
38
38
/// (if it applies, e.g. connect requests).
39
39
pub const DEFAULT_MAX_HOPS_TO_LIVE : usize = 10 ;
40
+
40
41
pub ( crate ) const OPERATION_TTL : Duration = Duration :: from_secs ( 60 ) ;
41
42
43
+ /// Current version of the crate.
44
+ pub ( crate ) const PCK_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
45
+
42
46
// Initialize the executor once.
43
47
static ASYNC_RT : Lazy < Option < Runtime > > = Lazy :: new ( GlobalExecutor :: initialize_async_rt) ;
44
48
@@ -51,27 +55,31 @@ const FREENET_GATEWAYS_INDEX: &str = "https://freenet.org/keys/gateways.toml";
51
55
#[ derive( clap:: Parser , Debug ) ]
52
56
pub struct ConfigArgs {
53
57
/// Node operation mode. Default is network mode.
54
- #[ clap ( value_enum, env = "MODE" ) ]
58
+ #[ arg ( value_enum, env = "MODE" ) ]
55
59
pub mode : Option < OperationMode > ,
56
60
57
- #[ clap ( flatten) ]
61
+ #[ command ( flatten) ]
58
62
pub ws_api : WebsocketApiArgs ,
59
63
60
- #[ clap ( flatten) ]
64
+ #[ command ( flatten) ]
61
65
pub network_api : NetworkArgs ,
62
66
63
- #[ clap ( flatten) ]
67
+ #[ command ( flatten) ]
64
68
pub secrets : SecretArgs ,
65
69
66
- #[ clap ( long, env = "LOG_LEVEL" ) ]
70
+ #[ arg ( long, env = "LOG_LEVEL" ) ]
67
71
pub log_level : Option < tracing:: log:: LevelFilter > ,
68
72
69
- #[ clap ( flatten) ]
73
+ #[ command ( flatten) ]
70
74
pub config_paths : ConfigPathsArgs ,
71
75
72
76
/// An arbitrary identifier for the node, mostly for debugging or testing purposes.
73
- #[ clap ( long) ]
77
+ #[ arg ( long, hide = true ) ]
74
78
pub id : Option < String > ,
79
+
80
+ /// Show the version of the application.
81
+ #[ arg( long, short) ]
82
+ pub version : bool ,
75
83
}
76
84
77
85
impl Default for ConfigArgs {
@@ -98,11 +106,16 @@ impl Default for ConfigArgs {
98
106
log_level : Some ( tracing:: log:: LevelFilter :: Info ) ,
99
107
config_paths : Default :: default ( ) ,
100
108
id : None ,
109
+ version : false ,
101
110
}
102
111
}
103
112
}
104
113
105
114
impl ConfigArgs {
115
+ pub fn current_version ( & self ) -> & str {
116
+ PCK_VERSION
117
+ }
118
+
106
119
fn read_config ( dir : & PathBuf ) -> std:: io:: Result < Option < Config > > {
107
120
if !dir. exists ( ) {
108
121
return Ok ( None ) ;
@@ -610,21 +623,6 @@ pub struct ConfigPathsArgs {
610
623
/// The configuration directory.
611
624
#[ arg( long, default_value = None , env = "CONFIG_DIR" ) ]
612
625
pub config_dir : Option < PathBuf > ,
613
- /// The contracts directory.
614
- #[ arg( long, default_value = None , env = "CONTRACTS_DIR" ) ]
615
- contracts_dir : Option < PathBuf > ,
616
- /// The delegates directory.
617
- #[ arg( long, default_value = None , env = "DELEGATES_DIR" ) ]
618
- delegates_dir : Option < PathBuf > ,
619
- /// The secrets directory.
620
- #[ arg( long, default_value = None , env = "SECRECTS_DIR" ) ]
621
- secrets_dir : Option < PathBuf > ,
622
- /// The database directory.
623
- #[ arg( long, default_value = None , env = "DB_DIR" ) ]
624
- db_dir : Option < PathBuf > ,
625
- /// The event log file.
626
- #[ arg( long, default_value = None , env = "EVENT_LOG" ) ]
627
- event_log : Option < PathBuf > ,
628
626
/// The data directory.
629
627
#[ arg( long, default_value = None , env = "DATA_DIR" ) ]
630
628
pub data_dir : Option < PathBuf > ,
@@ -633,11 +631,6 @@ pub struct ConfigPathsArgs {
633
631
impl ConfigPathsArgs {
634
632
fn merge ( & mut self , other : ConfigPaths ) {
635
633
self . config_dir . get_or_insert ( other. config_dir ) ;
636
- self . contracts_dir . get_or_insert ( other. contracts_dir ) ;
637
- self . delegates_dir . get_or_insert ( other. delegates_dir ) ;
638
- self . secrets_dir . get_or_insert ( other. secrets_dir ) ;
639
- self . db_dir . get_or_insert ( other. db_dir ) ;
640
- self . event_log . get_or_insert ( other. event_log ) ;
641
634
self . data_dir . get_or_insert ( other. data_dir ) ;
642
635
}
643
636
@@ -669,16 +662,10 @@ impl ConfigPathsArgs {
669
662
} ;
670
663
Ok ( defaults. data_dir ( ) . to_path_buf ( ) )
671
664
} ) ?;
672
- let contracts_dir = self
673
- . contracts_dir
674
- . unwrap_or_else ( || app_data_dir. join ( "contracts" ) ) ;
675
- let delegates_dir = self
676
- . delegates_dir
677
- . unwrap_or_else ( || app_data_dir. join ( "delegates" ) ) ;
678
- let secrets_dir = self
679
- . secrets_dir
680
- . unwrap_or_else ( || app_data_dir. join ( "secrets" ) ) ;
681
- let db_dir = self . db_dir . unwrap_or_else ( || app_data_dir. join ( "db" ) ) ;
665
+ let contracts_dir = app_data_dir. join ( "contracts" ) ;
666
+ let delegates_dir = app_data_dir. join ( "delegates" ) ;
667
+ let secrets_dir = app_data_dir. join ( "secrets" ) ;
668
+ let db_dir = app_data_dir. join ( "db" ) ;
682
669
683
670
if !contracts_dir. exists ( ) {
684
671
fs:: create_dir_all ( & contracts_dir) ?;
@@ -720,13 +707,13 @@ impl ConfigPathsArgs {
720
707
} ) ?;
721
708
722
709
Ok ( ConfigPaths {
710
+ config_dir,
711
+ data_dir : app_data_dir,
723
712
contracts_dir,
724
713
delegates_dir,
725
714
secrets_dir,
726
715
db_dir,
727
- data_dir : app_data_dir,
728
716
event_log,
729
- config_dir,
730
717
} )
731
718
}
732
719
}
0 commit comments