Use timers not affected by system clock updates (#42)
See paragraph two of https://docs.python.org/3/library/time.html#time.time
This commit is contained in:
parent
3b93189ef2
commit
ecde2c9258
@ -16,7 +16,7 @@ class KBucket(object):
|
||||
self.ksize = ksize
|
||||
|
||||
def touchLastUpdated(self):
|
||||
self.lastUpdated = time.time()
|
||||
self.lastUpdated = time.monotonic()
|
||||
|
||||
def getNodes(self):
|
||||
return list(self.nodes.values())
|
||||
@ -136,7 +136,7 @@ class RoutingTable(object):
|
||||
Get all of the buckets that haven't been updated in over
|
||||
an hour.
|
||||
"""
|
||||
hrago = time.time() - 3600
|
||||
hrago = time.monotonic() - 3600
|
||||
return [b for b in self.buckets if b.lastUpdated < hrago]
|
||||
|
||||
def removeContact(self, node):
|
||||
|
@ -52,7 +52,7 @@ class ForgetfulStorage(IStorage):
|
||||
def __setitem__(self, key, value):
|
||||
if key in self.data:
|
||||
del self.data[key]
|
||||
self.data[key] = (time.time(), value)
|
||||
self.data[key] = (time.monotonic(), value)
|
||||
self.cull()
|
||||
|
||||
def cull(self):
|
||||
@ -78,7 +78,7 @@ class ForgetfulStorage(IStorage):
|
||||
return repr(self.data)
|
||||
|
||||
def iteritemsOlderThan(self, secondsOld):
|
||||
minBirthday = time.time() - secondsOld
|
||||
minBirthday = time.monotonic() - secondsOld
|
||||
zipped = self._tripleIterable()
|
||||
matches = takewhile(lambda r: minBirthday >= r[1], zipped)
|
||||
return list(map(operator.itemgetter(0, 2), matches))
|
||||
|
Loading…
Reference in New Issue
Block a user