Files
libcoap/include
Jon Shallow 7a4d2db8f3 Fix RST deleting observer for non-confirmable observe
Code works as expected for confirmable observes as the sent pdu is
retained for potential re-transmission.

For non-confirmable observes, the RST is seen in the response packet but
previously had no way of finding the observe/subscription to cancel.

Keep the last sent message id in coap_subscription_t (as tid) and when the
RST comes in, search for the subscription that has the same message id as
the pdu and remove that subscription.

include/coap2/subscribe.h:

Add in tid to coap_subscription_t (as per coap_pdu_t).

src/net.c:

Match tid in incoming RST pdu with a subscription.  If found, delete the
subscription.

src/resource.c:

Save tid in both pdu and subscription when sending off an observe response.

To test code, make the following temporary change to coap-client

diff --git a/examples/client.c b/examples/client.c
index 4d3e4c7..0020b68 100644
--- a/examples/client.c
+++ b/examples/client.c
@@ -348,7 +348,8 @@ message_handler(struct coap_context_t *ctx,
 #endif

   /* check if this is a response to our original request */
-  if (!check_token(received)) {
+static int count = 0;
+  if (!check_token(received) || ++count == 5) {
     /* drop if this was just some message, or send RST in case of notification */
     if (!sent && (received->type == COAP_MESSAGE_CON ||
                   received->type == COAP_MESSAGE_NON))

and run (coap-server running on the same host)

coap-client -N -s 10 coap://127.0.0.1/time
2019-04-25 08:45:19 +01:00
..