fix age used in datastore to determine if a value is expired

This commit is contained in:
Jack Robison 2018-05-29 11:04:13 -04:00
parent 921ee3c4c1
commit 945da5985e
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -10,7 +10,7 @@ class DictDataStore(UserDict.DictMixin):
def __init__(self, getTime=None):
# Dictionary format:
# { <key>: (<value>, <lastPublished>, <originallyPublished> <originalPublisherID>) }
# { <key>: (<contact>, <value>, <lastPublished>, <originallyPublished> <originalPublisherID>) }
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: