diff --git a/lbrynet/blob_exchange/client.py b/lbrynet/blob_exchange/client.py index 7ab36fd96..4162ef593 100644 --- a/lbrynet/blob_exchange/client.py +++ b/lbrynet/blob_exchange/client.py @@ -185,9 +185,6 @@ async def request_blob(loop: asyncio.BaseEventLoop, blob: 'BlobFile', address: s Returns [, ] """ - if blob.get_is_verified() or blob.file_exists: - # file exists but not verified means someone is writing right now, give it time, come back later - return 0, connected_transport protocol = BlobExchangeClientProtocol(loop, blob_download_timeout) if connected_transport and not connected_transport.is_closing(): connected_transport.set_protocol(protocol) @@ -199,6 +196,9 @@ async def request_blob(loop: asyncio.BaseEventLoop, blob: 'BlobFile', address: s if not connected_transport: await asyncio.wait_for(loop.create_connection(lambda: protocol, address, tcp_port), peer_connect_timeout, loop=loop) + if blob.get_is_verified() or blob.file_exists: + # file exists but not verified means someone is writing right now, give it time, come back later + return 0, connected_transport return await protocol.download_blob(blob) except (asyncio.TimeoutError, ConnectionRefusedError, ConnectionAbortedError, OSError): return 0, None diff --git a/lbrynet/blob_exchange/downloader.py b/lbrynet/blob_exchange/downloader.py index 59a5b0ec5..b602225c5 100644 --- a/lbrynet/blob_exchange/downloader.py +++ b/lbrynet/blob_exchange/downloader.py @@ -26,7 +26,7 @@ class BlobDownloader: self.connections: typing.Dict['KademliaPeer', asyncio.Transport] = {} self.rounds_won: typing.Dict['KademliaPeer', int] = {} - def should_race_continue(self): + def should_race_continue(self, blob: 'BlobFile'): if len(self.active_connections) >= self.config.max_connections_per_download: return False # if a peer won 3 or more blob races and is active as a downloader, stop the race so bandwidth improves @@ -35,7 +35,7 @@ class BlobDownloader: # for peer, task in self.active_connections.items(): # if self.scores.get(peer, 0) >= 0 and self.rounds_won.get(peer, 0) >= 3 and not task.done(): # return False - return True + return not (blob.get_is_verified() or blob.file_exists) async def request_blob_from_peer(self, blob: 'BlobFile', peer: 'KademliaPeer'): if blob.get_is_verified(): @@ -91,7 +91,7 @@ class BlobDownloader: len(batch), len(self.ignored), len(self.active_connections) ) for peer in batch: - if not self.should_race_continue(): + if not self.should_race_continue(blob): break if peer not in self.active_connections and peer not in self.ignored: log.debug("request %s from %s:%i", blob_hash[:8], peer.address, peer.tcp_port)