コード例 #1
0
ファイル: test_p2pprotocol.py プロジェクト: zeta1999/QRL
 def test_wrap_message_works(self):
     veData = qrllegacy_pb2.VEData(version="version",
                                   genesis_prev_hash=b'genesis_hash')
     msg = qrllegacy_pb2.LegacyMessage(
         func_name=qrllegacy_pb2.LegacyMessage.VE, veData=veData)
     self.assertEqual(
         '000000191a170a0776657273696f6e120c67656e657369735f68617368',
         bin2hstr(P2PProtocol._wrap_message(msg)))
コード例 #2
0
    def test_trusted_time(self, send, get_peer):
        channel = P2PProtocol()
        with mock.patch('qrl.core.misc.ntp.getTime') as time_mock:
            time_mock.return_value = channel.connected_at + 1
            get_peer.return_value = IPMetadata('192.168.0.1', 1000)

            for _ in range(config.dev.trust_min_msgcount):
                buffer = bytes(
                    hstr2bin(
                        '000000191a170a0776657273696f6e120c67656e657369735f68617368'
                    ))
                channel.dataReceived(buffer)

            time_mock.return_value = channel.connected_at + config.dev.trust_min_conntime + 1
            self.assertTrue(self.peer_manager.trusted_peer(channel))
コード例 #3
0
    def setUp(self):
        self.channel = P2PProtocol()

        self.channel._observable = Mock()
        self.channel.peer_manager = Mock()
        self.channel.p2pchain_manager = Mock()
        self.channel.tx_manager = Mock()

        self.channel.factory = Mock(autospec=P2PFactory)
        self.channel.factory.p2p_msg_priority = p2p_msg_priority

        sample_peer_1 = Host('127.0.0.2', '9000')
        sample_host = Host('127.0.0.1', '9000')
        attrs = {'getPeer.return_value': sample_peer_1, 'getHost.return_value': sample_host}
        self.channel.transport = Mock(**attrs)
コード例 #4
0
ファイル: test_p2pprotocol.py プロジェクト: zeta1999/QRL
    def setUp(self):
        with patch('qrl.core.misc.ntp.getTime', new=replacement_getTime):
            self.channel = P2PProtocol()

        self.channel._observable = Mock()

        self.channel.factory = Mock(autospec=P2PFactory)
        self.channel.factory.p2p_msg_priority = p2p_msg_priority
        self.channel.factory._qrl_node = Mock(autospec=QRLNode)
        self.channel.factory._qrl_node.peer_manager = Mock(
            autospec=p2pPeerManager)
        self.channel.factory._qrl_node.peer_manager.is_banned = MagicMock(
            return_value=False)
        self.channel.factory._qrl_node.peer_manager.trusted_addresses = MagicMock(
            return_value=[])

        sample_peer_1 = Host('127.0.0.2', '9000')
        sample_host = Host('127.0.0.1', '9000')
        attrs = {
            'getPeer.return_value': sample_peer_1,
            'getHost.return_value': sample_host
        }
        self.channel.transport = Mock(**attrs)
コード例 #5
0
ファイル: p2pPeerManager.py プロジェクト: theQRL/QRL
 def ban_channel(self, channel: P2PProtocol):
     self._banned_peer_ips.add(channel.peer.ip)
     logger.warning('Banned %s', channel.peer.ip)
     channel.loseConnection()