Add knownnodes only by knownnodes.addKnownNode(),
now it can update lastseen.
This commit is contained in:
parent
1699c2b015
commit
739ff7b439
|
@ -65,7 +65,6 @@ def json_deserialize_knownnodes(source):
|
||||||
info = node['info']
|
info = node['info']
|
||||||
peer = Peer(str(peer['host']), peer.get('port', 8444))
|
peer = Peer(str(peer['host']), peer.get('port', 8444))
|
||||||
knownNodes[node['stream']][peer] = info
|
knownNodes[node['stream']][peer] = info
|
||||||
|
|
||||||
if not (knownNodesActual
|
if not (knownNodesActual
|
||||||
or info.get('self')) and peer not in DEFAULT_NODES:
|
or info.get('self')) and peer not in DEFAULT_NODES:
|
||||||
knownNodesActual = True
|
knownNodesActual = True
|
||||||
|
@ -95,11 +94,27 @@ def saveKnownNodes(dirName=None):
|
||||||
|
|
||||||
|
|
||||||
def addKnownNode(stream, peer, lastseen=None, is_self=False):
|
def addKnownNode(stream, peer, lastseen=None, is_self=False):
|
||||||
"""Add a new node to the dict"""
|
"""
|
||||||
|
Add a new node to the dict or update lastseen if it already exists
|
||||||
|
"""
|
||||||
|
# pylint: disable=too-many-branches
|
||||||
|
rating = 0.0
|
||||||
|
if not lastseen:
|
||||||
|
# FIXME: maybe about 28 days?
|
||||||
|
lastseen = int(time.time())
|
||||||
|
else:
|
||||||
|
lastseen = int(lastseen)
|
||||||
|
try:
|
||||||
|
knownNodes[stream][peer]['lastseen'] = lastseen
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
knownNodes[stream][peer] = {
|
knownNodes[stream][peer] = {
|
||||||
"lastseen": lastseen or time.time(),
|
'lastseen': lastseen,
|
||||||
"rating": 1 if is_self else 0,
|
'rating': rating or 1 if is_self else 0,
|
||||||
"self": is_self,
|
'self': is_self,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -456,15 +456,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
if len(knownnodes.knownNodes[stream]) < \
|
if len(knownnodes.knownNodes[stream]) < \
|
||||||
BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
|
BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
|
||||||
with knownnodes.knownNodesLock:
|
with knownnodes.knownNodesLock:
|
||||||
try:
|
knownnodes.addKnownNode(stream, peer, seenTime)
|
||||||
knownnodes.knownNodes[stream][peer]["lastseen"] = \
|
|
||||||
seenTime
|
|
||||||
except (TypeError, KeyError):
|
|
||||||
knownnodes.knownNodes[stream][peer] = {
|
|
||||||
"lastseen": seenTime,
|
|
||||||
"rating": 0,
|
|
||||||
"self": False,
|
|
||||||
}
|
|
||||||
# since we don't track peers outside of knownnodes,
|
# since we don't track peers outside of knownnodes,
|
||||||
# only spread if in knownnodes to prevent flood
|
# only spread if in knownnodes to prevent flood
|
||||||
# DISABLED TO WORKAROUND FLOOD/LEAK
|
# DISABLED TO WORKAROUND FLOOD/LEAK
|
||||||
|
|
|
@ -256,12 +256,8 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
TLSDispatcher.handle_read(self)
|
TLSDispatcher.handle_read(self)
|
||||||
if self.isOutbound and self.fullyEstablished:
|
if self.isOutbound and self.fullyEstablished:
|
||||||
for s in self.streams:
|
for s in self.streams:
|
||||||
try:
|
|
||||||
with knownnodes.knownNodesLock:
|
with knownnodes.knownNodesLock:
|
||||||
knownnodes.knownNodes[s][self.destination][
|
knownnodes.addKnownNode(s, self.destination, time.time())
|
||||||
"lastseen"] = time.time()
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
receiveDataQueue.put(self.destination)
|
receiveDataQueue.put(self.destination)
|
||||||
|
|
||||||
def handle_write(self):
|
def handle_write(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user