Path: blob/main/crypto/openssl/ssl/quic/quic_statm.c
48261 views
/*1* Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#include "internal/quic_statm.h"1011void ossl_statm_update_rtt(OSSL_STATM *statm,12OSSL_TIME ack_delay,13OSSL_TIME override_latest_rtt)14{15OSSL_TIME adjusted_rtt, latest_rtt = override_latest_rtt;1617/* Use provided RTT value, or else last RTT value. */18if (ossl_time_is_zero(latest_rtt))19latest_rtt = statm->latest_rtt;20else21statm->latest_rtt = latest_rtt;2223if (!statm->have_first_sample) {24statm->min_rtt = latest_rtt;25statm->smoothed_rtt = latest_rtt;26statm->rtt_variance = ossl_time_divide(latest_rtt, 2);27statm->have_first_sample = 1;28return;29}3031/* Update minimum RTT. */32if (ossl_time_compare(latest_rtt, statm->min_rtt) < 0)33statm->min_rtt = latest_rtt;3435/*36* Enforcement of max_ack_delay is the responsibility of37* the caller as it is context-dependent.38*/3940adjusted_rtt = latest_rtt;41if (ossl_time_compare(latest_rtt, ossl_time_add(statm->min_rtt, ack_delay)) >= 0)42adjusted_rtt = ossl_time_subtract(latest_rtt, ack_delay);4344statm->rtt_variance = ossl_time_divide(ossl_time_add(ossl_time_multiply(statm->rtt_variance, 3),45ossl_time_abs_difference(statm->smoothed_rtt,46adjusted_rtt)), 4);47statm->smoothed_rtt = ossl_time_divide(ossl_time_add(ossl_time_multiply(statm->smoothed_rtt, 7),48adjusted_rtt), 8);49}5051/* RFC 9002 kInitialRtt value. RFC recommended value. */52#define K_INITIAL_RTT ossl_ms2time(333)5354int ossl_statm_init(OSSL_STATM *statm)55{56statm->smoothed_rtt = K_INITIAL_RTT;57statm->latest_rtt = ossl_time_zero();58statm->min_rtt = ossl_time_infinite();59statm->rtt_variance = ossl_time_divide(K_INITIAL_RTT, 2);60statm->have_first_sample = 0;61return 1;62}6364void ossl_statm_destroy(OSSL_STATM *statm)65{66/* No-op. */67}6869void ossl_statm_get_rtt_info(OSSL_STATM *statm, OSSL_RTT_INFO *rtt_info)70{71rtt_info->min_rtt = statm->min_rtt;72rtt_info->latest_rtt = statm->latest_rtt;73rtt_info->smoothed_rtt = statm->smoothed_rtt;74rtt_info->rtt_variance = statm->rtt_variance;75}767778