1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//! The mixnet component of the Rust SDK for the Nym platform.
//!
//! **Start here:** [`MixnetClient::connect_new`] for an ephemeral client, or
//! [`MixnetClientBuilder`] for full configuration. See the
//! [tutorial](https://nymtech.net/docs/developers/rust/mixnet/tutorial) for a
//! step-by-step walkthrough.
//!
//! # Message example
//!
//! Send and receive raw message payloads through the Mixnet:
//!
//! ```no_run
//! use nym_sdk::mixnet::{self, MixnetMessageSender};
//!
//! #[tokio::main]
//! async fn main() {
//! let mut client = mixnet::MixnetClient::connect_new().await.unwrap();
//!
//! let our_address = client.nym_address();
//! println!("Our client nym address is: {our_address}");
//!
//! client.send_plain_message(*our_address, "hello there").await.unwrap();
//!
//! println!("Waiting for message");
//! if let Some(received) = client.wait_for_messages().await {
//! for r in received {
//! println!("Received: {}", String::from_utf8_lossy(&r.message));
//! }
//! }
//!
//! client.disconnect().await;
//! }
//! ```
//!
//! # Stream example
//!
//! Persistent bidirectional byte channels using
//! [`AsyncRead`](tokio::io::AsyncRead) + [`AsyncWrite`](tokio::io::AsyncWrite)
//! — see the [`stream`] submodule for the full API:
//!
//! ```no_run
//! use nym_sdk::mixnet;
//! use tokio::io::{AsyncReadExt, AsyncWriteExt};
//!
//! #[tokio::main]
//! async fn main() {
//! let mut sender = mixnet::MixnetClient::connect_new().await.unwrap();
//! let mut receiver = mixnet::MixnetClient::connect_new().await.unwrap();
//! let receiver_addr = *receiver.nym_address();
//!
//! // Receiver creates a listener (activates stream mode)
//! let mut listener = receiver.listener().unwrap();
//!
//! // Sender opens a stream to the receiver
//! let mut outbound = sender.open_stream(receiver_addr, None).await.unwrap();
//!
//! // Receiver accepts the incoming stream
//! let mut inbound = listener.accept().await.unwrap();
//!
//! // Write and read — just like a TCP socket
//! outbound.write_all(b"hello").await.unwrap();
//! outbound.flush().await.unwrap();
//!
//! let mut buf = vec![0u8; 1024];
//! let n = inbound.read(&mut buf).await.unwrap();
//! println!("Got: {}", String::from_utf8_lossy(&buf[..n]));
//!
//! // Streams deregister on drop, then disconnect clients
//! drop(outbound);
//! drop(inbound);
//! sender.disconnect().await;
//! receiver.disconnect().await;
//! }
//! ```
//!
// Local module exports
pub use ;
pub use Config;
pub use MixnetClient;
pub use MixnetClientSender;
pub use StoragePaths;
pub use ;
pub use Socks5MixnetClient;
pub use ;
pub use MixnetMessageSender;
// Re-exports from nym-client-core with documentation
pub use GatewaysDetailsStore;
/// Information about a currently active gateway connection.
pub use ActiveGateway;
/// Information about a gateway that failed to connect or is invalid.
pub use BadGateway;
/// Registration details for a gateway including keys and connection info.
pub use GatewayRegistration;
/// Ephemeral (in-memory) storage backend. Data is lost when the client disconnects.
pub use Ephemeral;
/// Trait for mixnet client storage implementations.
pub use MixnetClientStorage;
/// On-disk persistent storage backend. Data survives client restarts.
pub use OnDiskPersistent;
/// Receiver for client lifecycle events.
pub use EventReceiver;
/// Sender for client lifecycle events.
pub use EventSender;
/// Events emitted by the mixnet client during its lifecycle.
pub use MixnetClientEvent;
/// A message to be sent through the mixnet.
pub use InputMessage;
/// In-memory ephemeral key storage. Keys are lost when the client disconnects.
pub use InMemEphemeralKeys;
/// Trait for key storage implementations.
pub use KeyStore;
/// On-disk key storage. Keys persist across client restarts.
pub use OnDiskKeys;
/// The client's cryptographic keys (identity, encryption, gateway shared key).
pub use ClientKeys;
/// Events related to mix traffic (packet sending/receiving).
pub use MixTrafficEvent;
/// File-system backed reply SURB storage.
pub use Backend as ReplyStorage;
/// Combined reply storage supporting multiple backends.
pub use CombinedReplyStorage;
/// Empty reply storage that discards all SURBs. Replies will not work.
pub use Empty as EmptyReplyStorage;
/// Trait for reply SURB storage implementations.
pub use ReplyStorageBackend;
// Re-exports from nym-credential-storage
/// Ephemeral (in-memory) credential storage. Credentials are lost on disconnect.
pub use EphemeralStorage as EphemeralCredentialStorage;
/// A ticketbook stored in the credential storage.
pub use StoredIssuedTicketbook;
/// Trait for credential storage implementations.
pub use Storage as CredentialStorage;
// Re-exports from nym-crypto
/// Ed25519 digital signature cryptography (signing and verification).
pub use ed25519;
/// X25519 elliptic curve Diffie-Hellman key exchange.
pub use x25519;
// Re-exports from nym-network-defaults
/// Network configuration details (API endpoints, contract addresses, etc.).
pub use NymNetworkDetails;
// Re-exports from nym-socks5-client-core
/// SOCKS5 proxy configuration.
pub use Socks5;
// Re-exports from nym-sphinx
/// The Ed25519 public key identifying a client.
pub use ClientIdentity;
/// A Nym network address for sending messages. Format: `identity.encryption@gateway`.
pub use Recipient;
/// Error when parsing a [`Recipient`] from a string.
pub use RecipientFormattingError;
/// The Ed25519 public key identifying a mix node or gateway.
pub use NodeIdentity;
/// A tag identifying an anonymous sender, used for sending replies via SURBs.
pub use AnonymousSenderTag;
/// A message reconstructed from Sphinx packets after traversing the mixnet.
pub use ReconstructedMessage;
// Re-exports from nym-statistics-common
/// Events related to connection statistics.
pub use ConnectionStatsEvent;
/// Statistics events that can be reported by clients.
pub use ClientStatsEvents;
/// Channel for sending statistics events to be reported.
pub use ClientStatsSender;
// Re-exports from nym-task
/// Queue lengths for different transmission lanes, useful for backpressure.
pub use LaneQueueLengths;
/// Transmission lane for prioritizing different types of traffic.
pub use TransmissionLane;
// Re-exports from nym-topology
/// Trait for providing network topology information.
pub use TopologyProvider;
/// The network topology containing mix nodes, gateways, and their routing info.
pub use NymTopology;