From 99c2505bf5da748665b3a3031aac789a44abdc0a Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Wed, 24 Jun 2020 10:50:40 +0100 Subject: [PATCH] Add option to skip Tor send attempts in TorConfig (#453) --- api/src/owner.rs | 29 +++++++++++++++++++++++++++-- config/src/types.rs | 3 +++ controller/src/command.rs | 27 +++++++++++++++++++++++++++ libwallet/src/api_impl/types.rs | 2 ++ src/bin/grin-wallet.yml | 12 ++++++++++++ src/cmd/wallet_args.rs | 6 +++++- 6 files changed, 76 insertions(+), 3 deletions(-) diff --git a/api/src/owner.rs b/api/src/owner.rs index 13726946..d3c49bb8 100644 --- a/api/src/owner.rs +++ b/api/src/owner.rs @@ -662,13 +662,25 @@ where }; // Helper functionality. If send arguments exist, attempt to send sync and // finalize + let skip_tor = match send_args.as_ref() { + None => false, + Some(sa) => sa.skip_tor, + }; match send_args { Some(sa) => { let tor_config_lock = self.tor_config.lock(); + let tc = tor_config_lock.clone(); + let tc = match tc { + Some(mut c) => { + c.skip_send_attempt = Some(skip_tor); + Some(c) + } + None => None, + }; let res = try_slatepack_sync_workflow( &slate, &sa.dest, - tor_config_lock.clone(), + tc, None, false, self.doctest_mode, @@ -822,10 +834,18 @@ where match send_args { Some(sa) => { let tor_config_lock = self.tor_config.lock(); + let tc = tor_config_lock.clone(); + let tc = match tc { + Some(mut c) => { + c.skip_send_attempt = Some(sa.skip_tor); + Some(c) + } + None => None, + }; let res = try_slatepack_sync_workflow( &slate, &sa.dest, - tor_config_lock.clone(), + tc, None, true, self.doctest_mode, @@ -2316,6 +2336,11 @@ pub fn try_slatepack_sync_workflow( send_to_finalize: bool, test_mode: bool, ) -> Result, libwallet::Error> { + if let Some(tc) = &tor_config { + if tc.skip_send_attempt == Some(true) { + return Ok(None); + } + } let mut ret_slate = Slate::blank(2, false); let mut send_sync = |mut sender: HttpSlateSender, method_str: &str| match sender .send_tx(&slate, send_to_finalize) diff --git a/config/src/types.rs b/config/src/types.rs index af601def..9ab672c3 100644 --- a/config/src/types.rs +++ b/config/src/types.rs @@ -145,6 +145,8 @@ impl fmt::Display for ConfigError { /// Tor configuration #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct TorConfig { + /// whether to skip any attempts to send via TOR + pub skip_send_attempt: Option, /// Whether to start tor listener on listener startup (default true) pub use_tor_listener: bool, /// Just the address of the socks proxy for now @@ -156,6 +158,7 @@ pub struct TorConfig { impl Default for TorConfig { fn default() -> TorConfig { TorConfig { + skip_send_attempt: Some(false), use_tor_listener: true, socks_proxy_addr: "127.0.0.1:59050".to_owned(), send_config_dir: ".".into(), diff --git a/controller/src/command.rs b/controller/src/command.rs index 742c503b..58a70151 100644 --- a/controller/src/command.rs +++ b/controller/src/command.rs @@ -257,6 +257,7 @@ pub struct SendArgs { pub target_slate_version: Option, pub payment_proof_address: Option, pub ttl_blocks: Option, + pub skip_tor: bool, //TODO: Remove HF3 pub output_v4_slate: bool, } @@ -450,6 +451,14 @@ where Ok(()) })?; + let tor_config = match tor_config { + Some(mut c) => { + c.skip_send_attempt = Some(args.skip_tor); + Some(c) + } + None => None, + }; + let res = try_slatepack_sync_workflow(&slate, &args.dest, tor_config, tor_sender, false, test_mode); @@ -653,6 +662,7 @@ where pub struct ReceiveArgs { pub input_file: Option, pub input_slatepack_message: Option, + pub skip_tor: bool, } pub fn receive( @@ -680,6 +690,14 @@ where Some(&m) => Some(m.to_owned()), }; + let tor_config = match tor_config { + Some(mut c) => { + c.skip_send_attempt = Some(args.skip_tor); + Some(c) + } + None => None, + }; + controller::foreign_single_use(owner_api.wallet_inst.clone(), km, |api| { slate = api.receive_tx(&slate, Some(&g_args.account), None)?; Ok(()) @@ -962,6 +980,7 @@ pub struct ProcessInvoiceArgs { pub slate: Slate, pub estimate_selection_strategies: bool, pub ttl_blocks: Option, + pub skip_tor: bool, } /// Process invoice @@ -1036,6 +1055,14 @@ where Ok(()) })?; + let tor_config = match tor_config { + Some(mut c) => { + c.skip_send_attempt = Some(args.skip_tor); + Some(c) + } + None => None, + }; + let res = try_slatepack_sync_workflow(&slate, &dest, tor_config, None, true, test_mode); match res { diff --git a/libwallet/src/api_impl/types.rs b/libwallet/src/api_impl/types.rs index 21ad6aca..b7e31f46 100644 --- a/libwallet/src/api_impl/types.rs +++ b/libwallet/src/api_impl/types.rs @@ -86,6 +86,8 @@ pub struct InitTxSendArgs { pub post_tx: bool, /// Whether to use dandelion when posting. If false, skip the dandelion relay pub fluff: bool, + /// If set, skip the Slatepack TOR send attempt + pub skip_tor: bool, } impl Default for InitTxArgs { diff --git a/src/bin/grin-wallet.yml b/src/bin/grin-wallet.yml index 484981f6..26b87762 100644 --- a/src/bin/grin-wallet.yml +++ b/src/bin/grin-wallet.yml @@ -141,6 +141,10 @@ subcommands: short: b long: ttl_blocks takes_value: true + - manual: + help: If present, don't attempt to send the resulting Slatepack via TOR + short: m + long: manual #TODO: Remove HF3 - v4: help: Output a V4 slate prior to HF3 block @@ -162,6 +166,10 @@ subcommands: short: i long: input takes_value: true + - manual: + help: If present, don't attempt to send the resulting Slatepack via TOR + short: m + long: manual - finalize: about: Processes a Slatepack Message to finalize a transfer. args: @@ -231,6 +239,10 @@ subcommands: short: b long: ttl_blocks takes_value: true + - manual: + help: If present, don't attempt to send the resulting Slatepack via TOR + short: m + long: manual - outputs: about: Raw wallet output info (list of outputs) - txs: diff --git a/src/cmd/wallet_args.rs b/src/cmd/wallet_args.rs index e87b650c..baf95f14 100644 --- a/src/cmd/wallet_args.rs +++ b/src/cmd/wallet_args.rs @@ -506,7 +506,7 @@ pub fn parse_send_args(args: &ArgMatches) -> Result match SlatepackAddress::try_from(dest) { Ok(a) => Some(a), Err(_) => { - println!("No recipient Slatepack address. No payment proof will be requested."); + println!("No recipient Slatepack address or provided address invalid. No payment proof will be requested."); None } }, @@ -527,6 +527,7 @@ pub fn parse_send_args(args: &ArgMatches) -> Result Result Result