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

Reworking MQTT 5 Properties and integrating paho to RPC samples and code #2651

Merged
merged 7 commits into from
Oct 11, 2023

Conversation

RLeclair
Copy link
Member

@RLeclair RLeclair commented Oct 5, 2023

In this PR:

  • Integration of Paho Async C with the RPC code.
  • Two new samples for Paho RPC.
  • Re-work of MQTT property read and free.

NOTE: Added topic filter to received topic matching function using az_span. This is temporary.

@@ -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,
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

@vaavva vaavva left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @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. */
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @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)
Copy link
Member

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)?

Copy link
Member Author

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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member

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.?

Copy link
Member

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?)

Copy link
Member Author

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;
Copy link
Member

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

Comment on lines 533 to 534
// az_mqtt5_property_string response_topic_property = az_mqtt5_property_create_string(
// test_span);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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
Copy link
Member

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;
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @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);
Copy link
Member

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?

@RLeclair RLeclair merged commit 6cc11b5 into Azure:feature/v2 Oct 11, 2023
23 checks passed
@RLeclair RLeclair deleted the pahorpc branch October 11, 2023 00:22
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