Skip to content

Commit

Permalink
add bridge flags to pay and receive + few fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
deevope committed Jan 2, 2022
1 parent 2fad6ef commit eb68a20
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
11 changes: 6 additions & 5 deletions config/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn comments() -> HashMap<String, String> {
#transport = \"https\"
#Proxy address, eg IP:PORT or Hostname
#server = \"IP:PORT\"
#server = \"\"
#Username for the proxy server authentification
#user = \"\"
Expand Down Expand Up @@ -261,6 +261,7 @@ fn comments() -> HashMap<String, String> {
"
#Tor bridge relay: allow to send and receive via TOR in a country where it is censored.
#Enable it by entering a single bridge line. To disable it, you must comment it.
#Support of the transport: obfs4, meek and snowflake.
#obfs4proxy or snowflake client binary must be installed and on your path.
#For example, the bridge line must be in the following format for obfs4 transport: \"obfs4 [IP:PORT] [FINGERPRINT] cert=[CERT] iat-mode=[IAT-MODE]\"
#bridge_line = \"\"
Expand Down Expand Up @@ -314,7 +315,7 @@ pub fn migrate_comments(
old_version: Option<u32>,
) -> String {
let comments = comments();
// Prohibe the old key we are basing on to introduce new comments
// Prohibe the key we are basing on to introduce new comments for [tor.proxy]
let prohibited_key = match old_version {
None => vec!["[logging]"],
Some(_) => vec![],
Expand Down Expand Up @@ -377,18 +378,18 @@ pub fn migrate_comments(
let key_fmt = format!("{}\n", key_line);
if old_key_exist {
if prohibited_key.contains(&key.as_str()) {
// push new config comment
// push new config key/comments
let value = comments.get(&key).unwrap();
new_config_str.push_str(value);
new_config_str.push_str(&key_fmt);
} else {
// push old config comment
// push old config key/comment
let value = hm_key_cmt_old.get(&key).unwrap();
new_config_str.push_str(value);
new_config_str.push_str(&key_fmt);
}
} else {
// old key does not exist, we push new comments
// old key does not exist, we push new key/comments
let value = comments.get(&key).unwrap();
new_config_str.push_str(value);
new_config_str.push_str(&key_fmt);
Expand Down
2 changes: 1 addition & 1 deletion config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl GlobalWalletConfig {
}
/// This migration does the following:
/// - Adds "config_file_version = 2"
/// - Introduce new commented key [tor.bridge] and [tor.proxy]
/// - Introduce new key config_file_version, [tor.bridge] and [tor.proxy]
/// - Migrate old config key/value and comments while it does not conflict with newly indroduced key and comments
fn migrate_config_file_version_none_to_2(
config_str: String,
Expand Down
12 changes: 11 additions & 1 deletion controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ where

let tor_config = match tor_config {
Some(mut c) => {
c.bridge.bridge_line = args.bridge.clone();
if let Some(b) = args.bridge.clone() {
c.bridge.bridge_line = Some(b);
}
c.skip_send_attempt = Some(args.skip_tor);
Some(c)
}
Expand Down Expand Up @@ -532,6 +534,7 @@ pub struct ReceiveArgs {
pub input_slatepack_message: Option<String>,
pub skip_tor: bool,
pub outfile: Option<String>,
pub bridge: Option<String>,
}

pub fn receive<L, C, K>(
Expand Down Expand Up @@ -561,6 +564,9 @@ where

let tor_config = match tor_config {
Some(mut c) => {
if let Some(b) = args.bridge {
c.bridge.bridge_line = Some(b);
}
c.skip_send_attempt = Some(args.skip_tor);
Some(c)
}
Expand Down Expand Up @@ -816,6 +822,7 @@ pub struct ProcessInvoiceArgs {
pub ttl_blocks: Option<u64>,
pub skip_tor: bool,
pub outfile: Option<String>,
pub bridge: Option<String>,
}

/// Process invoice
Expand Down Expand Up @@ -892,6 +899,9 @@ where

let tor_config = match tor_config {
Some(mut c) => {
if let Some(b) = args.bridge {
c.bridge.bridge_line = Some(b);
}
c.skip_send_attempt = Some(args.skip_tor);
Some(c)
}
Expand Down
6 changes: 3 additions & 3 deletions impls/src/tor/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl PluginClient {
FlagParser::new(s, flags, bool_flags, true).collect()
}

/// Try to find the plugin client path in the env var
/// Try to find the plugin client path
pub fn get_client_path(plugin: &str) -> Result<String, Error> {
let plugin_path = env::var_os("PATH").and_then(|path| {
env::split_paths(&path)
Expand All @@ -291,7 +291,7 @@ impl PluginClient {
match plugin_path {
Some(path) => Ok(path.into_os_string().into_string().unwrap()),
None => {
let msg = format!("Transport plugin client \"{}\" is missing, make sure it's installed and in your path.", plugin);
let msg = format!("Transport client \"{}\" is missing, make sure it's installed and on your path.", plugin);
return Err(ErrorKind::TorBridge(msg).into());
}
}
Expand Down Expand Up @@ -327,7 +327,7 @@ impl PluginClient {
let ice_addr = arg.trim();
let vec_ice_addr = ice_addr.split(",");
for addr in vec_ice_addr {
addr.to_lowercase();
let addr = addr.to_lowercase();
if addr.starts_with("stun:") || addr.starts_with("turn:") {
let address = addr.replace("stun:", "").replace("turn:", "");
let _p_address = TorProxy::parse_address(&address)
Expand Down
12 changes: 11 additions & 1 deletion src/bin/grin-wallet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ subcommands:
long: outfile
takes_value: true
- bridge:
help: Enable bridge relay when sending via Slatepack workflow
help: Enable tor bridge relay when sending via Slatepack workflow
short: g
long: bridge
takes_value: true
Expand Down Expand Up @@ -184,6 +184,11 @@ subcommands:
short: u
long: outfile
takes_value: true
- bridge:
help: Enable tor bridge relay when receiving via Slatepack workflow
short: g
long: bridge
takes_value: true
- finalize:
about: Processes a Slatepack Message to finalize a transfer.
args:
Expand Down Expand Up @@ -267,6 +272,11 @@ subcommands:
short: u
long: outfile
takes_value: true
- bridge:
help: Enable tor bridge relay when paying invoice.
short: g
long: bridge
takes_value: true
- outputs:
about: Raw wallet output info (list of outputs)
- txs:
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/wallet_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,14 @@ pub fn parse_receive_args(args: &ArgMatches) -> Result<command::ReceiveArgs, Par

let outfile = parse_optional(args, "outfile")?;

let bridge = parse_optional(args, "bridge")?;

Ok(command::ReceiveArgs {
input_file,
input_slatepack_message,
skip_tor: args.is_present("manual"),
outfile,
bridge,
})
}

Expand All @@ -574,11 +577,14 @@ pub fn parse_unpack_args(args: &ArgMatches) -> Result<command::ReceiveArgs, Pars

let outfile = parse_optional(args, "outfile")?;

let bridge = parse_optional(args, "bridge")?;

Ok(command::ReceiveArgs {
input_file,
input_slatepack_message,
skip_tor: args.is_present("manual"),
outfile,
bridge,
})
}

Expand Down Expand Up @@ -733,6 +739,8 @@ pub fn parse_process_invoice_args(

let outfile = parse_optional(args, "outfile")?;

let bridge = parse_optional(args, "bridge")?;

Ok(command::ProcessInvoiceArgs {
minimum_confirmations: min_c,
selection_strategy: selection_strategy.to_owned(),
Expand All @@ -743,6 +751,7 @@ pub fn parse_process_invoice_args(
ttl_blocks,
skip_tor: args.is_present("manual"),
outfile,
bridge,
})
}

Expand Down

0 comments on commit eb68a20

Please sign in to comment.