需要一些实现ideea [英] Need some implementation ideea

查看:69
本文介绍了需要一些实现ideea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!


这就是问题所在:

我有一台接受连接的服务器。

每个请求范围处理它的线程。

我需要一种存储客户端IP的方法。

如果从单个IP发出的请求传递一个数字,比如10,我想在没有处理的情况下放弃

请求。

所有请求都有超时,所以说过了10秒后,请求

编号如果单个IP减少一个,那么客户在10秒内不能再发出10个请求。


有人可以帮我吗?

谢谢,Crirus

解决方案

Hi Crirus,


因为相对于

a请求和响应的生命所涉及的时间相对较长,并且因为这是一项提供所有请求的服务,

我的想法倾向于单独的进程作为''许可

经纪人''。另外,这样你只需要一个计时器来处理所有事情。


我会有一个''减量''事件列表,这些事件将使用
$来管理b $ b计时器。列表中的事件将包括发生的时间,
操作和IP。虽然这样的课程非常通用,但在你的情况下,

只会有一种类型的事件。计时器间隔将设置为

下一个事件。在勾选时它会减少相关IP的计数,并且相应地设置下一个间隔。


每个进入服务器的请求都会通过IP对这个经纪人

将检查其内部列表。如果超过阈值 - 没有

权限。如果低于 - 好的,关闭你去。


每个你走了会增加该IP的计数,并在列表末尾添加一个减量

事件,因为它会在很长时间内熄灭。


问候,

Fergus


Hi Crirus,


你能不能使用修改过的这个星期Armin确实发送了一个很好的例子吗?


\\\ by Armin

私人m_Thread为MyThread

Private Sub Button1_Click(_

ByVal sender As System.Object,_

ByVal e As System.EventArgs)_

Handles Button1.Click

m_Thread = New MyThread

AddHandler m_Thread.Progress,AddressOf OnProgress

AddHandler m_Thread.Done,AddressOf OnDone

m_Thread .Start()

End Sub

Public Delegate Sub ProgressDelegate(ByVal Progress As Integer)

Private Sub OnProgress(ByVal Progress As Integer)

如果Me.InvokeRequired则

Me.Invoke(New ProgressDelegate(_

AddressOf OnProgress _

),New Object(){Progress})

Else

Me.Button1.Text = Progress.ToString

结束如果

结束子

私人子OnDone()

m_Thread =没什么

结束子

///

\\ \

Class MyThread

公共活动进度(ByVal进度为整数)

公共活动完成()

私人m_Thread为线程

公共子开始()

m_Thread =新线程(AddressOf ThreadStart)

m_Thread.Start()

End Sub

Private Sub ThreadStart()

Dim i As Integer

for i = 1 to 100

Thread.Sleep(100)

RaiseEvent进度(i)

下一页

RaiseEvent完成()

结束分

结束课

///


Cor


< blockquote>嗨Fergus

很难跟随你的想法:(

我现在想的是一个名为Flood的lockSynk对象,它可以处理

IP'。

每个请求处理程序线程都应该将IP添加到Flood ip的列表中

在字典中维护它们中的一些(IP ,数字对)

如果允许重新使用IP,则add函数应该返回true ceipt数据。

因此,每个线程等待其他先前的线程从锁定返回并且

然后测试它自己的IP。

我现在的问题是如何减少

中添加的每个IP的号码,并且在该类中使用它自己的计时器。

无论如何,你可以转发你的想法另一种方式让我跟着它吗?


谢谢

Crirus


" Fergus Cooney" <音响**** @ post.com>在消息中写道

新闻:大江************** @ TK2MSFTNGP10.phx.gbl ...

Hi Crirus,

由于与请求和响应的
生命相比所涉及的时间相对较长,并且因为这是一个提供所有
请求的服务,我的想法倾向于一个单独的过程,充当''许可经纪人''。另外,这样你只需要一个计时器来处理所有事情。

我会有一个''减量''事件列表,这些事件将使用
计时器进行管理。列表中的事件将包括发生的时间,
一个动作和IP。虽然这样的类非常通用,但在
的情况下,只会有一种类型的事件。定时器间隔将在下一个事件中设置为
。在勾选时,它将减少相关IP
的计数并相应地设置下一个间隔。

每个进入服务器的请求都会将IP传递给此经纪人
将检查其内部列表。如果超过阈值 - 没有
许可。如果低于 - 好的话,关闭你去。

每个关闭你去会增加该IP的计数并在列表末尾添加一个
减量事件,因为会在这么多秒钟内完成。

问候,
Fergus



Hi there!

This is the problem:
I have a server that accept connections.
Each request span a thread that handle it.
I need a way to store the client IP''s.
If the requests made from a single IP pass a number, say 10, I want to drop
that request without processing.
All that request have a timeout so after say 10 sec elapsed, the requests
number made fom a single IP is decreased by one, so the client cant make
more that 10 requests in 10 secs.

Can someone help me?

Thanks, Crirus

解决方案

Hi Crirus,

Because of the relatively long time spans involved compared to the life of
a request and response, and because this is a service supplying all requests,
my thinking tends towards a separate process which acts as a ''permission
broker''. Also, that way you only need one timer to handle everything.

I''d have a list of ''decrement'' events which would be managed using the
timer. An event on the list would consist of the time when it is to occur, an
action and the IP. Although such a class is highly generalisable, in your case
there will only be one type of event. The timer interval would be set to the
next event. On the tick it would decrement the count of the associated IP and
set the next interval accordingly.

Each request coming in to the server would pass the IP to this broker
which would check against its internal list. If over the threshold - "no
permission". If under - "ok, off you go".

Each "off you go" would bump up the count for that IP and add a decrement
event to the end of the list, due to go off in so many seconds.

Regards,
Fergus


Hi Crirus,

Can you not use "modified" that nice example Armin did send in this week?

\\\ by Armin
Private m_Thread As MyThread
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
m_Thread = New MyThread
AddHandler m_Thread.Progress, AddressOf OnProgress
AddHandler m_Thread.Done, AddressOf OnDone
m_Thread.Start()
End Sub
Public Delegate Sub ProgressDelegate(ByVal Progress As Integer)
Private Sub OnProgress(ByVal Progress As Integer)
If Me.InvokeRequired Then
Me.Invoke(New ProgressDelegate( _
AddressOf OnProgress _
), New Object() {Progress})
Else
Me.Button1.Text = Progress.ToString
End If
End Sub
Private Sub OnDone()
m_Thread = Nothing
End Sub
///
\\\
Class MyThread
Public Event Progress(ByVal Progress As Integer)
Public Event Done()
Private m_Thread As Thread
Public Sub Start()
m_Thread = New Thread(AddressOf ThreadStart)
m_Thread.Start()
End Sub
Private Sub ThreadStart()
Dim i As Integer
For i = 1 To 100
Thread.Sleep(100)
RaiseEvent Progress(i)
Next
RaiseEvent Done()
End Sub
End Class
///

Cor


Hi Fergus
Hard to follow your ideea :(
What I was thinking by now is a lockSynk object, called Flood, that handle
the IP''s.
Each request handler thread should add the IP to the Flood ip''s list that
maintain a number of them in a dictionary (IP, number pair)
The add function should return true if IP is allowed to receipt data.
So, each thread wait for the others previous threads to return from lock and
then test it''s own IP .

The question I have right now is how to decrement each IP''s number added in
that with it''s own timer in that class.

Anyway, can you repost your ideea another way to lem me follow it?

Thanks
Crirus

"Fergus Cooney" <fi****@post.com> wrote in message
news:Oe**************@TK2MSFTNGP10.phx.gbl...

Hi Crirus,

Because of the relatively long time spans involved compared to the life of a request and response, and because this is a service supplying all requests, my thinking tends towards a separate process which acts as a ''permission
broker''. Also, that way you only need one timer to handle everything.

I''d have a list of ''decrement'' events which would be managed using the
timer. An event on the list would consist of the time when it is to occur, an action and the IP. Although such a class is highly generalisable, in your case there will only be one type of event. The timer interval would be set to the next event. On the tick it would decrement the count of the associated IP and set the next interval accordingly.

Each request coming in to the server would pass the IP to this broker
which would check against its internal list. If over the threshold - "no
permission". If under - "ok, off you go".

Each "off you go" would bump up the count for that IP and add a decrement event to the end of the list, due to go off in so many seconds.

Regards,
Fergus



这篇关于需要一些实现ideea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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