|
cwist
Modern C web framework with libttak runtime
|
#include <stddef.h>#include <stdint.h>#include <stdbool.h>

Go to the source code of this file.
Classes | |
| struct | quic_conn_fc |
| struct | quic_stream_fc |
Macros | |
| #define | QUIC_FLOW_CONTROL_MIN_INITIAL_WINDOW (1024ULL * 1024ULL) |
Typedefs | |
| typedef struct quic_conn_fc | quic_conn_fc_t |
| typedef struct quic_stream_fc | quic_stream_fc_t |
Enumerations | |
| enum | quic_net_quality_t { QUIC_NET_QUALITY_EXCELLENT = 0 , QUIC_NET_QUALITY_NORMAL , QUIC_NET_QUALITY_HIGH_RTT , QUIC_NET_QUALITY_POOR } |
Functions | |
| void | quic_flow_control_init (quic_conn_fc_t *fc, uint64_t initial_conn_window, uint64_t initial_stream_window, uint64_t max_conn_window, uint64_t max_stream_window) |
| Initialize the connection-level flow control state. | |
| void | quic_stream_fc_init (quic_stream_fc_t *sfc, uint64_t stream_id, uint64_t initial_stream_window) |
| Initialize the flow control state for a single stream. | |
| void | quic_flow_control_update_rtt (quic_conn_fc_t *fc, uint64_t rtt_sample_us) |
| Feed an RTT sample into the smoothed RTT estimator and re-evaluate quality. | |
| quic_net_quality_t | quic_flow_control_evaluate_quality (quic_conn_fc_t *fc) |
| Recompute the network quality class from the smoothed RTT. | |
| void | quic_flow_control_adjust_windows (quic_conn_fc_t *fc, quic_stream_fc_t *sfc) |
| Grow flow control windows when the network quality is degraded. | |
| void | quic_flow_control_consume_conn (quic_conn_fc_t *fc, uint64_t bytes) |
| Account for connection-level flow control bytes consumed by the peer. | |
| void | quic_flow_control_consume_stream (quic_conn_fc_t *fc, quic_stream_fc_t *sfc, uint64_t bytes) |
| Account for stream-level flow control bytes consumed by the peer. | |
| int | quic_flow_control_maybe_send_max_data (quic_conn_fc_t *fc, uint8_t *buf, size_t buf_len, size_t *written, bool force) |
| Write a MAX_DATA frame if the connection limit should be raised. | |
| int | quic_flow_control_maybe_send_max_stream_data (quic_conn_fc_t *fc, quic_stream_fc_t *sfc, uint8_t *buf, size_t buf_len, size_t *written, bool force) |
| Write a MAX_STREAM_DATA frame if the stream limit should be raised. | |
Definition at line 8 of file quic_flow_control.h.
| Enumerator | |
|---|---|
| QUIC_NET_QUALITY_EXCELLENT | |
| QUIC_NET_QUALITY_NORMAL | |
| QUIC_NET_QUALITY_HIGH_RTT | |
| QUIC_NET_QUALITY_POOR | |
Definition at line 14 of file quic_flow_control.h.
| void quic_flow_control_adjust_windows | ( | quic_conn_fc_t * | fc, |
| quic_stream_fc_t * | sfc | ||
| ) |
Grow flow control windows when the network quality is degraded.
Only acts when the connection quality is at least QUIC_NET_QUALITY_HIGH_RTT. Each window that is below its configured maximum is doubled, capped at that maximum. No-op if fc is NULL or quality is better than QUIC_NET_QUALITY_HIGH_RTT; sfc may be NULL, in which case only the connection window is adjusted.
| fc | Connection flow control state. |
| sfc | Stream flow control state to adjust, or NULL. |
Definition at line 206 of file quic_flow_control.c.
References cap, quic_conn_fc::conn_max_window, quic_conn_fc::conn_window_size, quic_conn_fc::quality, QUIC_NET_QUALITY_HIGH_RTT, and quic_conn_fc::stream_max_window.
| void quic_flow_control_consume_conn | ( | quic_conn_fc_t * | fc, |
| uint64_t | bytes | ||
| ) |
Account for connection-level flow control bytes consumed by the peer.
The consumed counter saturates at the QUIC varint maximum instead of wrapping. No-op if fc is NULL.
| fc | Connection flow control state. |
| bytes | Number of bytes consumed. |
Definition at line 230 of file quic_flow_control.c.
References quic_conn_fc::conn_consumed.
| void quic_flow_control_consume_stream | ( | quic_conn_fc_t * | fc, |
| quic_stream_fc_t * | sfc, | ||
| uint64_t | bytes | ||
| ) |
Account for stream-level flow control bytes consumed by the peer.
The consumed counter saturates at the QUIC varint maximum instead of wrapping. The connection state fc is not touched; sfc may be NULL, in which case the call is a no-op.
| fc | Connection flow control state (currently unused). |
| sfc | Stream flow control state. |
| bytes | Number of bytes consumed. |
Definition at line 245 of file quic_flow_control.c.
References cap.
| quic_net_quality_t quic_flow_control_evaluate_quality | ( | quic_conn_fc_t * | fc | ) |
Recompute the network quality class from the smoothed RTT.
Classifies by srtt thresholds: <= 50 ms excellent, <= 150 ms normal, <= 500 ms high RTT, above that poor. The result is stored in fc->quality and returned. Returns QUIC_NET_QUALITY_NORMAL if fc is NULL or no RTT sample has been recorded yet.
| fc | Connection flow control state. |
Definition at line 179 of file quic_flow_control.c.
References quic_conn_fc::quality, QUIC_NET_QUALITY_EXCELLENT, QUIC_NET_QUALITY_HIGH_RTT, QUIC_NET_QUALITY_NORMAL, QUIC_NET_QUALITY_POOR, quic_conn_fc::rtt_initialized, and quic_conn_fc::srtt_us.
Referenced by quic_flow_control_update_rtt().
| void quic_flow_control_init | ( | quic_conn_fc_t * | fc, |
| uint64_t | initial_conn_window, | ||
| uint64_t | initial_stream_window, | ||
| uint64_t | max_conn_window, | ||
| uint64_t | max_stream_window | ||
| ) |
Initialize the connection-level flow control state.
Initial and maximum windows are clamped to QUIC_FLOW_CONTROL_MIN_INITIAL_WINDOW, and each maximum is raised to at least the corresponding initial value. No-op if fc is NULL.
| fc | Flow control state to initialize. |
| initial_conn_window | Initial connection-level window in bytes. |
| initial_stream_window | Initial per-stream window in bytes. |
| max_conn_window | Upper bound for the connection window in bytes. |
| max_stream_window | Upper bound for the per-stream window in bytes. |
Definition at line 90 of file quic_flow_control.c.
References cap, quic_conn_fc::quality, and QUIC_NET_QUALITY_NORMAL.
| int quic_flow_control_maybe_send_max_data | ( | quic_conn_fc_t * | fc, |
| uint8_t * | buf, | ||
| size_t | buf_len, | ||
| size_t * | written, | ||
| bool | force | ||
| ) |
Write a MAX_DATA frame if the connection limit should be raised.
Unless force is set, a frame is produced only when at least half of the connection window has been consumed (see should_update()). The new maximum is consumed + window, never lower than the current maximum, and is stored back in fc->max_data on success. On entry *written is cleared to 0 when written is non-NULL.
| fc | Connection flow control state. |
| buf | Output buffer for the encoded frame. |
| buf_len | Capacity of buf in bytes. |
| written | Receives the encoded frame length in bytes. |
| force | Emit the frame even if the update threshold is not met. |
| 1 | Frame written; *written holds its length. |
| 0 | No update needed; nothing written. |
| -1 | Invalid argument or buf too small; nothing written. |
Definition at line 268 of file quic_flow_control.c.
References cap, quic_conn_fc::conn_consumed, quic_conn_fc::conn_window_size, quic_conn_fc::max_data, and QUIC_FRAME_MAX_DATA.
| int quic_flow_control_maybe_send_max_stream_data | ( | quic_conn_fc_t * | fc, |
| quic_stream_fc_t * | sfc, | ||
| uint8_t * | buf, | ||
| size_t | buf_len, | ||
| size_t * | written, | ||
| bool | force | ||
| ) |
Write a MAX_STREAM_DATA frame if the stream limit should be raised.
Unless force is set, a frame is produced only when at least half of the stream window has been consumed (see should_update()). The new maximum is consumed + window, never lower than the current maximum, and is stored back in sfc->max_stream_data on success. On entry *written is cleared to 0 when written is non-NULL.
| fc | Connection flow control state. |
| sfc | Stream flow control state. |
| buf | Output buffer for the encoded frame. |
| buf_len | Capacity of buf in bytes. |
| written | Receives the encoded frame length in bytes. |
| force | Emit the frame even if the update threshold is not met. |
| 1 | Frame written; *written holds its length. |
| 0 | No update needed; nothing written. |
| -1 | Invalid argument or buf too small; nothing written. |
Definition at line 308 of file quic_flow_control.c.
References cap, and QUIC_FRAME_MAX_STREAM_DATA.
| void quic_flow_control_update_rtt | ( | quic_conn_fc_t * | fc, |
| uint64_t | rtt_sample_us | ||
| ) |
Feed an RTT sample into the smoothed RTT estimator and re-evaluate quality.
Uses RFC 6298-style smoothing: rttvar is updated with weight 1/4 and srtt with weight 1/8; the first sample initializes both. Tracked state is confined to fc and is not thread-safe across concurrent calls on the same connection. No-op if fc is NULL or rtt_sample_us is zero.
| fc | Connection flow control state. |
| rtt_sample_us | Latest RTT sample in microseconds. |
Definition at line 147 of file quic_flow_control.c.
References cap, quic_conn_fc::min_rtt_us, quic_flow_control_evaluate_quality(), quic_conn_fc::rtt_initialized, quic_conn_fc::rttvar_us, and quic_conn_fc::srtt_us.
| void quic_stream_fc_init | ( | quic_stream_fc_t * | sfc, |
| uint64_t | stream_id, | ||
| uint64_t | initial_stream_window | ||
| ) |
Initialize the flow control state for a single stream.
The initial window is clamped to QUIC_FLOW_CONTROL_MIN_INITIAL_WINDOW. No-op if sfc is NULL.
| sfc | Stream flow control state to initialize. |
| stream_id | ID of the stream this state belongs to. |
| initial_stream_window | Initial per-stream window in bytes. |
Definition at line 124 of file quic_flow_control.c.
References cap.