UDPSocket constructor
UDPSocket({
- required UDX udx,
- required UDXMultiplexer multiplexer,
- required InternetAddress remoteAddress,
- required int remotePort,
- required ConnectionCids cids,
- UdxMetricsObserver? metricsObserver,
- bool isServer = false,
- Clock? clock,
Creates a new UDX connection socket.
Implementation
UDPSocket({
required this.udx,
required this.multiplexer,
required this.remoteAddress,
required this.remotePort,
required this.cids,
this.metricsObserver,
this.isServer = false,
Clock? clock,
}) : clock = clock ?? const SystemClock() {
_localConnectionMaxData = defaultInitialConnectionWindow;
_remoteConnectionMaxData = defaultInitialConnectionWindow;
_localMaxStreams = defaultMaxStreams;
_mtu = MtuDiscovery(clock: this.clock);
// Initialize connection-level packet management
_packetManager = PacketManager(clock: this.clock);
_congestionController = CongestionController(packetManager: _packetManager, clock: this.clock);
_packetManager.congestionController = _congestionController;
_lostQueue = LostQueue(
packetManager: _packetManager,
congestionController: _congestionController,
clock: this.clock,
send: _sendQuietly,
maxDatagram: () => _mtu.current,
);
// A PTO probe re-sends the oldest outstanding packets under fresh
// sequences, through this; their bytes are still in flight. Probe
// timeouts in a row while streams send more than the base datagram
// size are read as the path having stopped carrying that size (a
// carrier's tunnel after a handover drops every full-size packet and
// answers nothing): the size falls back to the base and the probe is
// re-chunked to fit, the first packet that can get through.
_packetManager.onRetransmit = (packet) => _sendQuietly(packet.toBytes());
_congestionController.onProbe = () {
if (_congestionController.ptoCount >= blackholePtos) _mtu.blackhole();
_packetManager.sendProbe(maxDatagram: _mtu.current);
};
_packetManager.onPacketsLost = _onPacketsLost;
// For client-initiated connections, address is validated by default
// For server-side connections (receiving SYN), address must be validated
_addressValidated = !isServer;
// Notify observer that handshake is starting
_handshakeStartTime = this.clock.now();
metricsObserver?.onHandshakeStart(
cids.localCid,
cids.remoteCid,
'${remoteAddress.address}:$remotePort',
);
_lastActivity = this.clock.now();
_armIdleCheck();
}