createIncoming static method
UDXStream
createIncoming(
- UDX udx,
- UDPSocket socket,
- int localId,
- int remoteId,
- String host,
- int port, {
- required ConnectionId destinationCid,
- required ConnectionId sourceCid,
- bool framed = false,
- int initialSeq = 0,
- int? initialCwnd,
- bool firewall()?,
- StreamType streamType = StreamType.bidirectional,
Implementation
static UDXStream createIncoming(
UDX udx,
UDPSocket socket,
int localId,
int remoteId,
String host,
int port, {
required ConnectionId destinationCid,
required ConnectionId sourceCid,
bool framed = false,
int initialSeq = 0,
int? initialCwnd,
bool Function(UDPSocket socket, int port, String host)? firewall,
StreamType streamType = StreamType.bidirectional,
}) {
if (socket.closing) {
throw StateError('UDXStream.createIncoming: Socket is closing');
}
final stream = UDXStream(
udx,
localId,
streamType: streamType,
isInitiator: false,
framed: framed,
initialSeq: initialSeq,
firewall: firewall,
);
stream._socket = socket;
stream.remoteId = remoteId;
stream.remoteHost = host;
stream.remotePort = port;
stream.remoteFamily = UDX.getAddressFamily(host);
socket.registerStream(stream);
stream._remoteConnectionWindowUpdateSubscription?.cancel();
stream._remoteConnectionWindowUpdateSubscription = stream._socket!.on('remoteConnectionWindowUpdate').listen(stream._handleRemoteConnectionWindowUpdate);
stream._connected = true;
stream.connectedAt = DateTime.now();
// Send SYN-ACK via socket's connection-level packet manager
// The SYN has already been received and processed by the socket.
// We send our SYN back to establish the bidirectional stream.
socket.sendStreamPacket(
remoteId,
localId,
[StreamFrame(data: Uint8List(0), isSyn: true)],
);
if (!socket.closing) {
socket.sendMaxDataFrame(UDPSocket.defaultInitialConnectionWindow);
}
stream.emit('accepted');
return stream;
}