Skip to content

Conversation

@SyntheticBird45
Copy link
Member

@SyntheticBird45 SyntheticBird45 commented Sep 10, 2025

What

Add support to pass P2P traffic to a specific SOCKS5 proxy. Authentication is supported. This is also used to implement ClearNet over Daemon tor anonymization of clearnet traffic.

Follows: #509

Changelog

In cuprate-p2p-transport:

  • Added new socks.rs file containing Socks that impl Transport<ClearNet>. As well as SocksClientConfig (socks5 proxy settings).

In cuprated:

  • Added TryFrom<ProxySettings> for SocksClientConfig to parse socks5 URL in user configuration. The urls are in the form of: socks5://username:password@host:port.
  • new socks_transport_config and transport_clearnet_daemon_config helpers.
  • Modified initialize_zones_p2p accordingly.

@github-actions github-actions bot added A-p2p Area: Related to P2P. A-binaries Area: Related to binaries. labels Sep 10, 2025
@SyntheticBird45 SyntheticBird45 marked this pull request as ready for review September 11, 2025 20:01
@SyntheticBird45 SyntheticBird45 changed the title Generic SOCKS5 proxy support + ClearNet over Daemon cuprated: Generic SOCKS5 proxy support + ClearNet over Daemon Sep 11, 2025
@SyntheticBird45 SyntheticBird45 marked this pull request as draft September 11, 2025 20:09
@SyntheticBird45 SyntheticBird45 marked this pull request as ready for review September 11, 2025 22:30
Comment on lines +50 to +78
impl TryFrom<ProxySettings> for SocksClientConfig {
type Error = anyhow::Error;

fn try_from(value: ProxySettings) -> Result<Self, Self::Error> {
let ProxySettings::Socks(url) = value else {
panic!("Tor proxy setting should not be parsed!")
};

let Some((_, url)) = url.split_once("socks5://") else {
return Err(anyhow!("Invalid proxy url header."));
};

let (authentication, addr) = url
.split_once('@')
.map(|(up, ad)| {
(
up.split_once(':')
.map(|(a, b)| (a.to_string(), b.to_string())),
ad,
)
})
.unwrap_or((None, url));

Ok(Self {
proxy: addr.parse()?,
authentication,
})
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can this be a free function that takes a proxy string?

Comment on lines +293 to +299
/// Gets the transport config for [`ClearNet`] over [`Socks`].
pub fn socks_transport_config(&self) -> TransportConfig<ClearNet, Socks> {
TransportConfig {
client_config: self.proxy.clone().try_into().unwrap(),
server_config: None,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

making that other function a free function means we don't need this

context_svc.clone(),
txpool_read_handle.clone(),
config.clearnet_p2p_config(),
config.p2p.clear_net.socks_transport_config(),
Copy link
Member

Choose a reason for hiding this comment

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

we can just call the free function here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-binaries Area: Related to binaries. A-p2p Area: Related to P2P.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants