From 60fccead9044b56969be09c96ab5fb04c876b073 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Mon, 9 Apr 2018 09:08:22 +0100 Subject: [PATCH 1/3] include/coap/coap_session.h: Add in support for DTLS retry counting --- include/coap/coap_session.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/coap/coap_session.h b/include/coap/coap_session.h index f3f4b54c..f0bcc962 100644 --- a/include/coap/coap_session.h +++ b/include/coap/coap_session.h @@ -83,6 +83,7 @@ typedef struct coap_session_t { unsigned int max_retransmit; /**< maximum re-transmit count (default 4) */ coap_fixed_point_t ack_timeout; /**< timeout waiting for ack (default 2 secs) */ coap_fixed_point_t ack_random_factor; /**< ack random factor backoff (default 1.5) */ + unsigned int dtls_timeout_count; /** Date: Mon, 9 Apr 2018 09:09:12 +0100 Subject: [PATCH 2/3] src/coap_openssl.c: Add in support for DTLS retry counting --- src/coap_openssl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/coap_openssl.c b/src/coap_openssl.c index c2aff57f..a97a3098 100644 --- a/src/coap_openssl.c +++ b/src/coap_openssl.c @@ -745,6 +745,8 @@ void *coap_dtls_new_client_session(coap_session_t *session) { SSL_set_options(ssl, SSL_OP_COOKIE_EXCHANGE); SSL_set_mtu(ssl, session->mtu); + session->dtls_timeout_count = 0; + r = SSL_connect(ssl); if (r == -1) { int ret = SSL_get_error(ssl, r); @@ -835,7 +837,9 @@ void coap_dtls_handle_timeout(coap_session_t *session) { SSL *ssl = (SSL *)session->tls; assert(ssl != NULL); - if (DTLSv1_handle_timeout(ssl) < 0) { + if (((session->state == COAP_SESSION_STATE_HANDSHAKE) && + (++session->dtls_timeout_count > session->max_retransmit)) || + (DTLSv1_handle_timeout(ssl) < 0)) { /* Too many retries */ coap_session_disconnected(session, COAP_NACK_TLS_FAILED); } From 2582d085f8f145fb977892d75fb196b8a06c7e6f Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Fri, 13 Apr 2018 14:05:17 +0100 Subject: [PATCH 3/3] examples/client.c: Run at least once per sec to aid debugging --- examples/client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/client.c b/examples/client.c index e3286413..f00eb333 100644 --- a/examples/client.c +++ b/examples/client.c @@ -1326,7 +1326,9 @@ main(int argc, char **argv) { while ( !(ready && coap_can_exit(ctx)) ) { - result = coap_run_once( ctx, wait_ms == 0 ? obs_ms : obs_ms == 0 ? wait_ms : min( wait_ms, obs_ms ) ); + result = coap_run_once( ctx, wait_ms == 0 ? + obs_ms : obs_ms == 0 ? + min(wait_ms, 1000) : min( wait_ms, obs_ms ) ); if ( result >= 0 ) { if ( wait_ms > 0 && !wait_ms_reset ) {