From 945da5985ee86ba9e1f9ac96c1cf25f7d6d609b2 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 29 May 2018 11:04:13 -0400 Subject: [PATCH] fix age used in datastore to determine if a value is expired --- lbrynet/dht/datastore.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lbrynet/dht/datastore.py b/lbrynet/dht/datastore.py index f9e06923c..012122335 100644 --- a/lbrynet/dht/datastore.py +++ b/lbrynet/dht/datastore.py @@ -10,7 +10,7 @@ class DictDataStore(UserDict.DictMixin): def __init__(self, getTime=None): # Dictionary format: - # { : (, , ) } + # { : (, , , ) } self._dict = {} if not getTime: from twisted.internet import reactor @@ -35,7 +35,7 @@ class DictDataStore(UserDict.DictMixin): """ Returns only non-expired peers """ - return filter(lambda peer: self._getTime() - peer[2] < constants.dataExpireTimeout, self._dict[key]) + return filter(lambda peer: self._getTime() - peer[3] < constants.dataExpireTimeout, self._dict[key]) def removeExpiredPeers(self): for key in self._dict.keys(): @@ -46,9 +46,7 @@ class DictDataStore(UserDict.DictMixin): self._dict[key] = unexpired_peers def hasPeersForBlob(self, key): - if key in self._dict and len(self.filter_bad_and_expired_peers(key)): - return True - return False + return True if key in self._dict and len(self.filter_bad_and_expired_peers(key)) else False def addPeerToBlob(self, contact, key, compact_address, lastPublished, originallyPublished, originalPublisherID): if key in self._dict: @@ -60,12 +58,6 @@ class DictDataStore(UserDict.DictMixin): def getPeersForBlob(self, key): return [] if key not in self._dict else [val[1] for val in self.filter_bad_and_expired_peers(key)] - def removePeer(self, value): - for key in self._dict: - self._dict[key] = [val for val in self._dict[key] if val[1] != value] - if not self._dict[key]: - del self._dict[key] - def getStoringContacts(self): contacts = set() for key in self._dict: