forked from LBRYCommunity/lbry-sdk
findValue inlinecallbacks refactor
This commit is contained in:
parent
43896c8d17
commit
16fcc3f5c1
1 changed files with 17 additions and 24 deletions
|
@ -418,14 +418,13 @@ class Node(object):
|
|||
to the specified key
|
||||
@rtype: twisted.internet.defer.Deferred
|
||||
"""
|
||||
# Prepare a callback for this operation
|
||||
outerDf = defer.Deferred()
|
||||
|
||||
def checkResult(result):
|
||||
if isinstance(result, dict):
|
||||
# Execute the search
|
||||
iterative_find_result = yield self._iterativeFind(key, rpc='findValue')
|
||||
if isinstance(iterative_find_result, dict):
|
||||
# We have found the value; now see who was the closest contact without it...
|
||||
# ...and store the key/value pair
|
||||
outerDf.callback(result)
|
||||
defer.returnValue(iterative_find_result)
|
||||
else:
|
||||
# The value wasn't found, but a list of contacts was returned
|
||||
# Now, see if we have the value (it might seem wasteful to search on the network
|
||||
|
@ -433,18 +432,12 @@ class Node(object):
|
|||
# network
|
||||
if self._dataStore.hasPeersForBlob(key):
|
||||
# Ok, we have the value locally, so use that
|
||||
peers = self._dataStore.getPeersForBlob(key)
|
||||
# Send this value to the closest node without it
|
||||
outerDf.callback({key: peers})
|
||||
peers = self._dataStore.getPeersForBlob(key)
|
||||
defer.returnValue({key: peers})
|
||||
else:
|
||||
# Ok, value does not exist in DHT at all
|
||||
outerDf.callback(result)
|
||||
|
||||
# Execute the search
|
||||
iterative_find_result = yield self._iterativeFind(key, rpc='findValue')
|
||||
checkResult(iterative_find_result)
|
||||
result = yield outerDf
|
||||
defer.returnValue(result)
|
||||
defer.returnValue(iterative_find_result)
|
||||
|
||||
def addContact(self, contact):
|
||||
""" Add/update the given contact; simple wrapper for the same method
|
||||
|
|
Loading…
Reference in a new issue