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 properties support #2273

Merged
merged 5 commits into from
Jul 16, 2020
Merged

Conversation

feymartynov
Copy link
Contributor

This is related to #1872.
Sorry for taking a long time to send the PR. We had to postpone testing of this feature but now it's good to go.
Also this PR includes MQTT v5 support for the MQTT event handler in the similar way as for the MQTT transport.

@lminiero
Copy link
Member

lminiero commented Jul 9, 2020

Thanks! From a quick glance it looks like a big patch, so I'll need some time to review it. I'll get back to you as soon as I have some feedback 👍

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.

Went through the code and found mostly things that need fixing per the code style, but I added a few notes on some other things as well. Thanks!

@@ -46,4 +47,7 @@ general: {
#tls_client_key = "/path/to/key.pem"
#tls_ciphers
#tls_version

# These options work with MQTT 5 only.
#add_user_properties = () # List of user property ["key", "value"] pairs to add.
Copy link
Member

Choose a reason for hiding this comment

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

It's nice to see the list/array features of libconfig finally used somewhere 🙂

@@ -142,6 +145,7 @@ typedef struct janus_mqttevh_context {

/* Connection data - authentication and url */
struct {
int mqtt_version;
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: please use tabs and not spaces (not sure if the same happens in other parts of the code, in case please fix it there too).

@@ -161,6 +165,9 @@ typedef struct janus_mqttevh_context {
char *disconnect_status;
int qos;
int retain;
#ifdef MQTTVERSION_5
GArray *add_user_properties;
Copy link
Member

Choose a reason for hiding this comment

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

See above on indentation.


#ifdef MQTTVERSION_5
static int janus_mqttevh_client_publish_message5(janus_mqttevh_context *ctx, const char *topic, int retain, char *payload, MQTTProperties *properties) {
int rc;
Copy link
Member

Choose a reason for hiding this comment

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

See above on indentation.

msg.payloadlen = strlen(payload);
msg.qos = ctx->publish.qos;
msg.retained = retain;
msg.properties = MQTTProperties_copy(properties);
Copy link
Member

Choose a reason for hiding this comment

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

See above on indentation.

@@ -956,32 +1254,32 @@ int janus_mqtt_client_subscribe(janus_mqtt_context *ctx, gboolean admin) {
MQTTAsync_responseOptions options = MQTTAsync_responseOptions_initializer;
options.context = ctx;
if(admin) {
#ifdef MQTTVERSION_5
#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.

See above on macros indentation.

if(ctx->connect.mqtt_version == MQTTVERSION_5) {
options.onSuccess5 = janus_mqtt_client_admin_subscribe_success5;
options.onFailure5 = janus_mqtt_client_admin_subscribe_failure5;
} else {
options.onSuccess = janus_mqtt_client_admin_subscribe_success;
options.onFailure = janus_mqtt_client_admin_subscribe_failure;
}
#else
#else
Copy link
Member

Choose a reason for hiding this comment

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

See above on macros indentation.

options.onSuccess = janus_mqtt_client_admin_subscribe_success;
options.onFailure = janus_mqtt_client_admin_subscribe_failure;
#endif
#endif
Copy link
Member

Choose a reason for hiding this comment

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

See above on macros indentation (not going to write it for them all, as I see there are others: please fix them all).

/* MQTT 5 specific types */
typedef struct janus_mqtt_transaction_state {
MQTTProperties *properties;
time_t created_at;
Copy link
Member

Choose a reason for hiding this comment

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

Why the time_t? It may be easier (and probably more easily compatible on other systems) to use a gint64 here and rely on janus_get_monotonic_time() instead.

@@ -28,6 +28,10 @@ general: {
#certfile = /path/to/cert.pem
#keyfile = /path/to/key.pem

# These options work with MQTT 5 only.
#vacuum_interval = 60 # Interval for removing old transcation states in seconds.
Copy link
Member

Choose a reason for hiding this comment

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

Typo: transcation --> transaction

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.

Looks good now, thanks for the fixes!

I'm quite busy so I won't be able to test them, though: considering I never use the MQTT plugins myself, I'm not even sure my checks there would make much sense. I'm assuming you're using MQTT extensively in your setups, so is it safe to say you've tested both of them and they still for fine for you? If so, I'm ok with merging them.

@feymartynov
Copy link
Contributor Author

Yes, sure. We have this branch running in production since December and it's OK so far.

@lminiero
Copy link
Member

Excellent, then it's safe to merge for me 👍 Thanks again for taking the time to work on this huge update and sharing it!

@lminiero lminiero merged commit 1a37a7f into meetecho:master Jul 16, 2020
@feymartynov feymartynov deleted the feature/mqttevh-v5 branch July 20, 2020 13:39
bartbalaz pushed a commit to bartbalaz/janus-gateway that referenced this pull request Jul 21, 2020
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