ddn.net.dtls.engine
DTLS engine for client and server roles.
Provides the main DtlsEngine class that manages DTLS connections over a datagram transport. Supports both client and server modes, multiple concurrent peers, and configurable timeouts.
The engine handles:
- DTLS handshake state machine
- Peer connection tracking
- Retransmission timers
- Idle peer pruning
- MTU configuration
class NativeDtlsEngine
Types 1
classNativeDtlsEngine : DtlsEngine
Main DTLS engine for client and server roles.
The engine manages DTLS connections over a single datagram socket. In server mode, it can handle multiple peers simultaneously. In client mode, it connects to a single server.
Thread safety: NOT thread-safe. All calls must be serialized.
Example (client):
auto engine = new NativeDtlsEngine(transport, timer, "example.com");
engine.setMinVersion(DtlsVersion.DTLS_1_2);
while (engine.handshake() != TlsProgress.DONE) {
// poll and handle I/O
}Example (server):
auto engine = new NativeDtlsEngine(transport, timer);
engine.setCertificateChain(certs);
engine.setPrivateKey(key);
// Process incoming datagrams in event loopMethods
DtlsCidManager cidManager() @safe pure nothrow @nogcReturns: The CID manager (package-internal access for NativeDtlsPeer).void setCertificateChain(const(char)[] pemData)Set the certificate chain for authentication from PEM data.void setCertificateChainDer(const(ubyte[])[] derCerts) @safeSet the certificate chain for authentication from DER data.void setPrivateKey(const(char)[] pemKey, const(char)[] password = null)Set the private key for authentication from PEM data.void setPrivateKeyDer(const(ubyte)[] derKey, const(char)[] password = null)Set the private key for authentication from DER data.void setTrustStore(TlsTrustStore trustStore) @safeSets the trust store for certificate verification.void setVerifyCallback(DtlsVerifyCallback callback) @safe pure nothrowSets a custom certificate verification callback.void setVerifyMode(TlsVerifyMode mode) @safe pure nothrow @nogcSets the certificate verification mode.void setServerAddress(DatagramEndpoint addr) @safe pure nothrow @nogcSets the target server address for client mode.TlsProgress processDatagram(const(ubyte)[] data, DatagramEndpoint from) @safeProcess an incoming datagram.void enablePmtuDiscovery(bool enable) @safeEnables or disables path MTU discovery (RFC 8899 PLPMTUD).void setOnMtuChanged(DtlsMtuChangedCallback callback) @safeSets the callback fired when a peer's discovered MTU changes.void setOnPeerMigrated(DtlsPeerMigratedCallback callback) @safeSets the callback fired when a peer migrates to a new address.void enableSessionResumption(bool enable) @safeEnables or disables session resumption (and 0-RTT early data).void setMaxEarlyDataSize(size_t bytes) @safeSets the maximum 0-RTT early data size advertised to clients.void setEarlyDataReplayProtection(EarlyDataReplayProtection mode) @safeSets the anti-replay strategy for 0-RTT early data.void setEarlyDataTimeWindow(Duration window) @safeSets the replay window duration for TIME_WINDOWED protection.void setOnSessionTicket(DtlsSessionCallback callback) @safeSets the callback fired when a session ticket is issued.void setOnEarlyData(DtlsEarlyDataCallback callback) @safeSets the callback fired when early data is received.void resumeWithSession(scope ref const DtlsSessionInfo session) @safeConfigures resumption with a previously stored session.TlsResult writeEarlyData(const(ubyte)[] data)Writes 0-RTT early data for a pending client resumption handshake.void setSrtpProfiles(const(SrtpProfile[]) profiles) @safeSets the DTLS-SRTP profiles to negotiate (RFC 5764).void setMaxHandshakingPeers(size_t limit) @safe pure nothrow @nogcSet the maximum number of peers in handshake state.void setOnPeerEvicted(DtlsEvictCallback callback) @safe pure nothrow @nogcSet the peer eviction callback.DtlsVersion negotiatedVersion(const DtlsPeerState state) const @safeGet the negotiated DTLS version for a peer.string cipherSuite(const DtlsPeerState state) const @safeGet the negotiated cipher suite for a peer.string alpnProtocol(const DtlsPeerState state) const @safeGet the negotiated ALPN protocol for a peer.string serverName() @property const @safe pure nothrow @nogcGet the server name (SNI) for client engines.TlsProgress sendAlert(DtlsPeerState state, AlertLevel level,
AlertDescription description) @safeBuild and send a DTLS alert record to a peer.Constructors
this(DtlsTransport transport, DtlsTimerSink timer, string serverName)Create a client engine.this(DtlsTransport transport, DtlsTimerSink timer)Create a server engine.