Пример #1
0
    def _try_peers(self, peers):
        """Loops through the list of peers and tries to connect to them (only
        one at a time right now).

        TODO: We're currently connecting to multiple peers, but not coordinating the work we send
              well.
        """
        for peer_entry in peers:
            if peer_entry['id'] == self.peer_id:
                continue

            print('Trying peer: {}'.format(peer_entry))
            peer = Peer(peer_entry['id'], peer_entry['ip'], peer_entry['port'],
                        self._torrent)
            try:
                peer.connect(self.peer_id)
            except PeerConnectionError:
                continue
            else:
                self._peers.append(peer)
                peer.subscribe_for_messages_to_client(
                    self.peer_message_receiver(peer))