def send_peer_list(self): """ Get Peers Sends the peers list. :return: """ remote_peers = self.factory.get_connected_peer_addrs() logger.debug('<<< Sending connected peers to %s [%s]', self.addr_remote, remote_peers) msg = qrllegacy_pb2.LegacyMessage(func_name=qrllegacy_pb2.LegacyMessage.PL, plData=qrllegacy_pb2.PLData(peer_ips=remote_peers)) self.send(msg)
def send_peer_list(self): """ Get Peers Sends the peers list. :return: """ trusted_peers = self.peer_manager.trusted_addresses logger.debug('<<< Sending connected peers to %s [%s]', self.peer, trusted_peers) msg = qrllegacy_pb2.LegacyMessage(func_name=qrllegacy_pb2.LegacyMessage.PL, plData=qrllegacy_pb2.PLData(peer_ips=trusted_peers, public_port=config.user.p2p_public_port)) self.send(msg)
def test_handle_peer_list_works(self, logger): """ Heavy error testing should be done in combine_peer_lists() and extend_known_peers(), which this fx uses. """ peer_list_message = qrllegacy_pb2.LegacyMessage( func_name=qrllegacy_pb2.LegacyMessage.PL, plData=qrllegacy_pb2.PLData( peer_ips={'127.0.0.3:5000', '127.0.0.4:5001'}, public_port=9000)) channel = make_channel() channel.host = IPMetadata('187.0.0.1', 9000) channel.peer = IPMetadata('187.0.0.2', 9000) channel.ip_public_port = '187.0.0.1:9000' # handle_peer_list() will call extend_known_peers(), so we gotta mock it out. It's tested elsewhere anyway. self.peer_manager.handle_peer_list(channel, peer_list_message)
def test_handle_peer_list_works(self, logger): """ Heavy error testing should be done in get_valid_peers() and update_peer_addresses(), which this fx uses. """ peer_list_message = qrllegacy_pb2.LegacyMessage( func_name=qrllegacy_pb2.LegacyMessage.PL, plData=qrllegacy_pb2.PLData( peer_ips={'127.0.0.3:5000', '127.0.0.4:5001'}, public_port=9000)) channel = make_channel() channel.host_ip = '187.0.0.1' channel.peer_ip = '187.0.0.2' # handle_peer_list() will call update_peer_addresses(), so we gotta mock it out. It's tested elsewhere anyway. self.peer_manager.update_peer_addresses = Mock( autospec=P2PPeerManager.update_peer_addresses) self.peer_manager.handle_peer_list(channel, peer_list_message) self.peer_manager.update_peer_addresses.assert_called_once_with( {"{0}:{1}".format(channel.peer_ip, 9000)})
def test_handle_peer_list_empty_peer_list_message(self, logger): """ An empty plData should result in no further processing being done. """ peer_list_message = qrllegacy_pb2.LegacyMessage( func_name=qrllegacy_pb2.LegacyMessage.PL, plData=qrllegacy_pb2.PLData(peer_ips={}, public_port=9000)) channel = make_channel() channel.host_ip = '127.0.0.1' channel.peer_ip = '127.0.0.2' self.peer_manager.extend_known_peers = Mock( autospec=P2PPeerManager.extend_known_peers) self.peer_manager.combine_peer_lists = Mock( autospec=P2PPeerManager.combine_peer_lists) self.peer_manager.handle_peer_list(channel, peer_list_message) self.peer_manager.combine_peer_lists.assert_not_called() self.peer_manager.extend_known_peers.assert_not_called()
def test_handle_peer_list_peer_discovery_disabled(self, config, logger): """ If enable_peer_discovery is False, no further processing should be done. """ config.user.enable_peer_discovery = False peer_list_message = qrllegacy_pb2.LegacyMessage( func_name=qrllegacy_pb2.LegacyMessage.PL, plData=qrllegacy_pb2.PLData( peer_ips={'127.0.0.3:5000', '127.0.0.4:5001'}, public_port=9000)) channel = make_channel() channel.host_ip = '127.0.0.1' channel.peer_ip = '127.0.0.2' self.peer_manager.extend_known_peers = Mock( autospec=P2PPeerManager.extend_known_peers) self.peer_manager.combine_peer_lists = Mock( autospec=P2PPeerManager.combine_peer_lists) self.peer_manager.handle_peer_list(channel, peer_list_message) self.peer_manager.combine_peer_lists.assert_not_called() self.peer_manager.extend_known_peers.assert_not_called()