-
Notifications
You must be signed in to change notification settings - Fork 232
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
[rest] commissioner api #2515
base: main
Are you sure you want to change the base?
[rest] commissioner api #2515
Conversation
Will this PR be picked up as we kind of need this functionality. I also see another PR #2514 but that is really large change. |
…d joiner request and a no bufs error on joiner post with 507 and 400 return codes.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2515 +/- ##
===========================================
- Coverage 55.77% 44.50% -11.28%
===========================================
Files 87 100 +13
Lines 6890 12145 +5255
Branches 0 894 +894
===========================================
+ Hits 3843 5405 +1562
- Misses 3047 6449 +3402
- Partials 0 291 +291 ☔ View full report in Codecov by Sentry. |
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 for the contribution! Overall loooks good to me, a few suggestions below:
schema: | ||
type: string | ||
description: Eui64 address or discerner of joiner to remove | ||
example: "0xabc/12" |
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.
Could you add document explains the format 0xabc/12? What does "/12" mean?
VerifyOrExit(otCommissionerGetState(mInstance) == OT_COMMISSIONER_STATE_DISABLED, | ||
error = OTBR_ERROR_DUPLICATED); |
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 accepting it in this case so that the REST API is idempotent?
VerifyOrExit(otCommissionerGetState(mInstance) != OT_COMMISSIONER_STATE_DISABLED, | ||
error = OTBR_ERROR_DUPLICATED); |
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.
Ditto, it's better to make the REST API idempotent.
else if (error != OTBR_ERROR_NONE) | ||
{ | ||
ErrorHandler(aResponse, HttpStatusCode::kStatusInternalServerError); | ||
} |
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's probably safer to have an else {}
to capture any error which may be missed from the if ()
statements.
{ | ||
ErrorHandler(aResponse, HttpStatusCode::kStatusBadRequest); | ||
} | ||
else if (error == OTBR_ERROR_OPENTHREAD) |
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.
Instead of using OTBR_ERROR_OPENTHREAD for InsufficientStorage, it's probably better to just use OT error directly, instead of casting OT error to OTBR error.
|
||
if (discerner.mLength == 0) | ||
{ | ||
VerifyOrExit(otCommissionerRemoveJoiner(mInstance, addrPtr) == OT_ERROR_NONE, error = OTBR_ERROR_NOT_FOUND); |
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 we consider it success if the joiner to be removed has already been removed? This will make the API idempotent.
} | ||
else | ||
{ | ||
VerifyOrExit(otCommissionerRemoveJoinerWithDiscerner(mInstance, &discerner) == OT_ERROR_NONE, |
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.
Ditto
src/utils/hex.cpp
Outdated
@@ -92,6 +92,24 @@ int Hex2Bytes(const char *aHex, uint8_t *aBytes, uint16_t aBytesLength) | |||
return static_cast<int>(cur - aBytes); | |||
} | |||
|
|||
size_t Uint2Hex(const uint64_t aUint, const uint8_t aUintLength, char *aHex) |
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 Long2Hex()
in this file fulfill your requirements?
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 issue with long2Hex is that the string in in little endian. I could write a string reversal if that would be preferable
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.
Okay, it looks like Long2Hex is never used. What about reusing the method name but change the implementation to big-endian?
BTW, I think the implementation can be simplified for big-endian:
snprintf("%08X", aUint64);
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.
using snprint("%016x", aUint64)
for direct conversion gives compiler warnings that %016lx
must be used for unsigned long but this then breaks 32bit architecture compatibility where it needs to be %016llx
…rrors and idempotent handling of duplicate PUT and not found delete requests
…o produce a big endian string
Added endpoints to the REST server to expose commissioner functionality over the REST API
These changes intend to implement commissioner functionality in the same style as the current rest API offering.
/node/commissioner/state
endpoint allows the user to get/set the commissioner state using GET and PUT requests respectively./node/commissioner/joiner
allows the user to manage joiners accepted by the commissioner, supporting POST, GET and DELETE request methods to add, get and remove a joiner respectively.All added endpoints and their usage have been documented in the openapi.yaml
Example usage:
Please give me feedback and let me know of any required changes 😄