UDPSocket class

Represents a single UDX connection, managed by a UDXMultiplexer.

This class handles the logic for a single connection, including stream management, flow control, and packet processing, but delegates the actual network I/O to the multiplexer.

Mixed-in types

Constructors

UDPSocket({required UDX udx, required UDXMultiplexer multiplexer, required InternetAddress remoteAddress, required int remotePort, required ConnectionCids cids, UdxMetricsObserver? metricsObserver, bool isServer = false})
Creates a new UDX connection socket.

Properties

busy → bool
Whether the socket is busy (has active streams).
no setter
cids ↔ ConnectionCids
The Connection IDs for this connection.
getter/setter pair
closing → bool
Whether the socket is closing.
no setter
congestionController → CongestionController
The connection-level congestion controller, exposed for stream flow control checks.
no setter
handshakeComplete → Future<void>
A future that completes when the handshake is successful.
no setter
hashCode → int
The hash code for this object.
no setterinherited
idle → bool
Whether the socket is idle (no active streams).
no setter
isHandshakeCompleted → bool
Whether anything has been received from the peer yet.
no setter
isServer → bool
Whether this socket was created for an inbound connection.
final
metricsObserver ↔ UdxMetricsObserver?
Metrics observer for this socket (optional).
getter/setter pair
multiplexer ↔ UDXMultiplexer
The multiplexer that owns this socket.
getter/setter pair
packetManager → PacketManager
The connection-level packet manager, exposed for sequence number access.
no setter
remoteAddress ↔ InternetAddress
The remote address of the peer.
getter/setter pair
remotePort ↔ int
The remote port of the peer.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
udx → UDX
The UDX instance that created this socket.
final

Methods

address() → Map<String, dynamic>?
Returns the remote peer's address.
advertiseConnectionWindowUpdate() → void
Called when the application has processed data.
allocateIncomingStreamId(int requested) → int
The local id for a stream the peer is opening. A peer that names one (dart-libp2p picks both ids of its first stream) gets it if it's free. go-udx and js-udx never learn our id for a stream they open: they address it to 0 throughout and identify it by their own id. Those, and any id already taken, get the next free even id, as a go-udx acceptor would.
canCreateNewStream() → bool
Checks if a new outgoing stream can be created.
close() → Future<void>
Closes the connection.
override
closeWithError(int errorCode, String reason, {int frameType = 0}) → Future<void>
Closes the connection with an error code and reason. Sends a CONNECTION_CLOSE frame to the peer before terminating.
decrementConnectionBytesSent(int bytes) → void
Called by UDXStream when data is acknowledged.
emit(String event, [dynamic data]) → void
Emits an event of the given type with the given data
inherited
flushBufferedStreams(String event, UDXEventCallback callback, List buffer) → void
Flushes buffered events for a specific event type to a new listener.
inherited
flushStreamBuffer() → void
Flushes buffered streams that were received before a listener was attached. This ensures that listeners attached after stream creation still receive the stream event.
getAvailableConnectionSendWindow() → int
Gets the available send window at the connection level.
getRecvBufferSize() → int
Gets the receive buffer size.
getRegisteredStreamsCount() → int
getSendBufferSize() → int
Gets the send buffer size.
getStreamBuffer() → List<UDXStream>
handleIncomingDatagram(Uint8List data, InternetAddress fromAddress, int fromPort) → Future<void>
Processes an incoming datagram from the multiplexer.
incrementConnectionBytesSent(int bytes) → void
Called by UDXStream when it sends data.
incrementOutgoingStreams() → void
Call this when a new outgoing stream is created.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
on(String event) → Stream<UDXEvent>
Returns a stream of events for the given type
inherited
onStreamDataProcessed(int bytesProcessed) → void
Called by UDXStream when it has received and processed data.
ping({Duration timeout = const Duration(seconds: 5)}) → Future<bool>
Send a PING frame and wait for ACK to verify connection liveness. Returns true if ACK received within timeout, false otherwise.
popInitialPacket(int streamId) → Uint8List?
Retrieves and removes the initial buffered packet for a stream.
registerStream(UDXStream stream) → void
send(Uint8List data) → void
Sends data to the peer via the multiplexer. Enforces anti-amplification limits per RFC 9000 Section 8.1.
sendMaxDataFrame(int localMaxData, {int streamId = 0}) → Future<void>
Sends a MAX_DATA frame to the peer.
sendMaxStreamsFrame() → Future<void>
sendStreamPacket(int dstStreamId, int srcStreamId, List<Frame> frames, {bool trackForRetransmit = true}) → void
Sends a packet with the given frames on behalf of a stream. Uses connection-level sequence numbers (per QUIC RFC 9000). If trackForRetransmit is true, the packet is registered with the PacketManager for retransmission and congestion control.
setLocalMaxStreamsForTest(int value) → void
setRecvBufferSize(int size) → void
Sets the receive buffer size.
setRemoteMaxStreamsForTest(int value) → void
setSendBufferSize(int size) → void
Sets the send buffer size.
setTTL(int ttl) → void
Sets the TTL (Time To Live) for outgoing packets. (Not implemented)
toString() → String
A string representation of this object.
inherited
unregisterStream(int streamId) → void
Unregisters a UDXStream from this socket.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

amplificationFactor → const int
defaultInitialConnectionWindow → const int
Default initial connection-level flow control window (e.g., 1MB).
defaultMaxStreams → const int
Default maximum number of concurrent streams.