clean up and clarify in docstring when/where None is returned while searching for peers

This commit is contained in:
Kay Kurokawa 2017-08-16 15:04:50 -04:00
parent e0985695ac
commit a9e6c89693
2 changed files with 24 additions and 21 deletions

View file

@ -73,8 +73,13 @@ class BlobRequester(object):
@defer.inlineCallbacks
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()
if blob_hash is None:
defer.returnValue([])
peers = yield self._find_peers_for_hash(blob_hash)
defer.returnValue(peers)
@ -112,6 +117,10 @@ class BlobRequester(object):
return defer.succeed(sent_request)
def _get_hash_for_peer_search(self):
"""
Get next unavailable hash for blob,
returns None if there is nothing left to download
"""
r = None
blobs_to_download = self._blobs_to_download()
if blobs_to_download:
@ -125,9 +134,6 @@ class BlobRequester(object):
return defer.succeed(r)
def _find_peers_for_hash(self, h):
if h is None:
return None
else:
d = self.peer_finder.find_peers_for_blob(h)
def choose_best_peers(peers):

View file

@ -163,9 +163,6 @@ class ConnectionManager(object):
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):
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]
random.shuffle(out)
return out[0:new_conns_needed]
@ -204,7 +201,7 @@ class ConnectionManager(object):
def _connect_to_peer(self, peer):
if peer is None or self.stopped:
if self.stopped:
return
log.debug("%s Trying to connect to %s", self._get_log_name(), peer)