-
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
net/gcoap: add user ptr to response handler functions #9857
net/gcoap: add user ptr to response handler functions #9857
Conversation
I can see the value in a context for a request, and passing the context via the request would be simpler than looking up the context in the handler. The example that comes to my mind is the state associated with a guaranteed delivery requirement. In other words, even a Confirmable request can fail. What then? I have only inspected the code so far, but it looks good. I will test as soon as I get the chance. My only regret is that this change will break all existing request code, but at least the fix is pretty mechanical. |
To future-proof the change, we can include the request memo in the callback rather than the context itself.
With this declaration, we can make more parameters available in the future via the memo without requiring that users change existing code. I replaced the remote endpoint parameter because I'm not sure how widely it is used, and of course the endpoint is available in the request memo. We could specify in the documentation that the user can count on only specific attributes -- remote_ep and context. |
In general, using the But then I just noticed, that I might have a large gap in understanding when it comes to CoAP and multicast traffic. I did never read into the group communication documents and it seems that I have misunderstood the RFC so far - it seems to me that the scenario above is not allowed in the first place?! In that case dropping the |
I totally blanked that the original purpose of the remote host in the handler was for the multicast case. I have essentially no multicast experience, so I read up on 7252 sec. 8 as well as 7390. What did you mean specifically about your gap in understanding from the groupcomm documents relative to the need for the remote parameter in the handler? As I read those documents, particularly 7390, sec 2.5, I agree it makes sense to retain the remote reference in the handler. For example, the client might make a multicast request for which it expects individual responses, like "Are you functioning nominally?" And now the client will know which servers responded. So, how about this declaration for the response handler? I re-added the remote server pointer and made the request memo const.
As I mentioned earlier in this thread, please document which memo attributes the implementer can count on. Let's limit the exposure of the internals. And yes, I completely agree that the context pointer must be included in gcoap_req_send2() and gcoap_req_send(), in order to place it in the request memo. |
Mainly that I simply never opened/read RFC7390 :-) I am still thinking about the best solution for selecting paramters to the resp_handler callback, my current thoughts are: I don't quite like the idea to pass the So let's see what our options can be (at least what I can think of right now):
On top when passing the |
just to get a feel: I just pushed a commit that drops the |
Thanks for summarizing the options for the handler. I like your latest resolution, like below.
I was in favor of keeping the I am not concerned about including the memo in the declaration. The memo as a whole really is a context object, qualifying the response PDU. Regarding the need to specify which fields in the PDU that the user should access:
I also agree that it's overkill to add some 'private' marking to the struct, at least for now. Maybe later when the APIs are stable. So, please document and update examples, and I'll test it out. When you update documentation, remember the Handling the response section in the module documentation. |
I fully agree, and looking at the function today I also still like the solution in passing the memo as first parameter. I will adapt the PR accordingly later today. |
43ee458
to
5490e47
Compare
Adapted this PR according to the results of our discussion:
|
Sorry to take so long to get back on this one, @haukepetersen. Let's get this merged! The code looks basically sound and matches our discussion above. I think the first step is to rebase and update cord_ep's use of gcoap_req_send2() and gcoap_resp_handler_t callback. We also need some instructions on how to test. |
no problem, I am not less responsible for delays in this PR... I will try to do the requested, but can't promise anything before next Wednesday... Will try my best. |
As we discussed, I rebased and updated the cord_ep* examples in my gcoap/req_user_context branch. Please rebase your opt_gcoap_contextptrtoresphandler branch so I can create a PR against it. Also, would you please confirm that the cord_epsim example fails with the default RD address of ff02::1. I use a tap interface between aiocoap-rd on my Linux workstation and the cord_epsim example for native. aiocoap complains with:
and eventually the cord_epsim example errors in the CLI with:
The example works when I compile with RD_ADDR set to the link local unicast address. |
5490e47
to
6046f2d
Compare
Confirmed! Even if I will change the |
also rebased. |
Right, and this PR provides the data for the client to deal with a response from a multicast request. I see a folllow-on PR on the horizon. :-) [edited for clarity] |
Fixed the issue for now in #10464 But the group communication stuff would indeed be nice to implement at some point :-) |
In the description you say:
I'm starting to understand CoRE RD. What exactly would you want to retrieve from the context? |
Now that the response handler has access to the coap_request_memo_t, we may want to streamline the implementation of cord_ep in a follow on PR. Presently cord_ep has separate handlers for on_update and on_remove. However, the coap_request_memo_t has access to the request header. So, a single handler could read the request code from the header instead of hard coding the code in the separate functions. |
b38f1c0
to
91282b0
Compare
Hej @kb2ma: lost this PR get out of view once more :-) I rebased it and adapted it to the latest changes in gcoap. Would you mind to have another look?! Thanks! |
Thanks for rebasing this PR back to life. I will look again after the release. It will be a good time to add infrastructure. |
sounds good to me! |
Having this would help applications using OSCORE (their response handler is basically "decrypt and verify with these nonces, then pass on to the actual response handler"). Is this PR in an overall state where we expect no further obstacles? If so, I'd make this branch a prerequisite for the OSCORE demos and build on it (reviewing the usability as I go), otherwise I'll need to work around (and can still review, but from a more theoretical perspective). |
go ahead! I hope its just the final review/verification that this PR is waiting for :-) |
Works very well for my OSCORE demo use case. (In its current example, the caller allocates a struct that contains the request ID necessary for correlation, and a mutex used to tell whoever allocated that struct that he may return thus freeing the struct). |
91282b0
to
9564c6e
Compare
addressed issues and rebased. Let me know when you want me to squash. |
Looks good. Tested all the clients. Please squash! |
9564c6e
to
3a7b60e
Compare
squashed |
This merges [9857] that was already required for the client-side tests. [9857]: RIOT-OS/RIOT#9857
Contribution description
This PR changes the
gcoap
API slightly to allow passing user defined pointers to response handler functions (gcoap_resp_handler_t
). This is analog to the user context pointers that were added to the resource handler functions in nanocoap a while ago (coap_resource_t
).Adding these user context pointers is quite useful, when handling concurrent requests of a similar type (i.e. registration to multiple CoRE RD's at the same time in my case).
I actually can't remember if this change has been discussed before, or if this change does even already exist. A quick search through the open PRs and issue did not yield any results, so I guess not?!
Testing procedure
So far, this is rather a request for comments, so all changes to the code are untested...
Issues/PRs references
none