Skip to main content

Crate naia_shared

Crate naia_shared 

Source
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
BandwidthConfig
Per-connection outbound bandwidth budget. Applied symmetrically to server-outbound and client-outbound send loops.
BandwidthMonitor
Rolling time-window byte counter for measuring incoming or outgoing bandwidth.
BaseConnection
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
ChannelKind
ChannelKind - should be one unique value for each type of Channel
ChannelKinds
Registry mapping Channel types to compact wire net-IDs and their ChannelSettings.
ChannelSettings
Configuration for a channel: delivery mode, traffic direction, and priority criticality.
ComponentFieldUpdate
A single serialised field update payload for a component, identified by field index.
ComponentKind
ComponentKind - should be one unique value for each type of Component
ComponentKinds
A map to hold all component types
ComponentUpdate
A serialised component-field update payload together with its ComponentKind tag.
CompressionConfig
Per-direction zstd compression settings for a connection.
ConnectionConfig
Contains Config properties which will be used by a Server or Client
ConnectionStats
Snapshot of per-connection network diagnostics.
Decoder
Packet decoder (no-op variant: passes payload through unchanged).
DiffMask
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).
EntityAuthAccessor
Read-only handle to an entity’s shared authority state; cloneable and safe to embed in components.
EntityConverterMut
Stateful converter used when writing messages: looks up or reserves host-side entity slots on demand.
EntityDoesNotExistError
Error returned when an entity look-up fails during entity-to-global conversion.
EntityIndex
Per-user dense index for a GlobalEntity known to a UserDiffHandler.
EntityMessageReceiver
Stateless helper that routes incoming entity messages into per-entity ordered queues.
EntityPriorityMut
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.
EntityPriorityRef
Read-only view of an entity’s priority state in one priority layer (global OR per-user). Acquired via the corresponding *_priority() method on WorldServer, Client, or their Bevy-adapter equivalents.
EntityProperty
A component field that stores an optional reference to another entity, with lifecycle tracking across host/remote/delegated states.
FakeEntityConverter
No-op converter that always succeeds with entity ID 0; useful in test contexts where real mapping is not needed.
FileBitWriter
GameDuration
Unsigned millisecond duration between two GameInstant values.
GameInstant
Server-relative millisecond timestamp that wraps at 2^22 ms (~70 minutes).
GlobalDiffHandler
Global registry of mutation channels for every (entity, component) pair, used to fan out property changes to per-user dirty queues.
GlobalEntity
Stable, process-wide identifier for a replicated entity, independent of any ECS-local handle.
GlobalEntityMap
Bidirectional map between world-local entities and their stable GlobalEntity identifiers.
GlobalPriorityState
Sender-wide priority layer. One instance lives on WorldServer. Entries are evicted on entity despawn.
GlobalRequestId
Globally-unique identifier for an outgoing request, spanning all connections.
GlobalResponseId
Globally-unique identifier for a response to a specific request.
HostAuthHandler
Server-side registry of per-entity authority channels, tracking which entities are delegated and their current status.
HostEntity
A host-assigned entity ID. Carries is_static so that static and dynamic entities from pools that both start at 0 remain distinct as hash map keys.
HostEntityAuthStatus
Combined view of an entity’s authority status from a specific endpoint’s perspective.
HostEntityChannel
Outbound state machine for a single host-owned entity, tracking its component set and authority sub-channel.
HostEntityGenerator
Issues and recycles wire-level HostEntity identifiers for a single connected user.
HostWorldManager
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.
LinkConditionerConfig
Contains configuration required to initialize a LinkConditioner
LocalEntityMap
Bidirectional lookup table between GlobalEntity identifiers and their connection-local HostEntity or RemoteEntity counterparts.
LocalResponseId
Connection-scoped u8 key correlating an incoming response with the original request.
LocalWorldManager
Unified manager for one connection’s host-side and remote-side entity state, routing commands and events between them.
LossMonitor
Rolling packet-loss estimator over the last 64 resolved packets. Tracks outcomes (acked vs lost) for PacketType::Data packets only; heartbeats and other non-data packets are excluded by the caller.
MessageContainer
A reference-counted wrapper around a heap-allocated Message trait object.
MessageKind
MessageKind - should be one unique value for each type of Message
MessageKinds
Registry mapping Message types to compact wire net-IDs and their deserializers.
MessageManager
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.
OutgoingPacket
OwnedBitReader
PingStore
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
PropertyMutator
Owned handle to a heap-allocated PropertyMutate implementor, used by EntityProperty to signal field changes.
Protocol
Builder and configuration container for a naia protocol definition.
ProtocolId
A unique identifier for a Protocol configuration.
Random
Container for cross-platform Random methods
ReliableSender
Retransmit-on-timeout sender that tracks unacknowledged messages and re-queues them after an RTT-based interval.
ReliableSettings
Tuning parameters for reliable channel delivery and backpressure.
RemoteEntity
A connection-local entity ID assigned by the remote peer, used on the receiving side of replication.
RemoteEntityChannel
Per-entity demultiplexer that buffers and reorders incoming messages from an unordered reliable channel into a causal stream.
RemoteWorldManager
Manages the inbound side of entity replication — entities whose authoritative state comes from the remote peer.
ReplicaDynMut
Mutable reference to a type-erased replicated component.
ReplicaDynMutWrapper
Type-erasing wrapper for a ReplicaDynMutTrait implementor.
ReplicaDynRef
Shared reference to a type-erased replicated component.
ReplicaDynRefWrapper
Type-erasing wrapper for a ReplicaDynRefTrait implementor.
ReplicaMutWrapper
Type-erasing wrapper around a ReplicaMutTrait<R> implementation.
ReplicaRefWrapper
Type-erasing wrapper around a ReplicaRefTrait<R> implementation.
RequestOrResponse
Wire envelope that carries either a request or a response payload with its local correlation ID.
ResourceAlreadyExists
Error returned when attempting to insert a resource type that is already present in the registry.
ResourceKinds
Protocol-wide table marking which ComponentKinds are Replicated Resources (vs ordinary components).
ResourceRegistry
Per-World bidirectional map between Resource TypeId and the hidden GlobalEntity carrying that resource as a single component.
ResponseReceiveKey
Typed token held by the receiver to identify which request a response answers.
ResponseSendKey
Typed token held by the sender to identify a pending request when its response arrives.
SerdeErr
The error message when failing to serialize/deserialize to/from the bit stream.
SharedGlobalWorldManager
Shared helpers for world-manager implementations that operate on the global entity registry.
SocketConfig
Contains Config properties which will be shared by Server and Client sockets
StandardHeader
Reliability header prepended to every naia packet carrying sequence and ack information.
TickBufferSettings
Capacity settings for a tick-buffered channel.
TimeQueue
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.
UserPriorityState
Per-connection priority layer. One instance lives on each user Connection (and on the client’s single Connection). Entries are evicted on scope exit for that user.
WorldReader
Stateless helper that deserializes entity update and message payloads from a bit stream into a LocalWorldManager.

