diff --git a/cyassl/internal.h b/cyassl/internal.h index 45b926c1a..7b2e4e382 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -661,7 +661,10 @@ enum Misc { CLIENT_HELLO_FIRST = 35, /* Protocol + RAN_LEN + sizeof(id_len) */ MAX_SUITE_NAME = 48, /* maximum length of cipher suite string */ DEFAULT_TIMEOUT = 500, /* default resumption timeout in seconds */ - DTLS_DEFAULT_TIMEOUT = 1, /* default timeout for DTLS receive */ + + DTLS_TIMEOUT_INIT = 1, /* default timeout init for DTLS receive */ + DTLS_TIMEOUT_MAX = 64, /* default max timeout for DTLS receive */ + DTLS_TIMEOUT_MULTIPLIER = 2, /* default timeout multiplier for DTLS recv */ MAX_PSK_ID_LEN = 128, /* max psk identity/hint supported */ MAX_PSK_KEY_LEN = 64, /* max psk key supported */ @@ -1667,7 +1670,8 @@ struct CYASSL { byte didStreamInit; /* for stream init and end */ #endif #ifdef CYASSL_DTLS - int dtls_timeout; + int dtls_timeout_init; /* starting timeout vaule */ + int dtls_timeout; /* current timeout value, changes */ DtlsPool* dtls_pool; DtlsMsg* dtls_msg_list; void* IOCB_CookieCtx; /* gen cookie ctx */ diff --git a/cyassl/ssl.h b/cyassl/ssl.h index c5629b28f..ffec73b12 100644 --- a/cyassl/ssl.h +++ b/cyassl/ssl.h @@ -254,6 +254,7 @@ CYASSL_API int CyaSSL_set_cipher_list(CYASSL*, const char*); /* Nonblocking DTLS helper functions */ CYASSL_API int CyaSSL_dtls_get_current_timeout(CYASSL* ssl); +CYASSL_API int CyaSSL_dtls_set_timeout_init(CYASSL* ssl, int); CYASSL_API int CyaSSL_dtls_got_timeout(CYASSL* ssl); CYASSL_API int CyaSSL_dtls(CYASSL* ssl); diff --git a/src/internal.c b/src/internal.c index 5d4cef0da..64676bc4a 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1346,7 +1346,8 @@ int InitSSL(CYASSL* ssl, CYASSL_CTX* ctx) ssl->keys.dtls_epoch = 0; ssl->keys.dtls_peer_epoch = 0; ssl->keys.dtls_expected_peer_epoch = 0; - ssl->dtls_timeout = DTLS_DEFAULT_TIMEOUT; + ssl->dtls_timeout_init = DTLS_TIMEOUT_INIT; + ssl->dtls_timeout = ssl->dtls_timeout_init; ssl->dtls_pool = NULL; ssl->dtls_msg_list = NULL; #endif @@ -1798,15 +1799,15 @@ void DtlsPoolReset(CYASSL* ssl) } pool->used = 0; } - ssl->dtls_timeout = DTLS_DEFAULT_TIMEOUT; + ssl->dtls_timeout = ssl->dtls_timeout_init; } int DtlsPoolTimeout(CYASSL* ssl) { int result = -1; - if (ssl->dtls_timeout < 64) { - ssl->dtls_timeout *= 2; + if (ssl->dtls_timeout < DTLS_TIMEOUT_MAX) { + ssl->dtls_timeout *= DTLS_TIMEOUT_MULTIPLIER; result = 0; } return result; diff --git a/src/ssl.c b/src/ssl.c index c8d5fe7f6..51fc423c9 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -3545,6 +3545,22 @@ int CyaSSL_dtls_get_current_timeout(CYASSL* ssl) } +/* user may need to alter init dtls recv timeout, SSL_SUCCESS on ok */ +int CyaSSL_dtls_set_timeout_init(CYASSL* ssl, int timeout) +{ + if (ssl == NULL || timeout < 0) + return BAD_FUNC_ARG; + +#ifdef CYASSL_DTLS + ssl->dtls_timeout_init = timeout; + + return SSL_SUCCESS; +#else + return NOT_COMPILED_IN; +#endif +} + + int CyaSSL_dtls_got_timeout(CYASSL* ssl) { #ifdef CYASSL_DTLS