Documentation
¶
Overview ¶
Package stream_datagram forwards UDP packets over an established peer message stream. Each stream has one fixed UDP peer and one socket; peer authentication and stream admission belong to the caller's existing link/session authority.
Index ¶
Constants ¶
const MaxPacketSize = 65507
MaxPacketSize bounds packets to the maximum IPv4 UDP payload.
Each packet is sent as one message on the peer stream, so a lost packet never delays the ones after it. A packet too large for one message falls back to the reliable control stream as a two-byte big-endian payload length followed by exactly that many bytes. Empty datagrams are preserved. Packets may arrive out of order, as UDP permits.
Variables ¶
This section is empty.
Functions ¶
func Forward ¶
func Forward(ctx context.Context, socket *net.UDPConn, peer *net.UDPAddr, peerStream stream.MessageStream) error
Forward owns socket and peerStream until it returns, including on failure. socket must be unconnected and peer is the only permitted UDP sender and destination. Other local senders are ignored. Cancellation or either side failing closes both resources and waits for every forwarding pump to finish. The caller binds a fresh socket per player/session; never share this socket with another Forward call. Only admitted sessions should reach this API.
func ForwardLocal ¶
ForwardLocal forwards one local application's UDP association. socket must be bound to loopback. Its first sender becomes the fixed peer for this stream; packets from other senders are ignored. The first packet is retained and forwarded. The caller owns admission of the remote stream and gives only its selected local application this endpoint. Cancellation closes both resources.
func ForwardTarget ¶
ForwardTarget allocates a dedicated upstream UDP association for one peer stream, then forwards to a fixed service endpoint. Separate calls produce separate source ports at the service, so replies cannot cross player streams. It owns peerStream even if binding the socket fails.
Types ¶
This section is empty.