From a96d827c0f0ee754e174874e62f2f1f2fcbeb561 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 5 Mar 2018 13:28:59 -0500 Subject: [PATCH] use reactor time in Delay --- lbrynet/dht/delay.py | 11 +++++------ lbrynet/dht/protocol.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lbrynet/dht/delay.py b/lbrynet/dht/delay.py index 9610a73f8..7ef26fcc6 100644 --- a/lbrynet/dht/delay.py +++ b/lbrynet/dht/delay.py @@ -1,18 +1,17 @@ -import time - - class Delay(object): maxToSendDelay = 10 ** -3 # 0.05 minToSendDelay = 10 ** -5 # 0.01 - def __init__(self, start=0): + def __init__(self, start=0, getTime=None): self._next = start + if not getTime: + from time import time as getTime + self._getTime = getTime # TODO: explain why this logic is like it is. And add tests that # show that it actually does what it needs to do. def __call__(self): - ts = time.time() - delay = 0 + ts = self._getTime() if ts >= self._next: delay = self.minToSendDelay self._next = ts + self.minToSendDelay diff --git a/lbrynet/dht/protocol.py b/lbrynet/dht/protocol.py index 2c624dead..505ce4202 100644 --- a/lbrynet/dht/protocol.py +++ b/lbrynet/dht/protocol.py @@ -29,7 +29,7 @@ class KademliaProtocol(protocol.DatagramProtocol): self._sentMessages = {} self._partialMessages = {} self._partialMessagesProgress = {} - self._delay = Delay() + self._delay = Delay(0, self._node.clock.seconds) # keep track of outstanding writes so that they # can be cancelled on shutdown self._call_later_list = {}