限制每个IP在Netty上的连接数 [英] Limit number of connections per IP on Netty

查看:896
本文介绍了限制每个IP在Netty上的连接数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种使用NetFilter的IPFilter类来限制Netty上每个IP连接的方法.但是,没有JavaDoc解释可以做到这种限制.

I've been searching for a while a way to limit the connections per IP on Netty using its IPFilter class. However, there is no JavaDoc explanation to do that kind of limitations.

我发现的唯一方法是使用两年前在jboss上发布的'ConnectionPerIPLimitUpStreamHandler',但是Norman Maurer表示不再需要该功能,因为该功能已添加到IPFilter类中.

The only way i've found is using the 'ConnectionPerIPLimitUpStreamHandler' released on jboss two years ago, but Norman Maurer said that it was no longer needed cuz this feature has been added to the IPFilter class.

因此,在简历中,我需要说明如何使用NetFilter的IPFilter类来限制Netty上每个IP地址的连接.

So, in resume, I need an explanation on how we could limit connections per IP address on Netty using its IPFilter class.

推荐答案

在我看来,您可以将源代码带到OneIpFilterHandler

Looks to me like you can take the source to OneIpFilterHandler and

1)更改并发映射,使值成为Integer来保存计数. 2)更改检查新连接的IP的位置,以允许计数是否低于阈值. 3)允许时更改同一位置以增加计数 4)更改释放IP地址的位置以减少计数并删除映射条目(如果其为零).

1) change the concurrent map so the values are Integer to hold the count. 2) change the place where it checks the IP of a new connection to allow if the count is below the threshhold. 3) change that same place to increment the count when you allow 4) change the place where it releases an IP address to reduce the count and remove the map entry if its zero.

通过所有这些考虑并发问题.

Think about concurrent issues through all this.

我知道这很模糊.但这是一个主意.可能会对您有帮助.

I know this is vague. But its an idea. It might help you.

这篇关于限制每个IP在Netty上的连接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