From 95fc981ae219b4ecadf0b2ac67cff026c659b0d5 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Mon, 31 Aug 2020 11:25:53 +0200 Subject: [PATCH] Finish timeOffsetWrongCount - now notifies in status bar - fixes #1433 --- src/network/tcp.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/network/tcp.py b/src/network/tcp.py index 0bdd3269..64153d9d 100644 --- a/src/network/tcp.py +++ b/src/network/tcp.py @@ -2,6 +2,7 @@ TCP protocol handler """ # pylint: disable=too-many-ancestors +import l10n import logging import math import random @@ -29,11 +30,13 @@ from network.socks5 import Socks5Connection from network.tls import TLSDispatcher from node import Peer from queues import invQueue, receiveDataQueue, UISignalQueue +from tr import _translate logger = logging.getLogger('default') maximumAgeOfNodesThatIAdvertiseToOthers = 10800 #: Equals three hours +maximumTimeOffsetWrongCount = 3 #: Connections with wrong time offset class TCPConnection(BMProto, TLSDispatcher): @@ -124,6 +127,22 @@ class TCPConnection(BMProto, TLSDispatcher): ' for %.2fs', delay) self.skipUntil = time.time() + delay + def checkTimeOffsetNotification(self): + """ + Check if we have connected to too many nodes which have too high + time offset from us + """ + if BMProto.timeOffsetWrongCount > \ + maximumTimeOffsetWrongCount and \ + not self.fullyEstablished: + UISignalQueue.put(( + 'updateStatusBar', + _translate( + "MainWindow", + "The time on your computer, %1, may be wrong. " + "Please verify your settings." + ).arg(l10n.formatTimestamp()))) + def state_connection_fully_established(self): """ State after the bitmessage protocol handshake is completed @@ -275,8 +294,10 @@ class TCPConnection(BMProto, TLSDispatcher): knownnodes.addKnownNode( self.streams, self.destination, time.time()) Dandelion().maybeRemoveStem(self) - elif host_is_global: - knownnodes.decreaseRating(self.destination) + else: + self.checkTimeOffsetNotification() + if host_is_global: + knownnodes.decreaseRating(self.destination) BMProto.handle_close(self)