pub struct Socks5MixnetClient { /* private fields */ }Expand description
A SOCKS5 proxy client connected to the Nym mixnet.
Socks5MixnetClient provides a SOCKS5 proxy interface to the Nym mixnet,
allowing HTTP(S) clients and other SOCKS5-compatible applications to route
their traffic through the mixnet without having to modify their networking
code.
Traffic leaves the mixnet through a network requester: a service running on
an exit gateway that makes requests on the client’s behalf and enforces the
Nym exit policy. You can let the client discover one for you or name a specific
one; see connect_with and NetworkRequesterSelector.
§Usage
- Connect, either by discovering a requester with
connect_withor naming a known one withconnect_new - Get the SOCKS5 URL via
socks5_url - Point your HTTP client at that SOCKS5 proxy
§Example
use nym_sdk::mixnet::Socks5MixnetClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to a known network requester by address
let client = Socks5MixnetClient::connect_new("provider_nym_address...").await?;
// Get the SOCKS5 proxy URL
let socks5_url = client.socks5_url();
println!("Configure your HTTP client to use: {}", socks5_url);
// Your HTTP client can now use the SOCKS5 proxy
// let http_client = reqwest::Client::builder()
// .proxy(reqwest::Proxy::all(&socks5_url)?)
// .build()?;
client.disconnect().await;
Ok(())
}Implementations§
Source§impl Socks5MixnetClient
impl Socks5MixnetClient
Sourcepub async fn connect_new<S: Into<String>>(
provider_mix_address: S,
) -> Result<Self>
pub async fn connect_new<S: Into<String>>( provider_mix_address: S, ) -> Result<Self>
Create a new client and connect to a network requester over the mixnet via SOCKS5 using ephemeral in-memory keys that are discarded at application close.
This is the zero-ceremony path when you already know the requester’s
address; it is shorthand for connect_with with
NetworkRequesterSelector::exact and the default listener bind.
Kept for backwards compatibility: it predates [connect_with] and overlaps
with the exact case, but existing callers pass an address string directly.
§Examples
use nym_sdk::mixnet;
#[tokio::main]
async fn main() {
let receiving_client = mixnet::MixnetClient::connect_new().await.unwrap();
let mut client = mixnet::Socks5MixnetClient::connect_new(receiving_client.nym_address().to_string()).await;
}
Sourcepub async fn connect_with(
requester: NetworkRequesterSelector,
bind: Option<SocketAddr>,
) -> Result<Self>
pub async fn connect_with( requester: NetworkRequesterSelector, bind: Option<SocketAddr>, ) -> Result<Self>
Create a new client and connect to a network requester chosen per the
given NetworkRequesterSelector: auto-discovered (Any),
country-restricted (InCountries), or a
known address (Exact).
The discovered requester enforces the Nym exit policy, so destinations outside that policy are refused at the exit regardless of which requester is selected.
bind sets the local SOCKS5 listener address; pass None for the default
127.0.0.1:1080, or Some(addr) to move it (for example when 1080 is
already taken, or to run more than one client at once).
§Examples
use nym_sdk::mixnet::{NetworkRequesterSelector, Socks5MixnetClient};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Any requester, weighted by performance, on the default port:
let any = Socks5MixnetClient::connect_with(NetworkRequesterSelector::any(), None).await?;
// Pinned to Switzerland or Germany, listening on 127.0.0.1:1081:
let pinned = Socks5MixnetClient::connect_with(
NetworkRequesterSelector::in_countries(["CH", "DE"])?,
Some("127.0.0.1:1081".parse()?),
)
.await?;
Ok(())
}Sourcepub fn nym_address(&self) -> &Recipient
pub fn nym_address(&self) -> &Recipient
Get the nym address of this client. The nym address is composed of the client identity, the client encryption key, and the gateway identity.
Sourcepub fn socks5_url(&self) -> String
pub fn socks5_url(&self) -> String
Get the SOCKS5 proxy URL that a HTTP(S) client can connect to.
Get a shallow clone of LaneQueueLengths. This is useful to manually implement some form
of backpressure logic.
Sourcepub async fn manually_overwrite_topology(&self, new_topology: NymTopology)
pub async fn manually_overwrite_topology(&self, new_topology: NymTopology)
Change the network topology used by this client for constructing sphinx packets into the provided one.
Sourcepub fn restore_automatic_topology_refreshing(&self)
pub fn restore_automatic_topology_refreshing(&self)
Restore default topology refreshing behaviour of this client.
Sourcepub async fn disconnect(self)
pub async fn disconnect(self)
Disconnect from the mixnet. Currently it is not supported to reconnect a disconnected client.
Sourcepub async fn wait_for_topology(
&self,
timeout: Duration,
) -> Result<(), NymTopologyError>
pub async fn wait_for_topology( &self, timeout: Duration, ) -> Result<(), NymTopologyError>
Wait for topology to become available, with a timeout.
Returns Ok(()) when topology is ready, or Err if timeout is reached.
Auto Trait Implementations§
impl !RefUnwindSafe for Socks5MixnetClient
impl !UnwindSafe for Socks5MixnetClient
impl Freeze for Socks5MixnetClient
impl Send for Socks5MixnetClient
impl Sync for Socks5MixnetClient
impl Unpin for Socks5MixnetClient
impl UnsafeUnpin for Socks5MixnetClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
Source§impl<T> Deprecatable for T
impl<T> Deprecatable for T
fn deprecate(self) -> Deprecated<Self>where
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> OptionalSet for T
impl<T> OptionalSet for T
Source§fn with_optional<F, T>(self, f: F, val: Option<T>) -> Self
fn with_optional<F, T>(self, f: F, val: Option<T>) -> Self
Some), the provided closure is applied.
Otherwise self is returned with no modifications.Source§fn with_validated_optional<F, T, V, E>(
self,
f: F,
value: Option<T>,
validate: V,
) -> Result<Self, E>
fn with_validated_optional<F, T, V, E>( self, f: F, value: Option<T>, validate: V, ) -> Result<Self, E>
Some) it is validated and then the provided closure is applied.
Otherwise self is returned with no modifications.Source§fn with_optional_env<F, T>(self, f: F, val: Option<T>, env_var: &str) -> Self
fn with_optional_env<F, T>(self, f: F, val: Option<T>, env_var: &str) -> Self
Some), the provided closure is applied.
Otherwise, if the environment was configured and the corresponding variable was set,
the value is parsed using the FromStr implementation and the closure is applied on that instead.
Finally, if none of those were available, self is returned with no modifications.Source§fn with_optional_custom_env<F, T, G>(
self,
f: F,
val: Option<T>,
env_var: &str,
parser: G,
) -> Self
fn with_optional_custom_env<F, T, G>( self, f: F, val: Option<T>, env_var: &str, parser: G, ) -> Self
Some), the provided closure is applied.
Otherwise, if the environment was configured and the corresponding variable was set,
the value is parsed using the provided parser and the closure is applied on that instead.
Finally, if none of those were available, self is returned with no modifications.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.