-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add MQTT v5 support #1709
Conversation
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. |
@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 This means the patch should be updated to:
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. |
You're right. I would also like to save back compatibility so I'm going to add missing |
@lminiero updated the PR. |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
transports/janus_mqtt.c
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
transports/janus_mqtt.c
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
transports/janus_mqtt.c
Outdated
#ifdef MQTTVERSION_5 | ||
if (ctx->connect.mqtt_version == MQTTVERSION_5) { | ||
create_options.MQTTVersion = MQTTVERSION_5; | ||
} |
There was a problem hiding this comment.
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.
af86eb5
to
a00a462
Compare
Updated the PR. |
Thanks a lot for the very quick fixes! I'll give it a test later to try and merge before I leave 👍 |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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?
transports/janus_mqtt.c
Outdated
#ifdef MQTTVERSION_5 | ||
ctx->connect.mqtt_version = MQTTVERSION_5; | ||
#else | ||
JANUS_LOG(LOG_FATAL, "Using MQTT v5 requires compilation with Paho >= 1.3.0"); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Updated the PR. |
Thanks, merging 👍 |
No description provided.