Exemple #1
0
    def _queueOutgoingDeliveries(self, conn):
        for ssn in self._iterSessions(conn, proton.PN_LOCAL_ACTIVE):
            ctx = proton.pn_session_get_context(ssn)
            sender = ctx.sender

            if sender is None:
                # No sender link
                sender = proton.pn_sender(ctx.session,
                                          "sender-%s" % str(uuid.uuid4()))
                ctx.sender = sender
                continue

            while proton.pn_link_credit(sender) > 0:
                try:
                    data = ctx._popPendingMessage()
                except Empty:
                    break
                else:
                    msg = proton.Message()
                    msg.body = data
                    d = proton.pn_delivery(sender,
                                           "delivery-%s" % str(uuid.uuid4()))

                    proton.pn_delivery_set_context(d, msg.encode())
                    self.log.debug("Queueing delivery (%s)",
                                   proton.pn_delivery_tag(d))
Exemple #2
0
    def _queueOutgoingDeliveries(self, conn):
        for ssn in self._iterSessions(conn, proton.PN_LOCAL_ACTIVE):
            ctx = proton.pn_session_get_context(ssn)
            sender = ctx.sender

            if sender is None:
                # No sender link
                sender = proton.pn_sender(ctx.session,
                                          "sender-%s" % str(uuid.uuid4()))
                ctx.sender = sender
                continue

            while proton.pn_link_credit(sender) > 0:
                try:
                    data = ctx._popPendingMessage()
                except Empty:
                    break
                else:
                    msg = proton.Message()
                    msg.body = data
                    d = proton.pn_delivery(sender,
                                           "delivery-%s" % str(uuid.uuid4()))

                    proton.pn_delivery_set_context(d, msg.encode())
                    self.log.debug("Queueing delivery (%s)",
                                   proton.pn_delivery_tag(d))
Exemple #3
0
    def _queueOutgoingDeliveries(self, conn):
        ctxs = (ctx for ctx in self._sessionContexts
                if ctx.connection == conn)

        for ctx in ctxs:
            sender = ctx.sender

            if sender is None:
                # No sender link
                sender = proton.pn_sender(ctx.session,
                                          "sender-%s" % str(uuid.uuid4()))
                ctx.sender = sender
                proton.pn_link_open(sender)
                continue

            if proton.pn_link_credit(sender) == 0:
                self.log.debug("Not enough credit, waiting")
                continue

            try:
                data = ctx._popPendingMessage()
            except Empty:
                continue
            else:
                msg = proton.Message()
                msg.body = data
                self.log.debug("Creating delivery")
                proton.pn_link_set_context(sender, msg.encode())

                proton.pn_delivery(sender,
                                   "response-delivery-%s" % str(uuid.uuid4()))
Exemple #4
0
    def _openClientSession(self):
        host, port = self._address
        amqpAddress = "ampq://%s:%d/vdsm" % (host, port)
        senderName = "jsonrpc.ProtonClient %s (%s)" % (
            str(uuid.uuid4()),
            amqpAddress,
        )
        self.log = logging.getLogger(senderName)

        self.connector = proton.pn_connector(self._reactor._driver, host,
                                             str(port), None)
        if self.connector is None:
            raise ProtonError("Could not create connector")

        self.connection = proton.pn_connection()
        proton.pn_connector_set_connection(self.connector, self.connection)

        sasl = proton.pn_connector_sasl(self.connector)
        proton.pn_sasl_mechanisms(sasl, "ANONYMOUS")
        proton.pn_sasl_client(sasl)

        proton.pn_connector_set_context(self.connector, CLIENT_AUTH)
        self.log.debug("Opening active connection")
        proton.pn_connection_open(self.connection)

        while True:
            # TODO: Handle connection being closed mid authentication
            if proton.pn_sasl_state(sasl) in (proton.PN_SASL_PASS, ):
                proton.pn_connector_set_context(self.connector, CONNECTED)
                break

            if proton.pn_sasl_state(sasl) == proton.PN_SASL_FAIL:
                yield Return(-1)

            yield

        self.session = proton.pn_session(self.connection)
        proton.pn_session_open(self.session)
        proton.pn_session_set_context(self.session, self)

        link = proton.pn_sender(self.session, senderName)
        dst = proton.pn_link_target(link)
        proton.pn_terminus_set_address(dst, amqpAddress)
        self.sender = link
        yield Return(1)
Exemple #5
0
    def _openClientSession(self):
        host, port = self._address
        amqpAddress = "ampq://%s:%d/vdsm" % (host, port)
        senderName = "jsonrpc.ProtonClient %s (%s)" % (str(uuid.uuid4()),
                                                       amqpAddress,)
        self.log = logging.getLogger(senderName)

        self.connector = proton.pn_connector(self._reactor._driver,
                                             host, str(port), None)
        if self.connector is None:
            raise ProtonError("Could not create connector")

        self.connection = proton.pn_connection()
        proton.pn_connector_set_connection(self.connector, self.connection)

        sasl = proton.pn_connector_sasl(self.connector)
        proton.pn_sasl_mechanisms(sasl, "ANONYMOUS")
        proton.pn_sasl_client(sasl)

        proton.pn_connector_set_context(self.connector, CLIENT_AUTH)
        self.log.debug("Opening active connection")
        proton.pn_connection_open(self.connection)

        while True:
            # TODO: Handle connection being closed mid authentication
            if proton.pn_sasl_state(sasl) in (proton.PN_SASL_PASS,):
                proton.pn_connector_set_context(self.connector, CONNECTED)
                break

            if proton.pn_sasl_state(sasl) == proton.PN_SASL_FAIL:
                yield Return(-1)

            yield

        self.session = proton.pn_session(self.connection)
        proton.pn_session_open(self.session)
        proton.pn_session_set_context(self.session, self)

        link = proton.pn_sender(self.session, senderName)
        dst = proton.pn_link_target(link)
        proton.pn_terminus_set_address(dst, amqpAddress)
        self.sender = link
        yield Return(1)