-
Notifications
You must be signed in to change notification settings - Fork 2k
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
gcoap: multi-transport support #16688
Conversation
That was supposed to be a draft PR... Oh well... clicked to quickly. |
Sending messages using both the |
I added support for listeners now, but I am not 100% happy yet, as RIOT/sys/net/application_layer/gcoap/gcoap.c Lines 801 to 802 in 604348a
To fix this, the only thing I can think of at the moment would require to expose the transport type to the request handler (currently the knowledge of those stops in |
I know there is |
Heavily edited #16688 (comment) to provide some better context. |
Input on the proposed design is welcome. |
Sorry, I'll get to it at earliest in 10 days :-(
|
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.
First test with a gcoap_dtls
server and both a gcoap_dtls
and gcoap
client is successful.
Both can access resources on the server via UDP and DTLS.
With this small change
--- a/examples/gcoap/gcoap_cli.c
+++ b/examples/gcoap/gcoap_cli.c
@@ -67,6 +67,9 @@ static ssize_t _riot_board_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, vo
/* CoAP resources. Must be sorted by path (ASCII order). */
static const coap_resource_t _resources[] = {
{ "/cli/stats", COAP_GET | COAP_PUT, _stats_handler, NULL },
+};
+
+static const coap_resource_t _resources_secure[] = {
{ "/riot/board", COAP_GET, _riot_board_handler, NULL },
};
@@ -78,7 +81,16 @@ static const char *_link_params[] = {
static gcoap_listener_t _listener = {
&_resources[0],
ARRAY_SIZE(_resources),
- GCOAP_SOCKET_TYPE_UNSPEC,
+ GCOAP_SOCKET_TYPE_UNDEF,
+ _encode_link,
+ NULL,
+ NULL
+};
+
+static gcoap_listener_t _listener_secure = {
+ &_resources_secure[0],
+ ARRAY_SIZE(_resources_secure),
+ GCOAP_SOCKET_TYPE_DTLS,
_encode_link,
NULL,
NULL
@@ -491,4 +503,5 @@ void gcoap_cli_init(void)
#endif
gcoap_register_listener(&_listener);
+ gcoap_register_listener(&_listener_secure);
}
The /riot/board
resource is only available using DTLS while /cli/stats
remains accessible using both UDP and DTLS.
It's unfortunately not possible for the gcoap_dtls
example to make unencrypted requests, but that's a limitation of the CLI command. Would probably be better if the coap
command accepted an URI instead of <addr>[%iface] <port> <path>
but this is for another PR.
@chrysn ping? |
Ok, I now added the transport filter for |
Why does that need special handling? |
See #16688 (comment) |
I wouldn't find it too bad if all handlers could know whether they've been accessed via DTLS or plain UDP. |
Another option would be to just duplicate the endpoint /* Internal variables */
const coap_resource_t _default_resources[] = {
{ "/.well-known/core", COAP_GET, _well_known_core_handler, GCOAP_SOCKET_TYPE_UDP },
};
const coap_resource_t _default_secure_resources[] = {
{ "/.well-known/core", COAP_GET, _well_known_core_handler, GCOAP_SOCKET_TYPE_DTLS },
};
static gcoap_listener_t _default_listener = {
&_default_resources[0],
ARRAY_SIZE(_default_resources),
GCOAP_SOCKET_TYPE_UDP,
NULL,
NULL,
_request_matcher_default
};
static gcoap_listener_t _default_secure_listener = {
&_default_resources[0],
ARRAY_SIZE(_default_secure_resources),
GCOAP_SOCKET_TYPE_DTLS,
NULL,
NULL,
_request_matcher_default
}; |
👎 While it looks simple now, just imagine additional transports coming in the future (TCP, TCP+TLS, SLIPMUX, BLE, QUIC ...). This simply does not scale. |
Mh with regards to e.g. block-wise and TCP transports, this could indeed make sense... |
No time to get it out of WIP ATM + I to me it make sense to wait at least until #16855 got somewhat started so I can put the new struct member of |
is there anything that can be done to help with this PR? |
As stated in #16688 (comment), we should work on #16855. I started some of that work in #17168. |
Other than that, some testing application would be great! |
Want to give this a rebase? Feel free to squash while you're at it. |
30a3391
to
491d2a5
Compare
Squashed first to make rebase less of a pain. |
23a8659 introduced DTLS support for CoAP, but did not make it possible to select the transport on request. Since switching between CoAP and CoAPS (CoAP-over-DTLS) as client is a valid use case (one might want to e.g. talk to one server over CoAP and to another over CoAPS), this change makes that possible.
491d2a5
to
287bfdc
Compare
Rebased and it at least still compiles. However, with the recent rework in #17471, the |
Ok, I think I was just tired yesterday. I tested it again today, and now it works
|
🎉 |
This is an API change in the latter, which would typically now take an extra argument GCOAP_SOCKET_TYPE_UNDEF. Follow-Up-For: RIOT-OS#16688
This is an API change in the latter, which would typically now take an extra argument GCOAP_SOCKET_TYPE_UNDEF. Follow-Up-For: RIOT-OS#16688
18392: drivers/servo: reimplement with high level interface r=benpicco a=maribu ### Contribution description The previous servo driver didn't provide any benefit over using PWM directly, as users controlled the servo in terms of PWM duty cycles. This changes the interface to provide a high level interface that abstracts the gory PWM details. In addition, a SAUL layer and auto-initialization is provided. ### Testing procedure The test application provides access to the servo driver via the `saul` shell command. ``` > saul 2022-08-02 22:12:31,826 # saul 2022-08-02 22:12:31,827 # ID Class Name 2022-08-02 22:12:31,830 # #0 ACT_SWITCH LD1(green) 2022-08-02 22:12:31,832 # #1 ACT_SWITCH LD2(blue) 2022-08-02 22:12:31,834 # #2 ACT_SWITCH LD3(red) 2022-08-02 22:12:31,837 # #3 SENSE_BTN B1(User button) 2022-08-02 22:12:31,838 # #4 ACT_SERVO servo > saul write 4 0 2022-08-02 22:12:41,443 # saul write 4 0 2022-08-02 22:12:41,445 # Writing to device #4 - servo 2022-08-02 22:12:41,447 # Data: 0 2022-08-02 22:12:41,450 # [servo] setting 0 to 2949 (0 / 255) 2022-08-02 22:12:41,453 # data successfully written to device #4 > saul write 4 256 2022-08-02 22:12:45,343 # saul write 4 256 2022-08-02 22:12:45,346 # Writing to device #4 - servo 2022-08-02 22:12:45,347 # Data: 256 2022-08-02 22:12:45,351 # [servo] setting 0 to 6865 (255 / 255) 2022-08-02 22:12:45,354 # data successfully written to device #4 ``` Each write resulted in the MG90S servo that I connected to move to the corresponding position. ### Issues/PRs references 19292: sys/phydat: Fix unit confusion r=benpicco a=maribu ### Contribution description Previously, `UNIT_G` was used for g-force with the correct symbol `g`, `UNIT_GR` for gram (as in kilogram) with the incorrect symbol `G` (which would be correct for Gauss), and `UNIT_GS` for Gauss with symbol `Gs` (which is an alternative correct symbol). To avoid confusion between G-Force, Gauss, and Gram the units have been renamed to `UNIT_G_FORCE`, `UNIT_GRAM`, and `UNIT_GAUSS`. In addition, gram now uses the correct symbol `g`; which sadly is the same as for g-force. But usually there is enough context to tell them apart. ### Testing procedure Green CI ### Issues/PRs references None 19294: sys/shell: don't include suit command by default r=benpicco a=benpicco 19295: gcoap: Finish the gcoap_get_resource_list_tl -> gcoap_get_resource_list renaming r=benpicco a=chrysn ### Contribution description In #16688, an argument was added to the `gcoap_get_resource_list` function by creating a new function `gcoap_get_resource_list_tl` with a deprecation and roll-over plan. This plan has not been acted on so far. This PR shortens the original plan by just adding the argument to `gcoap_get_resource_list` and removing `gcoap_get_resource_list_tl` in a single go. The rationale for this deviation is that while it's a public API, its only two practical consumers are the (built-in) well-known/core implementation, and the (built-in) CoRE Resource Directory (cord) endpoint. Moreover, a further change to this API (switching over to `coap_block_slicer_t`) is expected to happen within this release cycle, which would take something like 4 total releases to get through otherwise, which is unrealistic for an API that there are no known external users of. A second commit clean up ToDo items (in the changed function's documentation) that referred to a IETF draft that has long been abandoned by the CoRE WG. ### Testing procedure Plain inspection and CI passing should suffice. ### AOB There is a second analogous pair left over from #16688, `gcoap_req_send` / `gcoap_req_send_tl`. As that *is* expected to be used widely, I prefer not to mix these two concerns, and get the present one through without unnecessary hold-up. Co-authored-by: Marian Buschsieweke <[email protected]> Co-authored-by: Benjamin Valentin <[email protected]> Co-authored-by: chrysn <[email protected]>
19294: sys/shell: don't include suit command by default r=benpicco a=benpicco 19295: gcoap: Finish the gcoap_get_resource_list_tl -> gcoap_get_resource_list renaming r=benpicco a=chrysn ### Contribution description In #16688, an argument was added to the `gcoap_get_resource_list` function by creating a new function `gcoap_get_resource_list_tl` with a deprecation and roll-over plan. This plan has not been acted on so far. This PR shortens the original plan by just adding the argument to `gcoap_get_resource_list` and removing `gcoap_get_resource_list_tl` in a single go. The rationale for this deviation is that while it's a public API, its only two practical consumers are the (built-in) well-known/core implementation, and the (built-in) CoRE Resource Directory (cord) endpoint. Moreover, a further change to this API (switching over to `coap_block_slicer_t`) is expected to happen within this release cycle, which would take something like 4 total releases to get through otherwise, which is unrealistic for an API that there are no known external users of. A second commit clean up ToDo items (in the changed function's documentation) that referred to a IETF draft that has long been abandoned by the CoRE WG. ### Testing procedure Plain inspection and CI passing should suffice. ### AOB There is a second analogous pair left over from #16688, `gcoap_req_send` / `gcoap_req_send_tl`. As that *is* expected to be used widely, I prefer not to mix these two concerns, and get the present one through without unnecessary hold-up. Co-authored-by: Benjamin Valentin <[email protected]> Co-authored-by: chrysn <[email protected]>
This is an API change in the latter, which would typically now take an extra argument GCOAP_SOCKET_TYPE_UNDEF. Follow-Up-For: RIOT-OS#16688
Contribution description
#15549 introduced DTLS support for CoAP, but did not make it possible to select the transport on request. Since switching between CoAP and CoAPS (CoAP-over-DTLS) as client is a valid use case (one might want to e.g. talk to one server over CoAP and to another over CoAPS), this change makes that possible.
This is only a draft for now.
TODOs:
Testing procedure
Untested for now.
Issues/PRs references
Follow-up on #15549