Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added topic alias support. #660

Merged
merged 1 commit into from
Sep 16, 2020
Merged

Added topic alias support. #660

merged 1 commit into from
Sep 16, 2020

Conversation

redboltz
Copy link
Owner

@redboltz redboltz commented Sep 9, 2020

TopicAlias lifetime is the same as Session lifetime
It is different from MQTT v5 spec but practical choice.
See
https://lists.oasis-open.org/archives/mqtt-comment/202009/msg00000.html

Related fix:

When topic is empty and no topic alias entry is found, then
protocol_error.
The broker send DISCONNECT packet with protocol_error reason code.

process_disconnect implementation was simply doesn't call
on_mqtt_message_processed() but it was bad.
It caused exit from ioc.run() loop because the next async_read was not
called.
The correct behavior is calling on_mqtt_message_processed() and close
socket. The endpoint can detect the socket close by on_error().

@codecov
Copy link

codecov bot commented Sep 9, 2020

Codecov Report

Merging #660 into master will increase coverage by 0.55%.
The diff coverage is 90.78%.

@@            Coverage Diff             @@
##           master     #660      +/-   ##
==========================================
+ Coverage   82.13%   82.68%   +0.55%     
==========================================
  Files          45       46       +1     
  Lines        7012     7076      +64     
==========================================
+ Hits         5759     5851      +92     
+ Misses       1253     1225      -28     

@redboltz redboltz force-pushed the add_topic_alias_for_recv_3 branch 3 times, most recently from d9b5c4c to be46eb9 Compare September 9, 2020 14:50
@jonesmz
Copy link
Contributor

jonesmz commented Sep 9, 2020

I'm not sure that this is actually a safe change to make.

What happens if an MQTT client attempts to bind the topic alias a second time?

Could there be MQTT clients that attempt to use a topic alias upon first connecting to test that the broker does not have the topic alias?

@redboltz redboltz force-pushed the add_topic_alias_for_recv_3 branch 3 times, most recently from 1392cee to 365fd76 Compare September 10, 2020 02:02
@redboltz
Copy link
Owner Author

I'm not sure that this is actually a safe change to make.

What happens if an MQTT client attempts to bind the topic alias a second time?

The exising topic - topic_alias mapping is overritten.

The spec said that as follows:

A sender can modify the Topic Alias mapping by sending another PUBLISH in the same Network Connection with the same Topic Alias value and a different non-zero length Topic Name.

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

Could there be MQTT clients that attempt to use a topic alias upon first connecting to test that the broker does not have the topic alias?

No, it is a protocol violation.
The spec said that as follows:

  1. If the receiver does not already have a mapping for this Topic Alias

a) If the packet has a zero length Topic Name field it is a Protocol Error and the receiver uses DISCONNECT with Reason Code of 0x82 (Protocol Error) as described in section 4.13.

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

@redboltz
Copy link
Owner Author

sequence publish(topic, alias) result
1 "",1 protocol error (entry not found)
sequence publish(topic, alias) result
1 "topic1",1 register "topic1" - 1
2 "",1 find "topic1" by topic alias 1
3 "topic2",1 register(overwrite) "topic2" - 1
4 "",1 find "topic2" by topic alias 1

TopicAlias lifetime is the same as Session lifetime
It is different from MQTT v5 spec but practical choice.
See
https://lists.oasis-open.org/archives/mqtt-comment/202009/msg00000.html

Related fix:

When topic is empty and no topic alias entry is found, then
protocol_error.
The broker send DISCONNECT packet with protocol_error reason code.

process_disconnect implementation was simply doesn't call
`on_mqtt_message_processed()` but it was bad.
It caused exit from ioc.run() loop because the next async_read was not
called.
The correct behavior is calling `on_mqtt_message_processed()` and close
socket. The endpoint can detect the socket close by on_error().

Fixed topic alias.
@redboltz
Copy link
Owner Author

I will merge the PR tomorrow morning (JST).

@redboltz redboltz merged commit cd65c5f into master Sep 16, 2020
@redboltz redboltz deleted the add_topic_alias_for_recv_3 branch September 16, 2020 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants