eclipse / paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
313 stars 179 forks source link

Gateway sends PUBLISH using topic ID for which the REGISTER was rejected #230

Closed vera closed 3 years ago

vera commented 3 years ago

Wireshark trace:

User Datagram Protocol, Src Port: 10000, Dst Port: 10001
MQ Telemetry Transport Protocol for Sensor Networks
    Message
        Message Type: Register (0x0a)
        Message Length: 65
        Topic ID: 3
        Message ID: 1
        Topic Name: ...

User Datagram Protocol, Src Port: 10001, Dst Port: 10000
MQ Telemetry Transport Protocol for Sensor Networks
    Message
        Message Type: Register Ack (0x0b)
        Message Length: 7
        Topic ID: 3
        Message ID: 1
        Return Code: Rejected: invalid topic ID (0x02)

User Datagram Protocol, Src Port: 10000, Dst Port: 10001
MQ Telemetry Transport Protocol for Sensor Networks
    Message
        Message Type: Publish Message (0x0c)
        Message Length: 8
        0... .... = DUP: No
        .01. .... = QoS: Acknowledged deliver (0x1)
        ...1 .... = Retain: Yes
        .... ..00 = Topic ID Type: Normal ID (0x0)
        Topic ID: 3
        Message ID: 1
        Message: 8

User Datagram Protocol, Src Port: 10001, Dst Port: 10000
MQ Telemetry Transport Protocol for Sensor Networks
    Message
        Message Type: Publish Ack (0x0d)
        Message Length: 7
        Topic ID: 3
        Message ID: 1
        Return Code: Rejected: invalid topic ID (0x02)

(Port 10000 is the gateway, 10001 is the MQTT-SN client)

Is this the intended behaviour?

In this case, the topic ID is rejected due to an error in my client, but I think in any case the PUBLISH should not be sent until a topic ID was successfully registered.

ty4tw commented 3 years ago

Hi, When the REGISTER sent by a gateway is rejected, there’s no way to fix the negotiation. TopicIds are created by the gateway not by the clients. TopicIds sent by the gateway is always valid. So, there’s two choices, one is discarding a PUBLISh message from a broker. The other is sending PUBLISH in any case. I think we should involve more people to discuss about this issue. @icraggs, how do you think about this.

ty4tw commented 3 years ago

Hi,

When the gateway receives a PUBLISH message from the broker that matches the wildcard topic, it sends a REGISTER to the client before sending the PUBLISH. The TopicId is always uniquely determined by the gateway. Therefore, if the REGACK response is TOPICID_INVALID, the gateway considers the client unable to receive the message and discards the PUBLISH message.

I fix it like this.

ty4tw commented 3 years ago

Hi, Section 6.10 of the specification mention about this issue. The GW will wait for the REGACK message before it sends the PUBLISH message to the client. If the client receives a PUBLISH message with unkown topic id value, it sshall responde with a PUBACK message with the ReturnCode="Rejected:invalid Topic ID".

So, I will revert c65d66e