net/gcoap: expose remote sock_udp_ep to request handlers#13621
net/gcoap: expose remote sock_udp_ep to request handlers#13621haukepetersen wants to merge 2 commits intoRIOT-OS:masterfrom
Conversation
| #endif | ||
|
|
||
| #ifdef MODULE_GCOAP | ||
| #include "net/sock/udp.h" |
There was a problem hiding this comment.
| #include "net/sock/udp.h" | |
| typedef struct sock_udp_ep_t; |
|
Looks good to me. @kb2ma do you see any reason not to expose this? |
|
I understand the need. Let me think over the weekend about how this fits in the bigger picture. |
|
I agree that we could add the coap_udp_ep_t* remote value as an attribute of coap_pkt_t, and this approach has the advantage of being a simple solution. However, I recommend that we use this need to make gcoap more extensible for the future with the addition of a context struct. IMO coap_pkt_t is not a great fit for the nature of the data because the remote endpoint is not a part of the CoAP PDU. For client requests the remote is provided directly to So similar to #9857, I think it is worthwhile to add a separate struct for server side handling. Let's call it The downside to this approach is the limitation of the coap_resp_handler_t function definition to pass this data to the application handler. In this case we could specify a convention for gcoap that the I don't think this change to coap_resp_handler_t use will be too intrusive, but that depends on how much the context pointer is used at present. We could provide a macro based migration mechanism by defining GCOAP_REQ_HANDLER_CONTEXT_VOID and GCOAP_REQ_HANDLER_CONTEXT_CTX. When VOID, the code would work as it does at present. I am a proponent of these context structs as a way to accommodate growth in an API. #13637 is now another example from today that can be served in this way. Let me know what you think. |
|
Agree. Closing in favor of #13819 |
Contribution description
I currently have a use case, where I need to know the source UDP-endpoint (IPv6 address + port) of for incoming CoAP request. So far, there was no way that I could see to get access this information from within my application.
This PR adds a pointer to the remote
sock_udp_ep_tintocoap_pkt_t. As a pointer to the pkt is passed to a resources event handler, this allows to access a requests source address and port now.Caveat: the proposed solution hardcodes
sock_udp_ep_tand with this it is only able to work with with UDP. But for now I don't see this as a problem, asgcoapis hardcoded tosock_udpanyway. This is also the reason I only included theudp_remotefield fornanocaopin case thatgcoapis used. This way it does not pull this hardcodedsock_udpdependency intonanocoap.Testing procedure
If build tests and
examples/gcoapjust work as before, nothing is broken by this change.Issues/PRs references
none