Exemple #1
0
    def _register(self):
        self._stream.wait_for_ready()

        request = consensus_pb2.ConsensusRegisterRequest(
            name=self._engine.name(),
            version=self._engine.version(),
        )

        for (name, version) in self._engine.additional_protocols():
            protocol = request.additional_protocols.add()
            protocol.name = name
            protocol.version = version

        while True:
            future = self._stream.send(
                message_type=Message.CONSENSUS_REGISTER_REQUEST,
                content=request.SerializeToString())
            response = consensus_pb2.ConsensusRegisterResponse()
            response.ParseFromString(future.result(REGISTER_TIMEOUT).content)

            if (response.status ==
                    consensus_pb2.ConsensusRegisterResponse.NOT_READY):
                continue

            if response.status == consensus_pb2.ConsensusRegisterResponse.OK:
                if (response.HasField('chain_head')
                        and response.HasField('local_peer_info')):
                    return StartupState(response.chain_head, response.peers,
                                        response.local_peer_info)

                return None

            raise exceptions.ReceiveError(
                'Registration failed with status {}'.format(response.status))
    def _register(self):
        self._stream.wait_for_ready()

        request = consensus_pb2.ConsensusRegisterRequest(
            name=self._engine.name(),
            version=self._engine.version(),
        ).SerializeToString()

        while True:
            future = self._stream.send(
                message_type=Message.CONSENSUS_REGISTER_REQUEST,
                content=request)
            response = consensus_pb2.ConsensusRegisterResponse()
            response.ParseFromString(future.result(REGISTER_TIMEOUT).content)

            if (response.status ==
                    consensus_pb2.ConsensusRegisterResponse.NOT_READY):
                continue

            if response.status == consensus_pb2.ConsensusRegisterResponse.OK:
                return StartupState(response.chain_head, response.peers,
                                    response.local_peer_info)

            raise exceptions.ReceiveError(
                'Registration failed with status {}'.format(response.status))
    def _register(self):
        self._stream.wait_for_ready()

        future = self._stream.send(
            message_type=Message.CONSENSUS_REGISTER_REQUEST,
            content=consensus_pb2.ConsensusRegisterRequest(
                name=self._engine.name(),
                version=self._engine.version(),
            ).SerializeToString(),
        )

        response = consensus_pb2.ConsensusRegisterResponse()
        response.ParseFromString(future.result().content)

        if response.status != consensus_pb2.ConsensusRegisterResponse.OK:
            raise exceptions.ReceiveError(
                'Registration failed with status {}'.format(response.status))