1#![allow(elided_lifetimes_in_paths)]
10#![allow(missing_debug_implementations)]
11#![cfg_attr(not(fuzzing), warn(missing_docs))]
25#![allow(unreachable_pub)]
26#![allow(clippy::cognitive_complexity)]
27#![allow(clippy::too_many_arguments)]
28#![allow(clippy::use_self)]
29#![warn(dead_code)]
31#![allow(clippy::field_reassign_with_default)]
32#![allow(clippy::module_inception)]
33#![allow(clippy::useless_vec)]
34#![allow(private_interfaces)]
35#![allow(clippy::upper_case_acronyms)]
36#![allow(clippy::type_complexity)]
37#![allow(clippy::manual_clamp)]
38#![allow(clippy::needless_range_loop)]
39#![allow(clippy::borrowed_box)]
40#![allow(clippy::manual_strip)]
41#![allow(clippy::if_same_then_else)]
42#![allow(clippy::ptr_arg)]
43#![allow(clippy::incompatible_msrv)]
44#![allow(clippy::await_holding_lock)]
45#![allow(clippy::single_match)]
46#![allow(clippy::must_use_candidate)]
47#![allow(clippy::let_underscore_must_use)]
48#![allow(clippy::let_underscore_untyped)]
49#![allow(clippy::large_enum_variant)]
50#![allow(clippy::too_many_lines)]
51#![allow(clippy::result_large_err)]
52#![allow(clippy::enum_glob_use)]
53#![allow(clippy::match_like_matches_macro)]
54#![allow(clippy::struct_field_names)]
55#![allow(clippy::cast_precision_loss)]
56#![allow(clippy::cast_sign_loss)]
57#![allow(clippy::cast_possible_wrap)]
58#![allow(clippy::cast_possible_truncation)]
59#![allow(clippy::unnecessary_wraps)]
60#![allow(clippy::doc_markdown)]
61#![allow(clippy::module_name_repetitions)]
62#![allow(clippy::items_after_statements)]
63#![allow(clippy::missing_panics_doc)]
64#![allow(clippy::missing_errors_doc)]
65#![allow(clippy::similar_names)]
66#![allow(clippy::new_without_default)]
67#![allow(clippy::unwrap_or_default)]
68#![allow(clippy::uninlined_format_args)]
69#![allow(clippy::redundant_field_names)]
70#![allow(clippy::redundant_closure_for_method_calls)]
71#![allow(clippy::redundant_pattern_matching)]
72#![allow(clippy::option_if_let_else)]
73#![allow(clippy::trivially_copy_pass_by_ref)]
74#![allow(clippy::len_without_is_empty)]
75#![allow(clippy::explicit_auto_deref)]
76#![allow(clippy::blocks_in_conditions)]
77#![allow(clippy::collapsible_else_if)]
78#![allow(clippy::collapsible_if)]
79#![allow(clippy::unnecessary_cast)]
80#![allow(clippy::needless_bool)]
81#![allow(clippy::needless_borrow)]
82#![allow(clippy::redundant_static_lifetimes)]
83#![allow(clippy::match_ref_pats)]
84#![allow(clippy::should_implement_trait)]
85#![allow(clippy::wildcard_imports)]
86#![warn(unused_must_use)]
87#![allow(improper_ctypes)]
88#![allow(improper_ctypes_definitions)]
89#![allow(non_upper_case_globals)]
90#![allow(clippy::wrong_self_convention)]
91#![allow(clippy::vec_init_then_push)]
92#![allow(clippy::format_in_format_args)]
93#![allow(clippy::from_over_into)]
94#![allow(clippy::useless_conversion)]
95#![allow(clippy::never_loop)]
96#![allow(dropping_references)]
97#![allow(non_snake_case)]
98#![allow(clippy::unnecessary_literal_unwrap)]
99#![allow(clippy::assertions_on_constants)]
100#![allow(unused_imports)]
101
102use std::{
103 fmt,
104 net::{IpAddr, SocketAddr},
105 ops,
106};
107
108mod cid_queue;
110pub mod coding;
111mod constant_time;
112mod range_set;
113pub mod transport_parameters;
114mod varint;
115
116pub use varint::{VarInt, VarIntBoundsExceeded};
117
118pub mod config;
123pub mod connection;
125pub mod endpoint;
127pub mod frame;
129pub mod packet;
131pub mod shared;
133pub mod transport_error;
135pub mod candidate_discovery;
138pub mod cid_generator;
140mod congestion;
141mod protocol_violations;
142#[cfg(test)]
143mod protocol_violations_tests;
144
145pub mod nat_traversal_api;
148mod token;
149mod token_memory_cache;
150pub mod tracing;
152
153pub mod crypto;
156pub mod discovery;
158pub mod nat_traversal;
160pub mod transport;
162
163pub mod auth;
166pub mod chat;
168pub mod quic_node;
172pub mod stats_dashboard;
174pub mod terminal_ui;
176
177pub mod compliance_validator;
180
181pub mod logging;
184
185pub mod metrics;
187
188pub mod relay;
190
191pub mod trust;
193
194#[cfg(any(feature = "ring", feature = "aws-lc-rs"))]
196pub mod token_v2;
197
198pub mod high_level;
200
201pub use high_level::{
203 Accept, Connecting, Connection as HighLevelConnection, Endpoint,
204 RecvStream as HighLevelRecvStream, SendStream as HighLevelSendStream,
205};
206
207pub use crypto::raw_public_keys::key_utils::{
209 derive_peer_id_from_key_bytes, derive_peer_id_from_public_key, generate_ed25519_keypair,
210 public_key_from_bytes, public_key_to_bytes, verify_peer_id,
211};
212
213pub use candidate_discovery::{
215 CandidateDiscoveryManager, DiscoveryConfig, DiscoveryError, DiscoveryEvent, NetworkInterface,
216 ValidatedCandidate,
217};
218pub use connection::nat_traversal::{CandidateSource, CandidateState, NatTraversalRole};
219pub use connection::{
220 Chunk, Chunks, ClosedStream, Connection, ConnectionError, ConnectionStats, Datagrams, Event,
221 FinishError, ReadError, ReadableError, RecvStream, SendDatagramError, SendStream, StreamEvent,
222 Streams, WriteError, Written,
223};
224pub use endpoint::{
225 AcceptError, ConnectError, ConnectionHandle, DatagramEvent, Endpoint as LowLevelEndpoint,
226 Incoming,
227};
228pub use nat_traversal_api::{
229 BootstrapNode, CandidateAddress, EndpointRole, NatTraversalConfig, NatTraversalEndpoint,
230 NatTraversalError, NatTraversalEvent, NatTraversalStatistics, PeerId,
231};
232pub use quic_node::{NodeStats as QuicNodeStats, QuicNodeConfig, QuicP2PNode};
233pub use relay::{
234 AuthToken, RelayAction, RelayAuthenticator, RelayConnection, RelayConnectionConfig, RelayError,
235 RelayEvent, RelayResult, SessionId, SessionManager, SessionState,
236};
237pub use shared::{ConnectionId, EcnCodepoint, EndpointEvent};
238pub use transport_error::{Code as TransportErrorCode, Error as TransportError};
239
240pub const DEFAULT_SUPPORTED_VERSIONS: &[u32] = &[
249 0x00000001, 0xff00_001d, ];
252
253#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
255#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
256pub enum Side {
257 Client = 0,
259 Server = 1,
261}
262
263impl Side {
264 #[inline]
265 pub fn is_client(self) -> bool {
267 self == Self::Client
268 }
269
270 #[inline]
271 pub fn is_server(self) -> bool {
273 self == Self::Server
274 }
275}
276
277impl ops::Not for Side {
278 type Output = Self;
279 fn not(self) -> Self {
280 match self {
281 Self::Client => Self::Server,
282 Self::Server => Self::Client,
283 }
284 }
285}
286
287#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
289#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
290pub enum Dir {
291 Bi = 0,
293 Uni = 1,
295}
296
297impl Dir {
298 fn iter() -> impl Iterator<Item = Self> {
299 [Self::Bi, Self::Uni].iter().cloned()
300 }
301}
302
303impl fmt::Display for Dir {
304 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
305 use Dir::*;
306 f.pad(match *self {
307 Bi => "bidirectional",
308 Uni => "unidirectional",
309 })
310 }
311}
312
313#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
315#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
316pub struct StreamId(u64);
317
318impl fmt::Display for StreamId {
319 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
320 let initiator = match self.initiator() {
321 Side::Client => "client",
322 Side::Server => "server",
323 };
324 let dir = match self.dir() {
325 Dir::Uni => "uni",
326 Dir::Bi => "bi",
327 };
328 write!(
329 f,
330 "{} {}directional stream {}",
331 initiator,
332 dir,
333 self.index()
334 )
335 }
336}
337
338impl StreamId {
339 pub fn new(initiator: Side, dir: Dir, index: u64) -> Self {
341 Self((index << 2) | ((dir as u64) << 1) | initiator as u64)
342 }
343 pub fn initiator(self) -> Side {
345 if self.0 & 0x1 == 0 {
346 Side::Client
347 } else {
348 Side::Server
349 }
350 }
351 pub fn dir(self) -> Dir {
353 if self.0 & 0x2 == 0 { Dir::Bi } else { Dir::Uni }
354 }
355 pub fn index(self) -> u64 {
357 self.0 >> 2
358 }
359}
360
361impl From<StreamId> for VarInt {
362 fn from(x: StreamId) -> Self {
363 unsafe { Self::from_u64_unchecked(x.0) }
364 }
365}
366
367impl From<VarInt> for StreamId {
368 fn from(v: VarInt) -> Self {
369 Self(v.0)
370 }
371}
372
373impl From<StreamId> for u64 {
374 fn from(x: StreamId) -> Self {
375 x.0
376 }
377}
378
379impl coding::Codec for StreamId {
380 fn decode<B: bytes::Buf>(buf: &mut B) -> coding::Result<Self> {
381 VarInt::decode(buf).map(|x| Self(x.into_inner()))
382 }
383 fn encode<B: bytes::BufMut>(&self, buf: &mut B) {
384 match VarInt::from_u64(self.0) {
386 Ok(varint) => varint.encode(buf),
387 Err(_) => {
388 VarInt::MAX.encode(buf);
390 }
391 }
392 }
393}
394
395#[derive(Debug)]
397#[must_use]
398pub struct Transmit {
399 pub destination: SocketAddr,
401 pub ecn: Option<EcnCodepoint>,
403 pub size: usize,
405 pub segment_size: Option<usize>,
408 pub src_ip: Option<IpAddr>,
410}
411
412#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
414pub(crate) use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
415#[cfg(all(target_family = "wasm", target_os = "unknown"))]
416pub(crate) use web_time::{Duration, Instant, SystemTime, UNIX_EPOCH};
417
418pub(crate) const LOC_CID_COUNT: u64 = 8;
424pub(crate) const RESET_TOKEN_SIZE: usize = 16;
425pub(crate) const MAX_CID_SIZE: usize = 20;
426pub(crate) const MIN_INITIAL_SIZE: u16 = 1200;
427pub(crate) const INITIAL_MTU: u16 = 1200;
429pub(crate) const MAX_UDP_PAYLOAD: u16 = 65527;
430pub(crate) const TIMER_GRANULARITY: Duration = Duration::from_millis(1);
431pub(crate) const MAX_STREAM_COUNT: u64 = 1 << 60;
433
434pub use cid_generator::RandomConnectionIdGenerator;
436pub use config::{
437 AckFrequencyConfig, ClientConfig, EndpointConfig, MtuDiscoveryConfig, ServerConfig,
438 TransportConfig,
439};
440
441pub use crypto::pqc::{
443 HybridKem, HybridPreference, HybridSignature, MlDsa65, MlKem768, PqcConfig, PqcConfigBuilder,
444 PqcError, PqcMode, PqcResult,
445};
446pub(crate) use frame::Frame;
447pub use token::TokenStore;
448pub(crate) use token::{NoneTokenLog, ResetToken, TokenLog};
449pub(crate) use token_memory_cache::TokenMemoryCache;