-
Notifications
You must be signed in to change notification settings - Fork 102
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
Mqttv5 connect #294
Mqttv5 connect #294
Conversation
/bot run uncrustify |
* | ||
* These unit tests expect retrying only twice. | ||
*/ | ||
#define MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT ( 2U ) |
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.
Need to reduce duplication with MQTT3 UT folder.
|
||
void test_MQTTV5_DeserializeConnackOnlyMaxQos( void ) | ||
{ | ||
MQTTPacketInfo_t packetInfo; |
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 there is duplication of the first few lines of code across the deserialize tests. Can you verify and see if duplication exists and can be wrapped in an helper function?
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.
The common code and initialisation for each test case can be moved to "void setUp( void )"
Which is use to setup for each test case.
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.
Check this for example
/* | ||
* Max Packet Size cannot be null | ||
*/ | ||
properties.receiveMax = 24; |
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.
what about tests for other properties like session expiry? need tests for max bounds as well I guess? I think MQTT the GetConnectPropertiesSize needs further checks for testing MAX values of sessionexpiry, receive max and maxpacket size
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.
Max possible value of session expiry is uint32 max, receive max is uint16 max and max packet size is 268,435,456 bytes but even if we set it beyond that it doesn't matter because it is theoretically impossible for max packet size to be more than this because of the limitation of the encoded remaining length.
source/include/core_mqtt.h
Outdated
@@ -41,6 +41,8 @@ | |||
/* Include transport interface. */ | |||
#include "transport_interface.h" | |||
|
|||
/* Include transport interface. */ |
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.
Can be removed
* @return The number of vectors added. | ||
*/ | ||
|
||
static size_t addEncodedStringToVectorWithId( uint8_t serializedLength[ CORE_MQTT_SERIALIZED_LENGTH_FIELD_BYTES ], |
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.
Move all the static function declaration to the top of the file, same as "static int32_t sendBuffer"
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 guess what Monika is suggesting is to declare this function first here and then define it down where other static functions are defined.
* Connect flags + 1 = 13 | ||
* Keep alive + 2 = 15 */ | ||
uint8_t connectPacketHeader[ 15U ]; | ||
#else |
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.
Please move out the common code.
@@ -194,6 +246,200 @@ typedef struct MQTTSubscribeInfo | |||
uint16_t topicFilterLength; | |||
} MQTTSubscribeInfo_t; | |||
|
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.
The code below should also be encapsulated within MQTT_VERSION_5_ENABLED flag?
/bot run uncrustify |
incomplete data; it should be called again (probably after | ||
a delay). */ | ||
|
||
MQTTMalformedPacket=0x81, |
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.
Add description here as added for above options.
@@ -2878,4 +2878,5 @@ void test_MQTT_SerializeDisconnect_Happy_Path() | |||
TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus ); | |||
} | |||
|
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.
Remove this as we are not updating this file.
@@ -1116,6 +1116,7 @@ void test_MQTT_Init_Happy_Path( void ) | |||
TEST_ASSERT_EQUAL_MEMORY( &networkBuffer, &context.networkBuffer, sizeof( networkBuffer ) ); | |||
} | |||
|
|||
|
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.
Remove all extra lines added or removed which are not needed.
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.
Hi Pooja,
Thanks for the changes.
The PR looks pretty clean now. I can see that you have taken care of most of the comments from the last team review.
I have some minor comments and some clarifications.
* @brief Struct used to deserialize the will properties. | ||
* | ||
**/ | ||
typedef struct UserPropertiesVector |
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.
Please left align this structure definition.
* @return The number of vectors added. | ||
*/ | ||
|
||
static size_t addEncodedStringToVectorWithId( uint8_t serializedLength[ CORE_MQTT_SERIALIZED_LENGTH_FIELD_BYTES ], |
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 guess what Monika is suggesting is to declare this function first here and then define it down where other static functions are defined.
* @return The number of vectors added. | ||
*/ | ||
|
||
static size_t sendUserProperties( const MQTTUserProperties_t * pUserProperty, |
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.
Please follow the above comment for all static functions.
*pProperty = UINT16_DECODE( pVariableHeader ); | ||
pVariableHeader = &pVariableHeader[ sizeof( uint16_t ) ]; | ||
*pUsed = true; | ||
*pPropertyLength -= sizeof( uint16_t ); |
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 there be a scenario where pPropertyLength can be greater than sizeof( uint16_t ). Same is true for all similar cases in the other decode functions
} | ||
|
||
static MQTTStatus_t decodeutf_8( const char ** pProperty, | ||
uint16_t * pLength, |
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 we need the extra argument of pLength in this decode function while not in others. If we really need "pLength", then will the check in Line 1699 be against "pLength" instead of "sizeof( uint16_t )"
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 is used to store the length of the UTF 8 string. Before decoding, property length is compared with 2 byte for validation and then length is decoded.
@@ -2678,7 +3175,7 @@ MQTTStatus_t MQTT_CancelCallback( const MQTTContext_t * pContext, | |||
|
|||
MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext, | |||
const MQTTConnectInfo_t * pConnectInfo, | |||
const MQTTPublishInfo_t * pWillInfo, |
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 see const is removed because we are updating pWillInfo->propertyLength, why is this specific update is needed for v5?
else | ||
{ | ||
/*Add authentication method and data if provided*/ | ||
if( pAuthInfo->authMethodLength != 0U ) |
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 do we need authMethodLength & authDataLength checks again? As they are already done above. Adding extra if checks.
pIndexLocal = encodeRemainingLength( pIndexLocal, pConnectProperties->propertyLength ); | ||
|
||
/*Serialize session expiry if provided.*/ | ||
if( pConnectProperties->sessionExpiry != 0U ) |
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.
Multiple of these if's can be true? if not, we should use if else.
pIndexLocal[ 1 ] = UINT32_BYTE2( pPublishInfo->msgExpiryInterval ); | ||
pIndexLocal[ 2 ] = UINT32_BYTE1( pPublishInfo->msgExpiryInterval ); | ||
pIndexLocal[ 3 ] = UINT32_BYTE0( pPublishInfo->msgExpiryInterval ); | ||
pIndexLocal = &pIndexLocal[ 4 ]; |
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 are we incrementing the pointer in this different way than usual? Any reference to the existing code?
uint8_t * MQTT_SerializePublishProperties( const MQTTPublishInfo_t * pPublishInfo, | ||
uint8_t * pIndex ) | ||
{ | ||
uint8_t * pIndexLocal = pIndex; |
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.
How are we ensuring pIndexLocal or pIndex has enough space to do all the writes below?
MQTTV5 Connect and Connack
Description
Introduced a config variable MQTT_VERSION_5_ENABLED, which enables the users to use version 5 of MQTT. To support the new properties of connect and connack packet introduced in the version 5, I have modified the existing data structures and functions, and added some new functions. For unit testing I have modified the existing folder structure of test to create a separate folder for v5.
Test Steps
Checklist:
Related Issue
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.