use reactor time in Delay
This commit is contained in:
parent
4eab77fa10
commit
a96d827c0f
2 changed files with 6 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
Loading…
Reference in a new issue