blockTCPPort method

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

Blocks a specific TCP port.

  • port: The TCP port to be blocked.
  • sudo: A flag indicating if sudo privileges should be used. Defaults to false.
  • allowedPorts: A set of allowed ports. Ignored if allowAllPorts is true.
  • allowAllPorts: A flag indicating if all ports should be allowed.

Returns a Future that completes with true if the port was successfully blocked, or false if it failed.

Implementation

@override
Future<bool> blockTCPPort(int port,
    {bool sudo = false,
    required Set<int>? allowedPorts,
    required bool allowAllPorts}) async {
  if (port < 10) {
    throw ArgumentError("Invalid port: $port");
  }

  if (!allowAllPorts &&
      (allowedPorts == null || !allowedPorts.contains(port))) {
    return false;
  }

  blockedPorts.add(port);
  return true;
}