clean up and clarify in docstring when/where None is returned while searching for peers
This commit is contained in:
parent
e0985695ac
commit
a9e6c89693
2 changed files with 24 additions and 21 deletions
|
@ -73,8 +73,13 @@ class BlobRequester(object):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_new_peers_for_next_unavailable(self):
|
def get_new_peers_for_next_unavailable(self):
|
||||||
""" look for peers for the next unavailable blob """
|
"""
|
||||||
|
Look for peers for the next unavailable blob, if we have
|
||||||
|
all blobs, return an empty list
|
||||||
|
"""
|
||||||
blob_hash = yield self._get_hash_for_peer_search()
|
blob_hash = yield self._get_hash_for_peer_search()
|
||||||
|
if blob_hash is None:
|
||||||
|
defer.returnValue([])
|
||||||
peers = yield self._find_peers_for_hash(blob_hash)
|
peers = yield self._find_peers_for_hash(blob_hash)
|
||||||
defer.returnValue(peers)
|
defer.returnValue(peers)
|
||||||
|
|
||||||
|
@ -112,6 +117,10 @@ class BlobRequester(object):
|
||||||
return defer.succeed(sent_request)
|
return defer.succeed(sent_request)
|
||||||
|
|
||||||
def _get_hash_for_peer_search(self):
|
def _get_hash_for_peer_search(self):
|
||||||
|
"""
|
||||||
|
Get next unavailable hash for blob,
|
||||||
|
returns None if there is nothing left to download
|
||||||
|
"""
|
||||||
r = None
|
r = None
|
||||||
blobs_to_download = self._blobs_to_download()
|
blobs_to_download = self._blobs_to_download()
|
||||||
if blobs_to_download:
|
if blobs_to_download:
|
||||||
|
@ -125,9 +134,6 @@ class BlobRequester(object):
|
||||||
return defer.succeed(r)
|
return defer.succeed(r)
|
||||||
|
|
||||||
def _find_peers_for_hash(self, h):
|
def _find_peers_for_hash(self, h):
|
||||||
if h is None:
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
d = self.peer_finder.find_peers_for_blob(h)
|
d = self.peer_finder.find_peers_for_blob(h)
|
||||||
|
|
||||||
def choose_best_peers(peers):
|
def choose_best_peers(peers):
|
||||||
|
|
|
@ -163,9 +163,6 @@ class ConnectionManager(object):
|
||||||
self._next_manage_call = utils.call_later(self.MANAGE_CALL_INTERVAL_SEC, self.manage)
|
self._next_manage_call = utils.call_later(self.MANAGE_CALL_INTERVAL_SEC, self.manage)
|
||||||
|
|
||||||
def return_shuffled_peers_not_connected_to(self, peers, new_conns_needed):
|
def return_shuffled_peers_not_connected_to(self, peers, new_conns_needed):
|
||||||
if peers is None:
|
|
||||||
# can happen if there is some error in the lookup
|
|
||||||
return []
|
|
||||||
out = [peer for peer in peers if peer not in self._peer_connections]
|
out = [peer for peer in peers if peer not in self._peer_connections]
|
||||||
random.shuffle(out)
|
random.shuffle(out)
|
||||||
return out[0:new_conns_needed]
|
return out[0:new_conns_needed]
|
||||||
|
@ -204,7 +201,7 @@ class ConnectionManager(object):
|
||||||
|
|
||||||
|
|
||||||
def _connect_to_peer(self, peer):
|
def _connect_to_peer(self, peer):
|
||||||
if peer is None or self.stopped:
|
if self.stopped:
|
||||||
return
|
return
|
||||||
|
|
||||||
log.debug("%s Trying to connect to %s", self._get_log_name(), peer)
|
log.debug("%s Trying to connect to %s", self._get_log_name(), peer)
|
||||||
|
|
Loading…
Reference in a new issue