Expand description
§Naia Shared
Common functionality shared between naia-server & naia-client crates.
Modules§
- default_
channels - Built-in default channel definitions (DefaultUnreliable, DefaultReliable, etc.).
- handshake
- Standard handshake protocol module for client identification and connection timing exchange.
- link_
condition_ logic - Logic shared between client & server sockets related to simulating network conditions
Structs§
- AckManager
- Keeps track of sent & received packets, and contains ack information that is copied into the standard header on each outgoing packet
- Bandwidth
Config - Per-connection outbound bandwidth budget. Applied symmetrically to server-outbound and client-outbound send loops.
- Bandwidth
Monitor - Rolling time-window byte counter for measuring incoming or outgoing bandwidth.
- Base
Connection - Represents a connection to a remote host, and provides functionality to manage the connection and the communications to it
- BigMap
- Auto-incrementing dense map that generates monotone
u64-backed typed keys. - BitCounter
- BitReader
- BitWriter
- Channel
Kind - ChannelKind - should be one unique value for each type of Channel
- Channel
Kinds - Registry mapping
Channeltypes to compact wire net-IDs and theirChannelSettings. - Channel
Settings - Configuration for a channel: delivery mode, traffic direction, and priority criticality.
- Component
Field Update - A single serialised field update payload for a component, identified by field index.
- Component
Kind - ComponentKind - should be one unique value for each type of Component
- Component
Kinds - A map to hold all component types
- Component
Update - A serialised component-field update payload together with its
ComponentKindtag. - Compression
Config - Per-direction zstd compression settings for a connection.
- Connection
Config - Contains Config properties which will be used by a Server or Client
- Connection
Stats - Snapshot of per-connection network diagnostics.
- Decoder
- Packet decoder (no-op variant: passes payload through unchanged).
- Diff
Mask - Variable-length bitmask where each bit tracks whether the corresponding property on a replicated component has been mutated and needs to be sent to the remote peer.
- Encoder
- Packet encoder (no-op variant: passes payload through unchanged).
- Entity
Auth Accessor - Read-only handle to an entity’s shared authority state; cloneable and safe to embed in components.
- Entity
Converter Mut - Stateful converter used when writing messages: looks up or reserves host-side entity slots on demand.
- Entity
Does NotExist Error - Error returned when an entity look-up fails during entity-to-global conversion.
- Entity
Index - Per-user dense index for a
GlobalEntityknown to aUserDiffHandler. - Entity
Message Receiver - Stateless helper that routes incoming entity messages into per-entity ordered queues.
- Entity
Priority Mut - Mutable handle for reading and setting an entity’s priority in one priority layer. Lazy-creates a state entry on first write so set-and-forget works even before the entity enters scope for that user.
- Entity
Priority Ref - Read-only view of an entity’s priority state in one priority layer
(global OR per-user). Acquired via the corresponding
*_priority()method onWorldServer,Client, or their Bevy-adapter equivalents. - Entity
Property - A component field that stores an optional reference to another entity, with lifecycle tracking across host/remote/delegated states.
- Fake
Entity Converter - No-op converter that always succeeds with entity ID 0; useful in test contexts where real mapping is not needed.
- File
BitWriter - Game
Duration - Unsigned millisecond duration between two
GameInstantvalues. - Game
Instant - Server-relative millisecond timestamp that wraps at 2^22 ms (~70 minutes).
- Global
Diff Handler - Global registry of mutation channels for every (entity, component) pair, used to fan out property changes to per-user dirty queues.
- Global
Entity - Stable, process-wide identifier for a replicated entity, independent of any ECS-local handle.
- Global
Entity Map - Bidirectional map between world-local entities and their stable
GlobalEntityidentifiers. - Global
Priority State - Sender-wide priority layer. One instance lives on
WorldServer. Entries are evicted on entity despawn. - Global
Request Id - Globally-unique identifier for an outgoing request, spanning all connections.
- Global
Response Id - Globally-unique identifier for a response to a specific request.
- Host
Auth Handler - Server-side registry of per-entity authority channels, tracking which entities are delegated and their current status.
- Host
Entity - A host-assigned entity ID. Carries
is_staticso that static and dynamic entities from pools that both start at 0 remain distinct as hash map keys. - Host
Entity Auth Status - Combined view of an entity’s authority status from a specific endpoint’s perspective.
- Host
Entity Channel - Outbound state machine for a single host-owned entity, tracking its component set and authority sub-channel.
- Host
Entity Generator - Issues and recycles wire-level
HostEntityidentifiers for a single connected user. - Host
World Manager - Drives outbound entity-lifecycle replication for one side of a connection, tracking delivery state and processing inbound authority responses.
- Instant
- Represents a specific moment in time
- KeyGenerator
- Simple implementation of a store that manages a recycling pool of u16 keys
- KeyGenerator32
- u32 variant of
crate::KeyGenerator— same recycling semantics, wider key space. Forked rather than generic-ified to keep the existing u16 generator’s call sites untouched. - Link
Conditioner Config - Contains configuration required to initialize a LinkConditioner
- Local
Entity Map - Bidirectional lookup table between
GlobalEntityidentifiers and their connection-localHostEntityorRemoteEntitycounterparts. - Local
Response Id - Connection-scoped u8 key correlating an incoming response with the original request.
- Local
World Manager - Unified manager for one connection’s host-side and remote-side entity state, routing commands and events between them.
- Loss
Monitor - Rolling packet-loss estimator over the last 64 resolved packets.
Tracks outcomes (acked vs lost) for
PacketType::Datapackets only; heartbeats and other non-data packets are excluded by the caller. - Message
Container - A reference-counted wrapper around a heap-allocated
Messagetrait object. - Message
Kind - MessageKind - should be one unique value for each type of Message
- Message
Kinds - Registry mapping
Messagetypes to compact wire net-IDs and their deserializers. - Message
Manager - Handles incoming/outgoing messages, tracks the delivery status of Messages so that guaranteed Messages can be re-transmitted to the remote host
- MutReceiver
- Per-user receiver that accumulates dirty bits for a single component and notifies the user’s [
DirtySet] on first mutation. - Outgoing
Packet - Owned
BitReader - Ping
Store - Circular buffer that records the send time of outstanding pings indexed by
PingIndex. - Property
- A Property of an Component/Message, that contains data which must be tracked for updates
- Property
Mutator - Owned handle to a heap-allocated
PropertyMutateimplementor, used byEntityPropertyto signal field changes. - Protocol
- Builder and configuration container for a naia protocol definition.
- Protocol
Id - A unique identifier for a Protocol configuration.
- Random
- Container for cross-platform Random methods
- Reliable
Sender - Retransmit-on-timeout sender that tracks unacknowledged messages and re-queues them after an RTT-based interval.
- Reliable
Settings - Tuning parameters for reliable channel delivery and backpressure.
- Remote
Entity - A connection-local entity ID assigned by the remote peer, used on the receiving side of replication.
- Remote
Entity Channel - Per-entity demultiplexer that buffers and reorders incoming messages from an unordered reliable channel into a causal stream.
- Remote
World Manager - Manages the inbound side of entity replication — entities whose authoritative state comes from the remote peer.
- Replica
DynMut - Mutable reference to a type-erased replicated component.
- Replica
DynMut Wrapper - Type-erasing wrapper for a
ReplicaDynMutTraitimplementor. - Replica
DynRef - Shared reference to a type-erased replicated component.
- Replica
DynRef Wrapper - Type-erasing wrapper for a
ReplicaDynRefTraitimplementor. - Replica
MutWrapper - Type-erasing wrapper around a
ReplicaMutTrait<R>implementation. - Replica
RefWrapper - Type-erasing wrapper around a
ReplicaRefTrait<R>implementation. - Request
OrResponse - Wire envelope that carries either a request or a response payload with its local correlation ID.
- Resource
Already Exists - Error returned when attempting to insert a resource type that is already present in the registry.
- Resource
Kinds - Protocol-wide table marking which
ComponentKinds are Replicated Resources (vs ordinary components). - Resource
Registry - Per-
Worldbidirectional map between ResourceTypeIdand the hiddenGlobalEntitycarrying that resource as a single component. - Response
Receive Key - Typed token held by the receiver to identify which request a response answers.
- Response
Send Key - Typed token held by the sender to identify a pending request when its response arrives.
- Serde
Err - The error message when failing to serialize/deserialize to/from the bit stream.
- Shared
Global World Manager - Shared helpers for world-manager implementations that operate on the global entity registry.
- Socket
Config - Contains Config properties which will be shared by Server and Client sockets
- Standard
Header - Reliability header prepended to every naia packet carrying sequence and ack information.
- Tick
Buffer Settings - Capacity settings for a tick-buffered channel.
- Time
Queue - A queue for items marked by time, will only ever pop items from the queue if the time passes
- Timer
- A Timer with a given duration after which it will enter into a “Ringing” state. The Timer can be reset at an given time, or manually set to start “Ringing” again.
- Timestamp
- Returns the current wall-clock time as seconds since the Unix epoch.
- User
Priority State - Per-connection priority layer. One instance lives on each user
Connection(and on the client’s singleConnection). Entries are evicted on scope exit for that user. - World
Reader - Stateless helper that deserializes entity update and message payloads from a bit stream into a
LocalWorldManager.
Enums§
- Authority
Error - Errors raised by entity- and resource-authority operations.
- Channel
Criticality - Priority tier for a channel in the unified priority-sort send loop.
- Channel
Direction - Permitted send direction(s) for a channel.
- Channel
Mode - Delivery semantics for a channel.
- Compression
Mode - Selects the zstd compression strategy applied to a direction of traffic.
- Disconnect
Reason - Why a connection was terminated.
- Entity
Auth Channel State - Publication/delegation lifecycle state of an entity’s authority channel.
- Entity
Auth Status - Authority lifecycle state for a delegated entity as observed by one endpoint.
- Entity
Command - Wire command syncing entity lifecycle and authority transitions from host to remote.
- Entity
Event - ECS-level event produced by the replication system when the remote world state changes.
- Entity
Message - Per-entity ordered wire message carrying a single entity lifecycle or authority event.
- Entity
Message Type - Wire discriminant identifying the kind of entity/component event carried in an
EntityMessage. - Host
Type - Whether a given endpoint is a server or a client.
- Local
Request OrResponse Id - Connection-local discriminated ID that identifies a packet as carrying a request or a response.
- Owned
Local Entity - A connection-local entity ID that records whether the entity is host-owned or remote-owned.
- Packet
Type - Wire-level packet classification encoded in every packet header.
- Publicity
- Publication visibility of an entity — the shared axis used on both sides of the connection.
Constants§
- GAME_
TIME_ LIMIT - Wrapping period of
GameInstantin milliseconds (2^22 ≈ 70 minutes). - MTU_
SIZE_ BITS - MTU_
SIZE_ BYTES - The maximum of bytes that can be used for the payload of a given packet. (See #38 of http://ithare.com/64-network-dos-and-donts-for-game-engines-part-v-udp/)
Traits§
- BigMap
Key - Key type for
BigMap: must be convertible to/fromu64. - BitWrite
- Channel
- Marker trait for types that represent a named communication channel.
- Channel
Receiver - Trait implemented by all channel receivers that surface typed payloads.
- Channel
Sender - Core send-side trait implemented by every channel sender variant.
- Const
BitLength - Entity
AndGlobal Entity Converter - Bidirectional conversion between a world-type entity
Eand aGlobalEntity. - Global
Entity Spawner - Extends
EntityAndGlobalEntityConverterwith the ability to create, reserve, and destroy entity mappings. - Global
World Manager Type - Global world state queries needed during message and component serialization.
- InScope
Entities - Query interface for determining whether a given entity is currently within a receiver’s scope.
- Local
Entity AndGlobal Entity Converter - Conversions between the connection-local host/remote entity representations and the global entity space.
- Local
Entity AndGlobal Entity Converter Mut - Mutable extension of
LocalEntityAndGlobalEntityConverterthat can allocate new host-side entity slots. - Message
- Core trait for all naia message types — provides serialization, kind lookup, and entity-relation hooks.
- Message
Bevy - Core trait for all naia message types — provides serialization, kind lookup, and entity-relation hooks.
- Message
Builder - Factory trait that deserializes a concrete
Messagefrom raw bits. - Message
Channel Sender - Extended sender trait for message channels that writes wire bits and supports request/response lifecycle.
- MutChannel
Type - Internal trait implemented by the concrete mutation channel; produces receivers and propagates property-index notifications.
- Named
- Trait for types with a stable protocol name.
- Outgoing
Priority Hook - Per-tick hook the send loop calls to (a) advance accumulators for dirty entity bundles, and (b) reset accumulators for bundles that fully drained.
- Packet
Notifiable - Represents a manager that must be notified when packets have been dropped or delivered
- Property
Mutate - Tracks which Properties have changed and need to be queued for syncing with the Client
- Protocol
Plugin - Extension point for registering channels, messages, and components into a
Protocol. - Replica
DynMut Trait - Trait for mutable access to a type-erased replicated component.
- Replica
DynRef Trait - Trait for shared access to a type-erased replicated component.
- Replica
MutTrait - Trait for typed mutable access to a concrete replicated component.
- Replica
RefTrait - Trait for typed shared access to a concrete replicated component.
- Replicate
- A struct that implements Replicate is a Component, or otherwise, a container of Properties that can be scoped, tracked, and synced, with a remote host
- Replicate
Bevy - A struct that implements Replicate is a Component, or otherwise, a container of Properties that can be scoped, tracked, and synced, with a remote host
- Replicate
Builder - Factory trait for deserializing a concrete
Replicatecomponent or its partial updates from raw bits. - Replicated
Component - Marker trait equivalent to
Replicate; auto-implemented for allReplicatetypes when Bevy is not in use. - Request
- Marker trait for message types that expect a typed response.
- Response
- Marker trait for message types that are sent as a reply to a
Request. - Serde
- A trait for objects that can be serialized to a bitstream.
- Serde
Bevy Client - A trait for objects that can be serialized to a bitstream.
- Serde
Bevy Server - A trait for objects that can be serialized to a bitstream.
- Serde
Bevy Shared - A trait for objects that can be serialized to a bitstream.
- Serde
Float Conversion - Serde
Integer Conversion - Serde
Internal - A trait for objects that can be serialized to a bitstream.
- World
MutType - Structures that implement the WorldMutType trait will be able to be loaded into the Server at which point the Server will use this interface to keep the WorldMutType in-sync with it’s own Entities/Components
- World
RefType - Structures that implement the WorldMutType trait will be able to be loaded into the Server at which point the Server will use this interface to keep the WorldMutType in-sync with it’s own Entities/Components
Functions§
- generate_
identity_ token - sequence_
equal_ or_ greater_ than - Returns whether or not a wrapping number is equal to or greater than another sequence_equal_or_greater_than(1,2) will return false sequence_equal_or_greater_than(2,1) will return true sequence_equal_or_greater_than(1,1) will return true
- sequence_
equal_ or_ less_ than - Returns whether or not a wrapping number is equal to or less than another sequence_equal_or_less_than(1,2) will return true sequence_equal_or_less_than(2,1) will return false sequence_equal_or_less_than(1,1) will return true
- sequence_
greater_ than - Returns whether or not a wrapping number is greater than another sequence_greater_than(2,1) will return true sequence_greater_than(1,2) will return false sequence_greater_than(1,1) will return false
- sequence_
less_ than - Returns whether or not a wrapping number is greater than another sequence_less_than(1,2) will return true sequence_less_than(2,1) will return false sequence_less_than(1,1) will return false
- wrapping_
diff - Retrieves the wrapping difference between 2 u16 values wrapping_diff(1,2) will return 1 wrapping_diff(2,1) will return -1 wrapping_diff(65535,0) will return 1 wrapping_diff(0,65535) will return -1
Type Aliases§
- Identity
Token - Message
Index - Per-channel sequence number for reliable message ordering and deduplication.
- Ordered
Reliable Receiver - Reliable receiver that delivers messages to callers strictly in send order.
- Packet
Index - Sequential 16-bit index assigned to each outgoing packet for acknowledgement tracking.
- Ping
Index - Monotone wrapping sequence number used to correlate pings and pongs.
- Short
Message Index - Compact 8-bit message index used by tick-buffered channels.
- Signed
Float - Signed
Integer - Signed
Variable Float - Signed
Variable Integer - SubCommand
Id - Sequence number identifying a sub-command within a top-level entity command.
- Tick
- Server-side tick counter, wrapping at
u16::MAX. - Unordered
Reliable Receiver - Reliable receiver that delivers messages to callers as soon as they arrive, without ordering.
- Unsigned
Float - Unsigned
Integer - Unsigned
Variable Float - Unsigned
Variable Integer
Derive Macros§
- Channel
- Derives the Channel trait for a given struct
- Message
- Derives the Message trait for a given struct
- Message
Bevy - Derives the Message trait for a given struct, for the Bevy adapter
- Replicate
- Derives the Replicate trait for a given struct
- Replicate
Bevy - Derives the Replicate trait for a given struct, for the Bevy adapter.
Users add their own
#[derive(Component)]alongside this derive, so we skip auto-emitting a Bevy Component impl here. - Serde
- Serde
Bevy Client - Serde
Bevy Server - Serde
Bevy Shared - Serde
Internal