diff --git a/kademlia/routing.py b/kademlia/routing.py index c026312..852a150 100644 --- a/kademlia/routing.py +++ b/kademlia/routing.py @@ -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): diff --git a/kademlia/storage.py b/kademlia/storage.py index 30293d8..4e5dd64 100644 --- a/kademlia/storage.py +++ b/kademlia/storage.py @@ -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))