-
Notifications
You must be signed in to change notification settings - Fork 120
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
Reworking MQTT 5 Properties and integrating paho to RPC samples and code #2651
Conversation
@@ -45,6 +45,11 @@ static uint8_t correlation_id_buffers[RPC_CLIENT_MAX_PENDING_COMMANDS] | |||
[AZ_MQTT5_RPC_CORRELATION_ID_LENGTH]; | |||
static pending_commands_array pending_commands; | |||
|
|||
static az_mqtt5_options options = { | |||
.certificate_authority_trusted_roots = AZ_SPAN_LITERAL_EMPTY, | |||
.disable_tls_validation = true, |
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.
Aren't we using TLS in this sample?
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.
Reverted back to using TLS
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.
will finish reviewing the test files tomorrow
|
||
/** | ||
* @file | ||
* @brief RPC client sample for Mosquitto MQTT |
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.
* @brief RPC client sample for Mosquitto MQTT | |
* @brief RPC client sample for Paho MQTT |
@@ -0,0 +1,314 @@ | |||
/* Copyright (c) Microsoft Corporation. All rights reserved. */ |
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.
As a future work item, I'd recommend either combining the paho and mosquitto samples into one file with ifdefs or creating common functions for these samples to reduce duplication.
|
||
/** | ||
* @file | ||
* @brief Mosquitto rpc server sample |
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.
* @brief Mosquitto rpc server sample | |
* @brief RPC server sample for Paho MQTT |
az_result rc = _parse_response( | ||
recv_data, &correlation_data, &status, &error_message, &content_type, &resp_data); | ||
az_result rc = AZ_OK; | ||
if (recv_data->properties == NULL) |
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.
Does this check anything (would it ever be null)?
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.
Removed check
resp_data.error_message = AZ_SPAN_FROM_STR("Response does not have properties."); | ||
rc = AZ_ERROR_ITEM_NOT_FOUND; | ||
} | ||
else if (az_span_ptr(correlation_data_bindata) == NULL) |
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.
else if (az_span_ptr(correlation_data_bindata) == NULL) | |
else if (az_span_is_content_equal(correlation_data_bindata, AZ_SPAN_EMPTY)) |
for this and below, unless you'd expect size being non-zero an invalid case that we need to handle as well
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.
Since these values would be AZ_SPAN_EMPTY on any errors reading them, why do we need to create new az_spans for them in lines 385-388 instead of setting them directly to resp_data.?
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.
(realized this doesn't make sense for status/error message, but I think it makes sense for correlation_id and maybe content type?)
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.
I changed the correlation_id and content type to be assigned directly when creating resp_data
and changed the check to az_span_is_content_equal
, thanks for pointing this out!
} | ||
else | ||
{ | ||
resp_data.correlation_id = correlation_data_bindata; |
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.
Ideally, if the correlation id exists, it would be good to set it on resp_data even if there are other errors so the application can try and correlate the failure to the proper command request even if there are other issues with the message
// az_mqtt5_property_string response_topic_property = az_mqtt5_property_create_string( | ||
// test_span); |
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.
// az_mqtt5_property_string response_topic_property = az_mqtt5_property_create_string( | |
// test_span); |
az_span correlation_data_bindata = az_mqtt5_property_get_binarydata(&correlation_data); | ||
az_span content_type_str = az_mqtt5_property_get_string(&content_type); | ||
|
||
if (az_span_ptr(response_topic_str) != NULL && az_span_ptr(correlation_data_bindata) != NULL |
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.
If any of these are null, we probably need to set ret to a failure value to avoid changing the behavior.
@@ -429,6 +429,7 @@ AZ_NODISCARD az_result az_mqtt5_property_bag_clear(az_mqtt5_property_bag* proper | |||
{ | |||
_az_PRECONDITION_NOT_NULL(property_bag); | |||
|
|||
MQTTProperties_free(property_bag->pahoasync_properties); | |||
property_bag->pahoasync_properties->count = 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.
I think this line is now redundant - is this done within MQTTProperties_free?
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 does zero out all fields, removed line.
|
||
/** | ||
* @file | ||
* @brief RPC Server & Client sample for Mosquitto MQTT that supports multiple commands under the |
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.
* @brief RPC Server & Client sample for Mosquitto MQTT that supports multiple commands under the | |
* @brief RPC Server & Client sample for Paho MQTT that supports multiple commands under the |
@@ -880,6 +887,10 @@ static void test_az_mqtt5_rpc_client_invoke_begin_faulted_failure(void** state) | |||
az_mqtt5_rpc_client_invoke_begin(&test_rpc_client, NULL), AZ_ERROR_HFSM_INVALID_STATE); | |||
|
|||
assert_int_equal(ref_pub_req, 0); | |||
|
|||
#if defined(TRANSPORT_PAHO) | |||
MQTTAsync_destroy(&test_client); |
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.
Do we need MQTTProperties_free
here too?
In this PR:
NOTE: Added topic filter to received topic matching function using az_span. This is temporary.