Optional Tor Send/Listen Functionality (#226)

* udpate for beta release

* initial tor explorations

* rustfmt

* basic tor tx send working

* rustfmt

* add tor proxy info to config file

* rustfmt

* add utilities to output tor hidden service configuration files

* output tor config as part of listener startup

* rustfmt

* fully automate config and startup of tor process

* rustfmt

* remove unnecessary process kill commands from listener

* rustfmt

* assume defaults for tor sending config if section doesn't exist in grin-wallet.toml

* rustfmt

* ignore tor dev test

* update default paths output by config, compilation + confirmed working on windows

* rustfmt

* fix on osx/unix

* add timeout to tor connector, remove unwrap in client

* allow specifiying tor address without 'http://[].onion' on the command line

* fix api test

* rustfmt

* update address derivation path as per spec

* rustfmt

* move tor init to separate function

* rustfmt

* re-ignore tor dev test

* listen on tor by default if tor available

* rustfmt

* test fix

* remove explicit send via tor flag, and assume tor if address fits

* rustfmt
This commit is contained in:
Yeastplume
2019-10-14 20:24:09 +01:00
committed by GitHub
parent c60301946f
commit b4eeb50c66
34 changed files with 2311 additions and 153 deletions
+5
View File
@@ -68,6 +68,11 @@ subcommands:
- keybase
default_value: http
takes_value: true
- no_tor:
help: Don't start TOR listener when starting HTTP listener
short: n
long: no_tor
takes_value: false
- owner_api:
about: Runs the wallet's local web API
args:
+11 -2
View File
@@ -31,7 +31,9 @@ where
C: NodeClient + 'static,
{
// just get defaults from the global config
let wallet_config = config.members.unwrap().wallet;
let wallet_config = config.members.clone().unwrap().wallet;
let tor_config = config.members.unwrap().tor;
// Check the node version info, and exit with report if we're not compatible
//let mut node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None);
@@ -57,7 +59,14 @@ where
}
// ... if node isn't available, allow offline functions
let res = wallet_args::wallet_command(wallet_args, wallet_config, node_client, false, |_| {});
let res = wallet_args::wallet_command(
wallet_args,
wallet_config,
tor_config,
node_client,
false,
|_| {},
);
// we need to give log output a chance to catch up before exiting
thread::sleep(Duration::from_millis(100));
+25 -2
View File
@@ -19,9 +19,10 @@ use crate::util::{Mutex, ZeroingString};
/// Argument parsing and error handling for wallet commands
use clap::ArgMatches;
use failure::Fail;
use grin_wallet_config::WalletConfig;
use grin_wallet_config::{TorConfig, WalletConfig};
use grin_wallet_controller::command;
use grin_wallet_controller::{Error, ErrorKind};
use grin_wallet_impls::tor::config::is_tor_address;
use grin_wallet_impls::{DefaultLCProvider, DefaultWalletImpl};
use grin_wallet_impls::{PathToSlate, SlateGetter as _};
use grin_wallet_libwallet::Slate;
@@ -387,12 +388,16 @@ where
pub fn parse_listen_args(
config: &mut WalletConfig,
tor_config: &mut TorConfig,
args: &ArgMatches,
) -> Result<command::ListenArgs, ParseError> {
if let Some(port) = args.value_of("port") {
config.api_listen_port = port.parse().unwrap();
}
let method = parse_required(args, "method")?;
if args.is_present("no_tor") {
tor_config.use_tor_listener = false;
}
Ok(command::ListenArgs {
method: method.to_owned(),
})
@@ -468,10 +473,12 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
}
}
};
if !estimate_selection_strategies
&& method == "http"
&& !dest.starts_with("http://")
&& !dest.starts_with("https://")
&& is_tor_address(&dest).is_err()
{
let msg = format!(
"HTTP Destination should start with http://: or https://: {}",
@@ -769,6 +776,7 @@ pub fn parse_cancel_args(args: &ArgMatches) -> Result<command::CancelArgs, Parse
pub fn wallet_command<C, F>(
wallet_args: &ArgMatches,
mut wallet_config: WalletConfig,
tor_config: Option<TorConfig>,
mut node_client: C,
test_mode: bool,
wallet_inst_cb: F,
@@ -820,6 +828,17 @@ where
wallet_config.data_file_dir = top_level_wallet_dir.to_str().unwrap().into();
}
// for backwards compatibility: If tor config doesn't exist in the file, assume
// the top level directory for data
let tor_config = match tor_config {
Some(tc) => tc,
None => {
let mut tc = TorConfig::default();
tc.send_config_dir = wallet_config.data_file_dir.clone();
tc
}
};
// Instantiate wallet (doesn't open the wallet)
let wallet =
inst_wallet::<DefaultLCProvider<C, keychain::ExtKeychain>, C, keychain::ExtKeychain>(
@@ -896,11 +915,13 @@ where
}
("listen", Some(args)) => {
let mut c = wallet_config.clone();
let a = arg_parse!(parse_listen_args(&mut c, &args));
let mut t = tor_config.clone();
let a = arg_parse!(parse_listen_args(&mut c, &mut t, &args));
command::listen(
wallet,
Arc::new(Mutex::new(keychain_mask)),
&c,
&t,
&a,
&global_wallet_args.clone(),
)
@@ -924,6 +945,7 @@ where
command::send(
wallet,
km,
Some(tor_config),
a,
wallet_config.dark_background_color_scheme.unwrap_or(true),
)
@@ -945,6 +967,7 @@ where
command::process_invoice(
wallet,
km,
Some(tor_config),
a,
wallet_config.dark_background_color_scheme.unwrap_or(true),
)