Lines Matching +full:int +full:- +full:threshold
2 * Copyright 2022-2024 The OpenSSL Project Authors. All Rights Reserved.
23 int ossl_quic_txfc_init(QUIC_TXFC *txfc, QUIC_TXFC *conn_txfc) in OSSL_SAFE_MATH_UNSIGNED()
25 if (conn_txfc != NULL && conn_txfc->parent != NULL) in OSSL_SAFE_MATH_UNSIGNED()
28 txfc->swm = 0; in OSSL_SAFE_MATH_UNSIGNED()
29 txfc->cwm = 0; in OSSL_SAFE_MATH_UNSIGNED()
30 txfc->parent = conn_txfc; in OSSL_SAFE_MATH_UNSIGNED()
31 txfc->has_become_blocked = 0; in OSSL_SAFE_MATH_UNSIGNED()
37 return txfc->parent; in ossl_quic_txfc_get_parent()
40 int ossl_quic_txfc_bump_cwm(QUIC_TXFC *txfc, uint64_t cwm) in ossl_quic_txfc_bump_cwm()
42 if (cwm <= txfc->cwm) in ossl_quic_txfc_bump_cwm()
45 txfc->cwm = cwm; in ossl_quic_txfc_bump_cwm()
51 assert((txfc->swm + consumed) <= txfc->cwm); in ossl_quic_txfc_get_credit_local()
52 return txfc->cwm - (consumed + txfc->swm); in ossl_quic_txfc_get_credit_local()
61 if (txfc->parent != NULL) { in ossl_quic_txfc_get_credit()
62 assert(txfc->parent->parent == NULL); in ossl_quic_txfc_get_credit()
63 conn_r = ossl_quic_txfc_get_credit_local(txfc->parent, consumed); in ossl_quic_txfc_get_credit()
71 int ossl_quic_txfc_consume_credit_local(QUIC_TXFC *txfc, uint64_t num_bytes) in ossl_quic_txfc_consume_credit_local()
73 int ok = 1; in ossl_quic_txfc_consume_credit_local()
82 txfc->has_become_blocked = 1; in ossl_quic_txfc_consume_credit_local()
84 txfc->swm += num_bytes; in ossl_quic_txfc_consume_credit_local()
88 int ossl_quic_txfc_consume_credit(QUIC_TXFC *txfc, uint64_t num_bytes) in ossl_quic_txfc_consume_credit()
90 int ok = ossl_quic_txfc_consume_credit_local(txfc, num_bytes); in ossl_quic_txfc_consume_credit()
92 if (txfc->parent != NULL) { in ossl_quic_txfc_consume_credit()
93 assert(txfc->parent->parent == NULL); in ossl_quic_txfc_consume_credit()
94 if (!ossl_quic_txfc_consume_credit_local(txfc->parent, num_bytes)) in ossl_quic_txfc_consume_credit()
101 int ossl_quic_txfc_has_become_blocked(QUIC_TXFC *txfc, int clear) in ossl_quic_txfc_has_become_blocked()
103 int r = txfc->has_become_blocked; in ossl_quic_txfc_has_become_blocked()
106 txfc->has_become_blocked = 0; in ossl_quic_txfc_has_become_blocked()
113 return txfc->cwm; in ossl_quic_txfc_get_cwm()
118 return txfc->swm; in ossl_quic_txfc_get_swm()
126 int ossl_quic_rxfc_init(QUIC_RXFC *rxfc, QUIC_RXFC *conn_rxfc, in ossl_quic_rxfc_init()
132 if (conn_rxfc != NULL && conn_rxfc->parent != NULL) in ossl_quic_rxfc_init()
135 rxfc->swm = 0; in ossl_quic_rxfc_init()
136 rxfc->cwm = initial_window_size; in ossl_quic_rxfc_init()
137 rxfc->rwm = 0; in ossl_quic_rxfc_init()
138 rxfc->esrwm = 0; in ossl_quic_rxfc_init()
139 rxfc->hwm = 0; in ossl_quic_rxfc_init()
140 rxfc->cur_window_size = initial_window_size; in ossl_quic_rxfc_init()
141 rxfc->max_window_size = max_window_size; in ossl_quic_rxfc_init()
142 rxfc->parent = conn_rxfc; in ossl_quic_rxfc_init()
143 rxfc->error_code = 0; in ossl_quic_rxfc_init()
144 rxfc->has_cwm_changed = 0; in ossl_quic_rxfc_init()
145 rxfc->epoch_start = ossl_time_zero(); in ossl_quic_rxfc_init()
146 rxfc->now = now; in ossl_quic_rxfc_init()
147 rxfc->now_arg = now_arg; in ossl_quic_rxfc_init()
148 rxfc->is_fin = 0; in ossl_quic_rxfc_init()
149 rxfc->standalone = 0; in ossl_quic_rxfc_init()
153 int ossl_quic_rxfc_init_standalone(QUIC_RXFC *rxfc, in ossl_quic_rxfc_init_standalone()
163 rxfc->standalone = 1; in ossl_quic_rxfc_init_standalone()
169 return rxfc->parent; in ossl_quic_rxfc_get_parent()
175 rxfc->max_window_size = max_window_size; in ossl_quic_rxfc_set_max_window_size()
180 rxfc->epoch_start = rxfc->now(rxfc->now_arg); in rxfc_start_epoch()
181 rxfc->esrwm = rxfc->rwm; in rxfc_start_epoch()
184 static int on_rx_controlled_bytes(QUIC_RXFC *rxfc, uint64_t num_bytes) in on_rx_controlled_bytes()
186 int ok = 1; in on_rx_controlled_bytes()
187 uint64_t credit = rxfc->cwm - rxfc->swm; in on_rx_controlled_bytes()
192 rxfc->error_code = OSSL_QUIC_ERR_FLOW_CONTROL_ERROR; in on_rx_controlled_bytes()
195 rxfc->swm += num_bytes; in on_rx_controlled_bytes()
199 int ossl_quic_rxfc_on_rx_stream_frame(QUIC_RXFC *rxfc, uint64_t end, int is_fin) in ossl_quic_rxfc_on_rx_stream_frame()
203 if (!rxfc->standalone && rxfc->parent == NULL) in ossl_quic_rxfc_on_rx_stream_frame()
206 if (rxfc->is_fin && ((is_fin && rxfc->hwm != end) || end > rxfc->hwm)) { in ossl_quic_rxfc_on_rx_stream_frame()
208 rxfc->error_code = OSSL_QUIC_ERR_FINAL_SIZE_ERROR; in ossl_quic_rxfc_on_rx_stream_frame()
213 rxfc->is_fin = 1; in ossl_quic_rxfc_on_rx_stream_frame()
215 if (end > rxfc->hwm) { in ossl_quic_rxfc_on_rx_stream_frame()
216 delta = end - rxfc->hwm; in ossl_quic_rxfc_on_rx_stream_frame()
217 rxfc->hwm = end; in ossl_quic_rxfc_on_rx_stream_frame()
220 if (rxfc->parent != NULL) in ossl_quic_rxfc_on_rx_stream_frame()
221 on_rx_controlled_bytes(rxfc->parent, delta); /* result ignored */ in ossl_quic_rxfc_on_rx_stream_frame()
222 } else if (end < rxfc->hwm && is_fin) { in ossl_quic_rxfc_on_rx_stream_frame()
223 rxfc->error_code = OSSL_QUIC_ERR_FINAL_SIZE_ERROR; in ossl_quic_rxfc_on_rx_stream_frame()
230 /* threshold = 3/4 */
234 static int rxfc_cwm_bump_desired(QUIC_RXFC *rxfc) in rxfc_cwm_bump_desired()
236 int err = 0; in rxfc_cwm_bump_desired()
237 uint64_t window_rem = rxfc->cwm - rxfc->rwm; in rxfc_cwm_bump_desired()
238 uint64_t threshold in rxfc_cwm_bump_desired() local
239 = safe_muldiv_uint64_t(rxfc->cur_window_size, in rxfc_cwm_bump_desired()
245 * 1/2 as the threshold. in rxfc_cwm_bump_desired()
247 threshold = rxfc->cur_window_size / 2; in rxfc_cwm_bump_desired()
253 return !rxfc->is_fin && window_rem <= threshold; in rxfc_cwm_bump_desired()
256 static int rxfc_should_bump_window_size(QUIC_RXFC *rxfc, OSSL_TIME rtt) in rxfc_should_bump_window_size()
265 * b = rwm - esrwm in rxfc_should_bump_window_size()
274 * our 64-bit nanosecond representation, which will afford plenty of in rxfc_should_bump_window_size()
277 uint64_t b = rxfc->rwm - rxfc->esrwm; in rxfc_should_bump_window_size()
283 now = rxfc->now(rxfc->now_arg); in rxfc_should_bump_window_size()
284 dt = ossl_time_subtract(now, rxfc->epoch_start); in rxfc_should_bump_window_size()
285 t_window = ossl_time_muldiv(dt, rxfc->cur_window_size, b); in rxfc_should_bump_window_size()
296 new_window_size = rxfc->cur_window_size; in rxfc_adjust_window_size()
303 if (new_window_size > rxfc->max_window_size) /* takes precedence over min size */ in rxfc_adjust_window_size()
304 new_window_size = rxfc->max_window_size; in rxfc_adjust_window_size()
306 rxfc->cur_window_size = new_window_size; in rxfc_adjust_window_size()
320 new_cwm = rxfc->rwm + rxfc->cur_window_size; in rxfc_update_cwm()
321 if (new_cwm > rxfc->cwm) { in rxfc_update_cwm()
322 rxfc->cwm = new_cwm; in rxfc_update_cwm()
323 rxfc->has_cwm_changed = 1; in rxfc_update_cwm()
327 static int rxfc_on_retire(QUIC_RXFC *rxfc, uint64_t num_bytes, in rxfc_on_retire()
331 if (ossl_time_is_zero(rxfc->epoch_start)) in rxfc_on_retire()
335 rxfc->rwm += num_bytes; in rxfc_on_retire()
340 int ossl_quic_rxfc_on_retire(QUIC_RXFC *rxfc, in ossl_quic_rxfc_on_retire()
344 if (rxfc->parent == NULL && !rxfc->standalone) in ossl_quic_rxfc_on_retire()
350 if (rxfc->rwm + num_bytes > rxfc->swm) in ossl_quic_rxfc_on_retire()
356 if (!rxfc->standalone) in ossl_quic_rxfc_on_retire()
357 rxfc_on_retire(rxfc->parent, num_bytes, rxfc->cur_window_size, rtt); in ossl_quic_rxfc_on_retire()
364 return rxfc->cwm; in ossl_quic_rxfc_get_cwm()
369 return rxfc->swm; in ossl_quic_rxfc_get_swm()
374 return rxfc->rwm; in ossl_quic_rxfc_get_rwm()
379 return ossl_quic_rxfc_get_cwm(rxfc) - ossl_quic_rxfc_get_swm(rxfc); in ossl_quic_rxfc_get_credit()
382 int ossl_quic_rxfc_has_cwm_changed(QUIC_RXFC *rxfc, int clear) in ossl_quic_rxfc_has_cwm_changed()
384 int r = rxfc->has_cwm_changed; in ossl_quic_rxfc_has_cwm_changed()
387 rxfc->has_cwm_changed = 0; in ossl_quic_rxfc_has_cwm_changed()
392 int ossl_quic_rxfc_get_error(QUIC_RXFC *rxfc, int clear) in ossl_quic_rxfc_get_error()
394 int r = rxfc->error_code; in ossl_quic_rxfc_get_error()
397 rxfc->error_code = 0; in ossl_quic_rxfc_get_error()
402 int ossl_quic_rxfc_get_final_size(const QUIC_RXFC *rxfc, uint64_t *final_size) in ossl_quic_rxfc_get_final_size()
404 if (!rxfc->is_fin) in ossl_quic_rxfc_get_final_size()
408 *final_size = rxfc->hwm; in ossl_quic_rxfc_get_final_size()