-
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
sys/net/nanocoap: Implement Observe (Server-Side) #21147
base: master
Are you sure you want to change the base?
Conversation
f0a998f
to
124752f
Compare
a3e9b1c
to
c4de045
Compare
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.
I just had a high-level look at it and have some nit's below. In general I don't feel confident enough in nanocoap_sock
to tell whether this takes all nanocoap quirks into account, but the implementation looks good to me in general.
+ 1 /* payload marker */ | ||
+ 10 /* strlen("4294967295"), 4294967295 == UINT32_MAX */ | ||
+ 1 /* '\n' */; | ||
ssize_t hdr_len = coap_build_reply(pkt, COAP_CODE_CONTENT, buf, len, estimated_data_len); |
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.
Funny that payload_len
includes the option length o.O
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.
We should probably rename the variable. I doubt we are the first to be fooled by the misleading name.
if (IS_USED(MODULE_NANOCOAP_SERVER_OBSERVE) && (coap_get_type(pkt) == COAP_TYPE_RST)) { | ||
nanocoap_unregister_observer_by_udp_ep(coap_request_ctx_get_remote_udp(ctx)); |
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.
Hum, shouldn't that only apply when the pkt is a response to a notification on a given resource? https://datatracker.ietf.org/doc/html/rfc7641#section-3.5
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.
Yes, but that would require state to track this. This behavior would be in spec, as a server MUST drop the client on a RST for a notification. It would overshoot in case the RST is unrelated. But that would be the same as the sever loosing state for other reasons (e.g. due to power cycling).
I'll add a comment.
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.
On the other hand, it is 2 bytes of state to add per observation. I guess that is acceptable.
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.
I added the message ID of the most recently sent notification to the state.
Keeping only the message ID of the last send notification can result in the client sending a few more RST messages (e.g. because the RST arrives after the next notification is already send out). But the client will just assume the RST got lost on the network and will keep sending RST until the registration is dropped.
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.
On the other hand, it is 2 bytes of state to add per observation. I guess that is acceptable.
Probably not relevant to nanocoap
, but keep in mind that CoAP over BP opens the can of worms that the message ID size might be more more than 2 bytes 😅. Larger distance (such as in interplanetary communication) means higher latency means more packets in the air means larger number space for messaging required.
* is probably a good thing. */ | ||
(void)pkt; | ||
|
||
return sock_udp_ep_equal(&ctx->remote, req->remote); |
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.
This simple check should probably be reflected in the API documentation for now.
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.
This is actually the same check that has been used before:
RIOT/examples/nanocoap_server/coap_handler.c
Lines 207 to 210 in 297f7fe
if (event_timeout_is_pending(&event_timeout) && !sock_udp_ep_equal(context->remote, &_separate_ctx.remote)) { | |
puts("_separate_handler(): response already scheduled"); | |
return coap_build_reply(pkt, COAP_CODE_SERVICE_UNAVAILABLE, buf, len, 0); | |
} |
The new API would allow to also inspect the packet, but we have no real duplicate detection anywhere else in RIOT. Doing so correctly would require tracking some message IDs, and we don't have the code infrastructure for this. At least this would be a step in that direction by having the API prepared for this.
But given NSTART=1, I'm not sure if the overhead for tracking duplicates actually is worth it.
Freeze is over so if anyone wants to pick this up... |
This allows sending a separate response with CoAP Options and adds a helper to detect duplicate requests, so that resource handlers can repeat their empty ACK on duplicates.
This adds the new `nanocoap_server_observe` module that implements the server side of the CoAP Observe option. It does require cooperation from the resource handler to work, though. Co-Authored-By: mguetschow <[email protected]>
c4de045
to
26f4f06
Compare
Contribution description
Testing procedure
Starting the Server
Running a Client
Issues/PRs references
None