mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-02-01 17:01:10 +03:00
Add option to skip Tor send attempts in TorConfig (#453)
This commit is contained in:
parent
bf3f0a49e0
commit
99c2505bf5
6 changed files with 76 additions and 3 deletions
|
@ -662,13 +662,25 @@ where
|
||||||
};
|
};
|
||||||
// Helper functionality. If send arguments exist, attempt to send sync and
|
// Helper functionality. If send arguments exist, attempt to send sync and
|
||||||
// finalize
|
// finalize
|
||||||
|
let skip_tor = match send_args.as_ref() {
|
||||||
|
None => false,
|
||||||
|
Some(sa) => sa.skip_tor,
|
||||||
|
};
|
||||||
match send_args {
|
match send_args {
|
||||||
Some(sa) => {
|
Some(sa) => {
|
||||||
let tor_config_lock = self.tor_config.lock();
|
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(
|
let res = try_slatepack_sync_workflow(
|
||||||
&slate,
|
&slate,
|
||||||
&sa.dest,
|
&sa.dest,
|
||||||
tor_config_lock.clone(),
|
tc,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
self.doctest_mode,
|
self.doctest_mode,
|
||||||
|
@ -822,10 +834,18 @@ where
|
||||||
match send_args {
|
match send_args {
|
||||||
Some(sa) => {
|
Some(sa) => {
|
||||||
let tor_config_lock = self.tor_config.lock();
|
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(
|
let res = try_slatepack_sync_workflow(
|
||||||
&slate,
|
&slate,
|
||||||
&sa.dest,
|
&sa.dest,
|
||||||
tor_config_lock.clone(),
|
tc,
|
||||||
None,
|
None,
|
||||||
true,
|
true,
|
||||||
self.doctest_mode,
|
self.doctest_mode,
|
||||||
|
@ -2316,6 +2336,11 @@ pub fn try_slatepack_sync_workflow(
|
||||||
send_to_finalize: bool,
|
send_to_finalize: bool,
|
||||||
test_mode: bool,
|
test_mode: bool,
|
||||||
) -> Result<Option<Slate>, libwallet::Error> {
|
) -> Result<Option<Slate>, 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 ret_slate = Slate::blank(2, false);
|
||||||
let mut send_sync = |mut sender: HttpSlateSender, method_str: &str| match sender
|
let mut send_sync = |mut sender: HttpSlateSender, method_str: &str| match sender
|
||||||
.send_tx(&slate, send_to_finalize)
|
.send_tx(&slate, send_to_finalize)
|
||||||
|
|
|
@ -145,6 +145,8 @@ impl fmt::Display for ConfigError {
|
||||||
/// Tor configuration
|
/// Tor configuration
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||||
pub struct TorConfig {
|
pub struct TorConfig {
|
||||||
|
/// whether to skip any attempts to send via TOR
|
||||||
|
pub skip_send_attempt: Option<bool>,
|
||||||
/// Whether to start tor listener on listener startup (default true)
|
/// Whether to start tor listener on listener startup (default true)
|
||||||
pub use_tor_listener: bool,
|
pub use_tor_listener: bool,
|
||||||
/// Just the address of the socks proxy for now
|
/// Just the address of the socks proxy for now
|
||||||
|
@ -156,6 +158,7 @@ pub struct TorConfig {
|
||||||
impl Default for TorConfig {
|
impl Default for TorConfig {
|
||||||
fn default() -> TorConfig {
|
fn default() -> TorConfig {
|
||||||
TorConfig {
|
TorConfig {
|
||||||
|
skip_send_attempt: Some(false),
|
||||||
use_tor_listener: true,
|
use_tor_listener: true,
|
||||||
socks_proxy_addr: "127.0.0.1:59050".to_owned(),
|
socks_proxy_addr: "127.0.0.1:59050".to_owned(),
|
||||||
send_config_dir: ".".into(),
|
send_config_dir: ".".into(),
|
||||||
|
|
|
@ -257,6 +257,7 @@ pub struct SendArgs {
|
||||||
pub target_slate_version: Option<u16>,
|
pub target_slate_version: Option<u16>,
|
||||||
pub payment_proof_address: Option<SlatepackAddress>,
|
pub payment_proof_address: Option<SlatepackAddress>,
|
||||||
pub ttl_blocks: Option<u64>,
|
pub ttl_blocks: Option<u64>,
|
||||||
|
pub skip_tor: bool,
|
||||||
//TODO: Remove HF3
|
//TODO: Remove HF3
|
||||||
pub output_v4_slate: bool,
|
pub output_v4_slate: bool,
|
||||||
}
|
}
|
||||||
|
@ -450,6 +451,14 @@ where
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
let tor_config = match tor_config {
|
||||||
|
Some(mut c) => {
|
||||||
|
c.skip_send_attempt = Some(args.skip_tor);
|
||||||
|
Some(c)
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
let res =
|
let res =
|
||||||
try_slatepack_sync_workflow(&slate, &args.dest, tor_config, tor_sender, false, test_mode);
|
try_slatepack_sync_workflow(&slate, &args.dest, tor_config, tor_sender, false, test_mode);
|
||||||
|
|
||||||
|
@ -653,6 +662,7 @@ where
|
||||||
pub struct ReceiveArgs {
|
pub struct ReceiveArgs {
|
||||||
pub input_file: Option<String>,
|
pub input_file: Option<String>,
|
||||||
pub input_slatepack_message: Option<String>,
|
pub input_slatepack_message: Option<String>,
|
||||||
|
pub skip_tor: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn receive<L, C, K>(
|
pub fn receive<L, C, K>(
|
||||||
|
@ -680,6 +690,14 @@ where
|
||||||
Some(&m) => Some(m.to_owned()),
|
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| {
|
controller::foreign_single_use(owner_api.wallet_inst.clone(), km, |api| {
|
||||||
slate = api.receive_tx(&slate, Some(&g_args.account), None)?;
|
slate = api.receive_tx(&slate, Some(&g_args.account), None)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -962,6 +980,7 @@ pub struct ProcessInvoiceArgs {
|
||||||
pub slate: Slate,
|
pub slate: Slate,
|
||||||
pub estimate_selection_strategies: bool,
|
pub estimate_selection_strategies: bool,
|
||||||
pub ttl_blocks: Option<u64>,
|
pub ttl_blocks: Option<u64>,
|
||||||
|
pub skip_tor: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process invoice
|
/// Process invoice
|
||||||
|
@ -1036,6 +1055,14 @@ where
|
||||||
Ok(())
|
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);
|
let res = try_slatepack_sync_workflow(&slate, &dest, tor_config, None, true, test_mode);
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
|
|
|
@ -86,6 +86,8 @@ pub struct InitTxSendArgs {
|
||||||
pub post_tx: bool,
|
pub post_tx: bool,
|
||||||
/// Whether to use dandelion when posting. If false, skip the dandelion relay
|
/// Whether to use dandelion when posting. If false, skip the dandelion relay
|
||||||
pub fluff: bool,
|
pub fluff: bool,
|
||||||
|
/// If set, skip the Slatepack TOR send attempt
|
||||||
|
pub skip_tor: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InitTxArgs {
|
impl Default for InitTxArgs {
|
||||||
|
|
|
@ -141,6 +141,10 @@ subcommands:
|
||||||
short: b
|
short: b
|
||||||
long: ttl_blocks
|
long: ttl_blocks
|
||||||
takes_value: true
|
takes_value: true
|
||||||
|
- manual:
|
||||||
|
help: If present, don't attempt to send the resulting Slatepack via TOR
|
||||||
|
short: m
|
||||||
|
long: manual
|
||||||
#TODO: Remove HF3
|
#TODO: Remove HF3
|
||||||
- v4:
|
- v4:
|
||||||
help: Output a V4 slate prior to HF3 block
|
help: Output a V4 slate prior to HF3 block
|
||||||
|
@ -162,6 +166,10 @@ subcommands:
|
||||||
short: i
|
short: i
|
||||||
long: input
|
long: input
|
||||||
takes_value: true
|
takes_value: true
|
||||||
|
- manual:
|
||||||
|
help: If present, don't attempt to send the resulting Slatepack via TOR
|
||||||
|
short: m
|
||||||
|
long: manual
|
||||||
- finalize:
|
- finalize:
|
||||||
about: Processes a Slatepack Message to finalize a transfer.
|
about: Processes a Slatepack Message to finalize a transfer.
|
||||||
args:
|
args:
|
||||||
|
@ -231,6 +239,10 @@ subcommands:
|
||||||
short: b
|
short: b
|
||||||
long: ttl_blocks
|
long: ttl_blocks
|
||||||
takes_value: true
|
takes_value: true
|
||||||
|
- manual:
|
||||||
|
help: If present, don't attempt to send the resulting Slatepack via TOR
|
||||||
|
short: m
|
||||||
|
long: manual
|
||||||
- outputs:
|
- outputs:
|
||||||
about: Raw wallet output info (list of outputs)
|
about: Raw wallet output info (list of outputs)
|
||||||
- txs:
|
- txs:
|
||||||
|
|
|
@ -506,7 +506,7 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
|
||||||
false => match SlatepackAddress::try_from(dest) {
|
false => match SlatepackAddress::try_from(dest) {
|
||||||
Ok(a) => Some(a),
|
Ok(a) => Some(a),
|
||||||
Err(_) => {
|
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
|
None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -527,6 +527,7 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
|
||||||
ttl_blocks,
|
ttl_blocks,
|
||||||
target_slate_version: target_slate_version,
|
target_slate_version: target_slate_version,
|
||||||
output_v4_slate,
|
output_v4_slate,
|
||||||
|
skip_tor: args.is_present("manual"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,6 +554,7 @@ pub fn parse_receive_args(args: &ArgMatches) -> Result<command::ReceiveArgs, Par
|
||||||
Ok(command::ReceiveArgs {
|
Ok(command::ReceiveArgs {
|
||||||
input_file,
|
input_file,
|
||||||
input_slatepack_message,
|
input_slatepack_message,
|
||||||
|
skip_tor: args.is_present("manual"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,6 +581,7 @@ pub fn parse_unpack_args(args: &ArgMatches) -> Result<command::ReceiveArgs, Pars
|
||||||
Ok(command::ReceiveArgs {
|
Ok(command::ReceiveArgs {
|
||||||
input_file,
|
input_file,
|
||||||
input_slatepack_message,
|
input_slatepack_message,
|
||||||
|
skip_tor: args.is_present("manual"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -737,6 +740,7 @@ pub fn parse_process_invoice_args(
|
||||||
slate,
|
slate,
|
||||||
max_outputs,
|
max_outputs,
|
||||||
ttl_blocks,
|
ttl_blocks,
|
||||||
|
skip_tor: args.is_present("manual"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue