Class AbstractRemoteAddressFilter<T extends SocketAddress>

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler
    Direct Known Subclasses:
    IpSubnetFilter, RuleBasedIpFilter, UniqueIpFilter

    public abstract class AbstractRemoteAddressFilter<T extends SocketAddress>
    extends io.netty.channel.ChannelInboundHandlerAdapter
    This class provides the functionality to either accept or reject new Channels based on their IP address.

    You should inherit from this class if you would like to implement your own IP-based filter. Basically you have to implement accept(ChannelHandlerContext, SocketAddress) to decided whether you want to accept or reject a connection from the remote address.

    Furthermore overriding channelRejected(ChannelHandlerContext, SocketAddress) gives you the flexibility to respond to rejected (denied) connections. If you do not want to send a response, just have it return null. Take a look at RuleBasedIpFilter for details.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

        io.netty.channel.ChannelHandler.Sharable
    • Constructor Detail

      • AbstractRemoteAddressFilter

        public AbstractRemoteAddressFilter()
    • Method Detail

      • channelRegistered

        public void channelRegistered​(io.netty.channel.ChannelHandlerContext ctx)
                               throws Exception
        Specified by:
        channelRegistered in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelRegistered in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • channelActive

        public void channelActive​(io.netty.channel.ChannelHandlerContext ctx)
                           throws Exception
        Specified by:
        channelActive in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • accept

        protected abstract boolean accept​(io.netty.channel.ChannelHandlerContext ctx,
                                          T remoteAddress)
                                   throws Exception
        This method is called immediately after a Channel gets registered.
        Returns:
        Return true if connections from this IP address and port should be accepted. False otherwise.
        Throws:
        Exception
      • channelAccepted

        protected void channelAccepted​(io.netty.channel.ChannelHandlerContext ctx,
                                       T remoteAddress)
        This method is called if remoteAddress gets accepted by accept(ChannelHandlerContext, SocketAddress). You should override it if you would like to handle (e.g. respond to) accepted addresses.
      • channelRejected

        protected io.netty.channel.ChannelFuture channelRejected​(io.netty.channel.ChannelHandlerContext ctx,
                                                                 T remoteAddress)
        This method is called if remoteAddress gets rejected by accept(ChannelHandlerContext, SocketAddress). You should override it if you would like to handle (e.g. respond to) rejected addresses.
        Returns:
        A ChannelFuture if you perform I/O operations, so that the Channel can be closed once it completes. Null otherwise.