sendStatelessReset method

void sendStatelessReset(
  1. InternetAddress address,
  2. int port,
  3. ConnectionId connectionId
)

Sends a stateless reset packet to a peer.

This is used when the server has lost connection state but receives a packet for a connection. The stateless reset allows the client to quickly detect that the server has lost state and close the connection.

Implementation

void sendStatelessReset(
  InternetAddress address,
  int port,
  ConnectionId connectionId,
) {
  try {
    // Generate token for this CID if not already cached
    StatelessResetToken token;
    if (_resetTokens.containsKey(connectionId)) {
      token = _resetTokens[connectionId]!;
    } else {
      token = StatelessResetToken.generate(connectionId);
      _resetTokens[connectionId] = token;
    }

    // Create and send stateless reset packet
    final resetPacket = StatelessResetPacket.create(token);
    socket.send(resetPacket.toBytes(), address, port);
  } catch (e) {
    // Silently fail if we can't send stateless reset
    // (e.g., server secret not configured)
  }
}