sock/async: add function to retrieve session object of current DTLS event#15755
sock/async: add function to retrieve session object of current DTLS event#15755miri64 merged 4 commits intoRIOT-OS:masterfrom
Conversation
|
I have also added a very small doc fix commit. The documentation of |
e593e51 to
4db4112
Compare
You can use the HTML DetailsHIDE ME |
|
Pushed the discussed changes. Now, the event session is only set for Did not adjust the provided test procedure. You can see the expected behaviour in the test. For the |
|
Also adjusted the line length of the function head to comply the 80 character recommendation. |
|
LGTM. Can you also include the patch (only CONN_RECV and CONN_FIN part) as commit to show usage of |
sys/include/net/sock/async.h
Outdated
| * @note Only available with @ref SOCK_HAS_ASYNC defined. | ||
| * Should only be called within a DTLS event and only for the event | ||
| * types @ref SOCK_ASYNC_CONN_RDY and @ref SOCK_ASYNC_CONN_FIN. |
There was a problem hiding this comment.
Mhhh maybe add a return value, that signals to the caller when the the session is available or not? I know this makes the implementation more complicated than it is now, but sock is an end-user API that is supposed to be easy to use. Could be boolean or an errno-based status code
There was a problem hiding this comment.
Totally forgot, sorry. Squashed the undo directly with the related commit.
Regarding the return value. It would be nice to have it...but how? The only idea I have for this currently is to also add (e.g.) a boolean to the socket object and set this boolean when an event occurs. So setting it for the CONN_RDY, CONN_FIN to available and for every other event to not available. Would that be sufficient or do you imagine it differently?
There was a problem hiding this comment.
In the specific case of tinydtls you could use the size member of the session_t struct as a signifier if the session is set.
typedef struct {
socklen_t size; /**< size of addr */
union {
struct sockaddr sa;
struct sockaddr_storage st;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
} addr;
uint8_t ifindex;
} session_t;The object needs to zero'd of course. However, I would do this on read and socket init. This way, if you e.g. receive a CONN_RDY and a MSG_RECV in the same callback you don't accidentally remove the session before it can be read.
There was a problem hiding this comment.
Done :) Thank you! I've adjusted the test procedure to test that the session is not available for other event types.
76167fc to
69b265a
Compare
I've added the usage of the new function to the test. Are you okay with it the way it is now? |
2dc3423 to
6cb35f1
Compare
| sock_dtls_session_t session = { 0 }; | ||
|
|
||
| if (type & SOCK_ASYNC_CONN_RECV) { | ||
| puts("Session handshake received"); |
There was a problem hiding this comment.
Here and in the other event types that are not SOCK_ASYNC_CONN_FIN or SOCK_ASYNC_CONN_RDY (as well in the client), you could also use expect(!sock_dtls_get_event_session(sock, &session)) to make this proper tests ;-).
There was a problem hiding this comment.
Done! In the event types SOCK_ASYNC_CONN_FIN and SOCK_ASYNC_CONN_RDY we could also use expect(sock_dtls....) to test it since currently it is only printed and not tested. Would that be too much to also add it there? Would like to keep the session printing, because it is currently the only example usage of this new function.
There was a problem hiding this comment.
Would like to keep the session printing, because it is currently the only example usage of this new function.
Yes, as you print output, that provides enough result (more than expect which does not print anything when succeeding)
| sock_dtls_session_get_udp_ep(&session, &ep); | ||
|
|
||
| printf("Session became ready: "); | ||
| print_ipv6_addr_with_port(ep.addr.ipv6, sizeof(ep.addr), ep.port); |
There was a problem hiding this comment.
Any reason why you not use sock_udp_ep_fmt() from sys/include/net/sock/util.h here? Seems like re-inventing the wheel.
There was a problem hiding this comment.
I just knew the format function when the address is a ipv6_addr_t object but didn't see one for an endpoint. Was not my intention to reinvent, just did not found a proper function. I'll change it. Way nicer to have a proper function for it.
|
One last comment. Other than that: I tested everything and am fine with most changes (apart from the one mentioned above). You may squash directly. |
85e1bea to
7d08c05
Compare
|
Addressed last comment and squashed. Test uses |
7d08c05 to
328f0c9
Compare
328f0c9 to
c65b4d3
Compare
miri64
left a comment
There was a problem hiding this comment.
ACK. Re-tested and everything works as expected. :-)
Contribution description
This PR adds a new function to sock async:
sock_dtls_get_event_session()to retrieve the session object within a DTLS event. Currently it is not possible to get this session for every event type (e.g. SOCK_ASYNC_CONN_FIN, SOCK_ASYNC_CONN_RDY). It should work for every possible event type. The issue was described in #15517.I didn't get it to work properly with just a pointer in the socket structure, since the session needed to be stored somewhere and storing it was not possible within the
_event()function of tinydtls. So I placed it right away in the socket.Not sure whether I placed the new function correctly.
Testing procedure
Implementation in tinyDTLS can be tested with
pkg_tinydtls_sock_asyncIssues/PRs references
Fixes #15517