def __init__(self, sock: AbstractSocketConnectionProtocol,
                 node: "AbstractGatewayNode"):
        super(AbstractRelayConnection, self).__init__(sock, node)

        hello_msg = HelloMessage(protocol_version=self.protocol_version,
                                 network_num=self.network_num,
                                 node_id=self.node.opts.node_id)
        self.enqueue_msg(hello_msg)

        self.hello_messages = constants.BLOXROUTE_HELLO_MESSAGES
        self.header_size = constants.STARTING_SEQUENCE_BYTES_LEN + constants.BX_HDR_COMMON_OFF
        self.message_handlers = {
            BloxrouteMessageType.HELLO:
            self.msg_hello,
            BloxrouteMessageType.PING:
            self.msg_ping,
            BloxrouteMessageType.PONG:
            self.msg_pong,
            BloxrouteMessageType.ACK:
            self.msg_ack,
            BloxrouteMessageType.BROADCAST:
            self.msg_broadcast,
            BloxrouteMessageType.KEY:
            self.msg_key,
            BloxrouteMessageType.TRANSACTION:
            self.msg_tx,
            BloxrouteMessageType.TRANSACTIONS:
            self.msg_txs,
            BloxrouteMessageType.COMPRESSED_BLOCK_TXS:
            self.msg_compressed_block_txs,
            BloxrouteMessageType.BLOCK_HOLDING:
            self.msg_block_holding,
            BloxrouteMessageType.DISCONNECT_RELAY_PEER:
            self.msg_disconnect_relay_peer,
            BloxrouteMessageType.TX_SERVICE_SYNC_TXS:
            self.tx_sync_service.msg_tx_service_sync_txs,
            BloxrouteMessageType.TX_SERVICE_SYNC_COMPLETE:
            self.tx_sync_service.msg_tx_service_sync_complete,
            BloxrouteMessageType.BLOCK_CONFIRMATION:
            self.msg_cleanup,
            BloxrouteMessageType.TRANSACTION_CLEANUP:
            self.msg_cleanup,
            BloxrouteMessageType.NOTIFICATION:
            self.msg_notify,
            BloxrouteMessageType.REFRESH_BLOCKCHAIN_NETWORK:
            self.msg_refresh_blockchain_network
        }

        msg_size_validation_settings = MessageSizeValidationSettings(
            self.node.network.max_block_size_bytes,
            self.node.network.max_tx_size_bytes)
        self.message_validator = BloxrouteMessageValidator(
            msg_size_validation_settings, self.protocol_version)
        self.check_matching_relay_connection_alarm_id: Optional[AlarmId] = None
Пример #2
0
 def setUp(self) -> None:
     self.message_validation_settings = MessageSizeValidationSettings(max_block_size_bytes=100000,
                                                                      max_tx_size_bytes=50000)
     self.message_validator = BloxrouteMessageValidator(self.message_validation_settings,
                                                        protocol_version.PROTOCOL_VERSION)