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

Differentiate CONNECT packets properties and CONNACK packets properties #1200

Closed
wants to merge 2 commits into from
Closed

Conversation

heunghingwan
Copy link

Addressing bug in #1183

lib/client.js Outdated
}
if (packet.properties.serverKeepAlive && options.keepalive) {
options.keepalive = packet.properties.serverKeepAlive
this._shiftPingInterval()
}
if (packet.properties.maximumPacketSize) {
if (!options.properties) { options.properties = {} }
options.properties.maximumPacketSize = packet.properties.maximumPacketSize
options.properties.serverMaximumPacketSize = packet.properties.maximumPacketSize
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you've changed this but where is options.properties.serverMaximumPacketSize referenced?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not use anywhere, It should be use when client sending message, but I don't know the code enough to do it properly, may be this will better translate it meaning?

Suggested change
options.properties.serverMaximumPacketSize = packet.properties.maximumPacketSize
options.serverProperties.maximumPacketSize = packet.properties.maximumPacketSize

lib/client.js Outdated
@@ -503,11 +503,11 @@ MqttClient.prototype.publish = function (topic, message, opts, callback) {
if (options.protocolVersion === 5) {
packet.properties = opts.properties
if ((!options.properties && packet.properties && packet.properties.topicAlias) || ((opts.properties && options.properties) &&
((opts.properties.topicAlias && options.properties.topicAliasMaximum && opts.properties.topicAlias > options.properties.topicAliasMaximum) ||
(!options.properties.topicAliasMaximum && opts.properties.topicAlias)))) {
((opts.properties.topicAlias && options.properties.serverTopicAliasMaximum && opts.properties.topicAlias > options.properties.serverTopicAliasMaximum) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know that this change honors the MQTTv5 Spec definition for topicAliasMaximum:

34 (0x22) Byte, Identifier of the Topic Alias Maximum.
811 Followed by the Two Byte Integer representing the Topic Alias Maximum value. It is a Protocol Error to
812 include the Topic Alias Maximum value more than once. If the Topic Alias Maximum property is absent,
813 the default value is 0.
814
815 This value indicates the highest value that the Client will accept as a Topic Alias sent by the Server. The
816 Client uses this value to limit the number of Topic Aliases that it is willing to hold on this Connection. The
817 Server MUST NOT send a Topic Alias in a PUBLISH packet to the Client greater than Topic Alias
818 Maximum [MQTT-3.1.2-26]. A value of 0 indicates that the Client does not accept any Topic Aliases on
819 this connection. If Topic Alias Maximum is absent or zero, the Server MUST NOT send any Topic Aliases
820 to the Client [MQTT-3.1.2-27]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should honor topicAliasMaximum property in CONNACK packet, not CONNECT packets property sent by the client, as shown below: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901088

@YoDaMa
Copy link
Contributor

YoDaMa commented Nov 3, 2020

the option topicAliasMaximum should validate that the server does not send a topic value greater than specified. It should default to 0 aka no topic aliases accepted.

What you're proposing, serverTopicAliasMaximum will be for making sure that on publish the MQTT client does not publish a Topic Alias that is greater than the specified Maximum provided by the server on the CONNACK.

The serverMaximumPacketSize also doesn't seem like it is correct.

@YoDaMa
Copy link
Contributor

YoDaMa commented Nov 5, 2020

@heunghingwan I'll check more on this in a bit. I have a bit on my plate rn. Thank you for doing this though! Your contribution is appreciated.

@heunghingwan
Copy link
Author

After reading the specification, I found that it clearly shows that the server and client have independent topicAliasMaximum values:
3951 Topic Alias
3952 Decrease the size of the MQTT packet overhead by allowing the topic name to be abbreviated to a
3953 small integer. The Client and Server independently specify how many topic aliases they allow.
and maximumPacketSize values:
3969 Maximum Packet Size
3970 Allow the Client and Server to independently specify the maximum packet size they support. It is an
3971 error for the session partner to send a larger packet.

Those appendices summarize them well, glad I haven't miss them😁

@heunghingwan
Copy link
Author

fix by #1301 (#1300 for detail)

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