Simple connection karma to avoid update flood
This commit is contained in:
parent
f735862977
commit
555c136143
4 changed files with 31 additions and 5 deletions
|
@ -17,7 +17,7 @@ class Connection(object):
|
|||
"sock", "sock_wrapped", "ip", "port", "cert_pin", "site_lock", "id", "protocol", "type", "server", "unpacker", "req_id",
|
||||
"handshake", "crypt", "connected", "event_connected", "closed", "start_time", "last_recv_time",
|
||||
"last_message_time", "last_send_time", "last_sent_time", "incomplete_buff_recv", "bytes_recv", "bytes_sent",
|
||||
"last_ping_delay", "last_req_time", "last_cmd", "name", "updateName", "waiting_requests", "waiting_streams"
|
||||
"last_ping_delay", "last_req_time", "last_cmd", "bad_actions", "name", "updateName", "waiting_requests", "waiting_streams"
|
||||
)
|
||||
|
||||
def __init__(self, server, ip, port, sock=None, site_lock=None):
|
||||
|
@ -56,6 +56,7 @@ class Connection(object):
|
|||
self.last_ping_delay = None
|
||||
self.last_req_time = 0
|
||||
self.last_cmd = None
|
||||
self.bad_actions = 0
|
||||
|
||||
self.name = None
|
||||
self.updateName()
|
||||
|
@ -75,6 +76,12 @@ class Connection(object):
|
|||
def log(self, text):
|
||||
self.server.log.debug("%s > %s" % (self.name, text))
|
||||
|
||||
def badAction(self, weight=1):
|
||||
self.bad_actions += weight
|
||||
|
||||
def goodAction(self):
|
||||
self.bad_actions = 0
|
||||
|
||||
# Open connection to peer and wait for handshake
|
||||
def connect(self):
|
||||
self.log("Connecting...")
|
||||
|
|
|
@ -164,7 +164,9 @@ class ConnectionServer:
|
|||
self.connections.remove(connection)
|
||||
|
||||
def checkConnections(self):
|
||||
run_i = 0
|
||||
while self.running:
|
||||
run_i += 1
|
||||
time.sleep(60) # Check every minute
|
||||
self.ip_incoming = {} # Reset connected ips counter
|
||||
self.broken_ssl_peer_ids = {} # Reset broken ssl peerids count
|
||||
|
@ -205,3 +207,11 @@ class ConnectionServer:
|
|||
elif idle > 60 and connection.protocol == "?": # No connection after 1 min
|
||||
connection.log("[Cleanup] Connect timeout: %s" % idle)
|
||||
connection.close()
|
||||
|
||||
elif idle < 60 and connection.bad_actions > 40:
|
||||
connection.log("[Cleanup] Too many bad actions: %s" % connection.bad_actions)
|
||||
connection.close()
|
||||
|
||||
elif run_i % 30 == 0:
|
||||
# Reset bad action counter every 30 min
|
||||
connection.bad_actions = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue