Beispiel #1
0
    def _process_incoming_packets(self, connection):
        """
        This coroutinte fetches the message raw data from
        :attr:`self.incoming_queue`, parses it into the corresponding message
        object (an instance of one of the
        :class:`broker.messages.BaseMQTTMessage` subclasses) and passes it to
        the :attr:`self.incoming_transaction_manager` to be processed.

        It is started by calling :meth:`self.start()` and stops upon client
        disconnection.
        """
        while connection.is_readable:
            with client_process_context(self, connection):
                msg = yield connection.read_message()

                msg_obj = MQTTMessageFactory.make(msg)
                self.logger.debug("[B << C] [uid: %s] %s" %
                                  (self.uid, msg_obj.log_info()))

                action = self._get_action(msg_obj, IncomingActionFactory)
                assert isinstance(action, IncomingAction)
                action.run()

        self.logger.debug("[uid: %s] stopping _process_incoming_messages"
                          % self.uid)
Beispiel #2
0
 def get_inflight(self, packet_id):
     if packet_id in self._inflight:
         raw = self._inflight.get(packet_id)
         if raw is not None:
             return MQTTMessageFactory.make(raw)
     else:
         raise KeyError('Unknown packet id')
Beispiel #3
0
    def _process_incoming_packets(self, connection):
        """
        This coroutinte fetches the message raw data from
        :attr:`self.incoming_queue`, parses it into the corresponding message
        object (an instance of one of the
        :class:`broker.messages.BaseMQTTMessage` subclasses) and passes it to
        the :attr:`self.incoming_transaction_manager` to be processed.

        It is started by calling :meth:`self.start()` and stops upon client
        disconnection.
        """
        while connection.is_readable:
            with client_process_context(self, connection):
                msg = yield connection.read_message()

                msg_obj = MQTTMessageFactory.make(msg)
                self.logger.debug("[B << C] [uid: %s] %s" %
                                  (self.uid, msg_obj.log_info()))

                action = self._get_action(msg_obj, IncomingActionFactory)
                assert isinstance(action, IncomingAction)
                action.run()

        self.logger.debug("[uid: %s] stopping _process_incoming_messages" %
                          self.uid)
Beispiel #4
0
 def get_inflight(self, packet_id):
     if packet_id in self._inflight:
         raw = self._inflight.get(packet_id)
         if raw is not None:
             return MQTTMessageFactory.make(raw)
     else:
         raise KeyError('Unknown packet id')
Beispiel #5
0
    def read_connect_message(self, connection):
        bytes_ = yield connection.read_message()
        msg = MQTTMessageFactory.make(bytes_)

        if not isinstance(msg, Connect):
            raise ConnectError("The first message is expected to be CONNECT")

        client_logger.debug("[B << C] [uid: %s] %s" % (msg.client_uid, msg.log_info()))

        return msg
Beispiel #6
0
    def read_connect_message(self, connection):
        bytes_ = yield connection.read_message()
        msg = MQTTMessageFactory.make(bytes_)

        if not isinstance(msg, Connect):
            raise ConnectError('The first message is expected to be CONNECT')

        client_logger.debug("[B << C] [uid: %s] %s" %
                            (msg.client_uid, msg.log_info()))

        return msg
Beispiel #7
0
    def get_next(self):
        """
        Gets the next packet to be published.
        Should be used to start a new flow.
        """
        # todo: do in a transaction
        if len(self._queue) > 0:
            raw_data = self._queue.pop()

            msg = MQTTMessageFactory.make(raw_data)
            msg.id = self._ids_gen.next()
            self._inflight_ids.append(msg.id)
            self._inflight[msg.id] = msg.raw_data
            return msg

        else:
            return None
Beispiel #8
0
    def get_next(self):
        """
        Gets the next packet to be published.
        Should be used to start a new flow.
        """
        # todo: do in a transaction
        if len(self._queue) > 0:
            raw_data = self._queue.pop()

            msg = MQTTMessageFactory.make(raw_data)
            msg.id = self._ids_gen.next()
            self._inflight_ids.append(msg.id)
            self._inflight[msg.id] = msg.raw_data
            return msg

        else:
            return None
Beispiel #9
0
 def get_all_inflight(self):
     for packet_id in self._inflight_ids:
         raw = self._inflight.get(packet_id)
         if raw is not None:
             yield MQTTMessageFactory.make(raw)
Beispiel #10
0
 def get_all_inflight(self):
     for packet_id in self._inflight_ids:
         raw = self._inflight.get(packet_id)
         if raw is not None:
             yield MQTTMessageFactory.make(raw)