public abstract class AbstractRemoteAddressFilter<T extends SocketAddress>
extends io.netty.channel.ChannelInboundHandlerAdapter
Channel
s
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.
Constructor and Description |
---|
AbstractRemoteAddressFilter() |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
accept(io.netty.channel.ChannelHandlerContext ctx,
T remoteAddress)
This method is called immediately after a
Channel gets registered. |
protected void |
channelAccepted(io.netty.channel.ChannelHandlerContext ctx,
T remoteAddress)
This method is called if
remoteAddress gets accepted by
accept(ChannelHandlerContext, SocketAddress) . |
void |
channelActive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelRegistered(io.netty.channel.ChannelHandlerContext ctx) |
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) . |
channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
public void channelRegistered(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelRegistered
in interface io.netty.channel.ChannelInboundHandler
channelRegistered
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelActive
in interface io.netty.channel.ChannelInboundHandler
channelActive
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
protected abstract boolean accept(io.netty.channel.ChannelHandlerContext ctx, T remoteAddress) throws Exception
Channel
gets registered.Exception
protected void channelAccepted(io.netty.channel.ChannelHandlerContext ctx, T remoteAddress)
remoteAddress
gets accepted by
accept(ChannelHandlerContext, SocketAddress)
. You should override it if you would like to handle
(e.g. respond to) accepted addresses.protected io.netty.channel.ChannelFuture channelRejected(io.netty.channel.ChannelHandlerContext ctx, T remoteAddress)
remoteAddress
gets rejected by
accept(ChannelHandlerContext, SocketAddress)
. You should override it if you would like to handle
(e.g. respond to) rejected addresses.ChannelFuture
if you perform I/O operations, so that
the Channel
can be closed once it completes. Null otherwise.Copyright © 2008–2023 The Netty Project. All rights reserved.