redboltz / mqtt_cpp

Boost Software License 1.0
437 stars 107 forks source link

Server complaining Invalid PUBREL fixed header #598

Closed ajayb0507 closed 3 years ago

ajayb0507 commented 4 years ago

The 4 reserved bits for PUBREL fixed header is supposed to be 0010, however the mqtt_cpp client is sending 1001. Is there something I am missing ?

jonesmz commented 4 years ago

Well, it might be a bug.

Look here:

include/mqtt/v5_message.hpp line 1211:


template <std::size_t PacketIdBytes>
struct basic_pubrel_message {
    basic_pubrel_message(
        typename packet_id_type<PacketIdBytes>::type packet_id,
        v5::pubrel_reason_code reason_code,
        properties props)
        : fixed_header_(make_fixed_header(control_packet_type::pubrel, 0b0000)),

The fixed header is being set to 0, 0, 0, 0

include/mqtt/message.hpp line 186 however, sets it to 0, 0, 1, 0

template <std::size_t PacketIdBytes>
struct basic_pubrel_message : detail_v3_1_1::basic_header_packet_id_message<PacketIdBytes> {
    using base = detail_v3_1_1::basic_header_packet_id_message<PacketIdBytes>;
    basic_pubrel_message(typename packet_id_type<PacketIdBytes>::type packet_id)
        : base(control_packet_type::pubrel, 0b0010, packet_id)
    {
    }

At the very minimum, the v5 message is malformed, according to the v5 standard.

https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901142

@ajayb0507 Can you create two Pull Requests?

1) Modify the V5 flag to be 0b0010, like the standard says. 2) Modify endpoint.hpp in either the function handle_remaining_length() (line 4128) or process_payload (line 4213) to check these fixed header required bits for compliance?

As for you getting 1001, i honestly don't know where that's coming from.

Can you intercept the packets using wireshark?

Are you using MQTTv3_1_1, or MQTTv5 ?

ajayb0507 commented 4 years ago

Sorry about that, the 1001 was my mistake. it's sending 0b0000, instead of 0b0010. I have created the pull request for the 1st one. 2nd one still to-do. Thanks.

jonesmz commented 4 years ago

@ajayb0507 Is this still a problem?