fix issue in republishing keys with only digest available, fixing #25

This commit is contained in:
Brian Muller 2017-03-15 14:40:32 -04:00
parent 55594096d1
commit e8ab5f8335

View File

@ -80,8 +80,8 @@ class Server(object):
await asyncio.gather(*ds) await asyncio.gather(*ds)
# now republish keys older than one hour # now republish keys older than one hour
for key, value in self.storage.iteritemsOlderThan(3600): for dkey, value in self.storage.iteritemsOlderThan(3600):
await self.set(key, value) await self.digest_set(dkey, value)
def bootstrappableNeighbors(self): def bootstrappableNeighbors(self):
""" """
@ -151,20 +151,26 @@ class Server(object):
async def set(self, key, value): async def set(self, key, value):
""" """
Set the given key to the given value in the network. Set the given string key to the given value in the network.
""" """
self.log.debug("setting '%s' = '%s' on network" % (key, value)) self.log.debug("setting '%s' = '%s' on network" % (key, value))
dkey = digest(key) dkey = digest(key)
return await self.set_digest(dkey, value)
async def set_digest(self, dkey, value):
"""
Set the given SHA1 digest key (bytes) to the given value in the network.
"""
node = Node(dkey) node = Node(dkey)
nearest = self.protocol.router.findNeighbors(node) nearest = self.protocol.router.findNeighbors(node)
if len(nearest) == 0: if len(nearest) == 0:
self.log.warning("There are no known neighbors to set key %s" % key) self.log.warning("There are no known neighbors to set key %s" % dkey.hex())
return False return False
spider = NodeSpiderCrawl(self.protocol, node, nearest, self.ksize, self.alpha) spider = NodeSpiderCrawl(self.protocol, node, nearest, self.ksize, self.alpha)
nodes = await spider.find() nodes = await spider.find()
self.log.info("setting '%s' on %s" % (key, list(map(str, nodes)))) self.log.info("setting '%s' on %s" % (dkey.hex(), list(map(str, nodes))))
# if this node is close too, then store here as well # if this node is close too, then store here as well
if self.node.distanceTo(node) < max([n.distanceTo(node) for n in nodes]): if self.node.distanceTo(node) < max([n.distanceTo(node) for n in nodes]):