net/unicoap: Unified and Modular CoAP Stack: Minimal Client (pt 3)#22266
net/unicoap: Unified and Modular CoAP Stack: Minimal Client (pt 3)#22266carl-tud wants to merge 20 commits into
Conversation
There was a problem hiding this comment.
Can you make this a guide? (https://github.com/RIOT-OS/RIOT/tree/master/doc/guides/c_tutorials)
4d1d4f2 to
185b973
Compare
mguetschow
left a comment
There was a problem hiding this comment.
Have just started looking at the provided example :)
| @@ -0,0 +1,75 @@ | |||
| # Default Makefile, for simple unicoap server sample application | |||
There was a problem hiding this comment.
| # Default Makefile, for simple unicoap server sample application | |
| # Default Makefile, for simple unicoap client sample application |
| @@ -0,0 +1,30 @@ | |||
| # Sample Client Application With `unicoap` | |||
|
|
|||
| This a sample application demonstrating how you send CoAP requests using `unicoap`, | |||
There was a problem hiding this comment.
| This a sample application demonstrating how you send CoAP requests using `unicoap`, | |
| This is a sample application demonstrating how you send CoAP requests using `unicoap`, |
| python3 server.py" | ||
| ``` | ||
|
|
||
| to send a CoAP request through the tap interface to the CoAP server. |
There was a problem hiding this comment.
| to send a CoAP request through the tap interface to the CoAP server. | |
| Now, you can send CoAP requests from RIOT through the tap interface to the CoAP server. |
There was a problem hiding this comment.
Maybe you also want to briefly mention which endpoints the server supports?
| BOARD=native make flash term | ||
| ``` | ||
| This will compile and run the application. | ||
| The application will print a network-layer address. |
There was a problem hiding this comment.
| The application will print a network-layer address. |
Not really relevant on the client side I'd say?
| #if IS_USED(MODULE_UNICOAP_DRIVER_DTLS) | ||
| # include "net/sock/dtls/creds.h" | ||
| # include "net/credman.h" | ||
| # include "net/dsm.h" | ||
| # include "unicoap_example_dtls.h" | ||
|
|
||
| /* Example credential tag for credman. Tag together with the credential type needs to be unique. */ | ||
| # define EXAMPLE_DTLS_CREDENTIAL_TAG 42 /* This should answer your question. */ | ||
|
|
||
| static const uint8_t psk_id_0[] = PSK_DEFAULT_IDENTITY; | ||
| static const uint8_t psk_key_0[] = PSK_DEFAULT_KEY; | ||
| static const credman_credential_t credential = { | ||
| .type = CREDMAN_TYPE_PSK, | ||
| .tag = EXAMPLE_DTLS_CREDENTIAL_TAG, | ||
| .params = { | ||
| .psk = { | ||
| .key = { .s = psk_key_0, .len = sizeof(psk_key_0) - 1, }, | ||
| .id = { .s = psk_id_0, .len = sizeof(psk_id_0) - 1, }, | ||
| } | ||
| }, | ||
| }; | ||
| #endif /* IS_USED(MODULE_UNICOAP_DRIVER_DTLS) */ |
There was a problem hiding this comment.
Why commenting this out? Doesn't it work yet?
There was a problem hiding this comment.
Perhaps looking at C code for hours has damaged my neuronal capacity, but I don't see anything commented out?
|
|
||
| #define MAIN_QUEUE_SIZE (4) | ||
| static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; | ||
|
|
||
| static const shell_command_t commands[] = { | ||
| { "coap", "unicoap client", _cli }, | ||
| { NULL, NULL, NULL } | ||
| }; | ||
|
|
There was a problem hiding this comment.
| #define MAIN_QUEUE_SIZE (4) | |
| static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; | |
| static const shell_command_t commands[] = { | |
| { "coap", "unicoap client", _cli }, | |
| { NULL, NULL, NULL } | |
| }; | |
| SHELL_COMMAND(coap, "unicoap client", _cli) | |
Pretty sure you don't actually need the msg queue. You can start the shell below with NULL instead of commands.
mguetschow
left a comment
There was a problem hiding this comment.
First round of review, mostly typos and nitpicks. I couldn't find the promised client tutorial and the example might benefit from further comments as you did for the server example.
Otherwise: Great work, as always!
| /** | ||
| * @brief Flags for enabling advanced features in client exchanges | ||
| * | ||
| * Pass these flags to one the `unicoap_send_request` functions to modify transmission, |
There was a problem hiding this comment.
| * Pass these flags to one the `unicoap_send_request` functions to modify transmission, | |
| * Pass these flags to one of the `unicoap_send_request` functions to modify transmission, |
| * @brief Sets the type of the message to confirmable (`CON`), | ||
| * if the endpoint is an UDP or DTLS endpoint. | ||
| * | ||
| * This flag is ignored with reliable transports.. For unreliable transports, a message |
There was a problem hiding this comment.
| * This flag is ignored with reliable transports.. For unreliable transports, a message | |
| * This flag is ignored with reliable transports. For unreliable transports, a message |
| * This flag is ignored with reliable transports.. For unreliable transports, a message | ||
| * sent with this flag will require an acknowledgement to be sent from the CoAP | ||
| * peer. | ||
| * |
There was a problem hiding this comment.
What is the default here? Disabled I'd guess?
| * @name Private request API | ||
| */ | ||
| /** | ||
| * @brief Sends off client message and creates a state object for pending request |
There was a problem hiding this comment.
| * @brief Sends off client message and creates a state object for pending request | |
| * @brief Sends off client message and creates a state object for the pending request |
| * @param callback Callback -- either response or block callback, see @ref unicoap_callback_t | ||
| * @param callback_arg Opaque argument passed to callback | ||
| * @param flags Client flags | ||
| * @param profile Profile, e.g., OSCORE profile |
There was a problem hiding this comment.
| * @param profile Profile, e.g., OSCORE profile |
doesn't exist (yet?)
| /** @brief Callback function registered by the client API */ | ||
| unicoap_callback_t callback; | ||
|
|
||
| /** @brief Argument to passed to @p callback */ |
There was a problem hiding this comment.
| /** @brief Argument to passed to @p callback */ | |
| /** @brief Argument to be passed to @p callback */ |
| const uint8_t* token, size_t token_length); | ||
|
|
||
|
|
||
| unicoap_client_memo_t* unicoap_client_memo_find_refno(int refno); |
There was a problem hiding this comment.
doc missing, also below
| /* First bit is sign bit, then 3 bits for min index and then 12 bits of randomness. | ||
| * For 16 or fewer memos, we thus don't have to search at all. */ | ||
| size_t index_min = (refno & 0x7000) >> 12; | ||
| uint16_t reference_id = refno & 0xfff; |
There was a problem hiding this comment.
can we have (file-local) defines for these magic numbers?
| assert(refno > 0); | ||
| #if IS_ACTIVE(CONFIG_UNICOAP_CLIENT_CANCELLABLE) | ||
| /* First bit is sign bit, then 3 bits for min index and then 12 bits of randomness. | ||
| * For 16 or fewer memos, we thus don't have to search at all. */ |
There was a problem hiding this comment.
Why don't we just use the array index as refno?
| _STATE_DEBUG("[NOTIF] use of released state obj\n"); | ||
| return; | ||
| } | ||
| assert(memo->endpoint.proto != UNICOAP_PROTO_UNSPECIFIED); |
There was a problem hiding this comment.
This is kind of trivial now that we returned in the opposite case.
This PR is the third in a series to introduce
unicoap, a unified and modular CoAP implementation for RIOT. An overview of all PRs related tounicoapis presented in #21389, including reasons whyunicoapis needed and a performance analysis.What does this PR include?
The new API is more flexible. CoAP resource addresses are abstracted into a
unicoap_destination_tstructure and transport-specific settings are controlled by flags. For example, this is how you can send a request to aI'll organise the monolithic commit into multiple structured commits once this has passed review, and rebase this PR onto #21582 once merged.