From d9ddbe8d2469e7e9c85894a901c13f2647695d2a Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 4 Dec 2019 12:33:20 +0200 Subject: [PATCH] Do not update addrQueue if not added node to own knownnodes and more checks in knownnodes.addKnownNode moved from bmproto. --- src/knownnodes.py | 12 ++++++++++-- src/network/bmproto.py | 25 ++++++++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/knownnodes.py b/src/knownnodes.py index 26aa2f45..77c52a25 100644 --- a/src/knownnodes.py +++ b/src/knownnodes.py @@ -105,17 +105,25 @@ def addKnownNode(stream, peer, lastseen=None, is_self=False): else: lastseen = int(lastseen) try: - knownNodes[stream][peer]['lastseen'] = lastseen - except KeyError: + info = knownNodes[stream].get(peer) + if lastseen > info['lastseen']: + info['lastseen'] = lastseen + except (KeyError, TypeError): pass else: return + if not is_self: + if len(knownNodes[stream]) > BMConfigParser().safeGetInt( + "knownnodes", "maxnodes"): + return + knownNodes[stream][peer] = { 'lastseen': lastseen, 'rating': rating or 1 if is_self else 0, 'self': is_self, } + return True def createDefaultKnownNodes(): diff --git a/src/network/bmproto.py b/src/network/bmproto.py index 48c8c37c..6c23a234 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -447,22 +447,17 @@ class BMProto(AdvancedDispatcher, ObjectTracker): and port > 0 ): peer = Peer(decodedIP, port) - try: - if knownnodes.knownNodes[stream][peer]["lastseen"] > \ - seenTime: - continue - except KeyError: - pass - if len(knownnodes.knownNodes[stream]) < \ - BMConfigParser().safeGetInt("knownnodes", "maxnodes"): - with knownnodes.knownNodesLock: - knownnodes.addKnownNode(stream, peer, seenTime) - # since we don't track peers outside of knownnodes, - # only spread if in knownnodes to prevent flood - # DISABLED TO WORKAROUND FLOOD/LEAK - # addrQueue.put((stream, peer, seenTime, - # self.destination)) + with knownnodes.knownNodesLock: + # isnew = + knownnodes.addKnownNode(stream, peer, seenTime) + + # since we don't track peers outside of knownnodes, + # only spread if in knownnodes to prevent flood + # DISABLED TO WORKAROUND FLOOD/LEAK + # if isnew: + # addrQueue.put(( + # stream, peer, seenTime, self.destination)) return True def bm_command_portcheck(self):