Do not update addrQueue if not added node to own knownnodes

and more checks in knownnodes.addKnownNode moved from bmproto.
This commit is contained in:
Dmitri Bogomolov 2019-12-04 12:33:20 +02:00
parent 0dd49761d0
commit d9ddbe8d24
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 20 additions and 17 deletions

View File

@ -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():

View File

@ -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):