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.

Types 1

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.
void reset() @safe pure nothrowReset the buffer for a new message.
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.
private bool isComplete() const @safe pure nothrow @nogcChecks if all bytes have been received.
Constructors
this()Constructs a new fragment buffer.

Functions 2

fnubyte[][] fragmentHandshakeMessage(HandshakeType msgType, ushort messageSeq, const(ubyte)[] message, size_t mtu = DTLS_DEFAULT_MTU) @safe pureFragment a handshake message into MTU-sized DTLS records.
fnbool feedFragment(DtlsFragmentBuffer buffer, const(ubyte)[] fragment) @safe pure nothrowFeeds a complete DTLS handshake fragment (with header) into a reassembly buffer.

Variables 2

enumvarMAX_FRAGMENT_MESSAGE_SIZE = 65536
enumvarDTLS_DEFAULT_MTU = 1200

Default MTU for DTLS.

This is a conservative default that should work over most networks, accounting for IP and UDP header overhead.