ddn.net.dtls.fragment
DTLS handshake message fragmentation and reassembly.
DTLS handshake messages may be fragmented to fit within the path MTU. This module provides utilities for fragmenting outgoing messages and reassembling incoming fragments into complete messages.
See RFC 6347 Section 4.2.3 for the DTLS handshake message format.
class DtlsFragmentBuffer
Types 1
classDtlsFragmentBuffer
Reassembly buffer for fragmented DTLS handshake messages.
DTLS handshake messages may be fragmented to fit within the MTU. This class collects fragments and reassembles them into complete messages.
Fields
private ubyte[] buffer_private size_t messageLength_private bool[] received_private ushort expectedSeq_private bool hasData_Methods
bool feed(ushort messageSeq, uint fragmentOffset,
uint fragmentLength, uint totalLength,
const(ubyte)[] fragmentData) @safe pure nothrowFeed a fragment into the reassembly buffer.const(ubyte)[] message() const @safe pure nothrow @nogcReturns the reassembled message, or null if incomplete.bool hasData() @property const @safe pure nothrow @nogcReturns: true if any fragments have been received.ushort expectedSeq() @property const @safe pure nothrow @nogcReturns: The expected message sequence number.size_t messageLength() @property const @safe pure nothrow @nogcReturns: The total expected message length.size_t bytesReceived() @property const @safe pure nothrowReturns: The number of bytes received so far.private
void initializeBuffer(ushort messageSeq, uint totalLength) @safe pure nothrowInitializes the buffer for a new message.Constructors
this()Constructs a new fragment buffer.Functions 2
fn
ubyte[][] fragmentHandshakeMessage(HandshakeType msgType,
ushort messageSeq,
const(ubyte)[] message,
size_t mtu = DTLS_DEFAULT_MTU) @safe pureFragment a handshake message into MTU-sized DTLS records.fn
bool feedFragment(DtlsFragmentBuffer buffer, const(ubyte)[] fragment) @safe pure nothrowFeeds a complete DTLS handshake fragment (with header) into a reassembly buffer.Variables 2
enumvar
MAX_FRAGMENT_MESSAGE_SIZE = 65536enumvar
DTLS_DEFAULT_MTU = 1200Default MTU for DTLS.
This is a conservative default that should work over most networks, accounting for IP and UDP header overhead.