unacceptAddressOnTCPPort method

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

Reverses the acceptance ("unaccept") of an address on a specified TCP port.

This method is used to revoke a previously accepted address on a given TCP port. Optionally, it can be executed with elevated privileges using sudo.

  • address: The IP address or hostname to unaccept.
  • port: The TCP port from which the address will be unaccepted. If null will remove from all ports.
  • sudo: Indicates whether the operation should be executed with sudo privileges. Defaults to false.
  • allowedPorts: A set of ports that are allowed for this operation. If null, no port restrictions apply.
  • allowAllPorts: A flag to override allowedPorts and allow all ports to be unaccepted.

Returns:

  • A Future<bool> indicating whether the operation was successful.

Implementation

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

  if (port != null) {
    acceptedAddressesOnPort.remove((address, port));
  } else {
    acceptedAddressesOnPort.removeWhere((e) => e.$1 == address);
  }
  return true;
}