Exemplo n.º 1
0
    def broadcast(self, message_type, payload):
        message = consensus_pb2.ConsensusPeerMessage(message_type=message_type,
                                                     content=payload)

        request = consensus_pb2.ConsensusBroadcastRequest(message=message)

        response = self._send(
            request=request,
            message_type=Message.CONSENSUS_BROADCAST_REQUEST,
            response_type=consensus_pb2.ConsensusBroadcastResponse)

        if response.status != consensus_pb2.ConsensusBroadcastResponse.OK:
            raise exceptions.ReceiveError('Failed with status {}'.format(
                response.status))
Exemplo n.º 2
0
    def send_to(self, peer_id, message_type, payload):
        message = consensus_pb2.ConsensusPeerMessage(message_type=message_type,
                                                     content=payload)

        request = consensus_pb2.ConsensusSendToRequest(message=message,
                                                       peer_id=peer_id)

        response = self._send(
            request=request,
            message_type=Message.CONSENSUS_SEND_TO_REQUEST,
            response_type=consensus_pb2.ConsensusSendToResponse)

        if response.status != consensus_pb2.ConsensusSendToResponse.OK:
            raise exceptions.ReceiveError('Failed with status {}'.format(
                response.status))
Exemplo n.º 3
0
    def test_broadcast(self):
        self.mock_stream.send.return_value = self._make_future(
            message_type=Message.CONSENSUS_BROADCAST_RESPONSE,
            content=consensus_pb2.ConsensusBroadcastResponse(
                status=consensus_pb2.ConsensusBroadcastResponse.OK).
            SerializeToString())

        self.service.broadcast(message_type='message_type', payload=b'payload')

        self.mock_stream.send.assert_called_with(
            message_type=Message.CONSENSUS_BROADCAST_REQUEST,
            content=consensus_pb2.ConsensusBroadcastRequest(
                message=consensus_pb2.ConsensusPeerMessage(
                    message_type='message_type',
                    content=b'payload')).SerializeToString())
Exemplo n.º 4
0
    def test_send_to(self):
        self.mock_stream.send.return_value = self._make_future(
            message_type=Message.CONSENSUS_SEND_TO_RESPONSE,
            content=consensus_pb2.ConsensusSendToResponse(
                status=consensus_pb2.ConsensusSendToResponse.OK).
            SerializeToString())

        self.service.send_to(peer_id=b'peer_id',
                             message_type='message_type',
                             payload=b'payload')

        self.mock_stream.send.assert_called_with(
            message_type=Message.CONSENSUS_SEND_TO_REQUEST,
            content=consensus_pb2.ConsensusSendToRequest(
                message=consensus_pb2.ConsensusPeerMessage(
                    message_type='message_type', content=b'payload'),
                peer_id=b'peer_id').SerializeToString())
Exemplo n.º 5
0
    def broadcast_to_arbiter(self, message_type, payload):
        """
        FIXME - better use special message like CONSENSUS_BROADCAST_REQUEST and send only one message and validator take cluster's peer from topology
        """
        message = consensus_pb2.ConsensusPeerMessage(message_type=message_type,
                                                     content=payload,
                                                     name=self._name,
                                                     version=self._version)

        request = consensus_pb2.ConsensusBroadcastArbiterRequest(
            message=message)
        response = self._send(
            request=request,
            message_type=Message.CONSENSUS_BROADCAST_ARBITER_REQUEST,
            response_type=consensus_pb2.ConsensusBroadcastArbiterResponse)

        if response.status != consensus_pb2.ConsensusBroadcastArbiterResponse.OK:
            raise exceptions.ReceiveError('Failed with status {}'.format(
                response.status))