Coverage Report

Created: 2026-07-16 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/h2o/deps/quicly/include/quicly/constants.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2017 Fastly, Kazuho Oku
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5
 * of this software and associated documentation files (the "Software"), to
6
 * deal in the Software without restriction, including without limitation the
7
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
 * sell copies of the Software, and to permit persons to whom the Software is
9
 * furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in
12
 * all copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
 * IN THE SOFTWARE.
21
 */
22
#ifndef quicly_constants_h
23
#define quicly_constants_h
24
25
#ifdef __cplusplus
26
extern "C" {
27
#endif
28
29
#include <stddef.h>
30
#include <stdint.h>
31
#include "picotls.h"
32
33
0
#define QUICLY_DELAYED_ACK_TIMEOUT 25   /* milliseconds */
34
0
#define QUICLY_DEFAULT_MAX_ACK_DELAY 25 /* milliseconds */
35
0
#define QUICLY_LOCAL_MAX_ACK_DELAY 25   /* milliseconds */
36
0
#define QUICLY_DEFAULT_ACK_DELAY_EXPONENT 3
37
0
#define QUICLY_LOCAL_ACK_DELAY_EXPONENT 10
38
0
#define QUICLY_MIN_INITIAL_DCID_LEN 8
39
0
#define QUICLY_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT 2 /* If this transport parameter is absent, a default of 2 is assumed. (18.2) */
40
/**
41
 * how many CIDs is quicly willing to manage at the same time?
42
 * this value is used in two ways:
43
 * - active_connection_id_limit transport parameter advertised to the remote peer
44
 * - maximum number of connection IDs we issue to the remote peer at a moment
45
 */
46
0
#define QUICLY_LOCAL_ACTIVE_CONNECTION_ID_LIMIT 4
47
#define QUICLY_MIN_ACTIVE_CONNECTION_ID_LIMIT 2
48
#define QUICLY_DEFAULT_MAX_UDP_PAYLOAD_SIZE 65527
49
0
#define QUICLY_MIN_CLIENT_INITIAL_SIZE 1200
50
#define QUICLY_DEFAULT_MIN_PTO 1      /* milliseconds */
51
#define QUICLY_DEFAULT_INITIAL_RTT 66 /* initial retransmission timeout is *3, i.e. 200ms */
52
0
#define QUICLY_LOSS_DEFAULT_PACKET_THRESHOLD 3
53
54
0
#define QUICLY_DEFAULT_PACKET_TOLERANCE 2
55
0
#define QUICLY_MAX_PACKET_TOLERANCE 10
56
0
#define QUICLY_FIRST_ACK_FREQUENCY_LOSS_EPISODE 4
57
58
0
#define QUICLY_AEAD_TAG_SIZE 16
59
60
0
#define QUICLY_MAX_CID_LEN_V1 20
61
0
#define QUICLY_STATELESS_RESET_TOKEN_LEN 16
62
63
0
#define QUICLY_EPOCH_INITIAL 0
64
0
#define QUICLY_EPOCH_0RTT 1
65
0
#define QUICLY_EPOCH_HANDSHAKE 2
66
0
#define QUICLY_EPOCH_1RTT 3
67
0
#define QUICLY_NUM_EPOCHS 4
68
69
/**
70
 * Error code used by quicly. The code coalesces the following to an int64_t.
71
 * * 0..0x2ff: picotls error codes (of type int)
72
 * * 0x30000..0x400000000002ffff: QUIC application error codes
73
 * * 0x4000000000030000..0x800000000002ffff...: QUIC protocol error codes
74
 * Internal error codes should be allocated from the unused space below 0x30000 (i.e., unused space of picotls error codes);
75
 * quicly itself uses 0xffxx. `quicly_error_t` is defined as a signed type so that the picotls error code space can be mapped
76
 * without sign conversion.
77
 */
78
typedef int64_t quicly_error_t;
79
80
#define QUICLY_ERROR_IS_QUIC(e) ((uint64_t)(quicly_error_t)(e) - 0x30000u < 0x8000000000000000u)
81
0
#define QUICLY_ERROR_IS_QUIC_TRANSPORT(e) ((uint64_t)(quicly_error_t)(e) - 0x4000000000030000u < 0x4000000000000000u)
82
0
#define QUICLY_ERROR_IS_QUIC_APPLICATION(e) ((uint64_t)(quicly_error_t)(e) - 0x30000u < 0x4000000000000000u)
83
0
#define QUICLY_ERROR_GET_ERROR_CODE(e) (((uint64_t)(quicly_error_t)(e) - 0x30000u) & 0x3fffffffffffffffu)
84
0
#define QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(e) ((quicly_error_t)((uint64_t)(e) + 0x4000000000030000u))
85
7.46k
#define QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(e) ((quicly_error_t)(uint64_t)(e) + 0x30000)
86
/**
87
 * PTLS_ERROR_NO_MEMORY and QUICLY_ERROR_STATE_EXHAUSTION are special error codes that are internal but can be passed to
88
 * quicly_close. These are converted to QUICLY_TRANSPORT_ERROR_INTERNAL when sent over the wire.
89
 */
90
#define QUICLY_ERROR_IS_CONCEALED(err) ((err) == PTLS_ERROR_NO_MEMORY || (err) == QUICLY_ERROR_STATE_EXHAUSTION)
91
92
/* transport error codes */
93
#define QUICLY_TRANSPORT_ERROR_NONE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x0)
94
0
#define QUICLY_TRANSPORT_ERROR_INTERNAL QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x1)
95
#define QUICLY_TRANSPORT_ERROR_CONNECTION_REFUSED QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x2)
96
0
#define QUICLY_TRANSPORT_ERROR_FLOW_CONTROL QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x3)
97
0
#define QUICLY_TRANSPORT_ERROR_STREAM_LIMIT QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x4)
98
#define QUICLY_TRANSPORT_ERROR_STREAM_STATE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x5)
99
0
#define QUICLY_TRANSPORT_ERROR_FINAL_SIZE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x6)
100
0
#define QUICLY_TRANSPORT_ERROR_FRAME_ENCODING QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x7)
101
0
#define QUICLY_TRANSPORT_ERROR_TRANSPORT_PARAMETER QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x8)
102
0
#define QUICLY_TRANSPORT_ERROR_CONNECTION_ID_LIMIT QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x9)
103
0
#define QUICLY_TRANSPORT_ERROR_PROTOCOL_VIOLATION QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xa)
104
0
#define QUICLY_TRANSPORT_ERROR_INVALID_TOKEN QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xb)
105
#define QUICLY_TRANSPORT_ERROR_APPLICATION QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xc)
106
0
#define QUICLY_TRANSPORT_ERROR_CRYPTO_BUFFER_EXCEEDED QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xd)
107
#define QUICLY_TRANSPORT_ERROR_KEY_UPDATE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xe)
108
#define QUICLY_TRANSPORT_ERROR_AEAD_LIMIT_REACHED QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xf)
109
0
#define QUICLY_TRANSPORT_ERROR_CRYPTO(tls_alert) QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x100 + (tls_alert))
110
111
/* local error codes, used for signaling status between quicly and the application */
112
0
#define QUICLY_ERROR_PACKET_IGNORED 0xff01
113
0
#define QUICLY_ERROR_SENDBUF_FULL 0xff02    /* internal use only; the error code is never exposed to the application */
114
13.1k
#define QUICLY_ERROR_FREE_CONNECTION 0xff03 /* returned by quicly_send when the connection is freeable */
115
0
#define QUICLY_ERROR_RECEIVED_STATELESS_RESET 0xff04
116
0
#define QUICLY_ERROR_NO_COMPATIBLE_VERSION 0xff05
117
0
#define QUICLY_ERROR_IS_CLOSING 0xff06 /* indicates that the connection has already entered closing state */
118
0
#define QUICLY_ERROR_STATE_EXHAUSTION 0xff07
119
0
#define QUICLY_ERROR_INVALID_INITIAL_VERSION 0xff08
120
0
#define QUICLY_ERROR_DECRYPTION_FAILED 0xff09
121
122
typedef int64_t quicly_stream_id_t;
123
124
typedef struct st_quicly_conn_t quicly_conn_t;
125
126
static uint32_t quicly_u32_add_saturating(uint32_t x, uint32_t y);
127
128
/**
129
 * Used for emitting arbitrary debug message through probes. The debug message might get emitted unescaped as a JSON string,
130
 * therefore cannot contain characters that are required to be escaped as a JSON string (e.g., `\n`, `"`).
131
 */
132
void quicly__debug_printf(quicly_conn_t *conn, const char *function, int line, const char *fmt, ...)
133
    __attribute__((format(printf, 4, 5)));
134
135
#define quicly_debug_printf(conn, ...) quicly__debug_printf((conn), __FUNCTION__, __LINE__, __VA_ARGS__)
136
137
/* inline definitions */
138
139
inline uint32_t quicly_u32_add_saturating(uint32_t x, uint32_t y)
140
0
{
141
0
#ifdef __GNUC__ /* GCC or clang */
142
0
    uint32_t r;
143
0
    return __builtin_add_overflow(x, y, &r) ? UINT32_MAX : r;
144
#else
145
    return x > UINT32_MAX - y ? UINT32_MAX : x + y;
146
#endif
147
0
}
Unexecuted instantiation: driver.cc:quicly_u32_add_saturating(unsigned int, unsigned int)
Unexecuted instantiation: driver_common.cc:quicly_u32_add_saturating(unsigned int, unsigned int)
Unexecuted instantiation: socket.c:quicly_u32_add_saturating
Unexecuted instantiation: config.c:quicly_u32_add_saturating
Unexecuted instantiation: configurator.c:quicly_u32_add_saturating
Unexecuted instantiation: context.c:quicly_u32_add_saturating
Unexecuted instantiation: headers.c:quicly_u32_add_saturating
Unexecuted instantiation: request.c:quicly_u32_add_saturating
Unexecuted instantiation: util.c:quicly_u32_add_saturating
Unexecuted instantiation: access_log.c:quicly_u32_add_saturating
Unexecuted instantiation: file.c:quicly_u32_add_saturating
Unexecuted instantiation: mimemap.c:quicly_u32_add_saturating
Unexecuted instantiation: proxy.c:quicly_u32_add_saturating
Unexecuted instantiation: http1.c:quicly_u32_add_saturating
Unexecuted instantiation: connection.c:quicly_u32_add_saturating
Unexecuted instantiation: scheduler.c:quicly_u32_add_saturating
Unexecuted instantiation: stream.c:quicly_u32_add_saturating
Unexecuted instantiation: http2_debug_state.c:quicly_u32_add_saturating
Unexecuted instantiation: common.c:quicly_u32_add_saturating
Unexecuted instantiation: server.c:quicly_u32_add_saturating
Unexecuted instantiation: cc-reno.c:quicly_u32_add_saturating
Unexecuted instantiation: defaults.c:quicly_u32_add_saturating
Unexecuted instantiation: quicly.c:quicly_u32_add_saturating
Unexecuted instantiation: ranges.c:quicly_u32_add_saturating
Unexecuted instantiation: recvstate.c:quicly_u32_add_saturating
Unexecuted instantiation: remote_cid.c:quicly_u32_add_saturating
Unexecuted instantiation: sendstate.c:quicly_u32_add_saturating
Unexecuted instantiation: sentmap.c:quicly_u32_add_saturating
Unexecuted instantiation: streambuf.c:quicly_u32_add_saturating
Unexecuted instantiation: http3client.c:quicly_u32_add_saturating
Unexecuted instantiation: httpclient.c:quicly_u32_add_saturating
Unexecuted instantiation: absprio.c:quicly_u32_add_saturating
Unexecuted instantiation: logconf.c:quicly_u32_add_saturating
Unexecuted instantiation: compress.c:quicly_u32_add_saturating
Unexecuted instantiation: gzip.c:quicly_u32_add_saturating
Unexecuted instantiation: headers_util.c:quicly_u32_add_saturating
Unexecuted instantiation: frame.c:quicly_u32_add_saturating
Unexecuted instantiation: qpack.c:quicly_u32_add_saturating
Unexecuted instantiation: cc-cubic.c:quicly_u32_add_saturating
Unexecuted instantiation: cc-pico.c:quicly_u32_add_saturating
Unexecuted instantiation: local_cid.c:quicly_u32_add_saturating
Unexecuted instantiation: loss.c:quicly_u32_add_saturating
Unexecuted instantiation: http1client.c:quicly_u32_add_saturating
Unexecuted instantiation: http2client.c:quicly_u32_add_saturating
Unexecuted instantiation: pipe_sender.c:quicly_u32_add_saturating
Unexecuted instantiation: driver_url.cc:quicly_u32_add_saturating(unsigned int, unsigned int)
Unexecuted instantiation: driver_h3.cc:quicly_u32_add_saturating(unsigned int, unsigned int)
Unexecuted instantiation: quicly_mock.c:quicly_u32_add_saturating
Unexecuted instantiation: errordoc.c:quicly_u32_add_saturating
Unexecuted instantiation: expires.c:quicly_u32_add_saturating
Unexecuted instantiation: fastcgi.c:quicly_u32_add_saturating
Unexecuted instantiation: h2olog.c:quicly_u32_add_saturating
Unexecuted instantiation: connect.c:quicly_u32_add_saturating
Unexecuted instantiation: redirect.c:quicly_u32_add_saturating
Unexecuted instantiation: reproxy.c:quicly_u32_add_saturating
Unexecuted instantiation: throttle_resp.c:quicly_u32_add_saturating
Unexecuted instantiation: self_trace.c:quicly_u32_add_saturating
Unexecuted instantiation: server_timing.c:quicly_u32_add_saturating
Unexecuted instantiation: status.c:quicly_u32_add_saturating
Unexecuted instantiation: events.c:quicly_u32_add_saturating
Unexecuted instantiation: memory.c:quicly_u32_add_saturating
Unexecuted instantiation: requests.c:quicly_u32_add_saturating
Unexecuted instantiation: ssl.c:quicly_u32_add_saturating
Unexecuted instantiation: durations.c:quicly_u32_add_saturating
148
149
#ifdef __cplusplus
150
}
151
#endif
152
153
#endif