@@ -40,7 +40,7 @@ pub struct Config {
4040 pub utxos_limit : usize ,
4141 pub electrum_txs_limit : usize ,
4242 pub electrum_banner : String ,
43- pub rpc_logging_modes : Option < RpcLoggingModes > ,
43+ pub rpc_logging : RpcLogging ,
4444 pub zmq_addr : Option < SocketAddr > ,
4545
4646 /// Enable compaction during initial sync
@@ -74,10 +74,6 @@ fn str_to_socketaddr(address: &str, what: &str) -> SocketAddr {
7474impl Config {
7575 pub fn from_args ( ) -> Config {
7676 let network_help = format ! ( "Select network type ({})" , Network :: names( ) . join( ", " ) ) ;
77- let rpc_logging_help = format ! (
78- "Select possible RPC logging options: {}" ,
79- RpcLoggingModes :: get_modes( ) . join( ", " )
80- ) ;
8177
8278 let args = App :: new ( "Electrum Rust Server" )
8379 . version ( crate_version ! ( ) )
@@ -201,12 +197,20 @@ impl Config {
201197 . help ( "Welcome banner for the Electrum server, shown in the console to clients." )
202198 . takes_value ( true )
203199 ) . arg (
204- Arg :: with_name ( "rpc_logging_modes" )
205- . long ( "electrum-rpc-logging" )
206- . help ( & rpc_logging_help)
207- . takes_value ( true )
208- . multiple ( true )
209- . possible_values ( & RpcLoggingModes :: get_modes ( ) ) ,
200+ Arg :: with_name ( "enable_json_rpc_logging" )
201+ . long ( "enable-json-rpc-logging" )
202+ . help ( "turns on rpc logging" )
203+ . takes_value ( false )
204+ ) . arg (
205+ Arg :: with_name ( "hide_json_rpc_logging_parameters" )
206+ . long ( "hide-json-rpc-logging-parameters" )
207+ . help ( "disables parameter printing in rpc logs" )
208+ . takes_value ( false )
209+ ) . arg (
210+ Arg :: with_name ( "anonymize_json_rpc_logging_source_ip" )
211+ . long ( "anonymize-json-rpc-logging-source-ip" )
212+ . help ( "enables ip anonymization in rpc logs" )
213+ . takes_value ( false )
210214 ) . arg (
211215 Arg :: with_name ( "initial_sync_compaction" )
212216 . long ( "initial-sync-compaction" )
@@ -429,10 +433,15 @@ impl Config {
429433 electrum_rpc_addr,
430434 electrum_txs_limit : value_t_or_exit ! ( m, "electrum_txs_limit" , usize ) ,
431435 electrum_banner,
432- rpc_logging_modes : m. values_of ( "rpc_logging_modes" ) . map ( |vals| {
433- let collected = vals. collect :: < Vec < _ > > ( ) ;
434- RpcLoggingModes :: from_values ( & collected)
435- } ) ,
436+ rpc_logging : {
437+ let params = RpcLogging {
438+ enabled : m. is_present ( "enable_json_rpc_logging" ) ,
439+ hide_params : m. is_present ( "hide_json_rpc_logging_parameters" ) ,
440+ anonymize_ip : m. is_present ( "anonymize_json_rpc_logging_source_ip" ) ,
441+ } ;
442+ params. validate ( ) ;
443+ params
444+ } ,
436445 http_addr,
437446 http_socket_file,
438447 monitoring_addr,
@@ -475,38 +484,17 @@ impl Config {
475484}
476485
477486#[ derive( Debug , Default , Clone ) ]
478- pub struct RpcLoggingModes {
479- pub with_params : bool ,
480- pub anonymised : bool ,
487+ pub struct RpcLogging {
488+ pub enabled : bool ,
489+ pub hide_params : bool ,
490+ pub anonymize_ip : bool ,
481491}
482492
483- impl RpcLoggingModes {
484- pub fn from_values ( values : & [ & str ] ) -> Self {
485- let mut modes = Self :: default ( ) ;
486- let mut no_params = false ;
487-
488- for v in values {
489- match * v {
490- "with-params" => modes. with_params = true ,
491- "no-params" => no_params = true ,
492- "anonymised" => modes. anonymised = true ,
493- _ => panic ! ( "Unsupported RPC logging option: {}" , v) ,
494- }
495- }
496-
497- if modes. with_params && no_params {
498- panic ! ( "Contradiction: 'with-params' and 'no-params' cannot both be set." ) ;
499- }
500-
501- if no_params {
502- modes. with_params = false ;
493+ impl RpcLogging {
494+ pub fn validate ( & self ) {
495+ if !self . enabled && ( self . hide_params || self . anonymize_ip ) {
496+ panic ! ( "Flags '--hide-json-rpc-logging-parameters' or '--anonymize-json-rpc-logging-source-ip' require '--enable-json-rpc-logging'" ) ;
503497 }
504-
505- modes
506- }
507-
508- pub fn get_modes ( ) -> Vec < & ' static str > {
509- vec ! [ "with-params" , "no-params" , "anonymised" ]
510498 }
511499}
512500
0 commit comments