netty/netty — pull request #2286 by bucjac (2014-03-05 00:14:46+00:00)
Title: First draft of ipfilter

Hey there! So I started working #2129 tonight. This is a first draft and does not contain all the Subnet/CIDR filter stuff yet, as these are really just implementations of filter rules and I would like to ask for feedback on the design of the handler from @trustin and @normanmaurer and anyone who is reading this.

Using the ```IpFilterRuleHandler``` would be quite similar to the netty3.x version:
```java
IpFilterRuleHandler handler = new IpFilterRuleHandler ();
handler.addRule(new IpFilterRule() {
@Override
public boolean matches(InetAddress ipAddress) {
// logic goes here. return true/false for accepted/rejected.
}

@Override
public IpFilterRuleType ruleType() {
// return either IpFilterRuleType.ALLOW or IpFilterRuleType.DENY;
}
})
.addRule(...)
.addRule(...);

pipeline().addFirst("ipfilter", handler);
```

However, I got rid of the ```IpFilterListener``` and introduced ```AbstractIpFilteringHandler#rejected(ChannelHandlerContext ctx, InetSocketAddress ipAddress)``` instead. So if a connection gets rejected this method will be called (it replaces ```IpFilterListener#refused```). Always? No only if it is not annotated with Skip. Very similar to channelRegistered/Active/... methods, to avoid unnecessary function calls.

So if a developer decides that he would like to do something with the rejected channels, his code would look similar to this:
```
IpFilterRuleHandler handler = new IpFilterRuleHandler () {
@Override
protected ChannelFuture rejected(ChannelHandlerContext ctx, InetSocketAddress ipAddress) {
// logic goes here
return ctx.writeAndFlush(...);
}
}
```
Since the Skip annotation is not inherited, this works just fine.

Let me know what you think. Thanks :).