Exemplo n.º 1
0
    def _package_reply(self, reply: MessageBase, req_env: Envelope) -> Envelope:
        """
        Convenience method to create a reply envelope. The difference between this func and _package_msg, is that
        in the reply envelope the UUID must be the hash of the original request's uuid (not some randomly generated int)
        :param reply: The reply message (an instance of MessageBase)
        :param req_env: The original request envelope (an instance of Envelope)
        :return: An Envelope instance
        """
        self.log.debug("Creating REPLY envelope with msg type {} for request envelope {}".format(type(reply), req_env))
        request_uuid = req_env.meta.uuid
        reply_uuid = EnvelopeAuth.reply_uuid(request_uuid)

        return Envelope.create_from_message(message=reply, signing_key=self.signing_key,
                                            verifying_key=self.verifying_key, uuid=reply_uuid)
Exemplo n.º 2
0
    def send_request_env(self,
                         envelope: Envelope,
                         timeout=0,
                         ip: str = '',
                         vk: str = ''):
        url = "tcp://{}:{}".format(ip or vk, Constants.Ports.RouterDealer)
        reply_uuid = EnvelopeAuth.reply_uuid(envelope.meta.uuid)

        cmd = ReactorCommand.create_cmd(DealerRouterExecutor.__name__,
                                        DealerRouterExecutor.request.__name__,
                                        url=url,
                                        envelope=envelope,
                                        timeout=timeout,
                                        reply_uuid=reply_uuid)
        self.interface.send_cmd(cmd)