Add or update knownnode for connected Peer for both inbound

and outbound connections when fully established, update lastseen
before closing connection.
This commit is contained in:
Dmitri Bogomolov 2020-06-09 12:54:55 +03:00
parent d9ddbe8d24
commit 54e44eac95
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -140,13 +140,17 @@ class TCPConnection(BMProto, TLSDispatcher):
if not self.isOutbound and not self.local: if not self.isOutbound and not self.local:
state.clientHasReceivedIncomingConnections = True state.clientHasReceivedIncomingConnections = True
UISignalQueue.put(('setStatusIcon', 'green')) UISignalQueue.put(('setStatusIcon', 'green'))
UISignalQueue.put( UISignalQueue.put((
('updateNetworkStatusTab', ( 'updateNetworkStatusTab', (self.isOutbound, True, self.destination)
self.isOutbound, True, self.destination))) ))
self.antiIntersectionDelay(True) self.antiIntersectionDelay(True)
self.fullyEstablished = True self.fullyEstablished = True
if self.isOutbound: # The connection having host suitable for knownnodes
if self.isOutbound or not self.local and not state.socksIP:
knownnodes.increaseRating(self.destination) knownnodes.increaseRating(self.destination)
with knownnodes.knownNodesLock:
for s in self.streams:
knownnodes.addKnownNode(s, self.destination, time.time())
Dandelion().maybeAddStem(self) Dandelion().maybeAddStem(self)
self.sendAddr() self.sendAddr()
self.sendBigInv() self.sendBigInv()
@ -254,10 +258,6 @@ class TCPConnection(BMProto, TLSDispatcher):
def handle_read(self): def handle_read(self):
"""Callback for reading from a socket""" """Callback for reading from a socket"""
TLSDispatcher.handle_read(self) TLSDispatcher.handle_read(self)
if self.isOutbound and self.fullyEstablished:
for s in self.streams:
with knownnodes.knownNodesLock:
knownnodes.addKnownNode(s, self.destination, time.time())
receiveDataQueue.put(self.destination) receiveDataQueue.put(self.destination)
def handle_write(self): def handle_write(self):
@ -266,15 +266,20 @@ class TCPConnection(BMProto, TLSDispatcher):
def handle_close(self): def handle_close(self):
"""Callback for connection being closed.""" """Callback for connection being closed."""
if self.isOutbound and not self.fullyEstablished: host_is_global = self.isOutbound or not self.local and not state.socksIP
knownnodes.decreaseRating(self.destination)
if self.fullyEstablished: if self.fullyEstablished:
UISignalQueue.put(( UISignalQueue.put((
'updateNetworkStatusTab', 'updateNetworkStatusTab',
(self.isOutbound, False, self.destination) (self.isOutbound, False, self.destination)
)) ))
if self.isOutbound: if host_is_global:
with knownnodes.knownNodesLock:
for s in self.streams:
knownnodes.addKnownNode(
s, self.destination, time.time())
Dandelion().maybeRemoveStem(self) Dandelion().maybeRemoveStem(self)
elif host_is_global:
knownnodes.decreaseRating(self.destination)
BMProto.handle_close(self) BMProto.handle_close(self)