unacceptAddressOnTCPPort method
Future<bool>
unacceptAddressOnTCPPort(
- String address,
- int? port, {
- bool sudo = false,
- required Set<
int> ? allowedPorts, - 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. Ifnullwill remove from all ports.sudo: Indicates whether the operation should be executed with sudo privileges. Defaults tofalse.allowedPorts: A set of ports that are allowed for this operation. Ifnull, no port restrictions apply.allowAllPorts: A flag to overrideallowedPortsand 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;
}