Home / Class/ RuleBasedIpFilter Class — netty Architecture

RuleBasedIpFilter Class — netty Architecture

Architecture documentation for the RuleBasedIpFilter class in RuleBasedIpFilter.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  b81b6539_81f3_4c0f_da90_333d9c8e58ca["RuleBasedIpFilter"]
  bec26159_f615_e59d_55c9_ed9655c1a106["RuleBasedIpFilter.java"]
  b81b6539_81f3_4c0f_da90_333d9c8e58ca -->|defined in| bec26159_f615_e59d_55c9_ed9655c1a106
  b39050f6_6e5b_3129_9323_7eb8b6015fdf["RuleBasedIpFilter()"]
  b81b6539_81f3_4c0f_da90_333d9c8e58ca -->|method| b39050f6_6e5b_3129_9323_7eb8b6015fdf
  0073a99a_07c3_7ff4_8c30_64c1322c7746["accept()"]
  b81b6539_81f3_4c0f_da90_333d9c8e58ca -->|method| 0073a99a_07c3_7ff4_8c30_64c1322c7746

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ipfilter/RuleBasedIpFilter.java lines 43–92

@Sharable
public class RuleBasedIpFilter extends AbstractRemoteAddressFilter<InetSocketAddress> {

    private final boolean acceptIfNotFound;
    private final List<IpFilterRule> rules;

    /**
     * <p> Create new Instance of {@link RuleBasedIpFilter} and filter incoming connections
     * based on their IP address and {@code rules} applied. </p>
     *
     * <p> {@code acceptIfNotFound} is set to {@code true}. </p>
     *
     * @param rules An array of {@link IpFilterRule} containing all rules.
     */
    public RuleBasedIpFilter(IpFilterRule... rules) {
        this(true, rules);
    }

    /**
     * Create new Instance of {@link RuleBasedIpFilter} and filter incoming connections
     * based on their IP address and {@code rules} applied.
     *
     * @param acceptIfNotFound If {@code true} then accept connection from IP Address if it
     *                         doesn't match any rule.
     * @param rules            An array of {@link IpFilterRule} containing all rules.
     */
    public RuleBasedIpFilter(boolean acceptIfNotFound, IpFilterRule... rules) {
        ObjectUtil.checkNotNull(rules, "rules");

        this.acceptIfNotFound = acceptIfNotFound;
        this.rules = new ArrayList<IpFilterRule>(rules.length);

        for (IpFilterRule rule : rules) {
            if (rule != null) {
                this.rules.add(rule);
            }
        }
    }

    @Override
    protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) throws Exception {
        for (IpFilterRule rule : rules) {
            if (rule.matches(remoteAddress)) {
                return rule.ruleType() == IpFilterRuleType.ACCEPT;
            }
        }

        return acceptIfNotFound;
    }
}

Frequently Asked Questions

What is the RuleBasedIpFilter class?
RuleBasedIpFilter is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ipfilter/RuleBasedIpFilter.java.
Where is RuleBasedIpFilter defined?
RuleBasedIpFilter is defined in handler/src/main/java/io/netty/handler/ipfilter/RuleBasedIpFilter.java at line 43.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free