forked from LBRYCommunity/lbry-sdk
in ConnectionManager, be consistent and initialize conf values in __init__
This commit is contained in:
parent
a31b6b192f
commit
e2e28338f3
2 changed files with 9 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in a new issue