Enums§

AuthorityError
Errors raised by entity- and resource-authority operations.
ChannelCriticality
Priority tier for a channel in the unified priority-sort send loop.
ChannelDirection
Permitted send direction(s) for a channel.
ChannelMode
Delivery semantics for a channel.
CompressionMode
Selects the zstd compression strategy applied to a direction of traffic.
DisconnectReason
Why a connection was terminated.
EntityAuthChannelState
Publication/delegation lifecycle state of an entity’s authority channel.
EntityAuthStatus
Authority lifecycle state for a delegated entity as observed by one endpoint.
EntityCommand
Wire command syncing entity lifecycle and authority transitions from host to remote.
EntityEvent
ECS-level event produced by the replication system when the remote world state changes.
EntityMessage
Per-entity ordered wire message carrying a single entity lifecycle or authority event.
EntityMessageType
Wire discriminant identifying the kind of entity/component event carried in an EntityMessage.
HostType
Whether a given endpoint is a server or a client.
LocalRequestOrResponseId
Connection-local discriminated ID that identifies a packet as carrying a request or a response.
OwnedLocalEntity
A connection-local entity ID that records whether the entity is host-owned or remote-owned.
PacketType
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 GameInstant in 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§

BigMapKey
Key type for BigMap: must be convertible to/from u64.
BitWrite
Channel
Marker trait for types that represent a named communication channel.
ChannelReceiver
Trait implemented by all channel receivers that surface typed payloads.
ChannelSender
Core send-side trait implemented by every channel sender variant.
ConstBitLength
EntityAndGlobalEntityConverter
Bidirectional conversion between a world-type entity E and a GlobalEntity.
GlobalEntitySpawner
Extends EntityAndGlobalEntityConverter with the ability to create, reserve, and destroy entity mappings.
GlobalWorldManagerType
Global world state queries needed during message and component serialization.
InScopeEntities
Query interface for determining whether a given entity is currently within a receiver’s scope.
LocalEntityAndGlobalEntityConverter
Conversions between the connection-local host/remote entity representations and the global entity space.
LocalEntityAndGlobalEntityConverterMut
Mutable extension of LocalEntityAndGlobalEntityConverter that can allocate new host-side entity slots.
Message
Core trait for all naia message types — provides serialization, kind lookup, and entity-relation hooks.
MessageBevy
Core trait for all naia message types — provides serialization, kind lookup, and entity-relation hooks.
MessageBuilder
Factory trait that deserializes a concrete Message from raw bits.
MessageChannelSender
Extended sender trait for message channels that writes wire bits and supports request/response lifecycle.
MutChannelType
Internal trait implemented by the concrete mutation channel; produces receivers and propagates property-index notifications.
Named
Trait for types with a stable protocol name.
OutgoingPriorityHook
Per-tick hook the send loop calls to (a) advance accumulators for dirty entity bundles, and (b) reset accumulators for bundles that fully drained.
PacketNotifiable
Represents a manager that must be notified when packets have been dropped or delivered
PropertyMutate
Tracks which Properties have changed and need to be queued for syncing with the Client
ProtocolPlugin
Extension point for registering channels, messages, and components into a Protocol.
ReplicaDynMutTrait
Trait for mutable access to a type-erased replicated component.
ReplicaDynRefTrait
Trait for shared access to a type-erased replicated component.
ReplicaMutTrait
Trait for typed mutable access to a concrete replicated component.
ReplicaRefTrait
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
ReplicateBevy
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
ReplicateBuilder
Factory trait for deserializing a concrete Replicate component or its partial updates from raw bits.
ReplicatedComponent
Marker trait equivalent to Replicate; auto-implemented for all Replicate types 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.
SerdeBevyClient
A trait for objects that can be serialized to a bitstream.
SerdeBevyServer
A trait for objects that can be serialized to a bitstream.
SerdeBevyShared
A trait for objects that can be serialized to a bitstream.
SerdeFloatConversion
SerdeIntegerConversion
SerdeInternal
A trait for objects that can be serialized to a bitstream.
WorldMutType
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
WorldRefType
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§

IdentityToken
MessageIndex
Per-channel sequence number for reliable message ordering and deduplication.
OrderedReliableReceiver
Reliable receiver that delivers messages to callers strictly in send order.
PacketIndex
Sequential 16-bit index assigned to each outgoing packet for acknowledgement tracking.
PingIndex
Monotone wrapping sequence number used to correlate pings and pongs.
ShortMessageIndex
Compact 8-bit message index used by tick-buffered channels.
SignedFloat
SignedInteger
SignedVariableFloat
SignedVariableInteger
SubCommandId
Sequence number identifying a sub-command within a top-level entity command.
Tick
Server-side tick counter, wrapping at u16::MAX.
UnorderedReliableReceiver
Reliable receiver that delivers messages to callers as soon as they arrive, without ordering.
UnsignedFloat
UnsignedInteger
UnsignedVariableFloat
UnsignedVariableInteger

Derive Macros§

Channel
Derives the Channel trait for a given struct
Message
Derives the Message trait for a given struct
MessageBevy
Derives the Message trait for a given struct, for the Bevy adapter
Replicate
Derives the Replicate trait for a given struct
ReplicateBevy
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
SerdeBevyClient
SerdeBevyServer
SerdeBevyShared
SerdeInternal