only allowing one connection per IP address

Frederic Bregier fredbregier at free.fr
Fri Mar 20 16:54:39 EDT 2009


Hi William,

I think about your need. I think it could be included as a handler
in Netty for other users, so I try to develop a simple handler to do
that.

I implement first an abstract handler that stands to allow or disallow
connection
based on some methods to implement. See 
http://n2.nabble.com/file/n2511111/ChannelFilterHandler.java
ChannelFilterHandler.java 

Then I implement your need by first another abstract class that extends the
first one.
Its purpose is to check based on inetaddress if this one was already used,
and if so, it reject the connection.
It is an abstract since one may want to return something to the client
before closing
the connection (like "connection not allowed"). See 
http://n2.nabble.com/file/n2511111/OneIpFilterHandler.java
OneIpFilterHandler.java 

Then I implement the real class that just extends and implements the second
class
with the method returning a message. See example that I used in my FTP
server
program just to see if it works (it returns the 421 code from FTP RFC): 
http://n2.nabble.com/file/n2511111/FtpOneIpFilter.java FtpOneIpFilter.java 

You just have to add this filter in the pipeline like :
pipeline.addLast("OneIpFilter", oneIpFilter);
where oneIpFilter is constructed once for all connections (same object
reused).

I found easy now to implement a simple class (still abstract in order to
allow
specific reply) for banned inetAddress (black list filter). See 
http://n2.nabble.com/file/n2511111/BannedIpHandler.java BannedIpHandler.java 


Any comments, ideas or corrections are more than welcomed !!!

HTH, 

Cheers,
Frederic

-----
Hardware/Software Architect
-- 
View this message in context: http://n2.nabble.com/only-allowing-one-connection-per-IP-address-tp2495797p2511111.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list