Merge pull request #15690 from janosbrodbeck/pr/dtls/session_get_set_udp_ep

sock/dtls: add getter/setter for the remote UDP endpoint of sock_dtls_session_t
This commit is contained in:
Martine Lenders 2021-01-05 14:23:51 +01:00 committed by GitHub
commit ce0a363f62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -345,6 +345,24 @@ void sock_dtls_session_destroy(sock_dtls_t *sock, sock_dtls_session_t *remote)
dtls_close(sock->dtls_ctx, &remote->dtls_session);
}
void sock_dtls_session_get_udp_ep(const sock_dtls_session_t *session,
sock_udp_ep_t *ep)
{
assert(session);
assert(ep);
_session_to_ep(&session->dtls_session, ep);
}
void sock_dtls_session_set_udp_ep(sock_dtls_session_t *session,
const sock_udp_ep_t *ep)
{
assert(session);
assert(ep);
_ep_to_session(ep, &session->dtls_session);
}
ssize_t sock_dtls_send_aux(sock_dtls_t *sock, sock_dtls_session_t *remote,
const void *data, size_t len, uint32_t timeout,
sock_dtls_aux_tx_t *aux)

View File

@ -664,6 +664,31 @@ int sock_dtls_session_init(sock_dtls_t *sock, const sock_udp_ep_t *ep,
*/
void sock_dtls_session_destroy(sock_dtls_t *sock, sock_dtls_session_t *remote);
/**
* @brief Get the remote UDP endpoint from a session.
*
* @pre `(session != NULL) && (ep != NULL)`
*
* @param[in] session DTLS session
* @param[out] ep UDP endpoint
*/
void sock_dtls_session_get_udp_ep(const sock_dtls_session_t *session,
sock_udp_ep_t *ep);
/**
* @brief Set the remote UDP endpoint from a session.
*
* @pre `(session != NULL) && (ep != NULL)`
*
* @param[in] session DTLS session
* @param[in] ep UDP endpoint
*
* @note Function should only be needed when doing a blocking handshake with
* @ref sock_dtls_send() to set the remote UDP endpoint.
*/
void sock_dtls_session_set_udp_ep(sock_dtls_session_t *session,
const sock_udp_ep_t *ep);
/**
* @brief Receive handshake messages and application data from remote peer.
*
@ -882,6 +907,14 @@ ssize_t sock_dtls_send_aux(sock_dtls_t *sock, sock_dtls_session_t *remote,
* @note When blocking, we will need an extra thread to call
* @ref sock_dtls_recv() function to handle the incoming handshake
* messages.
* An example for a blocking handshake is:
* 1. Create an empty @ref sock_dtls_session_t object.
* 2. Set the UDP endpoint of the peer you want to connect to in the
* session object with @ref sock_dtls_session_set_udp_ep().
* 3. Call @ref sock_dtls_send() with a timeout greater than 0.
* The send function blocks until the handshake completes or the
* timeout expires. If the handshake was successful the data has
* been sent.
*
* @return The number of bytes sent on success
* @return -ENOTCONN, if `timeout == 0` and no existing session exists with