send method

void send(
  1. Uint8List data
)

Sends data to the peer via the multiplexer. Enforces anti-amplification limits per RFC 9000 Section 8.1.

Implementation

void send(Uint8List data) {
  if (_closing) throw StateError('Socket is closing');

  // Anti-amplification check: don't send more than 3x what we've received
  // until the address is validated
  if (!_addressValidated) {
    final limit = _bytesReceivedBeforeValidation * amplificationFactor;
    if (_bytesSentBeforeValidation + data.length > limit) {
      // Queue the packet until address is validated
      _pendingPackets.add(data);
      return;
    }
    _bytesSentBeforeValidation += data.length;
  }

  multiplexer.send(data, remoteAddress, remotePort);
}