Found with GnuTLS, believed not to be an issue with OpenSSL and likely (but not reproduced) to be an issue with MbedTLS. In coap_io_prepare_io() the DTLS layer is checked to see if there should be a (handshake) packet re-transmitted. The logic checks to see if there is a timeout and if so causes it to be re-transmitted. Unfortunately this check was also being done when not in the DTLS handshake phase and GnuTLS was returning 'timed out' based on the time since the last handshake transmission. As there was nothing being sent or received, when doing the retransmission, this caused a re-handshake. The fix is to only check for timeouts / re-transmits when in the handshake phase. This change does rigorous checking of state. src/coap_io.c: Only check timeouts / re-transmits when in Handshake phase. [There is also a cpu savings as most sessions will not be in the Handshake phase.] src/coap_gnutls.c: src/coap_mbedtls.c: src/coap_openssl.c: coap_dtls_get_timeout() assert if not handshaking coap_dtls_handle_timeout() assert if not handshaking Note: It is much easier to observe time when checking for this issue if #441 changes are included.
libcoap: A C implementation of the Constrained Application Protocol (RFC 7252)
Copyright (C) 2010—2020 by Olaf Bergmann bergmann@tzi.org and others
ABOUT LIBCOAP
libcoap is a C implementation of a lightweight application-protocol for devices that are constrained their resources such as computing power, RF range, memory, bandwidth, or network packet sizes. This protocol, CoAP, is standardized by the IETF as RFC 7252. For further information related to CoAP, see http://coap.technology.
You might want to check out libcoap-minimal for usage examples.
DOCUMENTATION
Documentation and further information can be found at https://libcoap.net.
PACKAGE CONTENTS
This package contains a protocol parser and basic networking functions for platforms with support for malloc() and BSD-style sockets. In addition, there is support for Contiki, LwIP and Espressif/ESP-IDF hosted environments.
The following RFCs are supported
-
RFC7252: The Constrained Application Protocol (CoAP)
-
RFC7641: Observing Resources in the Constrained Application Protocol (CoAP)
-
RFC7959: Block-Wise Transfers in the Constrained Application Protocol (CoAP)
-
RFC7967: Constrained Application Protocol (CoAP) Option for No Server Response
-
RFC8132: PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)
-
RFC8323: CoAP (Constrained Application Protocol) over TCP, TLS, and WebSockets
There is (D)TLS support for the following libraries
-
OpenSSL (Minimum version 1.1.0)
-
GnuTLS (Minimum version 3.3.0)
-
MbedTLS (Minimum version 2.7.10) [Currently only DTLS]
-
TinyDTLS [DTLS Only]
The examples directory contain a CoAP client, CoAP Resource Directory server and a CoAP server to demonstrate the use of this library.
BUILDING
Further information can be found at https://libcoap.net/install.html and BUILDING.
LICENSE INFORMATION
This library is published as open-source software without any warranty of any kind. Use is permitted under the terms of the simplified BSD license. It includes public domain software. libcoap binaries may also include open-source software with their respective licensing terms. Please refer to LICENSE for further details.