From: Nikos Mavrogiannopoulos Date: Fri, 17 Feb 2012 08:00:28 +0000 (+0100) Subject: Added gnutls_dtls_get_timeout() X-Git-Tag: gnutls_3_0_13~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fd77f201312a4bebb8e1b3ce393cc0d98f963d26;p=thirdparty%2Fgnutls.git Added gnutls_dtls_get_timeout() --- diff --git a/NEWS b/NEWS index 72d12af7ac..51675e25af 100644 --- a/NEWS +++ b/NEWS @@ -49,6 +49,7 @@ a fork (if PKCS #11 functionality is desirable). ** libgnutls: Depend on p11-kit 0.11. ** API and ABI modifications: +gnutls_dtls_get_timeout: Added gnutls_verify_stored_pubkey: Added gnutls_store_pubkey: Added gnutls_store_commitment: Added diff --git a/doc/cha-gtls-app.texi b/doc/cha-gtls-app.texi index 9207c26a8b..06802df1c3 100644 --- a/doc/cha-gtls-app.texi +++ b/doc/cha-gtls-app.texi @@ -579,9 +579,14 @@ In the case of DTLS it is also desirable to override the generic transport functions with functions that emulate the operation of @code{recvfrom} and @code{sendto}. In addition @acronym{DTLS} requires timers during the receive of a handshake -message. This requires the @funcref{gnutls_transport_set_pull_timeout_function} function to be used. +message, set using the @funcref{gnutls_transport_set_pull_timeout_function} +function. To check the retransmission timers the function +@funcref{gnutls_dtls_get_timeout} is provided, which returns the time +remaining until the next retransmission, or better the time until +@funcref{gnutls_handshake} should be called again. @showfuncdesc{gnutls_transport_set_pull_timeout_function} +@showfuncdesc{gnutls_dtls_get_timeout} @menu * Asynchronous operation:: @@ -645,7 +650,7 @@ of DTLS messages and prevent messages from being silently discarded by the transport layer. The ``correct'' maximum transfer unit can be obtained through a path MTU discovery mechanism @xcite{RFC4821}. -@showfuncC{gnutls_dtls_set_mtu,gnutls_dtls_get_mtu,gnutls_dtls_get_data_mtu} +@showfuncD{gnutls_dtls_set_mtu,gnutls_dtls_get_mtu,gnutls_dtls_get_data_mtu} @node TLS handshake diff --git a/lib/gnutls_dtls.c b/lib/gnutls_dtls.c index f91ea71b6a..a2c2261d92 100644 --- a/lib/gnutls_dtls.c +++ b/lib/gnutls_dtls.c @@ -596,6 +596,34 @@ unsigned int gnutls_dtls_get_mtu (gnutls_session_t session) return session->internals.dtls.mtu; } +/** + * gnutls_dtls_get_timeout: + * @session: is a #gnutls_session_t structure. + * + * This function will return the milliseconds remaining + * for a retransmission of the previously sent handshake + * message. This function is useful when DTLS is used in + * non-blocking mode, to estimate when to call gnutls_handshake() + * if no packets have been received. + * + * Returns: the remaining time in milliseconds. + * + * Since: 3.0.0 + **/ +unsigned int gnutls_dtls_get_timeout (gnutls_session_t session) +{ +struct timespec now; +unsigned int diff; + + gettime(&now); + + diff = timespec_sub_ms(&now, &session->internals.dtls.last_retransmit); + if (diff >= session->internals.dtls.actual_retrans_timeout_ms) + return 0; + else + return session->internals.dtls.actual_retrans_timeout_ms - diff; +} + #define COOKIE_SIZE 16 #define COOKIE_MAC_SIZE 16 diff --git a/lib/includes/gnutls/dtls.h b/lib/includes/gnutls/dtls.h index e25f6225bb..f65c0092e7 100644 --- a/lib/includes/gnutls/dtls.h +++ b/lib/includes/gnutls/dtls.h @@ -43,7 +43,9 @@ void gnutls_dtls_set_timeouts (gnutls_session_t session, unsigned int gnutls_dtls_get_mtu (gnutls_session_t session); unsigned int gnutls_dtls_get_data_mtu (gnutls_session_t session); - void gnutls_dtls_set_mtu (gnutls_session_t session, unsigned int mtu); +void gnutls_dtls_set_mtu (gnutls_session_t session, unsigned int mtu); + +unsigned int gnutls_dtls_get_timeout (gnutls_session_t session); /** * gnutls_dtls_prestate_st: diff --git a/lib/libgnutls.map b/lib/libgnutls.map index 82f39c469d..ee8c480c1b 100644 --- a/lib/libgnutls.map +++ b/lib/libgnutls.map @@ -774,6 +774,7 @@ GNUTLS_3_0_0 { gnutls_verify_stored_pubkey; gnutls_store_commitment; gnutls_store_pubkey; + gnutls_dtls_get_timeout; } GNUTLS_2_12; GNUTLS_PRIVATE {