Coverage Report

Created: 2025-12-14 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/ssl/quic/quic_statm.c
Line
Count
Source
1
/*
2
 * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include "internal/quic_statm.h"
11
12
void ossl_statm_update_rtt(OSSL_STATM *statm,
13
    OSSL_TIME ack_delay,
14
    OSSL_TIME override_latest_rtt)
15
0
{
16
0
    OSSL_TIME adjusted_rtt, latest_rtt = override_latest_rtt;
17
18
    /* Use provided RTT value, or else last RTT value. */
19
0
    if (ossl_time_is_zero(latest_rtt))
20
0
        latest_rtt = statm->latest_rtt;
21
0
    else
22
0
        statm->latest_rtt = latest_rtt;
23
24
0
    if (!statm->have_first_sample) {
25
0
        statm->min_rtt = latest_rtt;
26
0
        statm->smoothed_rtt = latest_rtt;
27
0
        statm->rtt_variance = ossl_time_divide(latest_rtt, 2);
28
0
        statm->have_first_sample = 1;
29
0
        return;
30
0
    }
31
32
    /* Update minimum RTT. */
33
0
    if (ossl_time_compare(latest_rtt, statm->min_rtt) < 0)
34
0
        statm->min_rtt = latest_rtt;
35
36
    /*
37
     * Enforcement of max_ack_delay is the responsibility of
38
     * the caller as it is context-dependent.
39
     */
40
41
0
    adjusted_rtt = latest_rtt;
42
0
    if (ossl_time_compare(latest_rtt, ossl_time_add(statm->min_rtt, ack_delay)) >= 0)
43
0
        adjusted_rtt = ossl_time_subtract(latest_rtt, ack_delay);
44
45
0
    statm->rtt_variance = ossl_time_divide(ossl_time_add(ossl_time_multiply(statm->rtt_variance, 3),
46
0
                                               ossl_time_abs_difference(statm->smoothed_rtt,
47
0
                                                   adjusted_rtt)),
48
0
        4);
49
0
    statm->smoothed_rtt = ossl_time_divide(ossl_time_add(ossl_time_multiply(statm->smoothed_rtt, 7),
50
0
                                               adjusted_rtt),
51
0
        8);
52
0
}
53
54
/* RFC 9002 kInitialRtt value. RFC recommended value. */
55
0
#define K_INITIAL_RTT ossl_ms2time(333)
56
57
int ossl_statm_init(OSSL_STATM *statm)
58
0
{
59
0
    statm->smoothed_rtt = K_INITIAL_RTT;
60
0
    statm->latest_rtt = ossl_time_zero();
61
0
    statm->min_rtt = ossl_time_infinite();
62
0
    statm->rtt_variance = ossl_time_divide(K_INITIAL_RTT, 2);
63
0
    statm->have_first_sample = 0;
64
0
    return 1;
65
0
}
66
67
void ossl_statm_destroy(OSSL_STATM *statm)
68
0
{
69
    /* No-op. */
70
0
}
71
72
void ossl_statm_get_rtt_info(OSSL_STATM *statm, OSSL_RTT_INFO *rtt_info)
73
0
{
74
0
    rtt_info->min_rtt = statm->min_rtt;
75
0
    rtt_info->latest_rtt = statm->latest_rtt;
76
0
    rtt_info->smoothed_rtt = statm->smoothed_rtt;
77
0
    rtt_info->rtt_variance = statm->rtt_variance;
78
0
}