Module io.netty5.handler
Package io.netty5.handler.ipfilter
Class AbstractRemoteAddressFilter<T extends SocketAddress>
- java.lang.Object
-
- io.netty5.handler.ipfilter.AbstractRemoteAddressFilter<T>
-
- All Implemented Interfaces:
ChannelHandler
- Direct Known Subclasses:
IpSubnetFilter
,RuleBasedIpFilter
,UniqueIpFilter
public abstract class AbstractRemoteAddressFilter<T extends SocketAddress> extends Object implements ChannelHandler
This class provides the functionality to either accept or reject newChannel
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 atRuleBasedIpFilter
for details.
-
-
Constructor Summary
Constructors Constructor Description AbstractRemoteAddressFilter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean
accept(ChannelHandlerContext ctx, T remoteAddress)
This method is called immediately after aChannel
gets registered.protected void
channelAccepted(ChannelHandlerContext ctx, T remoteAddress)
This method is called ifremoteAddress
gets accepted byaccept(ChannelHandlerContext, SocketAddress)
.void
channelActive(ChannelHandlerContext ctx)
TheChannel
of theChannelHandlerContext
is now activevoid
channelRegistered(ChannelHandlerContext ctx)
protected Future<Void>
channelRejected(ChannelHandlerContext ctx, T remoteAddress)
This method is called ifremoteAddress
gets rejected byaccept(ChannelHandlerContext, SocketAddress)
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Method Detail
-
channelRegistered
public void channelRegistered(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
- Specified by:
channelRegistered
in interfaceChannelHandler
- Throws:
Exception
-
channelActive
public void channelActive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
TheChannel
of theChannelHandlerContext
is now active- Specified by:
channelActive
in interfaceChannelHandler
- Throws:
Exception
-
accept
protected abstract boolean accept(ChannelHandlerContext ctx, T remoteAddress) throws Exception
This method is called immediately after aChannel
gets registered.- Returns:
- Return true if connections from this IP address and port should be accepted. False otherwise.
- Throws:
Exception
-
channelAccepted
protected void channelAccepted(ChannelHandlerContext ctx, T remoteAddress)
This method is called ifremoteAddress
gets accepted byaccept(ChannelHandlerContext, SocketAddress)
. You should override it if you would like to handle (e.g. respond to) accepted addresses.
-
channelRejected
protected Future<Void> channelRejected(ChannelHandlerContext ctx, T remoteAddress)
This method is called ifremoteAddress
gets rejected byaccept(ChannelHandlerContext, SocketAddress)
. You should override it if you would like to handle (e.g. respond to) rejected addresses.
-
-