From e2e28338f3e7fccf61fd5cd2c9b7931fcc88d205 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Wed, 2 Aug 2017 12:45:42 -0400 Subject: [PATCH] in ConnectionManager, be consistent and initialize conf values in __init__ --- lbrynet/core/client/ConnectionManager.py | 10 ++++++---- tests/unit/core/client/test_ConnectionManager.py | 8 +++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lbrynet/core/client/ConnectionManager.py b/lbrynet/core/client/ConnectionManager.py index 294172619..98efe2fed 100644 --- a/lbrynet/core/client/ConnectionManager.py +++ b/lbrynet/core/client/ConnectionManager.py @@ -26,11 +26,13 @@ class ConnectionManager(object): def __init__(self, downloader, rate_limiter, primary_request_creators, secondary_request_creators): + self.seek_head_blob_first = conf.settings['seek_head_blob_first'] + self.max_connections_per_stream = conf.settings['max_connections_per_stream'] + self.downloader = downloader self.rate_limiter = rate_limiter self._primary_request_creators = primary_request_creators self._secondary_request_creators = secondary_request_creators - self.seek_head_blob_first = conf.settings['seek_head_blob_first'] self._peer_connections = {} # {Peer: PeerConnectionHandler} self._connections_closing = {} # {Peer: deferred (fired when the connection is closed)} self._next_manage_call = None @@ -148,10 +150,10 @@ class ConnectionManager(object): @defer.inlineCallbacks def manage(self, schedule_next_call=True): self._manage_deferred = defer.Deferred() - if len(self._peer_connections) < conf.settings['max_connections_per_stream']: + if len(self._peer_connections) < self.max_connections_per_stream: log.debug("%s have %d connections, looking for %d", self._get_log_name(), len(self._peer_connections), - conf.settings['max_connections_per_stream']) + self.max_connections_per_stream) peers = yield self._get_new_peers() for peer in peers: self._connect_to_peer(peer) @@ -171,7 +173,7 @@ class ConnectionManager(object): @defer.inlineCallbacks def _get_new_peers(self): - new_conns_needed = conf.settings['max_connections_per_stream'] - len(self._peer_connections) + new_conns_needed = self.max_connections_per_stream - len(self._peer_connections) if new_conns_needed < 1: defer.returnValue([]) # we always get the peer from the first request creator diff --git a/tests/unit/core/client/test_ConnectionManager.py b/tests/unit/core/client/test_ConnectionManager.py index fa7a5ee30..4fa508d19 100644 --- a/tests/unit/core/client/test_ConnectionManager.py +++ b/tests/unit/core/client/test_ConnectionManager.py @@ -136,8 +136,6 @@ class TestIntegrationConnectionManager(unittest.TestCase): from lbrynet.core.client.ConnectionManager import ConnectionManager self.connection_manager = ConnectionManager(self.downloader, self.rate_limiter, [self.primary_request_creator], []) - - self.connection_manager.seek_head_blob_first = seek_head_blob_first self.connection_manager._start() @@ -242,14 +240,14 @@ class TestIntegrationConnectionManager(unittest.TestCase): """ test header first seeks """ - @defer.inlineCallbacks + @defer.inlineCallbacks def test_no_peer_for_head_blob(self): - # test that if we can't find blobs for the head blob, + # test that if we can't find blobs for the head blob, # it looks at the next unavailable and makes connection self._init_connection_manager(seek_head_blob_first=True) self.server = MocServerProtocolFactory(self.clock) self.server_port = reactor.listenTCP(PEER_PORT, self.server, interface=LOCAL_HOST) - + self.primary_request_creator.peers_to_return_head_blob = [] self.primary_request_creator.peers_to_return = [self.TEST_PEER]