Browse Source

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

HelloZeroNet 8 years ago
parent
commit
44a68104fb
4 changed files with 14 additions and 22 deletions
  1. 1 1
      src/Config.py
  2. 1 1
      src/Connection/ConnectionServer.py
  3. 6 13
      src/Test/TestConnectionServer.py
  4. 6 7
      src/main.py

+ 1 - 1
src/Config.py

@@ -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()

+ 1 - 1
src/Connection/ConnectionServer.py

@@ -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()

+ 6 - 13
src/Test/TestConnectionServer.py

@@ -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
-        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()
+        # 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()
 
-        # 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)

+ 6 - 7
src/main.py

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