Schema
Channels and events, frozen before networking starts. Both ends compare its fingerprint before any event is accepted.
Library active
DreamWeave's networking substrate: secure UDP between authenticated peers, with reliable-ordered and unreliable event channels and a schema handshake.
cargo add dream-netA multiplayer engine needs two kinds of traffic. A chat line, a spell cast or an inventory change must arrive exactly once and in order, however many packets the network loses. An actor’s position is stale the moment the next one exists, and resending it is worse than useless. Both kinds have to share one encrypted connection, reach only peers that proved who they are, and never let a hostile peer grow the server’s memory or crash it.
dream-net is that transport for the DreamWeave engine. It moves opaque event payloads between authenticated peers and stops there: it knows event ids, channels, peers and bytes, and never what an event means. Who may send what, and where it goes next, is decided above it.
The host hands dream-net an event id and bytes. They cross in a packet that many events share, inside an encrypted netcode datagram, and come out of the other host's poll with the sender attached.
Checks the event and its size against the schema, and copies the bytes into its channel's queue before returning.
Packs events from every channel into packets sized to one datagram. reliable numbers and acknowledges them; netcode encrypts them and sends them over UDP.
On the other host, after its update: lifecycle records and events in arrival order, with the authenticated sender.
Channels and events, frozen before networking starts. Both ends compare its fingerprint before any event is accepted.
Packet sizes, timers, and the byte budgets that bound every queue.
It is built on Más Bandwidth’s C libraries, vendored at pinned releases and compiled into the crate: netcode for connect tokens, encryption, replay protection and client slots, and reliable for packet acknowledgement, fragmentation and link statistics. dream-net adds the part they leave out: channels of events, packed many to a datagram, in its own bit-packed wire format.
update, poll, send,
flush. Nothing calls into the host from inside the transport.PeerId comes from the authenticated netcode slot and
carries a generation, so a handle to a peer that left never reaches the next one in its slot.use dream_net::{ChannelConfig, Schema, Server, ServerConfig, ServerEvent, TransportConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut schema = Schema::builder(1);
let reliable = schema.channel(ChannelConfig::reliable_ordered("reliable"))?;
let state = schema.channel(ChannelConfig::unreliable_unordered("state"))?;
schema.event("Chat", reliable, 256)?;
schema.event("ActorPosition", state, 28)?;
let schema = schema.build()?;
let chat = schema.event_id("Chat").expect("declared above");
let config = ServerConfig {
public_address: "127.0.0.1:0".parse()?,
protocol_id: 0x4452_4541_4d00_0001,
max_clients: 16,
transport: TransportConfig::default(),
};
let mut server = Server::new(config, &dream_net::generate_key(), schema, 0.0)?;
let mut buffer = [0u8; 256];
// once per frame, in one network phase
server.update(1.0 / 60.0);
while let Some(event) = server.poll_into(&mut buffer)? {
match event {
ServerEvent::Connected { peer, .. } => server.send(peer, chat, b"welcome")?,
ServerEvent::Message { peer, event, payload, .. } => {
println!("{peer} sent {event}: {:?}", &buffer[..payload]);
}
ServerEvent::Disconnected { .. } | ServerEvent::Rejected { .. } => {}
}
}
server.flush();
Ok(())
}
Luau scripts reach it through l3i, which binds dream-net as
the @dream/net module. The host still creates servers in Rust: the private key never reaches a
script.
Rust crate · 2.1.0
From your project's directory:
cargo add dream-net
Or by hand, in Cargo.toml:
[dependencies]
dream-net = "2.1.0"
Cargo reads a bare version as "this or any compatible newer release" and records the exact one in Cargo.lock.
[dependencies]
dream-net = { git = "https://github.com/DreamWeave-MP/dream-net" }
Cargo pins the commit it fetched in Cargo.lock; cargo update -p dream-net moves it forward.
Fixes AEAD nonce reuse in the netcode handshake (GHSA-8mrq-q9c6-h23v) by moving to netcode 1.5.0 and the NETCODE 1.03 protocol. 2.1.0 peers do not connect to 2.0.0 or 1.x peers: upgrade servers and clients together.
ConnectFailed { reason: TimedOut }. dream-net’s own wire format is unchanged.connect in the same process. That was 2.0.0’s stopgap for this advisory; netcode now makes a token used twice safe, and the server enforces one attempt per token, holding an unfinished token only for the address and salt that first presented it, for the token’s timeout. Still mint a new token for every attempt.The same digest as the crates.io index's checksum, which Cargo checks on every download.
The transport now runs on Más Bandwidth’s C netcode and reliable, vendored and compiled in, with single-use connect tokens and restart protection. The wire format is unchanged, so 2.0.0 and 1.x peers still connect to each other.
build.rs compiles the vendored C and refuses GCC, MSVC’s cl and fast-math flags rather than fall back. The crate declares links = "dream_net_native".Error::Netcode and generate_connect_token now carry NetcodeError, dream-net’s own type with the same variants and texts as netcode-official’s Error plus InvalidConnectTokenLifetime. Code that named or matched the old type must use NetcodeError.TransportConfig::reliable_config returns ReliableConfig and Connection::reliable_counters returns &ReliableCounters, dream-net’s own types, in place of the reliable crate’s Config and Counters.TransportConfig::validate refuses sent_packets_buffer_size and received_packets_buffer_size above 16384, the C reliable’s limit; 1.1.1 allowed 32768.connect in the same process, and a server refuses one that already established a session there, even after that session ended.NetcodeError, ReliableConfig and ReliableCounters.Server::with_max_token_lifetime and DEFAULT_MAX_CONNECT_TOKEN_LIFETIME, to set the token lifetime the start floor is built on.(MIT OR Apache-2.0) AND BSD-3-Clause AND ISC: dream-net’s own code is unchanged, and the vendored C carries its own terms. NOTICE.md reproduces every notice.MemoryUsage::reliable is now an upper bound on reliable’s endpoint, about 581 KB with the default TransportConfig, almost all of it fragment reassembly an idle connection does not hold.ConnectFailed at once, but keeps its session for mismatch_linger seconds, sending only its hello, so the server can report the mismatch too.Error::Netcode.The same digest as the crates.io index's checksum, which Cargo checks on every download.
Requires a ctutils with RUSTSEC-2026-0385 fixed, for the constant-time comparison behind netcode’s packet authentication.
The same digest as the crates.io index's checksum, which Cargo checks on every download.