From 0bb62515a8881d2f8f32e89ddf0f99be0f338b4e Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Wed, 11 Jan 2017 11:45:18 -0600 Subject: [PATCH] reorder functions to match call order --- lbrynet/core/client/ConnectionManager.py | 50 ++++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lbrynet/core/client/ConnectionManager.py b/lbrynet/core/client/ConnectionManager.py index 81b436e03..8a9899bb6 100644 --- a/lbrynet/core/client/ConnectionManager.py +++ b/lbrynet/core/client/ConnectionManager.py @@ -125,31 +125,6 @@ class ConnectionManager(object): del self._connections_closing[peer] d.callback(True) - def _rank_request_creator_connections(self): - """Returns an ordered list of our request creators, ranked according - to which has the least number of connections open that it - likes - """ - def count_peers(request_creator): - return len([ - p for p in self._peer_connections.itervalues() - if request_creator in p.request_creators]) - - return sorted(self._primary_request_creators, key=count_peers) - - def _connect_to_peer(self, peer): - if peer is None or self.stopped: - return - - from twisted.internet import reactor - - log.debug("Trying to connect to %s", peer) - factory = ClientProtocolFactory(peer, self.rate_limiter, self) - self._peer_connections[peer] = PeerConnectionHandler(self._primary_request_creators[:], - factory) - connection = reactor.connectTCP(peer.host, peer.port, factory) - self._peer_connections[peer].connection = connection - @defer.inlineCallbacks def _manage(self): from twisted.internet import reactor @@ -164,6 +139,18 @@ class ConnectionManager(object): log.exception('Something bad happened picking a peer') self._next_manage_call = reactor.callLater(1, self._manage) + def _rank_request_creator_connections(self): + """Returns an ordered list of our request creators, ranked according + to which has the least number of connections open that it + likes + """ + def count_peers(request_creator): + return len([ + p for p in self._peer_connections.itervalues() + if request_creator in p.request_creators]) + + return sorted(self._primary_request_creators, key=count_peers) + @defer.inlineCallbacks def _get_new_peers(self, request_creators): log.debug("Trying to get a new peer to connect to") @@ -187,3 +174,16 @@ class ConnectionManager(object): return peer log.debug("Couldn't find a good peer to connect to") return None + + def _connect_to_peer(self, peer): + if peer is None or self.stopped: + return + + from twisted.internet import reactor + + log.debug("Trying to connect to %s", peer) + factory = ClientProtocolFactory(peer, self.rate_limiter, self) + self._peer_connections[peer] = PeerConnectionHandler(self._primary_request_creators[:], + factory) + connection = reactor.connectTCP(peer.host, peer.port, factory) + self._peer_connections[peer].connection = connection