Class BlacklistFilter

  • All Implemented Interfaces:
    IoFilter

    public class BlacklistFilter
    extends IoFilterAdapter
    A IoFilter which blocks connections from blacklisted remote address.
    • Field Detail

      • blacklist

        private final java.util.List<Subnet> blacklist
        The list of blocked addresses
      • LOGGER

        private static final org.slf4j.Logger LOGGER
        A logger for this class
    • Constructor Detail

      • BlacklistFilter

        public BlacklistFilter()
    • Method Detail

      • setBlacklist

        public void setBlacklist​(java.net.InetAddress[] addresses)
        Sets the addresses to be blacklisted. NOTE: this call will remove any previously blacklisted addresses.
        Parameters:
        addresses - an array of addresses to be blacklisted.
      • setSubnetBlacklist

        public void setSubnetBlacklist​(Subnet[] subnets)
        Sets the subnets to be blacklisted. NOTE: this call will remove any previously blacklisted subnets.
        Parameters:
        subnets - an array of subnets to be blacklisted.
      • setBlacklist

        public void setBlacklist​(java.lang.Iterable<java.net.InetAddress> addresses)
        Sets the addresses to be blacklisted. NOTE: this call will remove any previously blacklisted addresses.
        Parameters:
        addresses - a collection of InetAddress objects representing the addresses to be blacklisted.
        Throws:
        java.lang.IllegalArgumentException - if the specified collections contains non-InetAddress objects.
      • setSubnetBlacklist

        public void setSubnetBlacklist​(java.lang.Iterable<Subnet> subnets)
        Sets the subnets to be blacklisted. NOTE: this call will remove any previously blacklisted subnets.
        Parameters:
        subnets - an array of subnets to be blacklisted.
      • block

        public void block​(java.net.InetAddress address)
        Blocks the specified endpoint.
        Parameters:
        address - The address to block
      • block

        public void block​(Subnet subnet)
        Blocks the specified subnet.
        Parameters:
        subnet - The subnet to block
      • unblock

        public void unblock​(java.net.InetAddress address)
        Unblocks the specified endpoint.
        Parameters:
        address - The address to unblock
      • unblock

        public void unblock​(Subnet subnet)
        Unblocks the specified subnet.
        Parameters:
        subnet - The subnet to unblock
      • event

        public void event​(IoFilter.NextFilter nextFilter,
                          IoSession session,
                          FilterEvent event)
                   throws java.lang.Exception
        Propagate an event up to the IoHandler
        Specified by:
        event in interface IoFilter
        Overrides:
        event in class IoFilterAdapter
        Parameters:
        nextFilter - the IoFilter.NextFilter for this filter. You can reuse this object until this filter is removed from the chain.
        session - The IoSession which has to process this invocation
        event - The event to propagate
        Throws:
        java.lang.Exception - If an error occurred while processing the event
      • blockSession

        private void blockSession​(IoSession session)
      • isBlocked

        private boolean isBlocked​(IoSession session)