Пример #1
0
    def send_request_env(self, envelope: Envelope, timeout=0, ip: str='', vk: str=''):
        url = "tcp://{}:{}".format(ip or vk, router_dealer)
        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)
Пример #2
0
 def remove_sub_filter(self, filter: str, ip: str='', vk: str=''):
     """
     Removes a filters from the sub socket. Unlike the remove_sub API, this does not disconnect a URL. It only
     unsubscribes to 'filter
     :param filter: A string to use as the filter frame. This filter will be unsubscribed.
     """
     url = "tcp://{}:{}".format(ip or vk, pub_sub)
     cmd = ReactorCommand.create_cmd(SubPubExecutor.__name__, SubPubExecutor.remove_sub_filter.__name__, url=url, filter=filter)
     self.interface.send_cmd(cmd)
Пример #3
0
 def add_router(self, ip: str='', vk: str=''):
     """
     Add a router socket at url. Routers are like 'async repliers', and can connect to many Dealer sockets (N-1)
     :param url: The URL the router socket should BIND to
     :param vk: The Node's VK to connect to. This will be looked up in the overlay network
     """
     url = "tcp://{}:{}".format(ip or vk, router_dealer)
     cmd = ReactorCommand.create_cmd(DealerRouterExecutor.__name__, DealerRouterExecutor.add_router.__name__, url=url)
     self.interface.send_cmd(cmd)
Пример #4
0
 def remove_pub(self, ip: str='', vk: str=''):
     """
     Removes a publisher (duh)
     :param url: The URL of the router that the created dealer socket should CONNECT to.
     :param vk: The Node's VK to connect to. This will be looked up in the overlay network
     """
     url = "tcp://{}:{}".format(ip or vk, pub_sub)
     cmd = ReactorCommand.create_cmd(SubPubExecutor.__name__, SubPubExecutor.remove_pub.__name__, url=url)
     self.interface.send_cmd(cmd)
Пример #5
0
 def add_pub(self, ip: str='', vk: str=''):
     """
     Create a publisher socket that BINDS to 'url'
     :param url: The URL to publish under.
     :param vk: The Node's VK to connect to. This will be looked up in the overlay network
     """
     url = "tcp://{}:{}".format(ip or vk, pub_sub)
     cmd = ReactorCommand.create_cmd(SubPubExecutor.__name__, SubPubExecutor.add_pub.__name__, url=url)
     self.interface.send_cmd(cmd)
Пример #6
0
 def send_pub_env(self, filter: str, envelope: Envelope):
     """
     Publish envelope with filter frame 'filter'.
     :param filter: A string to use as the filter frame
     :param envelope: An instance of Envelope
     """
     cmd = ReactorCommand.create_cmd(SubPubExecutor.__name__, SubPubExecutor.send_pub.__name__, filter=filter,
                                     envelope=envelope)
     self.interface.send_cmd(cmd)
Пример #7
0
 def add_sub(self, filter: str, ip: str='', vk: str=''):
     """
     Connects the subscriber socket to listen to 'URL' with filter 'filter'.
     :param url: The URL to CONNECT the sub socket to (ex 'tcp://17.1.3.4:4200')
     :param filter: The filter to subscribe to. Only data published with this filter will be received. Currently,
     only one filter per CONNECT is supported.
     """
     # url = "tcp://{}:{}".format(ip or vk, Constants.Ports.PubSub)
     url = "tcp://{}:{}".format(ip or vk, pub_sub)
     cmd = ReactorCommand.create_cmd(SubPubExecutor.__name__, SubPubExecutor.add_sub.__name__, filter=filter, url=url, vk=vk)
     self.interface.send_cmd(cmd)
Пример #8
0
 def add_dealer(self, ip: str='', vk: str=''):
     """
     Add a dealer socket at url. Dealers are like 'async requesters', and can connect to a single Router socket (1-1)
     (side note: A router socket, however, can connect to N dealers)
     'id' socketopt for the dealer socket will be this node's verifying key
     :param url: The URL of the router that the created dealer socket should CONNECT to.
     :param vk: The Node's VK to connect to. This will be looked up in the overlay network
     """
     url = "tcp://{}:{}".format(ip or vk, router_dealer)
     cmd = ReactorCommand.create_cmd(DealerRouterExecutor.__name__, DealerRouterExecutor.add_dealer.__name__,
                                     id=self.verifying_key, url=url, vk=vk)
     self.interface.send_cmd(cmd)
Пример #9
0
 def send_reply(self, message: MessageBase, request_envelope: Envelope):
     """
     Send a reply message (via a Router socket) for the original reqeust in request_envelope (which came from a
     Dealer socket). Replies envelope are created as a deterministic function of their original request envelope,
     so that both parties (the sender and receiver) are in agreement on what the reply envelope should look like
     :param message: A MessageBase instance that denotes the reply data
     :param request_envelope: An Envelope instance that denotes the envelope of the original request that we are
     replying to
     """
     requester_id = request_envelope.seal.verifying_key
     reply_env = self._package_reply(reply=message, req_env=request_envelope)
     cmd = ReactorCommand.create_cmd(DealerRouterExecutor.__name__, DealerRouterExecutor.reply.__name__,
                                     id=requester_id, envelope=reply_env)
     self.interface.send_cmd(cmd)
Пример #10
0
    def remove_sub(self, ip: str='', vk: str=''):
        """
        Stop subscribing to a URL and filter. Note that all other subscriber connections will drop this filter as well
        (so if there is another URL you are subscribing to with the same filter, that sub will no longer work). The
        pattern at this point is to have a single filter for each 'node type', ie witness/delegate/masternode.

        If you wish to stop subscribing to a URL, but not necessarily a filter, then call this method and pass in an
        empty string to FILTER. For example, a delegate might want to stop subscribing to a particular witness, but not
        all witnesses.

        :param filter: The filter to subscribe to. Only multipart messages with this filter as the first frame will be
        received
        :param url: The URL of the router that the created dealer socket should CONNECT to.
        :param vk: The Node's VK to connect to. This will be looked up in the overlay network
        """
        url = "tcp://{}:{}".format(ip or vk, pub_sub)
        cmd = ReactorCommand.create_cmd(SubPubExecutor.__name__, SubPubExecutor.remove_sub.__name__, url=url)
        self.interface.send_cmd(cmd)