Top Description Fields Constructors Methods
io.netty5.handler.ipfilter

public Class RuleBasedIpFilter

extends AbstractRemoteAddressFilter<InetSocketAddress>
Class Inheritance
Imports
io.netty5.channel.Channel, .ChannelHandlerContext, java.net.InetSocketAddress, .SocketAddress, java.util.ArrayList, .List

This class allows one to filter new Channels based on the IpFilterRules passed to its constructor. If no rules are provided, all connections will be accepted.

If you would like to explicitly take action on rejected Channels, you should override AbstractRemoteAddressFilter#channelRejected(ChannelHandlerContext, SocketAddress).

Consider using IpSubnetFilter for better performance while not as general purpose as this filter.

Field Summary

Modifier and TypeField and Description
private final boolean
private final List<IpFilterRule>

Constructor Summary

AccessConstructor and Description
public
RuleBasedIpFilter(IpFilterRule...
An array of IpFilterRule containing all rules.
rules
)

Create new Instance of RuleBasedIpFilter and filter incoming connections based on their IP address and rules applied.

public
RuleBasedIpFilter(boolean
If true then accept connection from IP Address if it doesn't match any rule.
acceptIfNotFound
,
IpFilterRule...
An array of IpFilterRule containing all rules.
rules
)

Create new Instance of RuleBasedIpFilter and filter incoming connections based on their IP address and rules applied.

Method Summary

Modifier and TypeMethod and Description
protected boolean
accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress)

Implements abstract io.netty5.handler.ipfilter.AbstractRemoteAddressFilter.accept.

This method is called immediately after a io.netty5.channel.Channel gets registered.
public boolean
isSharable()

Overrides default io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline.
Inherited from io.netty5.handler.ipfilter.AbstractRemoteAddressFilter:
channelAcceptedchannelActivechannelRegisteredchannelRejected

Field Detail

acceptIfNotFoundback to summary
private final boolean acceptIfNotFound
rulesback to summary
private final List<IpFilterRule> rules

Constructor Detail

RuleBasedIpFilterback to summary
public RuleBasedIpFilter(IpFilterRule... rules)

Create new Instance of RuleBasedIpFilter and filter incoming connections based on their IP address and rules applied.

acceptIfNotFound is set to true.

Parameters
rules:IpFilterRule[]

An array of IpFilterRule containing all rules.

RuleBasedIpFilterback to summary
public RuleBasedIpFilter(boolean acceptIfNotFound, IpFilterRule... rules)

Create new Instance of RuleBasedIpFilter and filter incoming connections based on their IP address and rules applied.

Parameters
acceptIfNotFound:boolean

If true then accept connection from IP Address if it doesn't match any rule.

rules:IpFilterRule[]

An array of IpFilterRule containing all rules.

Method Detail

acceptback to summary
protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) throws Exception

Implements abstract io.netty5.handler.ipfilter.AbstractRemoteAddressFilter.accept.

Doc from io.netty5.handler.ipfilter.AbstractRemoteAddressFilter.accept.

This method is called immediately after a io.netty5.channel.Channel gets registered.

Returns:boolean

Return true if connections from this IP address and port should be accepted. False otherwise.

Annotations
@Override
isSharableback to summary
public boolean isSharable()

Overrides default io.netty5.channel.ChannelHandler.isSharable.

Doc from io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline. By default, this method returns false. If this method returns false, you have to create a new handler instance every time you add it to a pipeline because it has unshared state such as member variables.

Annotations
@Override