bitfold_core/
lib.rs

1#![warn(missing_docs)]
2
3//! Core foundational types and utilities.
4//!
5//! This module provides the minimal set of core utilities shared across all layers:
6//! - Configuration types
7//! - Error handling
8//! - Protocol constants
9//! - Memory utilities (packet pooling)
10//! - Network utilities (DNS resolution, IP parsing/formatting)
11//!
12//! Protocol-specific logic is in other modules:
13//! - `bitfold-protocol`: command codec, congestion control, bandwidth management, channels
14//! - `bitfold-peer`: command queue for session batching
15//! - `bitfold-host`: connection management, throughput monitoring
16
17/// Protocol constants shared across layers.
18pub mod constants {
19    /// The size of the fragment header.
20    pub const FRAGMENT_HEADER_SIZE: u8 = 4;
21    /// The size of the acknowledgment header.
22    pub const ACKED_PACKET_HEADER: u8 = 8;
23    /// The size of the arranging header.
24    pub const ARRANGING_PACKET_HEADER: u8 = 3;
25    /// The size of the standard header.
26    pub const STANDARD_HEADER_SIZE: u8 = 5;
27    /// The ordering stream that will be used to order on if none was specified.
28    pub const DEFAULT_ORDERING_STREAM: u8 = 255;
29    /// The sequencing stream that will be used to sequence packets on if none was specified.
30    pub const DEFAULT_SEQUENCING_STREAM: u8 = 255;
31    /// Default maximal number of fragments to size.
32    pub const MAX_FRAGMENTS_DEFAULT: u16 = 16;
33    /// Default maximal size of each fragment.
34    pub const FRAGMENT_SIZE_DEFAULT: u16 = 1024;
35    /// Maximum transmission unit of the payload.
36    ///
37    /// Derived from ethernet_mtu - ipv6_header_size - udp_header_size - packet header size
38    ///       1452 = 1500         - 40               - 8               - 8
39    ///
40    /// This is not strictly guaranteed -- there may be less room in an ethernet frame than this due to
41    /// variability in ipv6 header size.
42    pub const DEFAULT_MTU: u16 = 1452;
43    /// This is the current protocol version.
44    ///
45    /// Incremental monolithic protocol number.
46    pub const PROTOCOL_VERSION: u16 = 3;
47}
48
49/// Configuration options for the protocol and runtime.
50pub mod config;
51/// Either/Or type for type-level choices.
52pub mod either;
53/// Error types and results.
54pub mod error;
55/// Packet interception for custom processing.
56pub mod interceptor;
57/// Packet pooling for memory efficiency.
58pub mod packet_pool;
59/// Shared, reference-counted byte slices with zero-copy slicing.
60pub mod shared;
61/// Transport abstraction for pluggable I/O.
62pub mod transport;
63/// Utility functions for DNS resolution and IP operations.
64pub mod utilities;