Skip to main content

NetAdapterConfig

Struct NetAdapterConfig 

Source
pub struct NetAdapterConfig {
Show 17 fields pub bind_addr: SocketAddr, pub peer_addr: SocketAddr, pub psk: [u8; 32], pub role: ConnectionRole, pub static_keypair: Option<StaticKeypair>, pub peer_static_pubkey: Option<[u8; 32]>, pub default_reliability: ReliabilityConfig, pub packet_pool_size: usize, pub heartbeat_interval: Duration, pub session_timeout: Duration, pub batched_io: bool, pub handshake_retries: usize, pub handshake_timeout: Duration, pub socket_recv_buffer: Option<usize>, pub socket_send_buffer: Option<usize>, pub num_shards: u16, pub entity_keypair: Option<EntityKeypair>,
}
Expand description

Configuration for the Net adapter.

Fields§

§bind_addr: SocketAddr

Local bind address

§peer_addr: SocketAddr

Remote peer address

§psk: [u8; 32]

Pre-shared key (32 bytes)

§role: ConnectionRole

Connection role (initiator or responder)

§static_keypair: Option<StaticKeypair>

Our static keypair (required for responder)

§peer_static_pubkey: Option<[u8; 32]>

Peer’s static public key (required for initiator)

§default_reliability: ReliabilityConfig

Default reliability mode for new streams

§packet_pool_size: usize

Packet pool size

§heartbeat_interval: Duration

Heartbeat interval

§session_timeout: Duration

Session timeout

§batched_io: bool

Enable batched I/O (sendmmsg/recvmmsg on Linux)

§handshake_retries: usize

Maximum retries for handshake

§handshake_timeout: Duration

Handshake timeout

§socket_recv_buffer: Option<usize>

Socket receive buffer size (None = use system default of 64MB)

§socket_send_buffer: Option<usize>

Socket send buffer size (None = use system default of 64MB)

§num_shards: u16

Number of shards (used to map stream IDs to shard IDs on receive)

§entity_keypair: Option<EntityKeypair>

Entity keypair for L1 identity (optional — if absent, origin_hash stays 0)

Implementations§

Source§

impl NetAdapterConfig

Source

pub const DEFAULT_POOL_SIZE: usize = 64

Default packet pool size

Source

pub const DEFAULT_HEARTBEAT_INTERVAL: Duration

Default heartbeat interval

Source

pub const DEFAULT_SESSION_TIMEOUT: Duration

Default session timeout

Source

pub const DEFAULT_HANDSHAKE_RETRIES: usize = 3

Default handshake retries

Source

pub const DEFAULT_HANDSHAKE_TIMEOUT: Duration

Default handshake timeout

Source

pub const MAX_PACKET_POOL_SIZE: usize

Upper bound on packet_pool_size. Pre-fix this was 1 << 20 (1 048 576), which sounds defensive but ThreadLocalPool:: with_local_capacity eagerly pre-allocates size PacketBuilder instances of ~16 KB each — at the old ceiling that’s ~16 GiB up-front per session, a guaranteed OOM. The cap was intended to prevent OOM; pre-fix it just postponed the death by one validation step. 16 384 is well past every realistic production setting (the default is 64) while bounding the worst-case at ~256 MiB.

Source

pub const MAX_HANDSHAKE_RETRIES: usize = 1024

Upper bound on handshake_retries. Pre-fix unbounded; a misconfigured large value just took forever to fail. 1024 covers any realistic flaky-network policy; the default is 3.

Source

pub fn initiator( bind_addr: SocketAddr, peer_addr: SocketAddr, psk: [u8; 32], peer_static_pubkey: [u8; 32], ) -> Self

Create a new initiator configuration.

The initiator must know the responder’s static public key.

Source

pub fn responder( bind_addr: SocketAddr, peer_addr: SocketAddr, psk: [u8; 32], static_keypair: StaticKeypair, ) -> Self

Create a new responder configuration.

The responder provides its static keypair for authentication.

Source

pub fn with_num_shards(self, num_shards: u16) -> Self

Set the number of shards

Source

pub fn with_entity_keypair(self, keypair: EntityKeypair) -> Self

Set the entity keypair for L1 identity

Source

pub fn with_reliability(self, reliability: ReliabilityConfig) -> Self

Set the default reliability mode

Source

pub fn with_pool_size(self, size: usize) -> Self

Set the packet pool size

Source

pub fn with_heartbeat_interval(self, interval: Duration) -> Self

Set the heartbeat interval

Source

pub fn with_session_timeout(self, timeout: Duration) -> Self

Set the session timeout

Source

pub fn with_batched_io(self, enabled: bool) -> Self

Enable or disable batched I/O

Source

pub fn with_handshake(self, retries: usize, timeout: Duration) -> Self

Set handshake configuration

Source

pub fn with_socket_buffers(self, recv_size: usize, send_size: usize) -> Self

Set socket buffer sizes (useful for testing with smaller buffers)

Source

pub fn validate(&self) -> Result<(), String>

Validate the configuration

Source

pub fn is_initiator(&self) -> bool

Check if this is an initiator configuration

Source

pub fn is_responder(&self) -> bool

Check if this is a responder configuration

Trait Implementations§

Source§

impl Clone for NetAdapterConfig

Source§

fn clone(&self) -> NetAdapterConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NetAdapterConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more