Skip to content
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
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

pokkst
Copy link
Contributor

@pokkst pokkst commented Aug 4, 2023

Allows user to specify the Tor SOCKS5 port exactly like the cli equivalent command so that registration over Tor is possible for clearnet or onion Rendezvous servers.

Example Tor Rendezvous server: /onion3/yn5wziq6coomwvk2regzvwmjc2hvbw3z2w35bdfersr3kdqat6jwh6ad:8888/p2p/12D3KooWDgGZKJHbHfaUFMoQHj4zEA8xcXW7tdw7rtQDMU7zoXVE

@pokkst pokkst changed the title Allow registering to Rendezvous over Tor; works with onion addresses. Allow ASB to use Tor, including registering to Tor Rendezvous servers Aug 4, 2023
@pokkst pokkst changed the title Allow ASB to use Tor, including registering to Tor Rendezvous servers Add Tor SOCKS option to ASB for registering to Tor Rendezvous servers Aug 4, 2023
@pokkst
Copy link
Contributor Author

pokkst commented Aug 4, 2023

I just realized the Tor client stuff is right above where the swarm is created, which I suppose could be used instead, though the port option during launch is much easier than configuring the Tor control port and permissions and whatnot.

@delta1
Copy link
Collaborator

delta1 commented Aug 5, 2023

hey thanks for the PR, i’ll only get a chance to review during the week

@pokkst pokkst changed the title Add Tor SOCKS option to ASB for registering to Tor Rendezvous servers Add Tor SOCKS option to ASB for registering to Tor Rendezvous servers and for Electrum client Aug 5, 2023
@pokkst
Copy link
Contributor Author

pokkst commented Aug 5, 2023

Sounds good. I've cleaned it up a bit so that it uses the port option from the config file, and also made it so when Tor is running the Electrum client will also use the Tor proxy, and made it so the ElectrumBlockchain client takes into account the config.

I have my own fork that also removes the Kraken price websocket in favor of the Feather price websocket, with Tor support for that as well, but I don't think it's as stable. I'm not sure whether it's on my end or Feather's end, but it keeps disconnecting and having to back off and try again.

swap/src/bin/asb.rs Outdated Show resolved Hide resolved
@pokkst
Copy link
Contributor Author

pokkst commented Dec 16, 2023

Any chance for a re-review?

Copy link
Collaborator

@delta1 delta1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, see if you agree with my feedback and take a stab at it

@@ -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?;
Copy link
Collaborator

@delta1 delta1 Dec 18, 2023

Choose a reason for hiding this comment

The 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

Comment on lines +103 to +132
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");
}

Copy link
Collaborator

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

@delta1
Copy link
Collaborator

delta1 commented Dec 18, 2023

pushed a commit to fix the fmt. there is a test compilation error

@pokkst
Copy link
Contributor Author

pokkst commented Dec 23, 2023

Sounds good. Will work on it this weekend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants