From 0529fe23131b1a9ee400392a8898386be7cd362f Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sat, 11 Mar 2017 12:14:40 +0100 Subject: [PATCH] Known node count updates - if too many nodes, only delete oldest nodes in bootstrap provider mode, in normal mode ignore new nodes as it used to before - in bootstrap provider mode, penalise nodes announced by others by 1 day instead of 3 hours --- src/class_receiveDataThread.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index 124e06c0..0ddd5739 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -630,17 +630,18 @@ class receiveDataThread(threading.Thread): knownnodes.knownNodes[recaddrStream] = {} peerFromAddrMessage = state.Peer(hostStandardFormat, recaddrPort) if peerFromAddrMessage not in knownnodes.knownNodes[recaddrStream]: - knownnodes.trimKnownNodes(recaddrStream) # only if recent if timeSomeoneElseReceivedMessageFromThisNode > (int(time.time()) - 10800) and timeSomeoneElseReceivedMessageFromThisNode < (int(time.time()) + 10800): - logger.debug('added new node ' + str(peerFromAddrMessage) + ' to knownNodes in stream ' + str(recaddrStream)) # bootstrap provider? if BMConfigParser().safeGetInt('bitmessagesettings', 'maxoutboundconnections') >= \ BMConfigParser().safeGetInt('bitmessagesettings', 'maxtotalconnections', 200): + knownnodes.trimKnownNodes(recaddrStream) with knownnodes.knownNodesLock: - knownnodes.knownNodes[recaddrStream][peerFromAddrMessage] = int(time.time()) - 10800 + knownnodes.knownNodes[recaddrStream][peerFromAddrMessage] = int(time.time()) - 86400 # penalise initially by 1 day + logger.debug('added new node ' + str(peerFromAddrMessage) + ' to knownNodes in stream ' + str(recaddrStream)) + shared.needToWriteKnownNodesToDisk = True # normal mode - else: + elif len(knownnodes.knownNodes[recaddrStream]) < 20000: with knownnodes.knownNodesLock: knownnodes.knownNodes[recaddrStream][peerFromAddrMessage] = timeSomeoneElseReceivedMessageFromThisNode hostDetails = ( @@ -648,7 +649,8 @@ class receiveDataThread(threading.Thread): recaddrStream, recaddrServices, hostStandardFormat, recaddrPort) protocol.broadcastToSendDataQueues(( recaddrStream, 'advertisepeer', hostDetails)) - shared.needToWriteKnownNodesToDisk = True + logger.debug('added new node ' + str(peerFromAddrMessage) + ' to knownNodes in stream ' + str(recaddrStream)) + shared.needToWriteKnownNodesToDisk = True # only update if normal mode elif BMConfigParser().safeGetInt('bitmessagesettings', 'maxoutboundconnections') < \ BMConfigParser().safeGetInt('bitmessagesettings', 'maxtotalconnections', 200):