-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Tor SOCKS option to ASB for registering to Tor Rendezvous servers and for Electrum client #1420
Open
pokkst
wants to merge
9
commits into
comit-network:master
Choose a base branch
from
pokkst:feature/asb-tor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−40
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5718571
Allow registering to Rendezvous over Tor; works with onion addresses.
pokkst 9b81d30
Remove tor_socks5_port option and use config port
pokkst 4fa0f35
Remove now-unnecessary changes
pokkst f02c771
Use Tor for Electrum client when Tor is running
pokkst cfaf9ee
Ensure ElectrumBlockchain client also uses config
pokkst 7e5e34f
More descriptive log message
pokkst f0c5883
Fix more descriptive log message
pokkst fb4a0e2
Merge branch 'master' into feature/asb-tor
delta1 82cbea4
chore: cargo fmt
delta1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,36 @@ async fn main() -> Result<()> { | |
let seed = | ||
Seed::from_file_or_generate(&config.data.dir).expect("Could not retrieve/initialize seed"); | ||
|
||
let tor_client = | ||
tor::Client::new(config.tor.socks5_port).with_control_port(config.tor.control_port); | ||
let _ac = match tor_client.assert_tor_running().await { | ||
Ok(_) => { | ||
tracing::info!("Setting up Tor hidden service"); | ||
let ac = | ||
register_tor_services(config.network.clone().listen, tor_client, &seed).await?; | ||
Some(ac) | ||
} | ||
Err(_) => { | ||
tracing::warn!("Tor not found. Running on clear net"); | ||
None | ||
} | ||
}; | ||
let tor_port = if _ac.is_some() { | ||
config.tor.socks5_port | ||
} else { | ||
0u16 | ||
}; | ||
let proxy_string = if tor_port != 0u16 { | ||
format!("127.0.0.1:{}", tor_port) | ||
} else { | ||
"".to_string() | ||
}; | ||
if proxy_string.is_empty() { | ||
tracing::info!(%proxy_string, "Not using SOCKS5 proxy"); | ||
} else { | ||
tracing::info!(%proxy_string, "Using SOCKS5 proxy at"); | ||
} | ||
|
||
match cmd { | ||
Command::Start { resume_only } => { | ||
// check and warn for duplicate rendezvous points | ||
|
@@ -140,29 +170,13 @@ async fn main() -> Result<()> { | |
} | ||
} | ||
|
||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; | ||
let bitcoin_wallet = | ||
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i suggest instead adding the tor port to env_config, then this additional argument is not necessary |
||
let bitcoin_balance = bitcoin_wallet.balance().await?; | ||
tracing::info!(%bitcoin_balance, "Bitcoin wallet balance"); | ||
|
||
let kraken_price_updates = kraken::connect(config.maker.price_ticker_ws_url.clone())?; | ||
|
||
// setup Tor hidden services | ||
let tor_client = | ||
tor::Client::new(config.tor.socks5_port).with_control_port(config.tor.control_port); | ||
let _ac = match tor_client.assert_tor_running().await { | ||
Ok(_) => { | ||
tracing::info!("Setting up Tor hidden service"); | ||
let ac = | ||
register_tor_services(config.network.clone().listen, tor_client, &seed) | ||
.await?; | ||
Some(ac) | ||
} | ||
Err(_) => { | ||
tracing::warn!("Tor not found. Running on clear net"); | ||
None | ||
} | ||
}; | ||
|
||
let kraken_rate = KrakenRate::new(config.maker.ask_spread, kraken_price_updates); | ||
let namespace = XmrBtcNamespace::from_is_testnet(testnet); | ||
|
||
|
@@ -175,7 +189,9 @@ async fn main() -> Result<()> { | |
env_config, | ||
namespace, | ||
&rendezvous_addrs, | ||
)?; | ||
tor_port, | ||
) | ||
.await?; | ||
|
||
for listen in config.network.listen.clone() { | ||
Swarm::listen_on(&mut swarm, listen.clone()) | ||
|
@@ -241,7 +257,8 @@ async fn main() -> Result<()> { | |
println!("{}", config_json); | ||
} | ||
Command::WithdrawBtc { amount, address } => { | ||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; | ||
let bitcoin_wallet = | ||
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?; | ||
|
||
let amount = match amount { | ||
Some(amount) => amount, | ||
|
@@ -264,20 +281,23 @@ async fn main() -> Result<()> { | |
let monero_balance = monero_wallet.get_balance().await?; | ||
tracing::info!(%monero_balance); | ||
|
||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; | ||
let bitcoin_wallet = | ||
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?; | ||
let bitcoin_balance = bitcoin_wallet.balance().await?; | ||
tracing::info!(%bitcoin_balance); | ||
tracing::info!(%bitcoin_balance, %monero_balance, "Current balance"); | ||
} | ||
Command::Cancel { swap_id } => { | ||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; | ||
let bitcoin_wallet = | ||
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?; | ||
|
||
let (txid, _) = cancel(swap_id, Arc::new(bitcoin_wallet), db).await?; | ||
|
||
tracing::info!("Cancel transaction successfully published with id {}", txid); | ||
} | ||
Command::Refund { swap_id } => { | ||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; | ||
let bitcoin_wallet = | ||
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?; | ||
let monero_wallet = init_monero_wallet(&config, env_config).await?; | ||
|
||
refund( | ||
|
@@ -291,7 +311,8 @@ async fn main() -> Result<()> { | |
tracing::info!("Monero successfully refunded"); | ||
} | ||
Command::Punish { swap_id } => { | ||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; | ||
let bitcoin_wallet = | ||
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?; | ||
|
||
let (txid, _) = punish(swap_id, Arc::new(bitcoin_wallet), db).await?; | ||
|
||
|
@@ -306,7 +327,8 @@ async fn main() -> Result<()> { | |
swap_id, | ||
do_not_await_finality, | ||
} => { | ||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; | ||
let bitcoin_wallet = | ||
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?; | ||
|
||
let (txid, _) = redeem( | ||
swap_id, | ||
|
@@ -319,7 +341,8 @@ async fn main() -> Result<()> { | |
tracing::info!("Redeem transaction successfully published with id {}", txid); | ||
} | ||
Command::ExportBitcoinWallet => { | ||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; | ||
let bitcoin_wallet = | ||
init_bitcoin_wallet(&config, &seed, env_config, proxy_string).await?; | ||
let wallet_export = bitcoin_wallet.wallet_export("asb").await?; | ||
println!("{}", wallet_export.to_string()) | ||
} | ||
|
@@ -332,11 +355,13 @@ async fn init_bitcoin_wallet( | |
config: &Config, | ||
seed: &Seed, | ||
env_config: swap::env::Config, | ||
proxy_string: String, | ||
) -> Result<bitcoin::Wallet> { | ||
tracing::debug!("Opening Bitcoin wallet"); | ||
let data_dir = &config.data.dir; | ||
let wallet = bitcoin::Wallet::new( | ||
config.bitcoin.electrum_rpc_url.clone(), | ||
proxy_string.as_str(), | ||
data_dir, | ||
seed.derive_extended_private_key(env_config.bitcoin_network)?, | ||
env_config, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be cleaned up into 1 match statement that returns an Option for the tor port, and do the logging there too