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

Add MQTT v5 support #1709

Merged
merged 1 commit into from
Aug 2, 2019
Merged

Add MQTT v5 support #1709

merged 1 commit into from
Aug 2, 2019

Conversation

feymartynov
Copy link
Contributor

No description provided.

@lminiero
Copy link
Member

lminiero commented Jul 24, 2019

Thanks! I won't be able to review until I get back home (currently abroad for a conference for the whole week), but from a quick glance you definitely broke the indentation of the configuration file. Please fix that.

@lminiero
Copy link
Member

lminiero commented Aug 1, 2019

@feymartynov ping on the config file fix 😉

On the rest of the patch, I don't think it's ok the way it is now. You updated the README to say that only v1.1 of the library is required, and that v1.3 is only needed if you want MQTTv5. Anyway, the code uses the *5 version of methods and structures (e.g., MQTTAsync_successData5) no matter what, which means that if someone has the v1.1 installed, compilation will fail because of the unrecognized structures.

This means the patch should be updated to:

  • either mandate support for v1.3 of the library (but I don't know how widespread that is, and it would break retrocompatibility to those with an older version of the library)
  • or add a new condition that you can #ifdef on to see if you can use the new stuff (but that will make the code "ugly", since it would be in a lot of places).

I personally don't want to break retrocompatibility (we've tried to ensure that for other transports too across the years), so I'd go for the second option, unless there's a strong and compelling point on 1.3 being pretty much universally deployed and available. Pinging @oej as well since AFAIK he's still using the MQTT code.

@feymartynov
Copy link
Contributor Author

You're right. I would also like to save back compatibility so I'm going to add missing #ifdefs and try to build it with Paho 1.1.

@feymartynov
Copy link
Contributor Author

@lminiero updated the PR.
Tested it with both Paho 1.1.0 (MQTT 3.1.1) and Paho 1.3.0 (MQTT 3.1.1 & 5).

Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

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

Thanks! Added some notes, mostly on indentation/code style, and a small nit on a memory leak. Apart from that, looks good to me! As soon as you update the code, I'll make some tests and in case merge.

@@ -7,6 +7,7 @@ general: {
url = "tcp:https://localhost:1883" # The connection URL of the MQTT broker: if you want
# to use SSL, make sure you type ssl:https:// instead of tcp:https://,
# and that you configure the SSL settings below
#mqtt_version = "3.1.1" # Protocol version. Available values: 3.1, 3.1.1 (default), 5.
Copy link
Member

Choose a reason for hiding this comment

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

Indentation still broken here... please use tabs as per the guidelines.

@@ -157,27 +162,95 @@ int janus_mqtt_client_message_arrived(void *context, char *topicName, int topicL
void janus_mqtt_client_delivery_complete(void *context, MQTTAsync_token token);
int janus_mqtt_client_connect(janus_mqtt_context *ctx);
void janus_mqtt_client_connect_success(void *context, MQTTAsync_successData *response);
#ifdef MQTTVERSION_5
void janus_mqtt_client_connect_success5(void *context, MQTTAsync_successData5 *response);
Copy link
Member

Choose a reason for hiding this comment

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

No need to indent here, it's a function declaration as the others; same for the others below.
Thinking about it, it might make sense to group all the v5 declarations together in a single #ifdef? Would make everything more readable IMO.

@@ -306,6 +379,25 @@ int janus_mqtt_init(janus_transport_callbacks *callback, const char *config_path
}

/* Connect configuration */
janus_config_item *mqtt_version = janus_config_get(config, config_general, janus_config_type_item, "mqtt_version");
const char *mqtt_version_str = (mqtt_version && mqtt_version->value) ? g_strdup(mqtt_version->value) : JANUS_MQTT_VERSION_DEFAULT;
Copy link
Member

Choose a reason for hiding this comment

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

No need to g_strdup here, you're not keeping mqtt_version_str: it's only declared and used here. The way it is now you're introducing a memory leak.

#ifdef MQTTVERSION_5
if (ctx->connect.mqtt_version == MQTTVERSION_5) {
create_options.MQTTVersion = MQTTVERSION_5;
}
Copy link
Member

Choose a reason for hiding this comment

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

Indentation is broken. The way the code is structured in the rest of the repo, the #ifdef, #endif, etc. are all shifted to the left (no indentation), while what they contain should have the same indentation as if they were not wrapped in there. I won't write it under all of the changes, so please update this wherever this occurs.

@feymartynov feymartynov force-pushed the mqttv5 branch 2 times, most recently from af86eb5 to a00a462 Compare August 2, 2019 12:46
@feymartynov
Copy link
Contributor Author

Updated the PR.

@lminiero
Copy link
Member

lminiero commented Aug 2, 2019

Thanks a lot for the very quick fixes! I'll give it a test later to try and merge before I leave 👍

Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

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

Did a quick test and found these last few nits: for some reason I had both an older and a recent version of Paho-C installed, and it was picking the old one, so trying v5 failed initially, which showed the error message with no endline.

Getting rid of that, I verified that it seems to be working as expected, thanks! As soon as you can fix those last few remaining nits I'll merge 👍

@@ -7,6 +7,7 @@ general: {
url = "tcp:https://localhost:1883" # The connection URL of the MQTT broker: if you want
# to use SSL, make sure you type ssl:https:// instead of tcp:https://,
# and that you configure the SSL settings below
#mqtt_version = "3.1.1" # Protocol version. Available values: 3.1, 3.1.1 (default), 5.
Copy link
Member

Choose a reason for hiding this comment

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

It looks like it's still spaces between the value and the comment. Can you fix that too?

#ifdef MQTTVERSION_5
ctx->connect.mqtt_version = MQTTVERSION_5;
#else
JANUS_LOG(LOG_FATAL, "Using MQTT v5 requires compilation with Paho >= 1.3.0");
Copy link
Member

Choose a reason for hiding this comment

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

There's a \n missing here.

} else if(strcmp(mqtt_version_str, JANUS_MQTT_VERSION_3_1_1) == 0) {
ctx->connect.mqtt_version = MQTTVERSION_3_1_1;
} else if(strcmp(mqtt_version_str, JANUS_MQTT_VERSION_5) == 0) {
#ifdef MQTTVERSION_5
Copy link
Member

Choose a reason for hiding this comment

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

This block of #ifdef #else #endif still has a broken indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? #ifdef #else #endif are aligned one tab left and the code itself is aligned like it would be without these directives.

@feymartynov
Copy link
Contributor Author

Updated the PR.

@lminiero
Copy link
Member

lminiero commented Aug 2, 2019

Thanks, merging 👍

@lminiero lminiero merged commit 506d970 into meetecho:master Aug 2, 2019
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.

None yet

2 participants