Commit 004aa1f0 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

The dead connections are now detected and removed

parent 1f36db14
...@@ -103,11 +103,20 @@ def killConnection(id): ...@@ -103,11 +103,20 @@ def killConnection(id):
log_message("Can't kill connection to " + peer + ": uncaught error", 1) log_message("Can't kill connection to " + peer + ": uncaught error", 1)
pass pass
def checkConnections():
for id in connection_dict:
p, iface = connection_dict[id]
if p.poll() != None:
log_message('Connection with ' + str(id) + ' has failed', 3)
free_interface_set.add(iface)
log_message('Updating peers database', 5)
peer_db.execute("UPDATE peers SET used = 0 WHERE id = ?", (id,))
def refreshConnections(): def refreshConnections():
checkConnections()
# Kill some random connections # Kill some random connections
try: try:
for i in range(0, int(config.refresh_count)): for i in range(0, max(0, len(connection_dict) - config.client_count + config.refresh_count)):
id = random.choice(connection_dict.keys()) id = random.choice(connection_dict.keys())
killConnection(id) killConnection(id)
except Exception: except Exception:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment