From 37e2fdbafb03c9e61370d068515fd9a9974ed310 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 1 Dec 2024 20:08:48 +0200 Subject: [PATCH] net.mbedtls: support compiling with `-d mbedtls_client_read_timeout_ms=7000`, `-d mbedtls_server_read_timeout_ms=60000`, and `-d trace_mbedtls_timeouts` --- vlib/net/mbedtls/ssl_connection.c.v | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/vlib/net/mbedtls/ssl_connection.c.v b/vlib/net/mbedtls/ssl_connection.c.v index 11f97861960458..dec82b2253b6bc 100644 --- a/vlib/net/mbedtls/ssl_connection.c.v +++ b/vlib/net/mbedtls/ssl_connection.c.v @@ -8,6 +8,9 @@ const ctr_drbg = C.mbedtls_ctr_drbg_context{} const entropy = C.mbedtls_entropy_context{} +const mbedtls_client_read_timeout_ms = $d('mbedtls_client_read_timeout_ms', 550) +const mbedtls_server_read_timeout_ms = $d('mbedtls_server_read_timeout_ms', 41_000) + fn init() { $if trace_ssl ? { eprintln(@METHOD) @@ -176,7 +179,10 @@ fn (mut l SSLListener) init() ! { C.mbedtls_net_init(&l.server_fd) C.mbedtls_ssl_init(&l.ssl) C.mbedtls_ssl_config_init(&l.conf) - C.mbedtls_ssl_conf_read_timeout(&l.conf, 41_000) + $if trace_mbedtls_timeouts ? { + dump(mbedtls_server_read_timeout_ms) + } + C.mbedtls_ssl_conf_read_timeout(&l.conf, mbedtls_server_read_timeout_ms) l.certs = &SSLCerts{} C.mbedtls_x509_crt_init(&l.certs.client_cert) C.mbedtls_pk_init(&l.certs.client_key) @@ -371,7 +377,10 @@ fn (mut s SSLConn) init() ! { if ret != 0 { return error_with_code('Failed to set SSL configuration', ret) } - C.mbedtls_ssl_conf_read_timeout(&s.conf, 550) + $if trace_mbedtls_timeouts ? { + dump(mbedtls_client_read_timeout_ms) + } + C.mbedtls_ssl_conf_read_timeout(&s.conf, mbedtls_client_read_timeout_ms) unsafe { C.mbedtls_ssl_conf_rng(&s.conf, C.mbedtls_ctr_drbg_random, &ctr_drbg)