Transport and encryption
The three transports (ENet, Steam P2P, GameNetworkingSockets), choosing one with net.Transport, and how ENet sessions are encrypted.
Under the session layer, a transport moves bytes between peers. Mowo has three: ENet over UDP for direct and LAN play, Steam P2P through the SteamPlatform plugin, and GameNetworkingSockets (GNS), Valve's open-source connection library, over IP. By default a composite transport picks between ENet and Steam for each connection, and ENet sessions are encrypted at the application layer.
Transports
| Transport | net.Transport | Use it for | Encryption and who may join |
|---|---|---|---|
| Composite (ENet + Steam) | composite (default) | Most games: direct IP and LAN through ENet, Steam friends through the relay | ENet: the engine's handshake below. Steam: Steam's own, with ticket authentication |
| ENet | enet | Direct IP only, no platform relay even when Steam runs | The engine's handshake below |
| GameNetworkingSockets | gns | Dedicated and listen servers over IP in builds without Steam, when you want the library to pace traffic and split large messages | Always encrypted by GNS; the same join key or net.psk as ENet decides who gets in |
| Steam relay | steam | Every connection through Steam, never a direct socket | Steam's own |
net.Transport is followed until a session hosts or joins: the transport is remade when the value differs from the one it was made from, so set it in your project's config (a packaged game applies that file after the network module started) or, outside a shipped build, on the command line (--cvar=net.Transport=gns). A change during a session waits for the next one, and a transport your code set with NetworkManager::SetTransport is never replaced. A value the build cannot honour (GNS on a platform it is not built for, steam without the Steam client running, an unknown name) logs why and uses the composite transport FNetTransportFactory.
Steam builds already reach GNS: the Steam relay is GameNetworkingSockets inside the Steam client. Choose gns for builds that ship without Steam. A game can still ship both: with the SteamPlatform plugin enabled, a monolithic package links the Steam SDK and GNS into one executable, and each transport keeps calling its own library.
ENet
ENet's packet throttle, which drops unreliable packets at random once acknowledgements arrive later than the first round trips it measured, is turned off on every connection ENetTransport. A single hitch of a few dozen milliseconds on either machine used to bring it to zero, after which every snapshot and high-rate RPC to that peer was dropped until acknowledgements came back on time. Unreliable traffic is paced by the replication layer's per-peer byte budget (net.peer_byte_budget) instead.
GameNetworkingSockets
FGnsTransport connects a client and a host over UDP FGnsTransport. What it adds over ENet:
- Encryption on every connection. Each connection runs its own key exchange and encrypts with AES-GCM. A connection that would run unencrypted is closed.
- Pacing. Each connection's send rate starts from its round trip and is capped by
net.gns.MaxSendRate(KB per second, default 4096; the floor is 256). The open-source library does not probe for more bandwidth after that. - Large messages. A message up to 512 KB is split and reassembled for you, on reliable and unreliable channels alike. A larger send is dropped with an error in the log.
- Lanes. The four network channels are four lanes of one connection, so a bulk transfer never holds a snapshot or a voice frame behind it. Reliable and bulk are reliable and ordered; unreliable is sequenced (an older update than one already delivered is dropped); voice is unreliable.
Who may join works as on ENet. GNS on its own only knows the other end by IP address, so every GNS connection first runs the engine's join-key exchange described under The handshake, and neither side reports the peer as connected until it passes. Players on the same machine need no key, players from other machines need the host's join key, and a configured net.psk is everybody's key. When a key is in use, payloads are additionally sealed with the keys that exchange derived, so even someone who sits between the two machines and completes GNS's own handshake with each side cannot read or change them. Peer ids are the transport's own counter, as on ENet; player identity, rejoin tokens and platform tickets stay in the session layer.
net.sim.* drives GNS's own packet loss, latency, jitter, reordering and duplication settings, so the network emulation sliders work the same. The connection statistics in the network graph (round trip, loss, bytes) come from GNS.
Not covered: peer-to-peer connections through NAT (ICE), which need a signalling service the engine does not run. Use the Steam relay for that.
GNS is available on Windows x64. Linux and macOS builds of the library are not shipped yet; there net.Transport=gns falls back to the composite transport.
Choosing between ENet and Steam
FCompositeTransport is the default transport. It always owns an ENet backend and creates a Steam backend only when the Steam client is available FCompositeTransport. It decides from the form of the address alone, with no network calls:
| Address | Example | Backend |
|---|---|---|
Contains . or : | 192.168.1.20, fe80::1 | ENet |
| Contains any non-digit | myserver | ENet |
| All digits, fits in 32 bits | 7777 | ENet |
| All digits, larger than 32 bits (a SteamID64) | 76561198000000000 | Steam P2P |
- Connect(address)
- ClassifyAddress
- IP or host
- ENet
FNetSession::GetRoute() reports Direct or SteamP2P, so a game can show which one carries the session. If an address looks like a SteamID64 but Steam is not available, the connect fails with a clear error instead of silently falling back to ENet.
Hosting on both
A listen server with Steam running hosts through the Steam relay only, in every build configuration, so peers never see the host's IP address. If the relay listen fails, hosting fails; it does not fall back to a direct UDP listener.
Direct hosting opens the ENet listener beside the relay, so an IP client and a Steam client can join the same session. Steam peer ids carry a high bit so the two id spaces never collide FCompositeTransport. Every peer then sees the host's IP address. Direct hosting is on when any of these asks for it:
- the session, with
FNetSessionSettings::directListen(a LAN or direct-IP game); - the project, with Network Privacy set to Allow direct on the Project › Platform page (
platform.allowDirectHosting); - the console variable
net.AllowDirectHost 1; - a dedicated server, whose address is public anyway.
Without Steam, a host listens on ENet as before.
Channels on each transport
All four network channels exist on both backends. ENet maps them to reliable ordered, unreliable sequenced, reliable unordered and unreliable unsequenced delivery. The Steam backend maps them to Steam's reliable and unreliable send flags, adding no-Nagle for the bulk and voice channels.
ENet encryption
ENet owns the UDP socket and its own reliability and sequencing, so encryption sits on the packet payload: encrypt before ENet sends, decrypt after it receives FNetCryptoSession. The primitives come from Monocypher: X25519 for key exchange, XChaCha20-Poly1305 for authenticated encryption, and BLAKE2b for key derivation. The engine's own layer covers ENet only; traffic on the Steam route goes through Steam Networking Sockets.
The handshake
One ephemeral X25519 exchange per connection, on the reliable channel:
- HelloThe client sends its public key.
- ReplyThe server sends its public key and a confirmation tag.
- ConfirmThe client sends its own confirmation tag.
Both sides hash a label, the optional pre-shared key, the X25519 shared secret and both public keys with BLAKE2b, then expand the result into a key and nonce salt per direction plus a confirmation key. A peer that derived different material cannot produce the tags. A peer is announced as connected only after confirmation, and a handshake that does not finish within 5 seconds drops the peer FNetCrypto. A second Hello on an established session is ignored rather than resetting its keys.
Data frames
[type][channel][counter, 8 bytes LE][MAC, 16 bytes][ciphertext]The overhead is 26 bytes per packet. The header is authenticated as associated data. The nonce is the direction's salt plus the channel plus the counter, and each channel has its own counter starting at 1, so a nonce never repeats under one key.
Replay protection
Each receive channel keeps a 1024-entry sliding window. A counter above the highest seen advances the window; an older one is accepted only if it is inside the window and not seen before. A strict "must increase" rule would drop legitimate traffic, because ENet reorders unreliable packets. The window is updated only after the MAC verifies, so a forged counter cannot poison it.
Configure encryption
| Setting | Default | Meaning |
|---|---|---|
net.encrypt | on | on encrypts every link, LAN included. auto encrypts only non-private addresses and leaves LAN and loopback in plaintext. off disables encryption. |
net.psk | empty | Pre-shared key mixed into the handshake. A peer without it fails confirmation. Empty means the host makes up a join key per session. |
MOWO_NET_ENCRYPT, MOWO_NET_PSK | unset | Environment overrides for the two cvars. |
In code, ENetTransport::SetEncryptionMode and SetPreSharedKey override them for one transport before Host or Connect ENetTransport::SetEncryptionMode.
Join keys
With encryption on and no net.psk, the host generates a 26-character join key for the session and uses it as the pre-shared key for every link from another machine FNetCrypto::GenerateJoinKey. Links from the same machine (loopback) need no key. The host logs the key and FNetSession::GetJoinKey() returns it as <address>:<port>#<key>; a player joins with --connect=<address>:<port>#<key> or by setting FNetSessionSettings::joinKey. Dashes and spaces in a typed key are ignored, letters are case-insensitive, and O, I and L are read as 0, 1 and 1.
So by default a direct session is both encrypted and authenticated: only someone the host gave the key to can complete the handshake. A configured net.psk replaces the per-session key for everybody.
A client that connects from another machine without the key, or with the wrong one, fails key confirmation and is dropped. A link that establishes with no key at all is encrypted but anonymous: safe from passive capture, open to an active man-in-the-middle. On a public address the transport logs a warning when that happens.
The plaintext gate
ENetTransport::Connect refuses to connect to a public internet address in plaintext. Loopback and private ranges are always allowed. Setting the environment variable MOWO_ALLOW_PLAINTEXT_INTERNET=1 overrides the refusal knowingly. With net.encrypt set to on or auto, public addresses are encrypted and the gate stays open.
Related
- Sessions and hosting for the session layer above the transport.
- Online platforms for the Steam backend, relay and ticket authentication.
- API:
FCompositeTransport,FGnsTransport,FNetTransportFactory,INetworkTransport,FNetCrypto,FNetCryptoSession,ENetEncryptionMode.
Engine sources
This page describes behavior implemented in these files of the engine repository, checked against commit c74f75b83.
- Engine/Source/Runtime/Networking/Public/Networking/CompositeTransport.h
- Engine/Source/Runtime/Networking/Public/Networking/NetCrypto.h
- Engine/Source/Runtime/Networking/Public/Networking/ENetTransport.h
- Engine/Source/Runtime/Networking/Public/Networking/NetworkTypes.h
- Engine/Source/Runtime/Networking/Public/Networking/GnsTransport.h
- Engine/Source/Runtime/Networking/Public/Networking/NetTransportFactory.h