Rev833, Fix gevent 1.0.2 compatibility, Allow 6 connection from same host within 1 minute

This commit is contained in:
HelloZeroNet 2016-01-05 20:18:17 +01:00
parent f5f26821d5
commit 44a68104fb
4 changed files with 14 additions and 22 deletions

View file

@ -8,7 +8,7 @@ class Config(object):
def __init__(self, argv):
self.version = "0.3.5"
self.rev = 830
self.rev = 833
self.argv = argv
self.action = None
self.createParser()

View file

@ -81,7 +81,7 @@ class ConnectionServer:
# Connection flood protection
if ip in self.ip_incoming and ip not in self.whitelist:
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)
time.sleep(30)
sock.close()

View file

@ -83,20 +83,13 @@ class TestConnection:
file_server.whitelist = [] # Disable 127.0.0.1 whitelist
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)
assert connection.handshake
connection.close()
connection = client.getConnection("127.0.0.1", 1544)
assert connection.handshake
connection.close()
connection = client.getConnection("127.0.0.1", 1544)
assert connection.handshake
connection.close()
# The 4. one will timeout
# The 7. one will timeout
with pytest.raises(gevent.Timeout):
with gevent.Timeout(0.1):
connection = client.getConnection("127.0.0.1", 1544)

View file

@ -7,14 +7,13 @@ import logging
# Third party modules
import gevent
from gevent import monkey
if "patch_subprocess" in dir(monkey): # New gevent
monkey.patch_all(thread=False, subprocess=False)
else: # Old gevent
import ssl
# Fix PROTOCOL_SSLv3 not defined
if "PROTOCOL_SSLv3" not in dir(ssl):
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)
# Not thread: pyfilesystem and systray icon, Not subprocess: Gevent 1.1+