Rev833, Fix gevent 1.0.2 compatibility, Allow 6 connection from same host within 1 minute
This commit is contained in:
parent
f5f26821d5
commit
44a68104fb
4 changed files with 14 additions and 22 deletions
|
@ -8,7 +8,7 @@ class Config(object):
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.version = "0.3.5"
|
self.version = "0.3.5"
|
||||||
self.rev = 830
|
self.rev = 833
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.createParser()
|
self.createParser()
|
||||||
|
|
|
@ -81,7 +81,7 @@ class ConnectionServer:
|
||||||
# Connection flood protection
|
# Connection flood protection
|
||||||
if ip in self.ip_incoming and ip not in self.whitelist:
|
if ip in self.ip_incoming and ip not in self.whitelist:
|
||||||
self.ip_incoming[ip] += 1
|
self.ip_incoming[ip] += 1
|
||||||
if self.ip_incoming[ip] > 3: # Allow 3 in 1 minute from same ip
|
if self.ip_incoming[ip] > 6: # Allow 6 in 1 minute from same ip
|
||||||
self.log.debug("Connection flood detected from %s" % ip)
|
self.log.debug("Connection flood detected from %s" % ip)
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
|
@ -83,20 +83,13 @@ class TestConnection:
|
||||||
file_server.whitelist = [] # Disable 127.0.0.1 whitelist
|
file_server.whitelist = [] # Disable 127.0.0.1 whitelist
|
||||||
client = ConnectionServer("127.0.0.1", 1545)
|
client = ConnectionServer("127.0.0.1", 1545)
|
||||||
|
|
||||||
# Only allow 3 connection in 1 minute
|
# Only allow 6 connection in 1 minute
|
||||||
|
for reconnect in range(6):
|
||||||
connection = client.getConnection("127.0.0.1", 1544)
|
connection = client.getConnection("127.0.0.1", 1544)
|
||||||
assert connection.handshake
|
assert connection.handshake
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
connection = client.getConnection("127.0.0.1", 1544)
|
# The 7. one will timeout
|
||||||
assert connection.handshake
|
|
||||||
connection.close()
|
|
||||||
|
|
||||||
connection = client.getConnection("127.0.0.1", 1544)
|
|
||||||
assert connection.handshake
|
|
||||||
connection.close()
|
|
||||||
|
|
||||||
# The 4. one will timeout
|
|
||||||
with pytest.raises(gevent.Timeout):
|
with pytest.raises(gevent.Timeout):
|
||||||
with gevent.Timeout(0.1):
|
with gevent.Timeout(0.1):
|
||||||
connection = client.getConnection("127.0.0.1", 1544)
|
connection = client.getConnection("127.0.0.1", 1544)
|
||||||
|
|
|
@ -7,14 +7,13 @@ import logging
|
||||||
# Third party modules
|
# Third party modules
|
||||||
import gevent
|
import gevent
|
||||||
from gevent import monkey
|
from gevent import monkey
|
||||||
|
if "patch_subprocess" in dir(monkey): # New gevent
|
||||||
|
monkey.patch_all(thread=False, subprocess=False)
|
||||||
|
else: # Old gevent
|
||||||
import ssl
|
import ssl
|
||||||
# Fix PROTOCOL_SSLv3 not defined
|
# Fix PROTOCOL_SSLv3 not defined
|
||||||
if "PROTOCOL_SSLv3" not in dir(ssl):
|
if "PROTOCOL_SSLv3" not in dir(ssl):
|
||||||
ssl.PROTOCOL_SSLv3 = ssl.PROTOCOL_SSLv23
|
ssl.PROTOCOL_SSLv3 = ssl.PROTOCOL_SSLv23
|
||||||
|
|
||||||
if "patch_subprocess" in dir(monkey):
|
|
||||||
monkey.patch_all(thread=False, subprocess=False)
|
|
||||||
else:
|
|
||||||
monkey.patch_all(thread=False)
|
monkey.patch_all(thread=False)
|
||||||
# Not thread: pyfilesystem and systray icon, Not subprocess: Gevent 1.1+
|
# Not thread: pyfilesystem and systray icon, Not subprocess: Gevent 1.1+
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue