acceptAddressOnTCPPort method

  1. @override
Future<bool> acceptAddressOnTCPPort(
  1. String address,
  2. int port, {
  3. bool sudo = false,
  4. required Set<int>? allowedPorts,
  5. required bool allowAllPorts,
})
override

Add rule to accept connections on a specified TCP port from the given address.

  • address: The address (IP or hostname) to accept connections from.
  • port: The TCP port number to accept connections on.
  • sudo: Whether elevated permissions are required to configure the port (default: false).
  • allowedPorts: A set of allowed ports for validation. If null, validation is skipped.
  • allowAllPorts: Whether to allow connections on all ports, overriding allowedPorts.

Returns a Future that completes with true if the operation succeeded, or false if it failed.

Implementation

@override
Future<bool> acceptAddressOnTCPPort(String address, int port,
    {bool sudo = false,
    required Set<int>? allowedPorts,
    required bool allowAllPorts}) async {
  if (!allowAllPorts &&
      (allowedPorts == null || !allowedPorts.contains(port))) {
    return false;
  }

  acceptedAddressesOnPort.add((address, port));
  return true;
}