getPeersForBlob inlinecallbacks refactor
This commit is contained in:
parent
8e9f3c90a1
commit
46e31d5b45
1 changed files with 13 additions and 20 deletions
|
@ -204,28 +204,21 @@ class Node(object):
|
||||||
def announceHaveBlob(self, key, port):
|
def announceHaveBlob(self, key, port):
|
||||||
return self.iterativeAnnounceHaveBlob(key, {'port': port, 'lbryid': self.lbryid})
|
return self.iterativeAnnounceHaveBlob(key, {'port': port, 'lbryid': self.lbryid})
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def getPeersForBlob(self, blob_hash):
|
def getPeersForBlob(self, blob_hash):
|
||||||
def expand_and_filter(result):
|
result = yield self.iterativeFindValue(blob_hash)
|
||||||
expanded_peers = []
|
expanded_peers = []
|
||||||
if isinstance(result, dict):
|
if result:
|
||||||
if blob_hash in result:
|
if blob_hash in result:
|
||||||
for peer in result[blob_hash]:
|
for peer in result[blob_hash]:
|
||||||
if self.lbryid != peer[6:]:
|
if self.lbryid != peer[6:]:
|
||||||
host = ".".join([str(ord(d)) for d in peer[:4]])
|
host = ".".join([str(ord(d)) for d in peer[:4]])
|
||||||
if host == "127.0.0.1":
|
if host == "127.0.0.1" and "from_peer" in result and result["from_peer"] != "self":
|
||||||
if "from_peer" in result:
|
|
||||||
if result["from_peer"] != "self":
|
|
||||||
host = result["from_peer"]
|
host = result["from_peer"]
|
||||||
port, = struct.unpack('>H', peer[4:6])
|
port, = struct.unpack('>H', peer[4:6])
|
||||||
|
if (host, port) not in expanded_peers:
|
||||||
expanded_peers.append((host, port))
|
expanded_peers.append((host, port))
|
||||||
return expanded_peers
|
defer.returnValue(expanded_peers)
|
||||||
|
|
||||||
def find_failed(err):
|
|
||||||
return []
|
|
||||||
|
|
||||||
d = self.iterativeFindValue(blob_hash)
|
|
||||||
d.addCallbacks(expand_and_filter, find_failed)
|
|
||||||
return d
|
|
||||||
|
|
||||||
def get_most_popular_hashes(self, num_to_return):
|
def get_most_popular_hashes(self, num_to_return):
|
||||||
return self.hash_watcher.most_popular_hashes(num_to_return)
|
return self.hash_watcher.most_popular_hashes(num_to_return)
|
||||||
|
|
Loading…
Reference in a new issue