Exemple #1
0
 def setup_zap(self, sender, **kwargs):
     self.zap_socket = zmq.Socket(zmq.Context.instance(), zmq.ROUTER)
     self.zap_socket.bind('inproc://zeromq.zap.01')
     if self.allow_any:
         _log.warn('insecure permissive authentication enabled')
     self.read_auth_file()
     self.core.spawn(watch_file, self.auth_file_path, self.read_auth_file)
Exemple #2
0
    def connect(self, reply_to, endpoint):
        if self.connected:
            return

        # Create new outgoing socket (drop any messages in transit)
        self.mailbox = zmq.Socket(self._ctx, zmq.DEALER)
        # Set our caller 'From' identity so that receiving node knows
        # who each message came from.
        # Set our own identity on the socket so that receiving node
        # knows who each message came from. Note that we cannot use
        # the UUID directly as the identity since it may contain a
        # zero byte at the start, which libzmq does not like for
        # historical and arguably bogus reasons that it nonetheless
        # enforces.
        # we set linger to 0 by default (In zyre this is done by czmq's zsys)
        self.mailbox.setsockopt(zmq.LINGER, 0)
        self.mailbox.setsockopt(zmq.IDENTITY, b'\x01' + reply_to.bytes)
        # Set a high-water mark that allows for reasonable activity
        self.mailbox.setsockopt(zmq.SNDHWM, PyrePeer.PEER_EXPIRED * 100)
        # Send messages immediately or return EAGAIN
        self.mailbox.setsockopt(zmq.SNDTIMEO, 0)

        # Connect through to peer node
        logger.debug("Connecting to peer {0} on endpoint {1}".format(
            self.identity, endpoint))

        self.mailbox.connect(endpoint)
        self.endpoint = endpoint
        self.connected = True
        self.ready = False
Exemple #3
0
 def __init__(self, zmq_socket_type, context=None):
     self._zmq_socket_type = zmq_socket_type
     self._context = context or Context.get_instance()
     self._socket = zmq.Socket(self._context, zmq_socket_type)
     self._send = self._socket.send_multipart
     self._recv = self._socket.recv_multipart
     if zmq_socket_type in (zmq.PUSH, zmq.PUB, zmq.XREQ, zmq.XREP):
         self._send = Sender(self._socket)
     if zmq_socket_type in (zmq.PULL, zmq.SUB, zmq.XREQ, zmq.XREP):
         self._recv = Receiver(self._socket)
Exemple #4
0
 def setup_zap(self, sender, **kwargs):
     self.zap_socket = zmq.Socket(zmq.Context.instance(), zmq.ROUTER)
     self.zap_socket.bind('inproc://zeromq.zap.01')
     if self.allow_any:
         _log.warning('insecure permissive authentication enabled')
     self.read_auth_file()
     self._read_protected_topics_file()
     self.core.spawn(watch_file, self.auth_file_path, self.read_auth_file)
     self.core.spawn(watch_file, self._protected_topics_file_path,
                     self._read_protected_topics_file)
     if self.core.messagebus == 'rmq':
         self.vip.peerlist.onadd.connect(self._check_topic_rules)
Exemple #5
0
        def monitor():
            # Call socket.monitor() directly rather than use
            # get_monitor_socket() so we can use green sockets with
            # regular contexts (get_monitor_socket() uses
            # self.context.socket()).
            addr = 'inproc://monitor.v-%d' % (id(self.socket), )
            sock = None
            if self.socket is not None:
                try:
                    self.socket.monitor(addr)
                    sock = zmq.Socket(self.context, zmq.PAIR)

                    sock.connect(addr)
                    while True:
                        try:
                            message = recv_monitor_message(sock)
                            self.onsockevent.send(self, **message)
                            event = message['event']
                            if event & zmq.EVENT_CONNECTED:
                                hello()
                            elif event & zmq.EVENT_DISCONNECTED:
                                self.__connected = False
                            elif event & zmq.EVENT_CONNECT_RETRIED:
                                self._reconnect_attempt += 1
                                if self._reconnect_attempt == 50:
                                    self.__connected = False
                                    sock.disable_monitor()
                                    self.stop()
                                    self.ondisconnected.send(self)
                            elif event & zmq.EVENT_MONITOR_STOPPED:
                                break
                        except ZMQError as exc:
                            if exc.errno == ENOTSOCK:
                                break

                except ZMQError as exc:
                    raise
                    # if exc.errno == EADDRINUSE:
                    #     pass
                finally:
                    try:
                        url = list(urlparse.urlsplit(self.address))
                        if url[0] in ['tcp'] and sock is not None:
                            sock.close()
                        if self.socket is not None:
                            self.socket.monitor(None, 0)
                    except Exception as exc:
                        _log.debug("Error in closing the socket: {}".format(
                            exc.message))
Exemple #6
0
 def monitor():
     # Call socket.monitor() directly rather than use
     # get_monitor_socket() so we can use green sockets with
     # regular contexts (get_monitor_socket() uses
     # self.context.socket()).
     addr = 'inproc://monitor.v-%d' % (id(self.socket), )
     self.socket.monitor(addr)
     try:
         sock = zmq.Socket(self.context, zmq.PAIR)
         sock.connect(addr)
         while True:
             message = recv_monitor_message(sock)
             self.onsockevent.send(self, **message)
             event = message['event']
             if event & zmq.EVENT_CONNECTED:
                 hello()
             elif event & zmq.EVENT_DISCONNECTED:
                 self.__connected = False
                 self.ondisconnected.send(self)
     finally:
         self.socket.monitor(None, 0)
Exemple #7
0
 def setup(self, sender, **kwargs):
     self.in_sock = zmq.Socket(self.core.context, zmq.PULL)
     self.out_sock = zmq.Socket(self.core.context, zmq.XPUB)
Exemple #8
0
 def setup_zap(self, sender, **kwargs):
     self.zap_socket = zmq.Socket(zmq.Context.instance(), zmq.ROUTER)
     self.zap_socket.bind('inproc://zeromq.zap.01')