[riot-notifications] [RIOT-OS/RIOT] gcoap: multi-transport support for clients (#16688)

benpicco notifications at github.com
Sat Aug 21 16:44:52 CEST 2021


@benpicco commented on this pull request.

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

```patch
--- 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.


> @@ -78,6 +78,7 @@ static const char *_link_params[] = {
 static gcoap_listener_t _listener = {
     &_resources[0],
     ARRAY_SIZE(_resources),
+    GCOAP_SOCKET_TYPE_UNSPEC,

```suggestion
    GCOAP_SOCKET_TYPE_UNDEF,
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16688#pullrequestreview-735499387
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210821/d77da158/attachment.htm>


More information about the notifications mailing list