No DNS resolving in knownnodes

This commit is contained in:
Dmitri Bogomolov 2019-07-21 16:50:49 +03:00
parent 4825c5a136
commit 7215003c6f
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -191,33 +191,24 @@ def cleanupKnownNodes():
""" """
now = int(time.time()) now = int(time.time())
needToWriteKnownNodesToDisk = False needToWriteKnownNodesToDisk = False
dns_done = False
spawnConnections = not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect'
) and BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'sendoutgoingconnections')
with knownNodesLock: with knownNodesLock:
for stream in knownNodes: for stream in knownNodes:
if stream not in state.streamsInWhichIAmParticipating: if stream not in state.streamsInWhichIAmParticipating:
continue continue
keys = knownNodes[stream].keys() keys = knownNodes[stream].keys()
if len(keys) <= 1: # leave at least one node
if not dns_done and spawnConnections:
dns()
dns_done = True
continue
for node in keys: for node in keys:
if len(knownNodes[stream]) <= 1: # leave at least one node
break
try: try:
# scrap old nodes age = now - knownNodes[stream][node]["lastseen"]
if (now - knownNodes[stream][node]["lastseen"] > # scrap old nodes (age > 28 days)
2419200): # 28 days if age > 2419200:
needToWriteKnownNodesToDisk = True needToWriteKnownNodesToDisk = True
del knownNodes[stream][node] del knownNodes[stream][node]
continue continue
# scrap old nodes with low rating # scrap old nodes (age > 3 hours) with low rating
if (now - knownNodes[stream][node]["lastseen"] > 10800 and if (age > 10800 and knownNodes[stream][node]["rating"] <=
knownNodes[stream][node]["rating"] <=
knownNodesForgetRating): knownNodesForgetRating):
needToWriteKnownNodesToDisk = True needToWriteKnownNodesToDisk = True
del knownNodes[stream][node] del knownNodes[stream][node]