Skip to main content

nym_smolmix/
lib.rs

1// Copyright 2024-2026 - Nym Technologies SA <contact@nymtech.net>
2
3#![doc = include_str!("ARCHITECTURE.md")]
4
5mod bridge;
6mod error;
7mod tunnel;
8
9/// Error type for all fallible smolmix operations.
10pub use error::SmolmixError;
11
12/// The IPv4/IPv6 address pair allocated to this tunnel by the IPR.
13pub use tunnel::IpPair;
14
15/// A Nym mixnet address, used to target a specific IPR exit node.
16pub use tunnel::Recipient;
17
18/// A TCP stream routed through the mixnet. Implements `AsyncRead + AsyncWrite`.
19///
20/// Obtained via [`Tunnel::tcp_connect`]. Use it anywhere a
21/// `tokio::net::TcpStream` is accepted: tokio-rustls, hyper, tokio-tungstenite,
22/// and the rest of the async ecosystem.
23///
24/// ```no_run
25/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
26/// # let tunnel = nym_smolmix::Tunnel::new().await?;
27/// use tokio::io::{AsyncReadExt, AsyncWriteExt};
28///
29/// let mut stream = tunnel.tcp_connect("1.1.1.1:80".parse()?).await?;
30/// stream.write_all(b"GET / HTTP/1.1\r\nHost: 1.1.1.1\r\nConnection: close\r\n\r\n").await?;
31/// let mut buf = Vec::new();
32/// stream.read_to_end(&mut buf).await?;
33/// # Ok(())
34/// # }
35/// ```
36pub use tunnel::TcpStream;
37
38/// A mixnet tunnel providing TCP and UDP socket access.
39pub use tunnel::Tunnel;
40
41/// Builder for configuring and creating a [`Tunnel`].
42///
43/// See [`Tunnel::builder()`] for usage.
44pub use tunnel::TunnelBuilder;
45
46/// A UDP socket routed through the mixnet. Supports `send_to` / `recv_from`.
47///
48/// Obtained via [`Tunnel::udp_socket`] or [`Tunnel::udp_socket_on`].
49///
50/// ```no_run
51/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
52/// # let tunnel = nym_smolmix::Tunnel::new().await?;
53/// let udp = tunnel.udp_socket().await?;
54/// udp.send_to(b"hello", "1.1.1.1:9999".parse()?).await?;
55///
56/// let mut buf = [0u8; 1024];
57/// let (len, _src) = udp.recv_from(&mut buf).await?;
58/// # Ok(())
59/// # }
60/// ```
61pub use tunnel::UdpSocket;