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

Improves tor flag logic in watchtower-plugin #160

Merged
merged 1 commit into from
Jan 20, 2023

Conversation

sr-gi
Copy link
Member

@sr-gi sr-gi commented Nov 28, 2022

Changes

The watchtower-plugin was specifying a custom tor flag to signal whether Tor may be used by the client. This was due to cln-plugin (v0.1.1-) not allowing plugins to access the CoreLN configuration options and, therefore, our plugin was unable to fetch the proxy / always-use-proxy options.

This fetches the aforementioned options and revamps the logic to comply with the always-use-proxy requirements, that is, if the flag is set all communications must be performed using Tor. Also, it replaces some of the currently used Strings for more meaningful types to store network data (such as AddressType, NetAddress, or ProxyInfo).

This drops our custom watchtower-proxy config option

teos-common/src/net.rs Outdated Show resolved Hide resolved
watchtower-plugin/src/main.rs Outdated Show resolved Hide resolved
teos-common/src/test_utils.rs Outdated Show resolved Hide resolved
@sr-gi sr-gi force-pushed the cln-tor-flag branch 4 times, most recently from e4a9e7b to 3be8ccb Compare January 14, 2023 23:45
Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

Some early review/suggestions.

watchtower-plugin/src/wt_client.rs Outdated Show resolved Hide resolved
watchtower-plugin/src/net/mod.rs Outdated Show resolved Hide resolved
Comment on lines 163 to 168
let client = if url.host_str().unwrap().ends_with(".onion") {
if let Some(proxy) = proxy {
let proxy = reqwest::Proxy::http(format!("socks5h://{}", proxy))
let proxy = reqwest::Proxy::http(proxy.get_socks_addr())
.map_err(|e| RequestError::ConnectionError(format!("{}", e)))?;
reqwest::Client::builder()
.proxy(proxy)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this checks if the host is a .onion url and uses the proxy for it.

But we don't make use of the always_use_proxy option flag that CLN provides. We should prioritize that first, i.e.: if always_use_proxy flag is set and the url isn't a .onion we should still use the proxy, as not using it in such a case will expose the node's IP address.

Something along the lines of:

if let Some(proxy) = proxy {
	if proxy.always_use || url.is_onion() {
		// construct a proxied client.
	} else {
		// construct a non-proxied client.
	}
} else {
	if url.is_onion() {
		return Err("url is onion but no proxy")
	}
	// construct a non-proxid client.
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be covered now, alongside some minor improvements.

I've added an endpoint param to some of the http functions. A followup would be nice defining the tower endpoints as an enum and replacing all string endpoint with the proper variant (I'm already working on this).

Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

LGTM

The `watchtower-plugin` was specifying a custom tor flag to signal whether Tor may be used by the client. This was due to `cln-plugin (v0.1.1-)` not allowing plugins to access the CoreLN configuration options and, therefore, our plugin was unable to fetch the `proxy` / `always-use-proxy` options.

This fetches the aforementioned options and revamps the logic to comply with the `always-use-proxy` requirements, that is, if the flag is set all communications must be performed using Tor. Also, it replaces some of the currently used `String`s for more meaningful types to store network data (such as `AddressType`, `NetAddress`, or `ProxyInfo`).

This drops our custom `watchtower-proxy` config option
@sr-gi
Copy link
Member Author

sr-gi commented Jan 20, 2023

Rebased to squash all changes

@sr-gi sr-gi removed the Seeking Code Review review me pls label Jan 20, 2023
@sr-gi sr-gi merged commit 19b3ad8 into talaia-labs:master Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cln-plugin Stuff related to watchtower-plugin feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants