1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 04:52:59 +01:00

pkg/tinydtls: remove sock_udp_ep_t from sock_dtls_session_t

This commit is contained in:
János Brodbeck 2020-12-13 05:34:29 +01:00
parent c8d16d21f7
commit 387acdfdb5
No known key found for this signature in database
GPG Key ID: 65C193B0D8D1BCE6
2 changed files with 17 additions and 21 deletions

View File

@ -162,14 +162,10 @@ static int _get_psk_info(struct dtls_context_t *ctx, const session_t *session,
(void)ctx;
(void)desc;
(void)desc_len;
(void)session;
int ret;
sock_dtls_session_t _session;
sock_udp_ep_t ep;
sock_dtls_t *sock = (sock_dtls_t *)dtls_get_app_data(ctx);
_session_to_ep(session, &ep);
memcpy(&_session.ep, &ep, sizeof(sock_udp_ep_t));
memcpy(&_session.dtls_session, session, sizeof(session_t));
sock_dtls_t *sock = dtls_get_app_data(ctx);
credman_credential_t credential;
ret = credman_get(&credential, sock->tag, CREDMAN_TYPE_PSK);
@ -327,8 +323,6 @@ int sock_dtls_session_init(sock_dtls_t *sock, const sock_udp_ep_t *ep,
}
/* prepare the remote party to connect to */
memcpy(&remote->ep, ep, sizeof(sock_udp_ep_t));
memcpy(&remote->dtls_session.addr, &ep->addr.ipv6, sizeof(ipv6_addr_t));
_ep_to_session(ep, &remote->dtls_session);
/* start the handshake */
@ -442,7 +436,6 @@ static inline void _copy_session(sock_dtls_t *sock, sock_dtls_session_t *remote)
{
memcpy(&remote->dtls_session, sock->buffer.session,
sizeof(remote->dtls_session));
_session_to_ep(&remote->dtls_session, &remote->ep);
}
static ssize_t _copy_buffer(sock_dtls_t *sock, sock_dtls_session_t *remote,
@ -456,11 +449,14 @@ static ssize_t _copy_buffer(sock_dtls_t *sock, sock_dtls_session_t *remote,
return -ENOBUFS;
}
#if SOCK_HAS_ASYNC
sock_udp_ep_t ep;
_session_to_ep(&remote->dtls_session, &ep);
if (sock->buf_ctx != NULL) {
memcpy(data, buf, sock->buffer.datalen);
_copy_session(sock, remote);
_check_more_chunks(sock->udp_sock, (void **)&buf, &sock->buf_ctx,
&remote->ep);
&ep);
if (sock->async_cb &&
/* is there a message in the sock's mbox? */
mbox_avail(&sock->mbox)) {
@ -490,7 +486,6 @@ static ssize_t _complete_handshake(sock_dtls_t *sock,
const session_t *session)
{
memcpy(&remote->dtls_session, session, sizeof(remote->dtls_session));
_session_to_ep(&remote->dtls_session, &remote->ep);
#ifdef SOCK_HAS_ASYNC
if (sock->async_cb) {
sock_async_flags_t flags = SOCK_ASYNC_CONN_RDY;
@ -519,6 +514,8 @@ ssize_t sock_dtls_recv_aux(sock_dtls_t *sock, sock_dtls_session_t *remote,
assert(data);
assert(remote);
sock_udp_ep_t ep;
/* loop breaks when timeout or application data read */
while (1) {
ssize_t res;
@ -538,13 +535,13 @@ ssize_t sock_dtls_recv_aux(sock_dtls_t *sock, sock_dtls_session_t *remote,
"sock_dtls_aux_rx_t became incompatible with "
"sock_udp_aux_rx_t");
res = sock_udp_recv_aux(sock->udp_sock, data, max_len, timeout,
&remote->ep, (sock_udp_aux_rx_t *)aux);
&ep, (sock_udp_aux_rx_t *)aux);
if (res <= 0) {
DEBUG("sock_dtls: error receiving UDP packet: %d\n", (int)res);
return res;
}
_ep_to_session(&remote->ep, &remote->dtls_session);
_ep_to_session(&ep, &remote->dtls_session);
res = dtls_handle_message(sock->dtls_ctx, &remote->dtls_session,
(uint8_t *)data, res);
@ -598,12 +595,13 @@ void _udp_cb(sock_udp_t *udp_sock, sock_async_flags_t flags, void *ctx)
sock_dtls_t *sock = ctx;
if (flags & SOCK_ASYNC_MSG_RECV) {
sock_dtls_session_t remote;
session_t remote;
sock_udp_ep_t remote_ep;
void *data = NULL;
void *data_ctx = NULL;
ssize_t res = sock_udp_recv_buf(udp_sock, &data, &data_ctx, 0,
&remote.ep);
&remote_ep);
if (res <= 0) {
DEBUG("sock_dtls: error receiving UDP packet: %d\n", (int)res);
return;
@ -612,15 +610,15 @@ void _udp_cb(sock_udp_t *udp_sock, sock_async_flags_t flags, void *ctx)
/* prevent overriding already set `buf_ctx` */
if (sock->buf_ctx != NULL) {
DEBUG("sock_dtls: unable to store buffer asynchronously\n");
_check_more_chunks(udp_sock, &data, &data_ctx, &remote.ep);
_check_more_chunks(udp_sock, &data, &data_ctx, &remote_ep);
return;
}
_ep_to_session(&remote.ep, &remote.dtls_session);
_ep_to_session(&remote_ep, &remote);
sock->buf_ctx = data_ctx;
res = dtls_handle_message(sock->dtls_ctx, &remote.dtls_session,
res = dtls_handle_message(sock->dtls_ctx, &remote,
data, res);
if (sock->buffer.data == NULL) {
_check_more_chunks(udp_sock, &data, &data_ctx, &remote.ep);
_check_more_chunks(udp_sock, &data, &data_ctx, &remote_ep);
sock->buf_ctx = NULL;
}
}

View File

@ -82,8 +82,6 @@ struct sock_dtls {
* @brief Information about remote client connected to the server
*/
struct sock_dtls_session {
sock_udp_ep_t ep; /**< Remote endpoint the session
is connected to */
session_t dtls_session; /**< TinyDTLS session */
};