Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions kademlia/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ async def get(self, key):
self.ksize, self.alpha)
return await spider.find()

async def get_digest(self, dkey):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make most sense to remove lines 145 - 155 and replace them with a call to this method (so there isn't any unnecessary duplication).

"""
Get a SHA1 digest key (bytes) if the network has it.

Returns:
:class:`None` if not found, the value otherwise.
"""
log.info("Looking up key %s", dkey)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.info("Looking up key %s", dkey)
log.info("Looking up key digest %s", dkey)

# if this node has it, return it
if self.storage.get(dkey) is not None:
return self.storage.get(dkey)
node = Node(dkey)
nearest = self.protocol.router.find_neighbors(node)
if not nearest:
log.warning("There are no known neighbors to get key %s", dkey)
return None
spider = ValueSpiderCrawl(self.protocol, node, nearest,
self.ksize, self.alpha)
return await spider.find()

async def set(self, key, value):
"""
Set the given string key to the given value in the network.
Expand Down