summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNode.js GitHub Bot <github-bot@iojs.org>2023-04-30 00:26:10 +0000
committerNode.js GitHub Bot <github-bot@iojs.org>2023-04-30 00:27:57 +0000
commit5e7d37e1e3bd9ea20eb626493e935ca4c204bcf1 (patch)
treecd68476210cda9909b838762248452f6de2fb357
parentd330578e3e94acc7c9e927347701a0d01059b95f (diff)
downloadnode-new-5e7d37e1e3bd9ea20eb626493e935ca4c204bcf1.tar.gz
deps: update ngtcp2 to 0.15.0
-rw-r--r--deps/ngtcp2/ngtcp2/crypto/boringssl/boringssl.c2
-rw-r--r--deps/ngtcp2/ngtcp2/crypto/openssl/openssl.c2
-rw-r--r--deps/ngtcp2/ngtcp2/crypto/picotls/picotls.c2
-rw-r--r--deps/ngtcp2/ngtcp2/crypto/wolfssl/wolfssl.c2
-rw-r--r--deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/ngtcp2.h218
-rw-r--r--deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h4
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_addr.h7
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.c635
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.h35
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.c448
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.h19
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.c460
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.h59
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.c259
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.h60
-rw-r--r--deps/ngtcp2/ngtcp2/lib/ngtcp2_rtb.c28
16 files changed, 1019 insertions, 1221 deletions
diff --git a/deps/ngtcp2/ngtcp2/crypto/boringssl/boringssl.c b/deps/ngtcp2/ngtcp2/crypto/boringssl/boringssl.c
index 8b650bdfc3..0cfe6a13e9 100644
--- a/deps/ngtcp2/ngtcp2/crypto/boringssl/boringssl.c
+++ b/deps/ngtcp2/ngtcp2/crypto/boringssl/boringssl.c
@@ -438,7 +438,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
return 0;
}
- ngtcp2_conn_handshake_completed(conn);
+ ngtcp2_conn_tls_handshake_completed(conn);
}
rv = SSL_process_quic_post_handshake(ssl);
diff --git a/deps/ngtcp2/ngtcp2/crypto/openssl/openssl.c b/deps/ngtcp2/ngtcp2/crypto/openssl/openssl.c
index 466d9e11ca..2fff43faf7 100644
--- a/deps/ngtcp2/ngtcp2/crypto/openssl/openssl.c
+++ b/deps/ngtcp2/ngtcp2/crypto/openssl/openssl.c
@@ -623,7 +623,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
}
}
- ngtcp2_conn_handshake_completed(conn);
+ ngtcp2_conn_tls_handshake_completed(conn);
}
rv = SSL_process_quic_post_handshake(ssl);
diff --git a/deps/ngtcp2/ngtcp2/crypto/picotls/picotls.c b/deps/ngtcp2/ngtcp2/crypto/picotls/picotls.c
index 315f3412e3..688ee3892d 100644
--- a/deps/ngtcp2/ngtcp2/crypto/picotls/picotls.c
+++ b/deps/ngtcp2/ngtcp2/crypto/picotls/picotls.c
@@ -409,7 +409,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
}
if (rv == 0) {
- ngtcp2_conn_handshake_completed(conn);
+ ngtcp2_conn_tls_handshake_completed(conn);
}
rv = 0;
diff --git a/deps/ngtcp2/ngtcp2/crypto/wolfssl/wolfssl.c b/deps/ngtcp2/ngtcp2/crypto/wolfssl/wolfssl.c
index 4c341de558..8ac581a9b3 100644
--- a/deps/ngtcp2/ngtcp2/crypto/wolfssl/wolfssl.c
+++ b/deps/ngtcp2/ngtcp2/crypto/wolfssl/wolfssl.c
@@ -332,7 +332,7 @@ int ngtcp2_crypto_read_write_crypto_data(ngtcp2_conn *conn,
}
DEBUG_MSG("WOLFSSL: handshake done\n");
- ngtcp2_conn_handshake_completed(conn);
+ ngtcp2_conn_tls_handshake_completed(conn);
}
rv = wolfSSL_process_quic_post_handshake(ssl);
diff --git a/deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/ngtcp2.h b/deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/ngtcp2.h
index 84617f7b71..37bc0badda 100644
--- a/deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/ngtcp2.h
+++ b/deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/ngtcp2.h
@@ -1891,7 +1891,7 @@ typedef struct ngtcp2_settings {
* given buffer size, :member:`max_tx_udp_payload_size`, and the
* received max_udp_payload QUIC transport parameter.
*/
- int no_tx_udp_payload_size_shaping;
+ uint8_t no_tx_udp_payload_size_shaping;
/**
* :member:`handshake_timeout` is the period of time before giving
* up QUIC connection establishment. If QUIC handshake is not
@@ -1969,7 +1969,7 @@ typedef struct ngtcp2_settings {
* :member:`no_pmtud`, if set to nonzero, disables Path MTU
* Discovery.
*/
- int no_pmtud;
+ uint8_t no_pmtud;
} ngtcp2_settings;
/**
@@ -3011,6 +3011,15 @@ typedef int (*ngtcp2_update_key)(
#define NGTCP2_PATH_VALIDATION_FLAG_PREFERRED_ADDR 0x01u
/**
+ * @macro
+ *
+ * :macro:`NGTCP2_PATH_VALIDATION_FLAG_NEW_TOKEN` indicates that
+ * server should send NEW_TOKEN for the new remote address. This flag
+ * is only set for server.
+ */
+#define NGTCP2_PATH_VALIDATION_FLAG_NEW_TOKEN 0x02u
+
+/**
* @functypedef
*
* :type:`ngtcp2_path_validation` is a callback function which tells
@@ -3103,10 +3112,9 @@ typedef enum ngtcp2_connection_id_status_type {
* :macro:`NGTCP2_ERR_CALLBACK_FAILURE` makes the library call return
* immediately.
*/
-typedef int (*ngtcp2_connection_id_status)(ngtcp2_conn *conn, int type,
- uint64_t seq, const ngtcp2_cid *cid,
- const uint8_t *token,
- void *user_data);
+typedef int (*ngtcp2_connection_id_status)(
+ ngtcp2_conn *conn, ngtcp2_connection_id_status_type type, uint64_t seq,
+ const ngtcp2_cid *cid, const uint8_t *token, void *user_data);
/**
* @functypedef
@@ -3758,12 +3766,12 @@ NGTCP2_EXTERN ngtcp2_ssize ngtcp2_conn_write_pkt_versioned(
/**
* @function
*
- * `ngtcp2_conn_handshake_completed` tells |conn| that the TLS stack
- * declares TLS handshake completion. This does not mean QUIC
+ * `ngtcp2_conn_tls_handshake_completed` tells |conn| that the TLS
+ * stack declares TLS handshake completion. This does not mean QUIC
* handshake has completed. The library needs extra conditions to be
* met.
*/
-NGTCP2_EXTERN void ngtcp2_conn_handshake_completed(ngtcp2_conn *conn);
+NGTCP2_EXTERN void ngtcp2_conn_tls_handshake_completed(ngtcp2_conn *conn);
/**
* @function
@@ -5031,14 +5039,6 @@ NGTCP2_EXTERN int ngtcp2_conn_initiate_migration(ngtcp2_conn *conn,
/**
* @function
*
- * `ngtcp2_conn_get_max_local_streams_uni` returns the cumulative
- * number of streams which local endpoint can open.
- */
-NGTCP2_EXTERN uint64_t ngtcp2_conn_get_max_local_streams_uni(ngtcp2_conn *conn);
-
-/**
- * @function
- *
* `ngtcp2_conn_get_max_data_left` returns the number of bytes that
* this local endpoint can send in this connection.
*/
@@ -5183,47 +5183,47 @@ ngtcp2_conn_get_early_crypto_ctx(ngtcp2_conn *conn);
/**
* @enum
*
- * :type:`ngtcp2_connection_close_error_code_type` defines connection
- * error code type.
+ * :type:`ngtcp2_ccerr_type` defines connection error type.
*/
-typedef enum ngtcp2_connection_close_error_code_type {
+typedef enum ngtcp2_ccerr_type {
/**
- * :enum:`NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT`
- * indicates the error code is QUIC transport error code.
+ * :enum:`NGTCP2_CCERR_TYPE_TRANSPORT` indicates the QUIC transport
+ * error, and the error code is QUIC transport error code.
*/
- NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT,
+ NGTCP2_CCERR_TYPE_TRANSPORT,
/**
- * :enum:`NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION`
- * indicates the error code is application error code.
+ * :enum:`NGTCP2_CCERR_TYPE_APPLICATION` indicates an application
+ * error, and the error code is application error code.
*/
- NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION,
+ NGTCP2_CCERR_TYPE_APPLICATION,
/**
- * :enum:`NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_VERSION_NEGOTIATION`
- * is a special case of QUIC transport error, and it indicates that
- * client receives Version Negotiation packet.
+ * :enum:`NGTCP2_CCERR_TYPE_VERSION_NEGOTIATION` is a special case
+ * of QUIC transport error, and it indicates that client receives
+ * Version Negotiation packet.
*/
- NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_VERSION_NEGOTIATION,
+ NGTCP2_CCERR_TYPE_VERSION_NEGOTIATION,
/**
- * :enum:`NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_IDLE_CLOSE`
- * is a special case of QUIC transport error, and it indicates that
- * connection is closed because of idle timeout.
+ * :enum:`NGTCP2_CCERR_TYPE_IDLE_CLOSE` is a special case of QUIC
+ * transport error, and it indicates that connection is closed
+ * because of idle timeout.
*/
- NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_IDLE_CLOSE
-} ngtcp2_connection_close_error_code_type;
+ NGTCP2_CCERR_TYPE_IDLE_CLOSE
+} ngtcp2_ccerr_type;
/**
* @struct
*
- * :type:`ngtcp2_connection_close_error` contains connection
- * error code, its type, and the optional reason phrase.
+ * :type:`ngtcp2_ccerr` contains connection error code, its type, and
+ * the optional reason phrase.
*/
-typedef struct ngtcp2_connection_close_error {
+typedef struct ngtcp2_ccerr {
/**
- * :member:`type` is the type of :member:`error_code`.
+ * :member:`type` is the type of this error.
*/
- ngtcp2_connection_close_error_code_type type;
+ ngtcp2_ccerr_type type;
/**
* :member:`error_code` is the error code for connection closure.
+ * Its interpretation depends on :member:`type`.
*/
uint64_t error_code;
/**
@@ -5244,103 +5244,97 @@ typedef struct ngtcp2_connection_close_error {
* :member:`reason`.
*/
size_t reasonlen;
-} ngtcp2_connection_close_error;
+} ngtcp2_ccerr;
/**
* @function
*
- * `ngtcp2_connection_close_error_default` initializes |ccerr| with
- * the default values. It sets the following fields:
+ * `ngtcp2_ccerr_default` initializes |ccerr| with the default values.
+ * It sets the following fields:
*
- * - :member:`type <ngtcp2_connection_close_error.type>` =
- * :enum:`ngtcp2_connection_close_error_code_type.NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT`
- * - :member:`error_code <ngtcp2_connection_close_error.error_code>` =
+ * - :member:`type <ngtcp2_ccerr.type>` =
+ * :enum:`ngtcp2_ccerr_type.NGTCP2_CCERR_TYPE_TRANSPORT`
+ * - :member:`error_code <ngtcp2_ccerr.error_code>` =
* :macro:`NGTCP2_NO_ERROR`.
- * - :member:`frame_type <ngtcp2_connection_close_error.frame_type>` =
- * 0
- * - :member:`reason <ngtcp2_connection_close_error.reason>` = NULL
- * - :member:`reasonlen <ngtcp2_connection_close_error.reasonlen>` = 0
+ * - :member:`frame_type <ngtcp2_ccerr.frame_type>` = 0
+ * - :member:`reason <ngtcp2_ccerr.reason>` = NULL
+ * - :member:`reasonlen <ngtcp2_ccerr.reasonlen>` = 0
*/
-NGTCP2_EXTERN void
-ngtcp2_connection_close_error_default(ngtcp2_connection_close_error *ccerr);
+NGTCP2_EXTERN void ngtcp2_ccerr_default(ngtcp2_ccerr *ccerr);
/**
* @function
*
- * `ngtcp2_connection_close_error_set_transport_error` sets
- * :member:`ccerr->type <ngtcp2_connection_close_error.type>` to
- * :enum:`ngtcp2_connection_close_error_code_type.NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT`,
- * and :member:`ccerr->error_code
- * <ngtcp2_connection_close_error.error_code>` to |error_code|.
- * |reason| is the reason phrase of length |reasonlen|. This function
- * does not make a copy of the reason phrase.
+ * `ngtcp2_ccerr_set_transport_error` sets :member:`ccerr->type
+ * <ngtcp2_ccerr.type>` to
+ * :enum:`ngtcp2_ccerr_type.NGTCP2_CCERR_TYPE_TRANSPORT`, and
+ * :member:`ccerr->error_code <ngtcp2_ccerr.error_code>` to
+ * |error_code|. |reason| is the reason phrase of length |reasonlen|.
+ * This function does not make a copy of the reason phrase.
*/
-NGTCP2_EXTERN void ngtcp2_connection_close_error_set_transport_error(
- ngtcp2_connection_close_error *ccerr, uint64_t error_code,
- const uint8_t *reason, size_t reasonlen);
+NGTCP2_EXTERN void ngtcp2_ccerr_set_transport_error(ngtcp2_ccerr *ccerr,
+ uint64_t error_code,
+ const uint8_t *reason,
+ size_t reasonlen);
/**
* @function
*
- * `ngtcp2_connection_close_error_set_transport_error_liberr` sets
- * type and error_code based on |liberr|.
+ * `ngtcp2_ccerr_set_liberr` sets type and error_code based on
+ * |liberr|.
*
* If |liberr| is :macro:`NGTCP2_ERR_RECV_VERSION_NEGOTIATION`,
- * :member:`ccerr->type <ngtcp2_connection_close_error.type>` is set
- * to
- * :enum:`ngtcp2_connection_close_error_code_type.NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_VERSION_NEGOTIATION`,
- * and :member:`ccerr->error_code
- * <ngtcp2_connection_close_error.error_code>` to
+ * :member:`ccerr->type <ngtcp2_ccerr.type>` is set to
+ * :enum:`ngtcp2_ccerr_type.NGTCP2_CCERR_TYPE_VERSION_NEGOTIATION`,
+ * and :member:`ccerr->error_code <ngtcp2_ccerr.error_code>` to
* :macro:`NGTCP2_NO_ERROR`. If |liberr| is
* :macro:`NGTCP2_ERR_IDLE_CLOSE`, :member:`ccerr->type
- * <ngtcp2_connection_close_error.type>` is set to
- * :enum:`ngtcp2_connection_close_error_code_type.NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_IDLE_CLOSE`,
- * and :member:`ccerr->error_code
- * <ngtcp2_connection_close_error.error_code>` to
+ * <ngtcp2_ccerr.type>` is set to
+ * :enum:`ngtcp2_ccerr_type.NGTCP2_CCERR_TYPE_IDLE_CLOSE`, and
+ * :member:`ccerr->error_code <ngtcp2_ccerr.error_code>` to
* :macro:`NGTCP2_NO_ERROR`. Otherwise, :member:`ccerr->type
- * <ngtcp2_connection_close_error.type>` is set to
- * :enum:`ngtcp2_connection_close_error_code_type.NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT`,
- * and :member:`ccerr->error_code
- * <ngtcp2_connection_close_error.error_code>` is set to an error code
- * inferred by |liberr| (see
+ * <ngtcp2_ccerr.type>` is set to
+ * :enum:`ngtcp2_ccerr_type.NGTCP2_CCERR_TYPE_TRANSPORT`, and
+ * :member:`ccerr->error_code <ngtcp2_ccerr.error_code>` is set to an
+ * error code inferred by |liberr| (see
* `ngtcp2_err_infer_quic_transport_error_code`). |reason| is the
* reason phrase of length |reasonlen|. This function does not make a
* copy of the reason phrase.
*/
-NGTCP2_EXTERN void ngtcp2_connection_close_error_set_transport_error_liberr(
- ngtcp2_connection_close_error *ccerr, int liberr, const uint8_t *reason,
- size_t reasonlen);
+NGTCP2_EXTERN void ngtcp2_ccerr_set_liberr(ngtcp2_ccerr *ccerr, int liberr,
+ const uint8_t *reason,
+ size_t reasonlen);
/**
* @function
*
- * `ngtcp2_connection_close_error_set_transport_error_tls_alert` sets
- * :member:`ccerr->type <ngtcp2_connection_close_error.type>` to
- * :enum:`ngtcp2_connection_close_error_code_type.NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT`,
- * and :member:`ccerr->error_code
- * <ngtcp2_connection_close_error.error_code>` to bitwise-OR of
- * :macro:`NGTCP2_CRYPTO_ERROR` and |tls_alert|. |reason| is the
+ * `ngtcp2_ccerr_set_tls_alert` sets :member:`ccerr->type
+ * <ngtcp2_ccerr.type>` to
+ * :enum:`ngtcp2_ccerr_type.NGTCP2_CCERR_TYPE_TRANSPORT`, and
+ * :member:`ccerr->error_code <ngtcp2_ccerr.error_code>` to bitwise-OR
+ * of :macro:`NGTCP2_CRYPTO_ERROR` and |tls_alert|. |reason| is the
* reason phrase of length |reasonlen|. This function does not make a
* copy of the reason phrase.
*/
-NGTCP2_EXTERN void ngtcp2_connection_close_error_set_transport_error_tls_alert(
- ngtcp2_connection_close_error *ccerr, uint8_t tls_alert,
- const uint8_t *reason, size_t reasonlen);
+NGTCP2_EXTERN void ngtcp2_ccerr_set_tls_alert(ngtcp2_ccerr *ccerr,
+ uint8_t tls_alert,
+ const uint8_t *reason,
+ size_t reasonlen);
/**
* @function
*
- * `ngtcp2_connection_close_error_set_application_error` sets
- * :member:`ccerr->type <ngtcp2_connection_close_error.type>` to
- * :enum:`ngtcp2_connection_close_error_code_type.NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION`,
- * and :member:`ccerr->error_code
- * <ngtcp2_connection_close_error.error_code>` to |error_code|.
- * |reason| is the reason phrase of length |reasonlen|. This function
- * does not make a copy of the reason phrase.
+ * `ngtcp2_ccerr_set_application_error` sets :member:`ccerr->type
+ * <ngtcp2_ccerr.type>` to
+ * :enum:`ngtcp2_ccerr_type.NGTCP2_CCERR_TYPE_APPLICATION`, and
+ * :member:`ccerr->error_code <ngtcp2_ccerr.error_code>` to
+ * |error_code|. |reason| is the reason phrase of length |reasonlen|.
+ * This function does not make a copy of the reason phrase.
*/
-NGTCP2_EXTERN void ngtcp2_connection_close_error_set_application_error(
- ngtcp2_connection_close_error *ccerr, uint64_t error_code,
- const uint8_t *reason, size_t reasonlen);
+NGTCP2_EXTERN void ngtcp2_ccerr_set_application_error(ngtcp2_ccerr *ccerr,
+ uint64_t error_code,
+ const uint8_t *reason,
+ size_t reasonlen);
/**
* @function
@@ -5361,13 +5355,13 @@ NGTCP2_EXTERN void ngtcp2_connection_close_error_set_application_error(
* If |pi| is not ``NULL``, this function stores packet metadata in it
* if it succeeds. The metadata includes ECN markings.
*
- * If :member:`ccerr->type <ngtcp2_connection_close_error.type>` ==
- * :enum:`ngtcp2_connection_close_error_code_type.NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT`,
- * this function sends CONNECTION_CLOSE (type 0x1c) frame. If
- * :member:`ccerr->type <ngtcp2_connection_close_error.type>` ==
- * :enum:`ngtcp2_connection_close_error_code_type.NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION`,
- * it sends CONNECTION_CLOSE (type 0x1d) frame. Otherwise, it does
- * not produce any data, and returns 0.
+ * If :member:`ccerr->type <ngtcp2_ccerr.type>` ==
+ * :enum:`ngtcp2_ccerr_type.NGTCP2_CCERR_TYPE_TRANSPORT`, this
+ * function sends CONNECTION_CLOSE (type 0x1c) frame. If
+ * :member:`ccerr->type <ngtcp2_ccerr.type>` ==
+ * :enum:`ngtcp2_ccerr_type.NGTCP2_CCERR_TYPE_APPLICATION`, it sends
+ * CONNECTION_CLOSE (type 0x1d) frame. Otherwise, it does not produce
+ * any data, and returns 0.
*
* This function must not be called from inside the callback
* functions.
@@ -5393,17 +5387,15 @@ NGTCP2_EXTERN void ngtcp2_connection_close_error_set_application_error(
NGTCP2_EXTERN ngtcp2_ssize ngtcp2_conn_write_connection_close_versioned(
ngtcp2_conn *conn, ngtcp2_path *path, int pkt_info_version,
ngtcp2_pkt_info *pi, uint8_t *dest, size_t destlen,
- const ngtcp2_connection_close_error *ccerr, ngtcp2_tstamp ts);
+ const ngtcp2_ccerr *ccerr, ngtcp2_tstamp ts);
/**
* @function
*
- * `ngtcp2_conn_get_connection_close_error` stores the received
- * connection close error in |ccerr|.
+ * `ngtcp2_conn_get_ccerr` returns the received connection close
+ * error.
*/
-NGTCP2_EXTERN void
-ngtcp2_conn_get_connection_close_error(ngtcp2_conn *conn,
- ngtcp2_connection_close_error *ccerr);
+NGTCP2_EXTERN const ngtcp2_ccerr *ngtcp2_conn_get_ccerr(ngtcp2_conn *conn);
/**
* @function
diff --git a/deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h b/deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h
index 00f007d682..d21bb10e02 100644
--- a/deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h
+++ b/deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h
@@ -36,7 +36,7 @@
*
* Version number of the ngtcp2 library release.
*/
-#define NGTCP2_VERSION "0.14.1"
+#define NGTCP2_VERSION "0.15.0"
/**
* @macro
@@ -46,6 +46,6 @@
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
* becomes 0x010203.
*/
-#define NGTCP2_VERSION_NUM 0x000e01
+#define NGTCP2_VERSION_NUM 0x000f00
#endif /* VERSION_H */
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_addr.h b/deps/ngtcp2/ngtcp2/lib/ngtcp2_addr.h
index fef878c826..8e3a9f591d 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_addr.h
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_addr.h
@@ -38,6 +38,13 @@
*/
void ngtcp2_addr_copy(ngtcp2_addr *dest, const ngtcp2_addr *src);
+/**
+ * @function
+ *
+ * `ngtcp2_addr_eq` returns nonzero if |a| equals |b|.
+ */
+int ngtcp2_addr_eq(const ngtcp2_addr *a, const ngtcp2_addr *b);
+
/* NGTCP2_ADDR_COMPARE_FLAG_NONE indicates that no flag set. */
#define NGTCP2_ADDR_COMPARE_FLAG_NONE 0x0u
/* NGTCP2_ADDR_COMPARE_FLAG_ADDR indicates IP addresses do not
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.c b/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.c
index 2fc7c2af7f..b69fe24685 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.c
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.c
@@ -25,6 +25,7 @@
#include "ngtcp2_bbr.h"
#include <assert.h>
+#include <string.h>
#include "ngtcp2_log.h"
#include "ngtcp2_macro.h"
@@ -42,116 +43,80 @@ static const double pacing_gain_cycle[] = {1.25, 0.75, 1, 1, 1, 1, 1, 1};
#define NGTCP2_RTPROP_FILTERLEN (10 * NGTCP2_SECONDS)
#define NGTCP2_BBR_BTL_BW_FILTERLEN 10
-static void bbr_update_on_ack(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_update_on_ack(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts);
-static void bbr_update_model_and_state(ngtcp2_bbr_cc *cc,
+static void bbr_update_model_and_state(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts);
-static void bbr_update_control_parameters(ngtcp2_bbr_cc *cc,
+static void bbr_update_control_parameters(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_on_transmit(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat);
-static void bbr_init_round_counting(ngtcp2_bbr_cc *cc);
-static void bbr_update_round(ngtcp2_bbr_cc *cc, const ngtcp2_cc_ack *ack);
-static void bbr_update_btl_bw(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_on_transmit(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_init_round_counting(ngtcp2_cc_bbr *bbr);
+static void bbr_update_round(ngtcp2_cc_bbr *bbr, const ngtcp2_cc_ack *ack);
+static void bbr_update_btl_bw(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_update_rtprop(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_update_rtprop(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_init_pacing_rate(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat);
-static void bbr_set_pacing_rate_with_gain(ngtcp2_bbr_cc *cc,
+static void bbr_init_pacing_rate(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_set_pacing_rate_with_gain(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat,
double pacing_gain);
-static void bbr_set_pacing_rate(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat);
-static void bbr_set_send_quantum(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat);
-static void bbr_update_target_cwnd(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat);
-static void bbr_modulate_cwnd_for_recovery(ngtcp2_bbr_cc *cc,
+static void bbr_set_pacing_rate(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_set_send_quantum(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_update_target_cwnd(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_modulate_cwnd_for_recovery(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_save_cwnd(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat);
-static void bbr_restore_cwnd(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat);
-static void bbr_modulate_cwnd_for_probe_rtt(ngtcp2_bbr_cc *cc,
+static void bbr_save_cwnd(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_restore_cwnd(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_modulate_cwnd_for_probe_rtt(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_set_cwnd(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_set_cwnd(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_init(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp initial_ts);
-static void bbr_enter_startup(ngtcp2_bbr_cc *cc);
-static void bbr_init_full_pipe(ngtcp2_bbr_cc *cc);
-static void bbr_check_full_pipe(ngtcp2_bbr_cc *cc);
-static void bbr_enter_drain(ngtcp2_bbr_cc *cc);
-static void bbr_check_drain(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_enter_startup(ngtcp2_cc_bbr *bbr);
+static void bbr_init_full_pipe(ngtcp2_cc_bbr *bbr);
+static void bbr_check_full_pipe(ngtcp2_cc_bbr *bbr);
+static void bbr_enter_drain(ngtcp2_cc_bbr *bbr);
+static void bbr_check_drain(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_enter_probe_bw(ngtcp2_bbr_cc *cc, ngtcp2_tstamp ts);
-static void bbr_check_cycle_phase(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_enter_probe_bw(ngtcp2_cc_bbr *bbr, ngtcp2_tstamp ts);
+static void bbr_check_cycle_phase(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts);
-static void bbr_advance_cycle_phase(ngtcp2_bbr_cc *cc, ngtcp2_tstamp ts);
-static int bbr_is_next_cycle_phase(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_advance_cycle_phase(ngtcp2_cc_bbr *bbr, ngtcp2_tstamp ts);
+static int bbr_is_next_cycle_phase(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts);
-static void bbr_handle_restart_from_idle(ngtcp2_bbr_cc *cc,
+static void bbr_handle_restart_from_idle(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_check_probe_rtt(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_check_probe_rtt(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_enter_probe_rtt(ngtcp2_bbr_cc *cc);
-static void bbr_handle_probe_rtt(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_enter_probe_rtt(ngtcp2_cc_bbr *bbr);
+static void bbr_handle_probe_rtt(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_exit_probe_rtt(ngtcp2_bbr_cc *cc, ngtcp2_tstamp ts);
-
-void ngtcp2_bbr_cc_init(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
- ngtcp2_rst *rst, ngtcp2_tstamp initial_ts,
- ngtcp2_rand rand, const ngtcp2_rand_ctx *rand_ctx,
- ngtcp2_log *log) {
- cc->ccb.log = log;
- cc->rst = rst;
- cc->rand = rand;
- cc->rand_ctx = *rand_ctx;
- cc->initial_cwnd = cstat->cwnd;
- bbr_init(cc, cstat, initial_ts);
-}
-
-void ngtcp2_bbr_cc_free(ngtcp2_bbr_cc *cc) { (void)cc; }
-
-int ngtcp2_cc_bbr_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
- ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
- ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
- const ngtcp2_rand_ctx *rand_ctx,
- const ngtcp2_mem *mem) {
- ngtcp2_bbr_cc *bbr_cc;
-
- bbr_cc = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_bbr_cc));
- if (bbr_cc == NULL) {
- return NGTCP2_ERR_NOMEM;
- }
-
- ngtcp2_bbr_cc_init(bbr_cc, cstat, rst, initial_ts, rand, rand_ctx, log);
-
- cc->ccb = &bbr_cc->ccb;
- cc->on_pkt_acked = ngtcp2_cc_bbr_cc_on_pkt_acked;
- cc->congestion_event = ngtcp2_cc_bbr_cc_congestion_event;
- cc->on_spurious_congestion = ngtcp2_cc_bbr_cc_on_spurious_congestion;
- cc->on_persistent_congestion = ngtcp2_cc_bbr_cc_on_persistent_congestion;
- cc->on_ack_recv = ngtcp2_cc_bbr_cc_on_ack_recv;
- cc->on_pkt_sent = ngtcp2_cc_bbr_cc_on_pkt_sent;
- cc->new_rtt_sample = ngtcp2_cc_bbr_cc_new_rtt_sample;
- cc->reset = ngtcp2_cc_bbr_cc_reset;
- cc->event = ngtcp2_cc_bbr_cc_event;
-
- return 0;
-}
+static void bbr_exit_probe_rtt(ngtcp2_cc_bbr *bbr, ngtcp2_tstamp ts);
-void ngtcp2_cc_bbr_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem) {
- ngtcp2_bbr_cc *bbr_cc = ngtcp2_struct_of(cc->ccb, ngtcp2_bbr_cc, ccb);
+void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log,
+ ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
+ ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
+ const ngtcp2_rand_ctx *rand_ctx) {
+ memset(bbr, 0, sizeof(*bbr));
- ngtcp2_bbr_cc_free(bbr_cc);
- ngtcp2_mem_free(mem, bbr_cc);
-}
+ bbr->cc.log = log;
+ bbr->cc.congestion_event = ngtcp2_cc_bbr_cc_congestion_event;
+ bbr->cc.on_spurious_congestion = ngtcp2_cc_bbr_cc_on_spurious_congestion;
+ bbr->cc.on_persistent_congestion = ngtcp2_cc_bbr_cc_on_persistent_congestion;
+ bbr->cc.on_ack_recv = ngtcp2_cc_bbr_cc_on_ack_recv;
+ bbr->cc.on_pkt_sent = ngtcp2_cc_bbr_cc_on_pkt_sent;
+ bbr->cc.reset = ngtcp2_cc_bbr_cc_reset;
-void ngtcp2_cc_bbr_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
- const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts) {
- (void)ccx;
- (void)cstat;
- (void)pkt;
- (void)ts;
+ bbr->rst = rst;
+ bbr->rand = rand;
+ bbr->rand_ctx = *rand_ctx;
+ bbr->initial_cwnd = cstat->cwnd;
+ bbr_init(bbr, cstat, initial_ts);
}
static int in_congestion_recovery(const ngtcp2_conn_stat *cstat,
@@ -160,256 +125,238 @@ static int in_congestion_recovery(const ngtcp2_conn_stat *cstat,
sent_time <= cstat->congestion_recovery_start_ts;
}
-void ngtcp2_cc_bbr_cc_congestion_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_bbr_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp sent_ts,
ngtcp2_tstamp ts) {
- ngtcp2_bbr_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr_cc, ccb);
+ ngtcp2_cc_bbr *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr, cc);
- if (cc->in_loss_recovery || cc->congestion_recovery_start_ts != UINT64_MAX ||
+ if (bbr->in_loss_recovery ||
+ bbr->congestion_recovery_start_ts != UINT64_MAX ||
in_congestion_recovery(cstat, sent_ts)) {
return;
}
- cc->congestion_recovery_start_ts = ts;
+ bbr->congestion_recovery_start_ts = ts;
}
-void ngtcp2_cc_bbr_cc_on_spurious_congestion(ngtcp2_cc *ccx,
+void ngtcp2_cc_bbr_cc_on_spurious_congestion(ngtcp2_cc *cc,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_bbr_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr_cc, ccb);
+ ngtcp2_cc_bbr *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr, cc);
(void)ts;
- cc->congestion_recovery_start_ts = UINT64_MAX;
+ bbr->congestion_recovery_start_ts = UINT64_MAX;
cstat->congestion_recovery_start_ts = UINT64_MAX;
- if (cc->in_loss_recovery) {
- cc->in_loss_recovery = 0;
- cc->packet_conservation = 0;
- bbr_restore_cwnd(cc, cstat);
+ if (bbr->in_loss_recovery) {
+ bbr->in_loss_recovery = 0;
+ bbr->packet_conservation = 0;
+ bbr_restore_cwnd(bbr, cstat);
}
}
-void ngtcp2_cc_bbr_cc_on_persistent_congestion(ngtcp2_cc *ccx,
+void ngtcp2_cc_bbr_cc_on_persistent_congestion(ngtcp2_cc *cc,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_bbr_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr_cc, ccb);
+ ngtcp2_cc_bbr *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr, cc);
(void)ts;
cstat->congestion_recovery_start_ts = UINT64_MAX;
- cc->congestion_recovery_start_ts = UINT64_MAX;
- cc->in_loss_recovery = 0;
- cc->packet_conservation = 0;
+ bbr->congestion_recovery_start_ts = UINT64_MAX;
+ bbr->in_loss_recovery = 0;
+ bbr->packet_conservation = 0;
- bbr_save_cwnd(cc, cstat);
+ bbr_save_cwnd(bbr, cstat);
cstat->cwnd = 2 * cstat->max_tx_udp_payload_size;
}
-void ngtcp2_cc_bbr_cc_on_ack_recv(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_bbr_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts) {
- ngtcp2_bbr_cc *bbr_cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr_cc, ccb);
+ ngtcp2_cc_bbr *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr, cc);
- bbr_update_on_ack(bbr_cc, cstat, ack, ts);
+ bbr_update_on_ack(bbr, cstat, ack, ts);
}
-void ngtcp2_cc_bbr_cc_on_pkt_sent(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_bbr_cc_on_pkt_sent(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt) {
- ngtcp2_bbr_cc *bbr_cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr_cc, ccb);
+ ngtcp2_cc_bbr *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr, cc);
(void)pkt;
- bbr_on_transmit(bbr_cc, cstat);
+ bbr_on_transmit(bbr, cstat);
}
-void ngtcp2_cc_bbr_cc_new_rtt_sample(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
- ngtcp2_tstamp ts) {
- (void)ccx;
- (void)cstat;
- (void)ts;
-}
-
-void ngtcp2_cc_bbr_cc_reset(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_bbr_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_bbr_cc *bbr_cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr_cc, ccb);
- bbr_init(bbr_cc, cstat, ts);
+ ngtcp2_cc_bbr *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr, cc);
+ bbr_init(bbr, cstat, ts);
}
-void ngtcp2_cc_bbr_cc_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
- ngtcp2_cc_event_type event, ngtcp2_tstamp ts) {
- (void)ccx;
- (void)cstat;
- (void)event;
- (void)ts;
-}
-
-static void bbr_update_on_ack(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_update_on_ack(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts) {
- bbr_update_model_and_state(cc, cstat, ack, ts);
- bbr_update_control_parameters(cc, cstat, ack);
+ bbr_update_model_and_state(bbr, cstat, ack, ts);
+ bbr_update_control_parameters(bbr, cstat, ack);
}
-static void bbr_update_model_and_state(ngtcp2_bbr_cc *cc,
+static void bbr_update_model_and_state(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts) {
- bbr_update_btl_bw(cc, cstat, ack);
- bbr_check_cycle_phase(cc, cstat, ack, ts);
- bbr_check_full_pipe(cc);
- bbr_check_drain(cc, cstat, ts);
- bbr_update_rtprop(cc, cstat, ts);
- bbr_check_probe_rtt(cc, cstat, ts);
+ bbr_update_btl_bw(bbr, cstat, ack);
+ bbr_check_cycle_phase(bbr, cstat, ack, ts);
+ bbr_check_full_pipe(bbr);
+ bbr_check_drain(bbr, cstat, ts);
+ bbr_update_rtprop(bbr, cstat, ts);
+ bbr_check_probe_rtt(bbr, cstat, ts);
}
-static void bbr_update_control_parameters(ngtcp2_bbr_cc *cc,
+static void bbr_update_control_parameters(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
- bbr_set_pacing_rate(cc, cstat);
- bbr_set_send_quantum(cc, cstat);
- bbr_set_cwnd(cc, cstat, ack);
+ bbr_set_pacing_rate(bbr, cstat);
+ bbr_set_send_quantum(bbr, cstat);
+ bbr_set_cwnd(bbr, cstat, ack);
}
-static void bbr_on_transmit(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat) {
- bbr_handle_restart_from_idle(cc, cstat);
+static void bbr_on_transmit(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat) {
+ bbr_handle_restart_from_idle(bbr, cstat);
}
-static void bbr_init_round_counting(ngtcp2_bbr_cc *cc) {
- cc->next_round_delivered = 0;
- cc->round_start = 0;
- cc->round_count = 0;
+static void bbr_init_round_counting(ngtcp2_cc_bbr *bbr) {
+ bbr->next_round_delivered = 0;
+ bbr->round_start = 0;
+ bbr->round_count = 0;
}
-static void bbr_update_round(ngtcp2_bbr_cc *cc, const ngtcp2_cc_ack *ack) {
- if (ack->pkt_delivered >= cc->next_round_delivered) {
- cc->next_round_delivered = cc->rst->delivered;
- ++cc->round_count;
- cc->round_start = 1;
+static void bbr_update_round(ngtcp2_cc_bbr *bbr, const ngtcp2_cc_ack *ack) {
+ if (ack->pkt_delivered >= bbr->next_round_delivered) {
+ bbr->next_round_delivered = bbr->rst->delivered;
+ ++bbr->round_count;
+ bbr->round_start = 1;
return;
}
- cc->round_start = 0;
+ bbr->round_start = 0;
}
-static void bbr_handle_recovery(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_handle_recovery(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
- if (cc->in_loss_recovery) {
- if (ack->pkt_delivered >= cc->congestion_recovery_next_round_delivered) {
- cc->packet_conservation = 0;
+ if (bbr->in_loss_recovery) {
+ if (ack->pkt_delivered >= bbr->congestion_recovery_next_round_delivered) {
+ bbr->packet_conservation = 0;
}
if (!in_congestion_recovery(cstat, ack->largest_acked_sent_ts)) {
- cc->in_loss_recovery = 0;
- cc->packet_conservation = 0;
- bbr_restore_cwnd(cc, cstat);
+ bbr->in_loss_recovery = 0;
+ bbr->packet_conservation = 0;
+ bbr_restore_cwnd(bbr, cstat);
}
return;
}
- if (cc->congestion_recovery_start_ts != UINT64_MAX) {
- cc->in_loss_recovery = 1;
- bbr_save_cwnd(cc, cstat);
+ if (bbr->congestion_recovery_start_ts != UINT64_MAX) {
+ bbr->in_loss_recovery = 1;
+ bbr_save_cwnd(bbr, cstat);
cstat->cwnd =
cstat->bytes_in_flight +
ngtcp2_max(ack->bytes_delivered, cstat->max_tx_udp_payload_size);
- cstat->congestion_recovery_start_ts = cc->congestion_recovery_start_ts;
- cc->congestion_recovery_start_ts = UINT64_MAX;
- cc->packet_conservation = 1;
- cc->congestion_recovery_next_round_delivered = cc->rst->delivered;
+ cstat->congestion_recovery_start_ts = bbr->congestion_recovery_start_ts;
+ bbr->congestion_recovery_start_ts = UINT64_MAX;
+ bbr->packet_conservation = 1;
+ bbr->congestion_recovery_next_round_delivered = bbr->rst->delivered;
}
}
-static void bbr_update_btl_bw(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_update_btl_bw(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
- bbr_update_round(cc, ack);
- bbr_handle_recovery(cc, cstat, ack);
+ bbr_update_round(bbr, ack);
+ bbr_handle_recovery(bbr, cstat, ack);
- if (cstat->delivery_rate_sec < cc->btl_bw && cc->rst->rs.is_app_limited) {
+ if (cstat->delivery_rate_sec < bbr->btl_bw && bbr->rst->rs.is_app_limited) {
return;
}
- ngtcp2_window_filter_update(&cc->btl_bw_filter, cstat->delivery_rate_sec,
- cc->round_count);
+ ngtcp2_window_filter_update(&bbr->btl_bw_filter, cstat->delivery_rate_sec,
+ bbr->round_count);
- cc->btl_bw = ngtcp2_window_filter_get_best(&cc->btl_bw_filter);
+ bbr->btl_bw = ngtcp2_window_filter_get_best(&bbr->btl_bw_filter);
}
-static void bbr_update_rtprop(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_update_rtprop(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- cc->rtprop_expired = ts > cc->rtprop_stamp + NGTCP2_RTPROP_FILTERLEN;
+ bbr->rtprop_expired = ts > bbr->rtprop_stamp + NGTCP2_RTPROP_FILTERLEN;
/* Need valid RTT sample */
if (cstat->latest_rtt &&
- (cstat->latest_rtt <= cc->rt_prop || cc->rtprop_expired)) {
- cc->rt_prop = cstat->latest_rtt;
- cc->rtprop_stamp = ts;
+ (cstat->latest_rtt <= bbr->rt_prop || bbr->rtprop_expired)) {
+ bbr->rt_prop = cstat->latest_rtt;
+ bbr->rtprop_stamp = ts;
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
- "bbr update RTprop=%" PRIu64, cc->rt_prop);
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
+ "bbr update RTprop=%" PRIu64, bbr->rt_prop);
}
}
-static void bbr_init_pacing_rate(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat) {
+static void bbr_init_pacing_rate(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat) {
double nominal_bandwidth =
- (double)cc->initial_cwnd / (double)NGTCP2_MILLISECONDS;
+ (double)bbr->initial_cwnd / (double)NGTCP2_MILLISECONDS;
- cstat->pacing_rate = cc->pacing_gain * nominal_bandwidth;
+ cstat->pacing_rate = bbr->pacing_gain * nominal_bandwidth;
}
-static void bbr_set_pacing_rate_with_gain(ngtcp2_bbr_cc *cc,
+static void bbr_set_pacing_rate_with_gain(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat,
double pacing_gain) {
- double rate = pacing_gain * (double)cc->btl_bw / NGTCP2_SECONDS;
+ double rate = pacing_gain * (double)bbr->btl_bw / NGTCP2_SECONDS;
- if (cc->filled_pipe || rate > cstat->pacing_rate) {
+ if (bbr->filled_pipe || rate > cstat->pacing_rate) {
cstat->pacing_rate = rate;
}
}
-static void bbr_set_pacing_rate(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat) {
- bbr_set_pacing_rate_with_gain(cc, cstat, cc->pacing_gain);
+static void bbr_set_pacing_rate(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat) {
+ bbr_set_pacing_rate_with_gain(bbr, cstat, bbr->pacing_gain);
}
-static void bbr_set_send_quantum(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat) {
- uint64_t send_quantum;
- (void)cc;
+static void bbr_set_send_quantum(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat) {
+ size_t floor, send_quantum;
+ (void)bbr;
if (cstat->pacing_rate < 1.2 * 1024 * 1024 / 8 / NGTCP2_SECONDS) {
- cstat->send_quantum = cstat->max_tx_udp_payload_size;
- } else if (cstat->pacing_rate < 24.0 * 1024 * 1024 / 8 / NGTCP2_SECONDS) {
- cstat->send_quantum = cstat->max_tx_udp_payload_size * 2;
+ floor = cstat->max_tx_udp_payload_size;
} else {
- send_quantum = (uint64_t)(cstat->pacing_rate *
- (double)((cstat->min_rtt == UINT64_MAX ||
- cstat->min_rtt < NGTCP2_MILLISECONDS)
- ? NGTCP2_MILLISECONDS
- : cstat->min_rtt));
- cstat->send_quantum = (size_t)ngtcp2_min(send_quantum, 64 * 1024);
+ floor = 2 * cstat->max_tx_udp_payload_size;
}
- cstat->send_quantum =
- ngtcp2_max(cstat->send_quantum, cstat->max_tx_udp_payload_size * 10);
+ send_quantum = (size_t)(cstat->pacing_rate * NGTCP2_MILLISECONDS);
+
+ send_quantum = ngtcp2_min(send_quantum, 64 * 1024);
+ cstat->send_quantum = ngtcp2_max(send_quantum, floor);
}
-static uint64_t bbr_inflight(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static uint64_t bbr_inflight(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
double gain) {
uint64_t quanta = 3 * cstat->send_quantum;
double estimated_bdp;
- if (cc->rt_prop == UINT64_MAX) {
+ if (bbr->rt_prop == UINT64_MAX) {
/* no valid RTT samples yet */
- return cc->initial_cwnd;
+ return bbr->initial_cwnd;
}
- estimated_bdp = (double)cc->btl_bw * (double)cc->rt_prop / NGTCP2_SECONDS;
+ estimated_bdp = (double)bbr->btl_bw * (double)bbr->rt_prop / NGTCP2_SECONDS;
return (uint64_t)(gain * estimated_bdp) + quanta;
}
-static void bbr_update_target_cwnd(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat) {
- cc->target_cwnd = bbr_inflight(cc, cstat, cc->cwnd_gain);
+static void bbr_update_target_cwnd(ngtcp2_cc_bbr *bbr,
+ ngtcp2_conn_stat *cstat) {
+ bbr->target_cwnd = bbr_inflight(bbr, cstat, bbr->cwnd_gain);
}
-static void bbr_modulate_cwnd_for_recovery(ngtcp2_bbr_cc *cc,
+static void bbr_modulate_cwnd_for_recovery(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
if (ack->bytes_lost > 0) {
@@ -421,48 +368,48 @@ static void bbr_modulate_cwnd_for_recovery(ngtcp2_bbr_cc *cc,
}
}
- if (cc->packet_conservation) {
+ if (bbr->packet_conservation) {
cstat->cwnd =
ngtcp2_max(cstat->cwnd, cstat->bytes_in_flight + ack->bytes_delivered);
}
}
-static void bbr_save_cwnd(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat) {
- if (!cc->in_loss_recovery && cc->state != NGTCP2_BBR_STATE_PROBE_RTT) {
- cc->prior_cwnd = cstat->cwnd;
+static void bbr_save_cwnd(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat) {
+ if (!bbr->in_loss_recovery && bbr->state != NGTCP2_BBR_STATE_PROBE_RTT) {
+ bbr->prior_cwnd = cstat->cwnd;
return;
}
- cc->prior_cwnd = ngtcp2_max(cc->prior_cwnd, cstat->cwnd);
+ bbr->prior_cwnd = ngtcp2_max(bbr->prior_cwnd, cstat->cwnd);
}
-static void bbr_restore_cwnd(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat) {
- cstat->cwnd = ngtcp2_max(cstat->cwnd, cc->prior_cwnd);
+static void bbr_restore_cwnd(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat) {
+ cstat->cwnd = ngtcp2_max(cstat->cwnd, bbr->prior_cwnd);
}
static uint64_t min_pipe_cwnd(size_t max_udp_payload_size) {
return max_udp_payload_size * 4;
}
-static void bbr_modulate_cwnd_for_probe_rtt(ngtcp2_bbr_cc *cc,
+static void bbr_modulate_cwnd_for_probe_rtt(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat) {
- if (cc->state == NGTCP2_BBR_STATE_PROBE_RTT) {
+ if (bbr->state == NGTCP2_BBR_STATE_PROBE_RTT) {
cstat->cwnd =
ngtcp2_min(cstat->cwnd, min_pipe_cwnd(cstat->max_tx_udp_payload_size));
}
}
-static void bbr_set_cwnd(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_set_cwnd(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
- bbr_update_target_cwnd(cc, cstat);
- bbr_modulate_cwnd_for_recovery(cc, cstat, ack);
+ bbr_update_target_cwnd(bbr, cstat);
+ bbr_modulate_cwnd_for_recovery(bbr, cstat, ack);
- if (!cc->packet_conservation) {
- if (cc->filled_pipe) {
+ if (!bbr->packet_conservation) {
+ if (bbr->filled_pipe) {
cstat->cwnd =
- ngtcp2_min(cstat->cwnd + ack->bytes_delivered, cc->target_cwnd);
- } else if (cstat->cwnd < cc->target_cwnd ||
- cc->rst->delivered < cc->initial_cwnd) {
+ ngtcp2_min(cstat->cwnd + ack->bytes_delivered, bbr->target_cwnd);
+ } else if (cstat->cwnd < bbr->target_cwnd ||
+ bbr->rst->delivered < bbr->initial_cwnd) {
cstat->cwnd += ack->bytes_delivered;
}
@@ -470,225 +417,225 @@ static void bbr_set_cwnd(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_max(cstat->cwnd, min_pipe_cwnd(cstat->max_tx_udp_payload_size));
}
- bbr_modulate_cwnd_for_probe_rtt(cc, cstat);
+ bbr_modulate_cwnd_for_probe_rtt(bbr, cstat);
}
-static void bbr_init(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp initial_ts) {
- cc->pacing_gain = NGTCP2_BBR_HIGH_GAIN;
- cc->prior_cwnd = 0;
- cc->target_cwnd = 0;
- cc->btl_bw = 0;
- cc->rt_prop = UINT64_MAX;
- cc->rtprop_stamp = initial_ts;
- cc->cycle_stamp = UINT64_MAX;
- cc->probe_rtt_done_stamp = UINT64_MAX;
- cc->cycle_index = 0;
- cc->rtprop_expired = 0;
- cc->idle_restart = 0;
- cc->packet_conservation = 0;
- cc->probe_rtt_round_done = 0;
-
- cc->congestion_recovery_start_ts = UINT64_MAX;
- cc->congestion_recovery_next_round_delivered = 0;
- cc->in_loss_recovery = 0;
+ bbr->pacing_gain = NGTCP2_BBR_HIGH_GAIN;
+ bbr->prior_cwnd = 0;
+ bbr->target_cwnd = 0;
+ bbr->btl_bw = 0;
+ bbr->rt_prop = UINT64_MAX;
+ bbr->rtprop_stamp = initial_ts;
+ bbr->cycle_stamp = UINT64_MAX;
+ bbr->probe_rtt_done_stamp = UINT64_MAX;
+ bbr->cycle_index = 0;
+ bbr->rtprop_expired = 0;
+ bbr->idle_restart = 0;
+ bbr->packet_conservation = 0;
+ bbr->probe_rtt_round_done = 0;
+
+ bbr->congestion_recovery_start_ts = UINT64_MAX;
+ bbr->congestion_recovery_next_round_delivered = 0;
+ bbr->in_loss_recovery = 0;
cstat->send_quantum = cstat->max_tx_udp_payload_size * 10;
- ngtcp2_window_filter_init(&cc->btl_bw_filter, NGTCP2_BBR_BTL_BW_FILTERLEN);
+ ngtcp2_window_filter_init(&bbr->btl_bw_filter, NGTCP2_BBR_BTL_BW_FILTERLEN);
- bbr_init_round_counting(cc);
- bbr_init_full_pipe(cc);
- bbr_init_pacing_rate(cc, cstat);
- bbr_enter_startup(cc);
+ bbr_init_round_counting(bbr);
+ bbr_init_full_pipe(bbr);
+ bbr_init_pacing_rate(bbr, cstat);
+ bbr_enter_startup(bbr);
}
-static void bbr_enter_startup(ngtcp2_bbr_cc *cc) {
- cc->state = NGTCP2_BBR_STATE_STARTUP;
- cc->pacing_gain = NGTCP2_BBR_HIGH_GAIN;
- cc->cwnd_gain = NGTCP2_BBR_HIGH_GAIN;
+static void bbr_enter_startup(ngtcp2_cc_bbr *bbr) {
+ bbr->state = NGTCP2_BBR_STATE_STARTUP;
+ bbr->pacing_gain = NGTCP2_BBR_HIGH_GAIN;
+ bbr->cwnd_gain = NGTCP2_BBR_HIGH_GAIN;
}
-static void bbr_init_full_pipe(ngtcp2_bbr_cc *cc) {
- cc->filled_pipe = 0;
- cc->full_bw = 0;
- cc->full_bw_count = 0;
+static void bbr_init_full_pipe(ngtcp2_cc_bbr *bbr) {
+ bbr->filled_pipe = 0;
+ bbr->full_bw = 0;
+ bbr->full_bw_count = 0;
}
-static void bbr_check_full_pipe(ngtcp2_bbr_cc *cc) {
- if (cc->filled_pipe || !cc->round_start || cc->rst->rs.is_app_limited) {
+static void bbr_check_full_pipe(ngtcp2_cc_bbr *bbr) {
+ if (bbr->filled_pipe || !bbr->round_start || bbr->rst->rs.is_app_limited) {
/* no need to check for a full pipe now. */
return;
}
- /* cc->btl_bw still growing? */
- if (cc->btl_bw * 100 >= cc->full_bw * 125) {
+ /* bbr->btl_bw still growing? */
+ if (bbr->btl_bw * 100 >= bbr->full_bw * 125) {
/* record new baseline level */
- cc->full_bw = cc->btl_bw;
- cc->full_bw_count = 0;
+ bbr->full_bw = bbr->btl_bw;
+ bbr->full_bw_count = 0;
return;
}
/* another round w/o much growth */
- ++cc->full_bw_count;
- if (cc->full_bw_count >= 3) {
- cc->filled_pipe = 1;
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
- "bbr filled pipe, btl_bw=%" PRIu64, cc->btl_bw);
+ ++bbr->full_bw_count;
+ if (bbr->full_bw_count >= 3) {
+ bbr->filled_pipe = 1;
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
+ "bbr filled pipe, btl_bw=%" PRIu64, bbr->btl_bw);
}
}
-static void bbr_enter_drain(ngtcp2_bbr_cc *cc) {
- cc->state = NGTCP2_BBR_STATE_DRAIN;
+static void bbr_enter_drain(ngtcp2_cc_bbr *bbr) {
+ bbr->state = NGTCP2_BBR_STATE_DRAIN;
/* pace slowly */
- cc->pacing_gain = 1.0 / NGTCP2_BBR_HIGH_GAIN;
+ bbr->pacing_gain = 1.0 / NGTCP2_BBR_HIGH_GAIN;
/* maintain cwnd */
- cc->cwnd_gain = NGTCP2_BBR_HIGH_GAIN;
+ bbr->cwnd_gain = NGTCP2_BBR_HIGH_GAIN;
}
-static void bbr_check_drain(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_check_drain(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- if (cc->state == NGTCP2_BBR_STATE_STARTUP && cc->filled_pipe) {
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ if (bbr->state == NGTCP2_BBR_STATE_STARTUP && bbr->filled_pipe) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
"bbr exit Startup and enter Drain");
- bbr_enter_drain(cc);
+ bbr_enter_drain(bbr);
}
- if (cc->state == NGTCP2_BBR_STATE_DRAIN &&
- cstat->bytes_in_flight <= bbr_inflight(cc, cstat, 1.0)) {
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ if (bbr->state == NGTCP2_BBR_STATE_DRAIN &&
+ cstat->bytes_in_flight <= bbr_inflight(bbr, cstat, 1.0)) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
"bbr exit Drain and enter ProbeBW");
/* we estimate queue is drained */
- bbr_enter_probe_bw(cc, ts);
+ bbr_enter_probe_bw(bbr, ts);
}
}
-static void bbr_enter_probe_bw(ngtcp2_bbr_cc *cc, ngtcp2_tstamp ts) {
+static void bbr_enter_probe_bw(ngtcp2_cc_bbr *bbr, ngtcp2_tstamp ts) {
uint8_t rand;
- cc->state = NGTCP2_BBR_STATE_PROBE_BW;
- cc->pacing_gain = 1;
- cc->cwnd_gain = 2;
+ bbr->state = NGTCP2_BBR_STATE_PROBE_BW;
+ bbr->pacing_gain = 1;
+ bbr->cwnd_gain = 2;
- assert(cc->rand);
+ assert(bbr->rand);
- cc->rand(&rand, 1, &cc->rand_ctx);
+ bbr->rand(&rand, 1, &bbr->rand_ctx);
- cc->cycle_index = NGTCP2_BBR_GAIN_CYCLELEN - 1 - (size_t)(rand * 7 / 256);
- bbr_advance_cycle_phase(cc, ts);
+ bbr->cycle_index = NGTCP2_BBR_GAIN_CYCLELEN - 1 - (size_t)(rand * 7 / 256);
+ bbr_advance_cycle_phase(bbr, ts);
}
-static void bbr_check_cycle_phase(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_check_cycle_phase(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts) {
- if (cc->state == NGTCP2_BBR_STATE_PROBE_BW &&
- bbr_is_next_cycle_phase(cc, cstat, ack, ts)) {
- bbr_advance_cycle_phase(cc, ts);
+ if (bbr->state == NGTCP2_BBR_STATE_PROBE_BW &&
+ bbr_is_next_cycle_phase(bbr, cstat, ack, ts)) {
+ bbr_advance_cycle_phase(bbr, ts);
}
}
-static void bbr_advance_cycle_phase(ngtcp2_bbr_cc *cc, ngtcp2_tstamp ts) {
- cc->cycle_stamp = ts;
- cc->cycle_index = (cc->cycle_index + 1) & (NGTCP2_BBR_GAIN_CYCLELEN - 1);
- cc->pacing_gain = pacing_gain_cycle[cc->cycle_index];
+static void bbr_advance_cycle_phase(ngtcp2_cc_bbr *bbr, ngtcp2_tstamp ts) {
+ bbr->cycle_stamp = ts;
+ bbr->cycle_index = (bbr->cycle_index + 1) & (NGTCP2_BBR_GAIN_CYCLELEN - 1);
+ bbr->pacing_gain = pacing_gain_cycle[bbr->cycle_index];
}
-static int bbr_is_next_cycle_phase(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static int bbr_is_next_cycle_phase(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts) {
- int is_full_length = (ts - cc->cycle_stamp) > cc->rt_prop;
+ int is_full_length = (ts - bbr->cycle_stamp) > bbr->rt_prop;
- if (cc->pacing_gain > 1) {
+ if (bbr->pacing_gain > 1) {
return is_full_length && (ack->bytes_lost > 0 ||
ack->prior_bytes_in_flight >=
- bbr_inflight(cc, cstat, cc->pacing_gain));
+ bbr_inflight(bbr, cstat, bbr->pacing_gain));
}
- if (cc->pacing_gain < 1) {
+ if (bbr->pacing_gain < 1) {
return is_full_length ||
- ack->prior_bytes_in_flight <= bbr_inflight(cc, cstat, 1);
+ ack->prior_bytes_in_flight <= bbr_inflight(bbr, cstat, 1);
}
return is_full_length;
}
-static void bbr_handle_restart_from_idle(ngtcp2_bbr_cc *cc,
+static void bbr_handle_restart_from_idle(ngtcp2_cc_bbr *bbr,
ngtcp2_conn_stat *cstat) {
- if (cstat->bytes_in_flight == 0 && cc->rst->app_limited) {
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, "bbr restart from idle");
+ if (cstat->bytes_in_flight == 0 && bbr->rst->app_limited) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV, "bbr restart from idle");
- cc->idle_restart = 1;
+ bbr->idle_restart = 1;
- if (cc->state == NGTCP2_BBR_STATE_PROBE_BW) {
- bbr_set_pacing_rate_with_gain(cc, cstat, 1);
+ if (bbr->state == NGTCP2_BBR_STATE_PROBE_BW) {
+ bbr_set_pacing_rate_with_gain(bbr, cstat, 1);
}
}
}
-static void bbr_check_probe_rtt(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_check_probe_rtt(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- if (cc->state != NGTCP2_BBR_STATE_PROBE_RTT && cc->rtprop_expired &&
- !cc->idle_restart) {
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV, "bbr enter ProbeRTT");
+ if (bbr->state != NGTCP2_BBR_STATE_PROBE_RTT && bbr->rtprop_expired &&
+ !bbr->idle_restart) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV, "bbr enter ProbeRTT");
- bbr_enter_probe_rtt(cc);
- bbr_save_cwnd(cc, cstat);
- cc->probe_rtt_done_stamp = UINT64_MAX;
+ bbr_enter_probe_rtt(bbr);
+ bbr_save_cwnd(bbr, cstat);
+ bbr->probe_rtt_done_stamp = UINT64_MAX;
}
- if (cc->state == NGTCP2_BBR_STATE_PROBE_RTT) {
- bbr_handle_probe_rtt(cc, cstat, ts);
+ if (bbr->state == NGTCP2_BBR_STATE_PROBE_RTT) {
+ bbr_handle_probe_rtt(bbr, cstat, ts);
}
- cc->idle_restart = 0;
+ bbr->idle_restart = 0;
}
-static void bbr_enter_probe_rtt(ngtcp2_bbr_cc *cc) {
- cc->state = NGTCP2_BBR_STATE_PROBE_RTT;
- cc->pacing_gain = 1;
- cc->cwnd_gain = 1;
+static void bbr_enter_probe_rtt(ngtcp2_cc_bbr *bbr) {
+ bbr->state = NGTCP2_BBR_STATE_PROBE_RTT;
+ bbr->pacing_gain = 1;
+ bbr->cwnd_gain = 1;
}
-static void bbr_handle_probe_rtt(ngtcp2_bbr_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_handle_probe_rtt(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- uint64_t app_limited = cc->rst->delivered + cstat->bytes_in_flight;
+ uint64_t app_limited = bbr->rst->delivered + cstat->bytes_in_flight;
/* Ignore low rate samples during NGTCP2_BBR_STATE_PROBE_RTT. */
- cc->rst->app_limited = app_limited ? app_limited : 1;
+ bbr->rst->app_limited = app_limited ? app_limited : 1;
- if (cc->probe_rtt_done_stamp == UINT64_MAX &&
+ if (bbr->probe_rtt_done_stamp == UINT64_MAX &&
cstat->bytes_in_flight <= min_pipe_cwnd(cstat->max_tx_udp_payload_size)) {
- cc->probe_rtt_done_stamp = ts + NGTCP2_BBR_PROBE_RTT_DURATION;
- cc->probe_rtt_round_done = 0;
- cc->next_round_delivered = cc->rst->delivered;
+ bbr->probe_rtt_done_stamp = ts + NGTCP2_BBR_PROBE_RTT_DURATION;
+ bbr->probe_rtt_round_done = 0;
+ bbr->next_round_delivered = bbr->rst->delivered;
return;
}
- if (cc->probe_rtt_done_stamp != UINT64_MAX) {
- if (cc->round_start) {
- cc->probe_rtt_round_done = 1;
+ if (bbr->probe_rtt_done_stamp != UINT64_MAX) {
+ if (bbr->round_start) {
+ bbr->probe_rtt_round_done = 1;
}
- if (cc->probe_rtt_round_done && ts > cc->probe_rtt_done_stamp) {
- cc->rtprop_stamp = ts;
- bbr_restore_cwnd(cc, cstat);
- bbr_exit_probe_rtt(cc, ts);
+ if (bbr->probe_rtt_round_done && ts > bbr->probe_rtt_done_stamp) {
+ bbr->rtprop_stamp = ts;
+ bbr_restore_cwnd(bbr, cstat);
+ bbr_exit_probe_rtt(bbr, ts);
}
}
}
-static void bbr_exit_probe_rtt(ngtcp2_bbr_cc *cc, ngtcp2_tstamp ts) {
- if (cc->filled_pipe) {
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+static void bbr_exit_probe_rtt(ngtcp2_cc_bbr *bbr, ngtcp2_tstamp ts) {
+ if (bbr->filled_pipe) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
"bbr exit ProbeRTT and enter ProbeBW");
- bbr_enter_probe_bw(cc, ts);
+ bbr_enter_probe_bw(bbr, ts);
return;
}
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
"bbr exit ProbeRTT and enter Startup");
- bbr_enter_startup(cc);
+ bbr_enter_startup(bbr);
}
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.h b/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.h
index b90be6bd97..ff5b5f5802 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.h
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr.h
@@ -45,11 +45,11 @@ typedef enum ngtcp2_bbr_state {
} ngtcp2_bbr_state;
/*
- * ngtcp2_bbr_cc is BBR congestion controller, described in
+ * ngtcp2_cc_bbr is BBR congestion controller, described in
* https://tools.ietf.org/html/draft-cardwell-iccrg-bbr-congestion-control-00
*/
-typedef struct ngtcp2_bbr_cc {
- ngtcp2_cc_base ccb;
+typedef struct ngtcp2_cc_bbr {
+ ngtcp2_cc cc;
/* The max filter used to estimate BBR.BtlBw. */
ngtcp2_window_filter btl_bw_filter;
@@ -108,25 +108,12 @@ typedef struct ngtcp2_bbr_cc {
/* in_loss_recovery becomes nonzero when BBR enters loss recovery
period. */
int in_loss_recovery;
-} ngtcp2_bbr_cc;
+} ngtcp2_cc_bbr;
-int ngtcp2_cc_bbr_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
- ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
- ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
- const ngtcp2_rand_ctx *rand_ctx,
- const ngtcp2_mem *mem);
-
-void ngtcp2_cc_bbr_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem);
-
-void ngtcp2_bbr_cc_init(ngtcp2_bbr_cc *bbr_cc, ngtcp2_conn_stat *cstat,
- ngtcp2_rst *rst, ngtcp2_tstamp initial_ts,
- ngtcp2_rand rand, const ngtcp2_rand_ctx *rand_ctx,
- ngtcp2_log *log);
-
-void ngtcp2_bbr_cc_free(ngtcp2_bbr_cc *cc);
-
-void ngtcp2_cc_bbr_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
- const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts);
+void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *cc, ngtcp2_log *log,
+ ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
+ ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
+ const ngtcp2_rand_ctx *rand_ctx);
void ngtcp2_cc_bbr_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp sent_ts, ngtcp2_tstamp ts);
@@ -145,13 +132,7 @@ void ngtcp2_cc_bbr_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
void ngtcp2_cc_bbr_cc_on_pkt_sent(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt);
-void ngtcp2_cc_bbr_cc_new_rtt_sample(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
- ngtcp2_tstamp ts);
-
void ngtcp2_cc_bbr_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-void ngtcp2_cc_bbr_cc_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
- ngtcp2_cc_event_type event, ngtcp2_tstamp ts);
-
#endif /* NGTCP2_BBR_H */
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.c b/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.c
index a1fbfe1a35..bc86cdde41 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.c
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.c
@@ -25,6 +25,7 @@
#include "ngtcp2_bbr2.h"
#include <assert.h>
+#include <string.h>
#include "ngtcp2_log.h"
#include "ngtcp2_macro.h"
@@ -59,221 +60,221 @@
#define NGTCP2_BBR_PACING_MARGIN_PERCENT 1
-static void bbr_on_init(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_on_init(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp initial_ts);
-static void bbr_on_transmit(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_on_transmit(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_reset_congestion_signals(ngtcp2_bbr2_cc *bbr);
+static void bbr_reset_congestion_signals(ngtcp2_cc_bbr2 *bbr);
-static void bbr_reset_lower_bounds(ngtcp2_bbr2_cc *bbr);
+static void bbr_reset_lower_bounds(ngtcp2_cc_bbr2 *bbr);
-static void bbr_init_round_counting(ngtcp2_bbr2_cc *bbr);
+static void bbr_init_round_counting(ngtcp2_cc_bbr2 *bbr);
-static void bbr_init_full_pipe(ngtcp2_bbr2_cc *bbr);
+static void bbr_init_full_pipe(ngtcp2_cc_bbr2 *bbr);
-static void bbr_init_pacing_rate(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_init_pacing_rate(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat);
-static void bbr_set_pacing_rate_with_gain(ngtcp2_bbr2_cc *bbr,
+static void bbr_set_pacing_rate_with_gain(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
double pacing_gain);
-static void bbr_set_pacing_rate(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_set_pacing_rate(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat);
-static void bbr_enter_startup(ngtcp2_bbr2_cc *bbr);
+static void bbr_enter_startup(ngtcp2_cc_bbr2 *bbr);
-static void bbr_check_startup_done(ngtcp2_bbr2_cc *bbr,
+static void bbr_check_startup_done(ngtcp2_cc_bbr2 *bbr,
const ngtcp2_cc_ack *ack);
-static void bbr_update_on_ack(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_update_on_ack(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts);
-static void bbr_update_model_and_state(ngtcp2_bbr2_cc *cc,
+static void bbr_update_model_and_state(ngtcp2_cc_bbr2 *cc,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts);
-static void bbr_update_control_parameters(ngtcp2_bbr2_cc *cc,
+static void bbr_update_control_parameters(ngtcp2_cc_bbr2 *cc,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_update_on_loss(ngtcp2_bbr2_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_update_on_loss(ngtcp2_cc_bbr2 *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts);
-static void bbr_update_latest_delivery_signals(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_latest_delivery_signals(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_advance_latest_delivery_signals(ngtcp2_bbr2_cc *bbr,
+static void bbr_advance_latest_delivery_signals(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_update_congestion_signals(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_congestion_signals(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_adapt_lower_bounds_from_congestion(ngtcp2_bbr2_cc *bbr,
+static void bbr_adapt_lower_bounds_from_congestion(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_init_lower_bounds(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_init_lower_bounds(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat);
-static void bbr_loss_lower_bounds(ngtcp2_bbr2_cc *bbr);
+static void bbr_loss_lower_bounds(ngtcp2_cc_bbr2 *bbr);
-static void bbr_bound_bw_for_model(ngtcp2_bbr2_cc *bbr);
+static void bbr_bound_bw_for_model(ngtcp2_cc_bbr2 *bbr);
-static void bbr_update_max_bw(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_update_max_bw(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_update_round(ngtcp2_bbr2_cc *bbr, const ngtcp2_cc_ack *ack);
+static void bbr_update_round(ngtcp2_cc_bbr2 *bbr, const ngtcp2_cc_ack *ack);
-static void bbr_start_round(ngtcp2_bbr2_cc *bbr);
+static void bbr_start_round(ngtcp2_cc_bbr2 *bbr);
-static int bbr_is_in_probe_bw_state(ngtcp2_bbr2_cc *bbr);
+static int bbr_is_in_probe_bw_state(ngtcp2_cc_bbr2 *bbr);
-static void bbr_update_ack_aggregation(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_ack_aggregation(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts);
-static void bbr_enter_drain(ngtcp2_bbr2_cc *bbr);
+static void bbr_enter_drain(ngtcp2_cc_bbr2 *bbr);
-static void bbr_check_drain(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_check_drain(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_enter_probe_bw(ngtcp2_bbr2_cc *bbr, ngtcp2_tstamp ts);
+static void bbr_enter_probe_bw(ngtcp2_cc_bbr2 *bbr, ngtcp2_tstamp ts);
-static void bbr_start_probe_bw_down(ngtcp2_bbr2_cc *bbr, ngtcp2_tstamp ts);
+static void bbr_start_probe_bw_down(ngtcp2_cc_bbr2 *bbr, ngtcp2_tstamp ts);
-static void bbr_start_probe_bw_cruise(ngtcp2_bbr2_cc *bbr);
+static void bbr_start_probe_bw_cruise(ngtcp2_cc_bbr2 *bbr);
-static void bbr_start_probe_bw_refill(ngtcp2_bbr2_cc *bbr);
+static void bbr_start_probe_bw_refill(ngtcp2_cc_bbr2 *bbr);
-static void bbr_start_probe_bw_up(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_start_probe_bw_up(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_update_probe_bw_cycle_phase(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_probe_bw_cycle_phase(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts);
-static int bbr_check_time_to_cruise(ngtcp2_bbr2_cc *bbr,
+static int bbr_check_time_to_cruise(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat, ngtcp2_tstamp ts);
-static int bbr_has_elapsed_in_phase(ngtcp2_bbr2_cc *bbr,
+static int bbr_has_elapsed_in_phase(ngtcp2_cc_bbr2 *bbr,
ngtcp2_duration interval, ngtcp2_tstamp ts);
-static uint64_t bbr_inflight_with_headroom(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_inflight_with_headroom(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_raise_inflight_hi_slope(ngtcp2_bbr2_cc *bbr,
+static void bbr_raise_inflight_hi_slope(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_probe_inflight_hi_upward(ngtcp2_bbr2_cc *bbr,
+static void bbr_probe_inflight_hi_upward(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_adapt_upper_bounds(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_adapt_upper_bounds(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts);
-static int bbr_check_time_to_probe_bw(ngtcp2_bbr2_cc *bbr,
+static int bbr_check_time_to_probe_bw(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_pick_probe_wait(ngtcp2_bbr2_cc *bbr);
+static void bbr_pick_probe_wait(ngtcp2_cc_bbr2 *bbr);
-static int bbr_is_reno_coexistence_probe_time(ngtcp2_bbr2_cc *bbr,
+static int bbr_is_reno_coexistence_probe_time(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static uint64_t bbr_target_inflight(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_target_inflight(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static int bbr_check_inflight_too_high(ngtcp2_bbr2_cc *bbr,
+static int bbr_check_inflight_too_high(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
static int is_inflight_too_high(const ngtcp2_rs *rs);
-static void bbr_handle_inflight_too_high(ngtcp2_bbr2_cc *bbr,
+static void bbr_handle_inflight_too_high(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_rs *rs, ngtcp2_tstamp ts);
-static void bbr_handle_lost_packet(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_handle_lost_packet(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts);
-static uint64_t bbr_inflight_hi_from_lost_packet(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_inflight_hi_from_lost_packet(ngtcp2_cc_bbr2 *bbr,
const ngtcp2_rs *rs,
const ngtcp2_cc_pkt *pkt);
-static void bbr_update_min_rtt(ngtcp2_bbr2_cc *bbr, const ngtcp2_cc_ack *ack,
+static void bbr_update_min_rtt(ngtcp2_cc_bbr2 *bbr, const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts);
-static void bbr_check_probe_rtt(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_check_probe_rtt(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_enter_probe_rtt(ngtcp2_bbr2_cc *bbr);
+static void bbr_enter_probe_rtt(ngtcp2_cc_bbr2 *bbr);
-static void bbr_handle_probe_rtt(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_handle_probe_rtt(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static void bbr_check_probe_rtt_done(ngtcp2_bbr2_cc *bbr,
+static void bbr_check_probe_rtt_done(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat, ngtcp2_tstamp ts);
-static void bbr_mark_connection_app_limited(ngtcp2_bbr2_cc *bbr,
+static void bbr_mark_connection_app_limited(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_exit_probe_rtt(ngtcp2_bbr2_cc *bbr, ngtcp2_tstamp ts);
+static void bbr_exit_probe_rtt(ngtcp2_cc_bbr2 *bbr, ngtcp2_tstamp ts);
-static void bbr_handle_restart_from_idle(ngtcp2_bbr2_cc *bbr,
+static void bbr_handle_restart_from_idle(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-static uint64_t bbr_bdp_multiple(ngtcp2_bbr2_cc *bbr, uint64_t bw, double gain);
+static uint64_t bbr_bdp_multiple(ngtcp2_cc_bbr2 *bbr, uint64_t bw, double gain);
-static uint64_t bbr_quantization_budget(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_quantization_budget(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
uint64_t inflight);
-static uint64_t bbr_inflight(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static uint64_t bbr_inflight(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
uint64_t bw, double gain);
-static void bbr_update_max_inflight(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_max_inflight(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_update_offload_budget(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_offload_budget(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
static uint64_t min_pipe_cwnd(size_t max_udp_payload_size);
-static void bbr_advance_max_bw_filter(ngtcp2_bbr2_cc *bbr);
+static void bbr_advance_max_bw_filter(ngtcp2_cc_bbr2 *bbr);
-static void bbr_modulate_cwnd_for_recovery(ngtcp2_bbr2_cc *bbr,
+static void bbr_modulate_cwnd_for_recovery(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_save_cwnd(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_save_cwnd(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat);
-static void bbr_restore_cwnd(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_restore_cwnd(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat);
-static uint64_t bbr_probe_rtt_cwnd(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_probe_rtt_cwnd(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_bound_cwnd_for_probe_rtt(ngtcp2_bbr2_cc *bbr,
+static void bbr_bound_cwnd_for_probe_rtt(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_set_cwnd(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_set_cwnd(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_bound_cwnd_for_model(ngtcp2_bbr2_cc *bbr,
+static void bbr_bound_cwnd_for_model(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat);
-static void bbr_set_send_quantum(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat);
+static void bbr_set_send_quantum(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat);
static int in_congestion_recovery(const ngtcp2_conn_stat *cstat,
ngtcp2_tstamp sent_time);
-static void bbr_handle_recovery(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_handle_recovery(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack);
-static void bbr_on_init(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_on_init(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp initial_ts) {
ngtcp2_window_filter_init(&bbr->max_bw_filter, NGTCP2_BBR_MAX_BW_FILTERLEN);
ngtcp2_window_filter_init(&bbr->extra_acked_filter,
@@ -344,30 +345,30 @@ static void bbr_on_init(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
bbr->prior_bw_lo = 0;
}
-static void bbr_reset_congestion_signals(ngtcp2_bbr2_cc *bbr) {
+static void bbr_reset_congestion_signals(ngtcp2_cc_bbr2 *bbr) {
bbr->loss_in_round = 0;
bbr->bw_latest = 0;
bbr->inflight_latest = 0;
}
-static void bbr_reset_lower_bounds(ngtcp2_bbr2_cc *bbr) {
+static void bbr_reset_lower_bounds(ngtcp2_cc_bbr2 *bbr) {
bbr->bw_lo = UINT64_MAX;
bbr->inflight_lo = UINT64_MAX;
}
-static void bbr_init_round_counting(ngtcp2_bbr2_cc *bbr) {
+static void bbr_init_round_counting(ngtcp2_cc_bbr2 *bbr) {
bbr->next_round_delivered = 0;
bbr->round_start = 0;
bbr->round_count = 0;
}
-static void bbr_init_full_pipe(ngtcp2_bbr2_cc *bbr) {
+static void bbr_init_full_pipe(ngtcp2_cc_bbr2 *bbr) {
bbr->filled_pipe = 0;
bbr->full_bw = 0;
bbr->full_bw_count = 0;
}
-static void bbr_check_startup_full_bandwidth(ngtcp2_bbr2_cc *bbr) {
+static void bbr_check_startup_full_bandwidth(ngtcp2_cc_bbr2 *bbr) {
if (bbr->filled_pipe || !bbr->round_start || bbr->rst->rs.is_app_limited) {
return;
}
@@ -382,12 +383,12 @@ static void bbr_check_startup_full_bandwidth(ngtcp2_bbr2_cc *bbr) {
if (bbr->full_bw_count >= 3) {
bbr->filled_pipe = 1;
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
"bbr2 filled pipe, full_bw=%" PRIu64, bbr->full_bw);
}
}
-static void bbr_check_startup_high_loss(ngtcp2_bbr2_cc *bbr,
+static void bbr_check_startup_high_loss(ngtcp2_cc_bbr2 *bbr,
const ngtcp2_cc_ack *ack) {
if (bbr->filled_pipe || !bbr->round_start || bbr->rst->rs.is_app_limited) {
return;
@@ -405,14 +406,14 @@ static void bbr_check_startup_high_loss(ngtcp2_bbr2_cc *bbr,
bbr->filled_pipe = 1;
}
-static void bbr_init_pacing_rate(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat) {
+static void bbr_init_pacing_rate(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat) {
double nominal_bandwidth = (double)bbr->initial_cwnd;
cstat->pacing_rate = NGTCP2_BBR_STARTUP_PACING_GAIN * nominal_bandwidth /
(double)NGTCP2_MILLISECONDS;
}
-static void bbr_set_pacing_rate_with_gain(ngtcp2_bbr2_cc *bbr,
+static void bbr_set_pacing_rate_with_gain(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
double pacing_gain) {
double rate = pacing_gain * (double)bbr->bw *
@@ -423,19 +424,19 @@ static void bbr_set_pacing_rate_with_gain(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_set_pacing_rate(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat) {
+static void bbr_set_pacing_rate(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat) {
bbr_set_pacing_rate_with_gain(bbr, cstat, bbr->pacing_gain);
}
-static void bbr_enter_startup(ngtcp2_bbr2_cc *bbr) {
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV, "bbr2 enter Startup");
+static void bbr_enter_startup(ngtcp2_cc_bbr2 *bbr) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV, "bbr2 enter Startup");
bbr->state = NGTCP2_BBR2_STATE_STARTUP;
bbr->pacing_gain = NGTCP2_BBR_STARTUP_PACING_GAIN;
bbr->cwnd_gain = NGTCP2_BBR_STARTUP_CWND_GAIN;
}
-static void bbr_check_startup_done(ngtcp2_bbr2_cc *bbr,
+static void bbr_check_startup_done(ngtcp2_cc_bbr2 *bbr,
const ngtcp2_cc_ack *ack) {
bbr_check_startup_full_bandwidth(bbr);
bbr_check_startup_high_loss(bbr, ack);
@@ -445,18 +446,18 @@ static void bbr_check_startup_done(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_on_transmit(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_on_transmit(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
bbr_handle_restart_from_idle(bbr, cstat, ts);
}
-static void bbr_update_on_ack(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_update_on_ack(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts) {
bbr_update_model_and_state(bbr, cstat, ack, ts);
bbr_update_control_parameters(bbr, cstat, ack);
}
-static void bbr_update_model_and_state(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_model_and_state(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts) {
@@ -472,7 +473,7 @@ static void bbr_update_model_and_state(ngtcp2_bbr2_cc *bbr,
bbr_bound_bw_for_model(bbr);
}
-static void bbr_update_control_parameters(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_control_parameters(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
bbr_set_pacing_rate(bbr, cstat);
@@ -480,12 +481,12 @@ static void bbr_update_control_parameters(ngtcp2_bbr2_cc *bbr,
bbr_set_cwnd(bbr, cstat, ack);
}
-static void bbr_update_on_loss(ngtcp2_bbr2_cc *cc, ngtcp2_conn_stat *cstat,
+static void bbr_update_on_loss(ngtcp2_cc_bbr2 *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts) {
bbr_handle_lost_packet(cc, cstat, pkt, ts);
}
-static void bbr_update_latest_delivery_signals(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_latest_delivery_signals(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
bbr->loss_round_start = 0;
bbr->bw_latest = ngtcp2_max(bbr->bw_latest, cstat->delivery_rate_sec);
@@ -498,7 +499,7 @@ static void bbr_update_latest_delivery_signals(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_advance_latest_delivery_signals(ngtcp2_bbr2_cc *bbr,
+static void bbr_advance_latest_delivery_signals(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
if (bbr->loss_round_start) {
bbr->bw_latest = cstat->delivery_rate_sec;
@@ -506,7 +507,7 @@ static void bbr_advance_latest_delivery_signals(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_update_congestion_signals(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_congestion_signals(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
bbr_update_max_bw(bbr, cstat, ack);
@@ -530,7 +531,7 @@ static void bbr_update_congestion_signals(ngtcp2_bbr2_cc *bbr,
bbr->loss_in_round = 0;
}
-static void bbr_adapt_lower_bounds_from_congestion(ngtcp2_bbr2_cc *bbr,
+static void bbr_adapt_lower_bounds_from_congestion(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
if (!bbr->filled_pipe || bbr_is_in_probe_bw_state(bbr)) {
return;
@@ -542,7 +543,7 @@ static void bbr_adapt_lower_bounds_from_congestion(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_init_lower_bounds(ngtcp2_bbr2_cc *bbr,
+static void bbr_init_lower_bounds(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
if (bbr->bw_lo == UINT64_MAX) {
bbr->bw_lo = bbr->max_bw;
@@ -553,7 +554,7 @@ static void bbr_init_lower_bounds(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_loss_lower_bounds(ngtcp2_bbr2_cc *bbr) {
+static void bbr_loss_lower_bounds(ngtcp2_cc_bbr2 *bbr) {
bbr->bw_lo = ngtcp2_max(bbr->bw_latest, bbr->bw_lo * NGTCP2_BBR_BETA_NUMER /
NGTCP2_BBR_BETA_DENOM);
bbr->inflight_lo = ngtcp2_max(bbr->inflight_latest,
@@ -561,12 +562,12 @@ static void bbr_loss_lower_bounds(ngtcp2_bbr2_cc *bbr) {
NGTCP2_BBR_BETA_DENOM);
}
-static void bbr_bound_bw_for_model(ngtcp2_bbr2_cc *bbr) {
+static void bbr_bound_bw_for_model(ngtcp2_cc_bbr2 *bbr) {
bbr->bw = ngtcp2_min(bbr->max_bw, bbr->bw_lo);
bbr->bw = ngtcp2_min(bbr->bw, bbr->bw_hi);
}
-static void bbr_update_max_bw(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_update_max_bw(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
bbr_update_round(bbr, ack);
bbr_handle_recovery(bbr, cstat, ack);
@@ -579,7 +580,7 @@ static void bbr_update_max_bw(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
}
}
-static void bbr_update_round(ngtcp2_bbr2_cc *bbr, const ngtcp2_cc_ack *ack) {
+static void bbr_update_round(ngtcp2_cc_bbr2 *bbr, const ngtcp2_cc_ack *ack) {
if (ack->pkt_delivered >= bbr->next_round_delivered) {
bbr_start_round(bbr);
@@ -598,11 +599,11 @@ static void bbr_update_round(ngtcp2_bbr2_cc *bbr, const ngtcp2_cc_ack *ack) {
bbr->round_start = 0;
}
-static void bbr_start_round(ngtcp2_bbr2_cc *bbr) {
+static void bbr_start_round(ngtcp2_cc_bbr2 *bbr) {
bbr->next_round_delivered = bbr->rst->delivered;
}
-static int bbr_is_in_probe_bw_state(ngtcp2_bbr2_cc *bbr) {
+static int bbr_is_in_probe_bw_state(ngtcp2_cc_bbr2 *bbr) {
switch (bbr->state) {
case NGTCP2_BBR2_STATE_PROBE_BW_DOWN:
case NGTCP2_BBR2_STATE_PROBE_BW_CRUISE:
@@ -614,7 +615,7 @@ static int bbr_is_in_probe_bw_state(ngtcp2_bbr2_cc *bbr) {
}
}
-static void bbr_update_ack_aggregation(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_ack_aggregation(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts) {
@@ -638,15 +639,15 @@ static void bbr_update_ack_aggregation(ngtcp2_bbr2_cc *bbr,
bbr->extra_acked = ngtcp2_window_filter_get_best(&bbr->extra_acked_filter);
}
-static void bbr_enter_drain(ngtcp2_bbr2_cc *bbr) {
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV, "bbr2 enter Drain");
+static void bbr_enter_drain(ngtcp2_cc_bbr2 *bbr) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV, "bbr2 enter Drain");
bbr->state = NGTCP2_BBR2_STATE_DRAIN;
bbr->pacing_gain = 1. / NGTCP2_BBR_STARTUP_CWND_GAIN;
bbr->cwnd_gain = NGTCP2_BBR_STARTUP_CWND_GAIN;
}
-static void bbr_check_drain(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_check_drain(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
if (bbr->state == NGTCP2_BBR2_STATE_DRAIN &&
cstat->bytes_in_flight <= bbr_inflight(bbr, cstat, bbr->bw, 1.0)) {
@@ -654,13 +655,12 @@ static void bbr_check_drain(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
}
}
-static void bbr_enter_probe_bw(ngtcp2_bbr2_cc *bbr, ngtcp2_tstamp ts) {
+static void bbr_enter_probe_bw(ngtcp2_cc_bbr2 *bbr, ngtcp2_tstamp ts) {
bbr_start_probe_bw_down(bbr, ts);
}
-static void bbr_start_probe_bw_down(ngtcp2_bbr2_cc *bbr, ngtcp2_tstamp ts) {
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV,
- "bbr2 start ProbeBW_DOWN");
+static void bbr_start_probe_bw_down(ngtcp2_cc_bbr2 *bbr, ngtcp2_tstamp ts) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV, "bbr2 start ProbeBW_DOWN");
bbr_reset_congestion_signals(bbr);
@@ -678,8 +678,8 @@ static void bbr_start_probe_bw_down(ngtcp2_bbr2_cc *bbr, ngtcp2_tstamp ts) {
bbr->cwnd_gain = 2;
}
-static void bbr_start_probe_bw_cruise(ngtcp2_bbr2_cc *bbr) {
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV,
+static void bbr_start_probe_bw_cruise(ngtcp2_cc_bbr2 *bbr) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
"bbr2 start ProbeBW_CRUISE");
bbr->state = NGTCP2_BBR2_STATE_PROBE_BW_CRUISE;
@@ -687,8 +687,8 @@ static void bbr_start_probe_bw_cruise(ngtcp2_bbr2_cc *bbr) {
bbr->cwnd_gain = 2;
}
-static void bbr_start_probe_bw_refill(ngtcp2_bbr2_cc *bbr) {
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV,
+static void bbr_start_probe_bw_refill(ngtcp2_cc_bbr2 *bbr) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
"bbr2 start ProbeBW_REFILL");
bbr_reset_lower_bounds(bbr);
@@ -704,9 +704,9 @@ static void bbr_start_probe_bw_refill(ngtcp2_bbr2_cc *bbr) {
bbr->cwnd_gain = 2;
}
-static void bbr_start_probe_bw_up(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_start_probe_bw_up(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV, "bbr2 start ProbeBW_UP");
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV, "bbr2 start ProbeBW_UP");
bbr->ack_phase = NGTCP2_BBR2_ACK_PHASE_ACKS_PROBE_STARTING;
@@ -720,7 +720,7 @@ static void bbr_start_probe_bw_up(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
bbr_raise_inflight_hi_slope(bbr, cstat);
}
-static void bbr_update_probe_bw_cycle_phase(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_probe_bw_cycle_phase(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts) {
@@ -770,7 +770,7 @@ static void bbr_update_probe_bw_cycle_phase(ngtcp2_bbr2_cc *bbr,
}
}
-static int bbr_check_time_to_cruise(ngtcp2_bbr2_cc *bbr,
+static int bbr_check_time_to_cruise(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat, ngtcp2_tstamp ts) {
(void)ts;
@@ -785,13 +785,13 @@ static int bbr_check_time_to_cruise(ngtcp2_bbr2_cc *bbr,
return 0;
}
-static int bbr_has_elapsed_in_phase(ngtcp2_bbr2_cc *bbr,
+static int bbr_has_elapsed_in_phase(ngtcp2_cc_bbr2 *bbr,
ngtcp2_duration interval,
ngtcp2_tstamp ts) {
return ts > bbr->cycle_stamp + interval;
}
-static uint64_t bbr_inflight_with_headroom(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_inflight_with_headroom(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
uint64_t headroom;
uint64_t mpcwnd;
@@ -811,7 +811,7 @@ static uint64_t bbr_inflight_with_headroom(ngtcp2_bbr2_cc *bbr,
return mpcwnd;
}
-static void bbr_raise_inflight_hi_slope(ngtcp2_bbr2_cc *bbr,
+static void bbr_raise_inflight_hi_slope(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
uint64_t growth_this_round = cstat->max_tx_udp_payload_size
<< bbr->bw_probe_up_rounds;
@@ -821,7 +821,7 @@ static void bbr_raise_inflight_hi_slope(ngtcp2_bbr2_cc *bbr,
cstat->max_tx_udp_payload_size;
}
-static void bbr_probe_inflight_hi_upward(ngtcp2_bbr2_cc *bbr,
+static void bbr_probe_inflight_hi_upward(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
uint64_t delta;
@@ -843,7 +843,7 @@ static void bbr_probe_inflight_hi_upward(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_adapt_upper_bounds(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_adapt_upper_bounds(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts) {
if (bbr->ack_phase == NGTCP2_BBR2_ACK_PHASE_ACKS_PROBE_STARTING &&
bbr->round_start) {
@@ -877,7 +877,7 @@ static void bbr_adapt_upper_bounds(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
}
}
-static int bbr_check_time_to_probe_bw(ngtcp2_bbr2_cc *bbr,
+static int bbr_check_time_to_probe_bw(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
if (bbr_has_elapsed_in_phase(bbr, bbr->bw_probe_wait, ts) ||
@@ -890,7 +890,7 @@ static int bbr_check_time_to_probe_bw(ngtcp2_bbr2_cc *bbr,
return 0;
}
-static void bbr_pick_probe_wait(ngtcp2_bbr2_cc *bbr) {
+static void bbr_pick_probe_wait(ngtcp2_cc_bbr2 *bbr) {
uint8_t rand;
bbr->rand(&rand, 1, &bbr->rand_ctx);
@@ -903,7 +903,7 @@ static void bbr_pick_probe_wait(ngtcp2_bbr2_cc *bbr) {
(ngtcp2_tstamp)((double)rand / 255. * NGTCP2_SECONDS);
}
-static int bbr_is_reno_coexistence_probe_time(ngtcp2_bbr2_cc *bbr,
+static int bbr_is_reno_coexistence_probe_time(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
uint64_t reno_rounds =
bbr_target_inflight(bbr, cstat) / cstat->max_tx_udp_payload_size;
@@ -911,14 +911,14 @@ static int bbr_is_reno_coexistence_probe_time(ngtcp2_bbr2_cc *bbr,
return bbr->rounds_since_bw_probe >= ngtcp2_min(reno_rounds, 63);
}
-static uint64_t bbr_target_inflight(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_target_inflight(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
uint64_t bdp = bbr_inflight(bbr, cstat, bbr->bw, 1.0);
return ngtcp2_min(bdp, cstat->cwnd);
}
-static int bbr_check_inflight_too_high(ngtcp2_bbr2_cc *bbr,
+static int bbr_check_inflight_too_high(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
if (is_inflight_too_high(&bbr->rst->rs)) {
@@ -937,7 +937,7 @@ static int is_inflight_too_high(const ngtcp2_rs *rs) {
rs->tx_in_flight * NGTCP2_BBR_LOSS_THRESH_NUMER;
}
-static void bbr_handle_inflight_too_high(ngtcp2_bbr2_cc *bbr,
+static void bbr_handle_inflight_too_high(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_rs *rs,
ngtcp2_tstamp ts) {
@@ -956,7 +956,7 @@ static void bbr_handle_inflight_too_high(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_handle_lost_packet(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_handle_lost_packet(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts) {
ngtcp2_rs rs = {0};
@@ -976,7 +976,7 @@ static void bbr_handle_lost_packet(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
}
}
-static uint64_t bbr_inflight_hi_from_lost_packet(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_inflight_hi_from_lost_packet(ngtcp2_cc_bbr2 *bbr,
const ngtcp2_rs *rs,
const ngtcp2_cc_pkt *pkt) {
uint64_t inflight_prev, lost_prev, lost_prefix;
@@ -1002,7 +1002,7 @@ static uint64_t bbr_inflight_hi_from_lost_packet(ngtcp2_bbr2_cc *bbr,
return inflight_prev + lost_prefix;
}
-static void bbr_update_min_rtt(ngtcp2_bbr2_cc *bbr, const ngtcp2_cc_ack *ack,
+static void bbr_update_min_rtt(ngtcp2_cc_bbr2 *bbr, const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts) {
int min_rtt_expired;
@@ -1021,12 +1021,12 @@ static void bbr_update_min_rtt(ngtcp2_bbr2_cc *bbr, const ngtcp2_cc_ack *ack,
bbr->min_rtt = bbr->probe_rtt_min_delay;
bbr->min_rtt_stamp = bbr->probe_rtt_min_stamp;
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
"bbr2 update min_rtt=%" PRIu64, bbr->min_rtt);
}
}
-static void bbr_check_probe_rtt(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_check_probe_rtt(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
if (bbr->state != NGTCP2_BBR2_STATE_PROBE_RTT && bbr->probe_rtt_expired &&
!bbr->idle_restart) {
@@ -1048,15 +1048,15 @@ static void bbr_check_probe_rtt(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
}
}
-static void bbr_enter_probe_rtt(ngtcp2_bbr2_cc *bbr) {
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV, "bbr2 enter ProbeRTT");
+static void bbr_enter_probe_rtt(ngtcp2_cc_bbr2 *bbr) {
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV, "bbr2 enter ProbeRTT");
bbr->state = NGTCP2_BBR2_STATE_PROBE_RTT;
bbr->pacing_gain = 1;
bbr->cwnd_gain = NGTCP2_BBR_PROBE_RTT_CWND_GAIN;
}
-static void bbr_handle_probe_rtt(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_handle_probe_rtt(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
bbr_mark_connection_app_limited(bbr, cstat);
@@ -1081,7 +1081,7 @@ static void bbr_handle_probe_rtt(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
}
}
-static void bbr_check_probe_rtt_done(ngtcp2_bbr2_cc *bbr,
+static void bbr_check_probe_rtt_done(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
if (bbr->probe_rtt_done_stamp != UINT64_MAX &&
@@ -1092,7 +1092,7 @@ static void bbr_check_probe_rtt_done(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_mark_connection_app_limited(ngtcp2_bbr2_cc *bbr,
+static void bbr_mark_connection_app_limited(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
uint64_t app_limited = bbr->rst->delivered + cstat->bytes_in_flight;
@@ -1103,7 +1103,7 @@ static void bbr_mark_connection_app_limited(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_exit_probe_rtt(ngtcp2_bbr2_cc *bbr, ngtcp2_tstamp ts) {
+static void bbr_exit_probe_rtt(ngtcp2_cc_bbr2 *bbr, ngtcp2_tstamp ts) {
bbr_reset_lower_bounds(bbr);
if (bbr->filled_pipe) {
@@ -1114,11 +1114,11 @@ static void bbr_exit_probe_rtt(ngtcp2_bbr2_cc *bbr, ngtcp2_tstamp ts) {
}
}
-static void bbr_handle_restart_from_idle(ngtcp2_bbr2_cc *bbr,
+static void bbr_handle_restart_from_idle(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
if (cstat->bytes_in_flight == 0 && bbr->rst->app_limited) {
- ngtcp2_log_info(bbr->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(bbr->cc.log, NGTCP2_LOG_EVENT_RCV,
"bbr2 restart from idle");
bbr->idle_restart = 1;
@@ -1132,7 +1132,7 @@ static void bbr_handle_restart_from_idle(ngtcp2_bbr2_cc *bbr,
}
}
-static uint64_t bbr_bdp_multiple(ngtcp2_bbr2_cc *bbr, uint64_t bw,
+static uint64_t bbr_bdp_multiple(ngtcp2_cc_bbr2 *bbr, uint64_t bw,
double gain) {
uint64_t bdp;
@@ -1149,7 +1149,7 @@ static uint64_t min_pipe_cwnd(size_t max_udp_payload_size) {
return max_udp_payload_size * 4;
}
-static uint64_t bbr_quantization_budget(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_quantization_budget(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
uint64_t inflight) {
bbr_update_offload_budget(bbr, cstat);
@@ -1165,14 +1165,14 @@ static uint64_t bbr_quantization_budget(ngtcp2_bbr2_cc *bbr,
return inflight;
}
-static uint64_t bbr_inflight(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static uint64_t bbr_inflight(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
uint64_t bw, double gain) {
uint64_t inflight = bbr_bdp_multiple(bbr, bw, gain);
return bbr_quantization_budget(bbr, cstat, inflight);
}
-static void bbr_update_max_inflight(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_max_inflight(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
uint64_t inflight;
@@ -1183,16 +1183,16 @@ static void bbr_update_max_inflight(ngtcp2_bbr2_cc *bbr,
bbr->max_inflight = bbr_quantization_budget(bbr, cstat, inflight);
}
-static void bbr_update_offload_budget(ngtcp2_bbr2_cc *bbr,
+static void bbr_update_offload_budget(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
bbr->offload_budget = 3 * cstat->send_quantum;
}
-static void bbr_advance_max_bw_filter(ngtcp2_bbr2_cc *bbr) {
+static void bbr_advance_max_bw_filter(ngtcp2_cc_bbr2 *bbr) {
++bbr->cycle_count;
}
-static void bbr_modulate_cwnd_for_recovery(ngtcp2_bbr2_cc *bbr,
+static void bbr_modulate_cwnd_for_recovery(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
if (ack->bytes_lost > 0) {
@@ -1210,7 +1210,7 @@ static void bbr_modulate_cwnd_for_recovery(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_save_cwnd(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat) {
+static void bbr_save_cwnd(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat) {
if (!bbr->in_loss_recovery && bbr->state != NGTCP2_BBR2_STATE_PROBE_RTT) {
bbr->prior_cwnd = cstat->cwnd;
return;
@@ -1219,11 +1219,11 @@ static void bbr_save_cwnd(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat) {
bbr->prior_cwnd = ngtcp2_max(bbr->prior_cwnd, cstat->cwnd);
}
-static void bbr_restore_cwnd(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat) {
+static void bbr_restore_cwnd(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat) {
cstat->cwnd = ngtcp2_max(cstat->cwnd, bbr->prior_cwnd);
}
-static uint64_t bbr_probe_rtt_cwnd(ngtcp2_bbr2_cc *bbr,
+static uint64_t bbr_probe_rtt_cwnd(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
uint64_t probe_rtt_cwnd =
bbr_bdp_multiple(bbr, bbr->bw, NGTCP2_BBR_PROBE_RTT_CWND_GAIN);
@@ -1232,7 +1232,7 @@ static uint64_t bbr_probe_rtt_cwnd(ngtcp2_bbr2_cc *bbr,
return ngtcp2_max(probe_rtt_cwnd, mpcwnd);
}
-static void bbr_bound_cwnd_for_probe_rtt(ngtcp2_bbr2_cc *bbr,
+static void bbr_bound_cwnd_for_probe_rtt(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
uint64_t probe_rtt_cwnd;
@@ -1243,7 +1243,7 @@ static void bbr_bound_cwnd_for_probe_rtt(ngtcp2_bbr2_cc *bbr,
}
}
-static void bbr_set_cwnd(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_set_cwnd(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
uint64_t mpcwnd;
@@ -1267,7 +1267,7 @@ static void bbr_set_cwnd(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
bbr_bound_cwnd_for_model(bbr, cstat);
}
-static void bbr_bound_cwnd_for_model(ngtcp2_bbr2_cc *bbr,
+static void bbr_bound_cwnd_for_model(ngtcp2_cc_bbr2 *bbr,
ngtcp2_conn_stat *cstat) {
uint64_t cap = UINT64_MAX;
uint64_t mpcwnd = min_pipe_cwnd(cstat->max_tx_udp_payload_size);
@@ -1286,17 +1286,20 @@ static void bbr_bound_cwnd_for_model(ngtcp2_bbr2_cc *bbr,
cstat->cwnd = ngtcp2_min(cstat->cwnd, cap);
}
-static void bbr_set_send_quantum(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat) {
- size_t send_quantum = (size_t)(cstat->pacing_rate *
- (double)((bbr->min_rtt == UINT64_MAX ||
- bbr->min_rtt < NGTCP2_MILLISECONDS)
- ? NGTCP2_MILLISECONDS
- : bbr->min_rtt));
+static void bbr_set_send_quantum(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat) {
+ size_t floor, send_quantum;
(void)bbr;
- cstat->send_quantum = ngtcp2_min(send_quantum, 64 * 1024);
- cstat->send_quantum =
- ngtcp2_max(cstat->send_quantum, cstat->max_tx_udp_payload_size * 10);
+ if (cstat->pacing_rate < 1.2 * 1024 * 1024 / 8 / NGTCP2_SECONDS) {
+ floor = cstat->max_tx_udp_payload_size;
+ } else {
+ floor = 2 * cstat->max_tx_udp_payload_size;
+ }
+
+ send_quantum = (size_t)(cstat->pacing_rate * NGTCP2_MILLISECONDS);
+
+ send_quantum = ngtcp2_min(send_quantum, 64 * 1024);
+ cstat->send_quantum = ngtcp2_max(send_quantum, floor);
}
static int in_congestion_recovery(const ngtcp2_conn_stat *cstat,
@@ -1305,7 +1308,7 @@ static int in_congestion_recovery(const ngtcp2_conn_stat *cstat,
sent_time <= cstat->congestion_recovery_start_ts;
}
-static void bbr_handle_recovery(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
+static void bbr_handle_recovery(ngtcp2_cc_bbr2 *bbr, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack) {
if (bbr->in_loss_recovery) {
if (ack->pkt_delivered >= bbr->congestion_recovery_next_round_delivered) {
@@ -1337,39 +1340,16 @@ static void bbr_handle_recovery(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
}
}
-static void bbr2_cc_init(ngtcp2_bbr2_cc *bbr, ngtcp2_conn_stat *cstat,
- ngtcp2_rst *rst, ngtcp2_tstamp initial_ts,
- ngtcp2_rand rand, const ngtcp2_rand_ctx *rand_ctx,
- ngtcp2_log *log) {
- bbr->ccb.log = log;
- bbr->rst = rst;
- bbr->rand = rand;
- bbr->rand_ctx = *rand_ctx;
- bbr->initial_cwnd = cstat->cwnd;
-
- bbr_on_init(bbr, cstat, initial_ts);
-}
-
-static void bbr2_cc_free(ngtcp2_bbr2_cc *bbr) { (void)bbr; }
-
-static void bbr2_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
- const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts) {
- (void)ccx;
- (void)cstat;
- (void)pkt;
- (void)ts;
-}
-
-static void bbr2_cc_on_pkt_lost(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+static void bbr2_cc_on_pkt_lost(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts) {
- ngtcp2_bbr2_cc *bbr = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr2_cc, ccb);
+ ngtcp2_cc_bbr2 *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr2, cc);
bbr_update_on_loss(bbr, cstat, pkt, ts);
}
-static void bbr2_cc_congestion_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+static void bbr2_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp sent_ts, ngtcp2_tstamp ts) {
- ngtcp2_bbr2_cc *bbr = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr2_cc, ccb);
+ ngtcp2_cc_bbr2 *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr2, cc);
if (!bbr->filled_pipe || bbr->in_loss_recovery ||
bbr->congestion_recovery_start_ts != UINT64_MAX ||
@@ -1380,10 +1360,10 @@ static void bbr2_cc_congestion_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
bbr->congestion_recovery_start_ts = ts;
}
-static void bbr2_cc_on_spurious_congestion(ngtcp2_cc *ccx,
+static void bbr2_cc_on_spurious_congestion(ngtcp2_cc *cc,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_bbr2_cc *bbr = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr2_cc, ccb);
+ ngtcp2_cc_bbr2 *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr2, cc);
(void)ts;
bbr->congestion_recovery_start_ts = UINT64_MAX;
@@ -1401,10 +1381,10 @@ static void bbr2_cc_on_spurious_congestion(ngtcp2_cc *ccx,
}
}
-static void bbr2_cc_on_persistent_congestion(ngtcp2_cc *ccx,
+static void bbr2_cc_on_persistent_congestion(ngtcp2_cc *cc,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_bbr2_cc *bbr = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr2_cc, ccb);
+ ngtcp2_cc_bbr2 *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr2, cc);
(void)ts;
cstat->congestion_recovery_start_ts = UINT64_MAX;
@@ -1418,74 +1398,46 @@ static void bbr2_cc_on_persistent_congestion(ngtcp2_cc *ccx,
ngtcp2_max(cstat->cwnd, min_pipe_cwnd(cstat->max_tx_udp_payload_size));
}
-static void bbr2_cc_on_ack_recv(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+static void bbr2_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts) {
- ngtcp2_bbr2_cc *bbr = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr2_cc, ccb);
+ ngtcp2_cc_bbr2 *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr2, cc);
bbr_update_on_ack(bbr, cstat, ack, ts);
}
-static void bbr2_cc_on_pkt_sent(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+static void bbr2_cc_on_pkt_sent(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt) {
- ngtcp2_bbr2_cc *bbr = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr2_cc, ccb);
+ ngtcp2_cc_bbr2 *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr2, cc);
bbr_on_transmit(bbr, cstat, pkt->sent_ts);
}
-static void bbr2_cc_new_rtt_sample(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
- ngtcp2_tstamp ts) {
- (void)ccx;
- (void)cstat;
- (void)ts;
-}
-
-static void bbr2_cc_reset(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+static void bbr2_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_bbr2_cc *bbr = ngtcp2_struct_of(ccx->ccb, ngtcp2_bbr2_cc, ccb);
+ ngtcp2_cc_bbr2 *bbr = ngtcp2_struct_of(cc, ngtcp2_cc_bbr2, cc);
bbr_on_init(bbr, cstat, ts);
}
-static void bbr2_cc_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
- ngtcp2_cc_event_type event, ngtcp2_tstamp ts) {
- (void)ccx;
- (void)cstat;
- (void)event;
- (void)ts;
-}
-
-int ngtcp2_cc_bbr2_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
- ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
- ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
- const ngtcp2_rand_ctx *rand_ctx,
- const ngtcp2_mem *mem) {
- ngtcp2_bbr2_cc *bbr;
-
- bbr = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_bbr2_cc));
- if (bbr == NULL) {
- return NGTCP2_ERR_NOMEM;
- }
-
- bbr2_cc_init(bbr, cstat, rst, initial_ts, rand, rand_ctx, log);
+void ngtcp2_cc_bbr2_init(ngtcp2_cc_bbr2 *bbr, ngtcp2_log *log,
+ ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
+ ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
+ const ngtcp2_rand_ctx *rand_ctx) {
+ memset(bbr, 0, sizeof(*bbr));
- cc->ccb = &bbr->ccb;
- cc->on_pkt_acked = bbr2_cc_on_pkt_acked;
- cc->on_pkt_lost = bbr2_cc_on_pkt_lost;
- cc->congestion_event = bbr2_cc_congestion_event;
- cc->on_spurious_congestion = bbr2_cc_on_spurious_congestion;
- cc->on_persistent_congestion = bbr2_cc_on_persistent_congestion;
- cc->on_ack_recv = bbr2_cc_on_ack_recv;
- cc->on_pkt_sent = bbr2_cc_on_pkt_sent;
- cc->new_rtt_sample = bbr2_cc_new_rtt_sample;
- cc->reset = bbr2_cc_reset;
- cc->event = bbr2_cc_event;
+ bbr->cc.log = log;
+ bbr->cc.on_pkt_lost = bbr2_cc_on_pkt_lost;
+ bbr->cc.congestion_event = bbr2_cc_congestion_event;
+ bbr->cc.on_spurious_congestion = bbr2_cc_on_spurious_congestion;
+ bbr->cc.on_persistent_congestion = bbr2_cc_on_persistent_congestion;
+ bbr->cc.on_ack_recv = bbr2_cc_on_ack_recv;
+ bbr->cc.on_pkt_sent = bbr2_cc_on_pkt_sent;
+ bbr->cc.reset = bbr2_cc_reset;
- return 0;
-}
-
-void ngtcp2_cc_bbr2_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem) {
- ngtcp2_bbr2_cc *bbr = ngtcp2_struct_of(cc->ccb, ngtcp2_bbr2_cc, ccb);
+ bbr->rst = rst;
+ bbr->rand = rand;
+ bbr->rand_ctx = *rand_ctx;
+ bbr->initial_cwnd = cstat->cwnd;
- bbr2_cc_free(bbr);
- ngtcp2_mem_free(mem, bbr);
+ bbr_on_init(bbr, cstat, initial_ts);
}
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.h b/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.h
index 50dc05a5f2..3b95759327 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.h
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_bbr2.h
@@ -54,11 +54,11 @@ typedef enum ngtcp2_bbr2_ack_phase {
} ngtcp2_bbr2_ack_phase;
/*
- * ngtcp2_bbr2_cc is BBR v2 congestion controller, described in
+ * ngtcp2_cc_bbr2 is BBR v2 congestion controller, described in
* https://datatracker.ietf.org/doc/html/draft-cardwell-iccrg-bbr-congestion-control-01
*/
-typedef struct ngtcp2_bbr2_cc {
- ngtcp2_cc_base ccb;
+typedef struct ngtcp2_cc_bbr2 {
+ ngtcp2_cc cc;
uint64_t initial_cwnd;
ngtcp2_rst *rst;
@@ -136,14 +136,11 @@ typedef struct ngtcp2_bbr2_cc {
uint64_t prior_inflight_lo;
uint64_t prior_inflight_hi;
uint64_t prior_bw_lo;
-} ngtcp2_bbr2_cc;
+} ngtcp2_cc_bbr2;
-int ngtcp2_cc_bbr2_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
- ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
- ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
- const ngtcp2_rand_ctx *rand_ctx,
- const ngtcp2_mem *mem);
-
-void ngtcp2_cc_bbr2_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem);
+void ngtcp2_cc_bbr2_init(ngtcp2_cc_bbr2 *bbr, ngtcp2_log *log,
+ ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
+ ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
+ const ngtcp2_rand_ctx *rand_ctx);
#endif /* NGTCP2_BBR2_H */
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.c b/deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.c
index d6d0da85f2..32f7cd488a 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.c
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.c
@@ -25,6 +25,7 @@
#include "ngtcp2_cc.h"
#include <assert.h>
+#include <string.h>
#if defined(_MSC_VER)
# include <intrin.h>
@@ -57,45 +58,24 @@ ngtcp2_cc_pkt *ngtcp2_cc_pkt_init(ngtcp2_cc_pkt *pkt, int64_t pkt_num,
return pkt;
}
-static void reno_cc_reset(ngtcp2_reno_cc *cc) {
- cc->max_delivery_rate_sec = 0;
- cc->target_cwnd = 0;
- cc->pending_add = 0;
+static void reno_cc_reset(ngtcp2_cc_reno *reno) {
+ reno->max_delivery_rate_sec = 0;
+ reno->target_cwnd = 0;
+ reno->pending_add = 0;
}
-void ngtcp2_reno_cc_init(ngtcp2_reno_cc *cc, ngtcp2_log *log) {
- cc->ccb.log = log;
- reno_cc_reset(cc);
-}
-
-void ngtcp2_reno_cc_free(ngtcp2_reno_cc *cc) { (void)cc; }
-
-int ngtcp2_cc_reno_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
- const ngtcp2_mem *mem) {
- ngtcp2_reno_cc *reno_cc;
-
- reno_cc = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_reno_cc));
- if (reno_cc == NULL) {
- return NGTCP2_ERR_NOMEM;
- }
-
- ngtcp2_reno_cc_init(reno_cc, log);
-
- cc->ccb = &reno_cc->ccb;
- cc->on_pkt_acked = ngtcp2_cc_reno_cc_on_pkt_acked;
- cc->congestion_event = ngtcp2_cc_reno_cc_congestion_event;
- cc->on_persistent_congestion = ngtcp2_cc_reno_cc_on_persistent_congestion;
- cc->on_ack_recv = ngtcp2_cc_reno_cc_on_ack_recv;
- cc->reset = ngtcp2_cc_reno_cc_reset;
-
- return 0;
-}
+void ngtcp2_cc_reno_init(ngtcp2_cc_reno *reno, ngtcp2_log *log) {
+ memset(reno, 0, sizeof(*reno));
-void ngtcp2_cc_reno_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem) {
- ngtcp2_reno_cc *reno_cc = ngtcp2_struct_of(cc->ccb, ngtcp2_reno_cc, ccb);
+ reno->cc.log = log;
+ reno->cc.on_pkt_acked = ngtcp2_cc_reno_cc_on_pkt_acked;
+ reno->cc.congestion_event = ngtcp2_cc_reno_cc_congestion_event;
+ reno->cc.on_persistent_congestion =
+ ngtcp2_cc_reno_cc_on_persistent_congestion;
+ reno->cc.on_ack_recv = ngtcp2_cc_reno_cc_on_ack_recv;
+ reno->cc.reset = ngtcp2_cc_reno_cc_reset;
- ngtcp2_reno_cc_free(reno_cc);
- ngtcp2_mem_free(mem, reno_cc);
+ reno_cc_reset(reno);
}
static int in_congestion_recovery(const ngtcp2_conn_stat *cstat,
@@ -104,10 +84,10 @@ static int in_congestion_recovery(const ngtcp2_conn_stat *cstat,
sent_time <= cstat->congestion_recovery_start_ts;
}
-void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt,
ngtcp2_tstamp ts) {
- ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb);
+ ngtcp2_cc_reno *reno = ngtcp2_struct_of(cc, ngtcp2_cc_reno, cc);
uint64_t m;
(void)ts;
@@ -115,28 +95,28 @@ void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
return;
}
- if (cc->target_cwnd && cc->target_cwnd < cstat->cwnd) {
+ if (reno->target_cwnd && reno->target_cwnd < cstat->cwnd) {
return;
}
if (cstat->cwnd < cstat->ssthresh) {
cstat->cwnd += pkt->pktlen;
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(reno->cc.log, NGTCP2_LOG_EVENT_RCV,
"pkn=%" PRId64 " acked, slow start cwnd=%" PRIu64,
pkt->pkt_num, cstat->cwnd);
return;
}
- m = cstat->max_tx_udp_payload_size * pkt->pktlen + cc->pending_add;
- cc->pending_add = m % cstat->cwnd;
+ m = cstat->max_tx_udp_payload_size * pkt->pktlen + reno->pending_add;
+ reno->pending_add = m % cstat->cwnd;
cstat->cwnd += m / cstat->cwnd;
}
-void ngtcp2_cc_reno_cc_congestion_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_reno_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp sent_ts,
ngtcp2_tstamp ts) {
- ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb);
+ ngtcp2_cc_reno *reno = ngtcp2_struct_of(cc, ngtcp2_cc_reno, cc);
uint64_t min_cwnd;
if (in_congestion_recovery(cstat, sent_ts)) {
@@ -149,120 +129,100 @@ void ngtcp2_cc_reno_cc_congestion_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
cstat->cwnd = ngtcp2_max(cstat->cwnd, min_cwnd);
cstat->ssthresh = cstat->cwnd;
- cc->pending_add = 0;
+ reno->pending_add = 0;
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(reno->cc.log, NGTCP2_LOG_EVENT_RCV,
"reduce cwnd because of packet loss cwnd=%" PRIu64,
cstat->cwnd);
}
-void ngtcp2_cc_reno_cc_on_persistent_congestion(ngtcp2_cc *ccx,
+void ngtcp2_cc_reno_cc_on_persistent_congestion(ngtcp2_cc *cc,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- (void)ccx;
+ (void)cc;
(void)ts;
cstat->cwnd = 2 * cstat->max_tx_udp_payload_size;
cstat->congestion_recovery_start_ts = UINT64_MAX;
}
-void ngtcp2_cc_reno_cc_on_ack_recv(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_reno_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack, ngtcp2_tstamp ts) {
- ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb);
+ ngtcp2_cc_reno *reno = ngtcp2_struct_of(cc, ngtcp2_cc_reno, cc);
uint64_t target_cwnd, initcwnd;
(void)ack;
(void)ts;
/* TODO Use sliding window for min rtt measurement */
/* TODO Use sliding window */
- cc->max_delivery_rate_sec =
- ngtcp2_max(cc->max_delivery_rate_sec, cstat->delivery_rate_sec);
+ reno->max_delivery_rate_sec =
+ ngtcp2_max(reno->max_delivery_rate_sec, cstat->delivery_rate_sec);
- if (cstat->min_rtt != UINT64_MAX && cc->max_delivery_rate_sec) {
+ if (cstat->min_rtt != UINT64_MAX && reno->max_delivery_rate_sec) {
target_cwnd =
- cc->max_delivery_rate_sec * cstat->smoothed_rtt / NGTCP2_SECONDS;
+ reno->max_delivery_rate_sec * cstat->smoothed_rtt / NGTCP2_SECONDS;
initcwnd = ngtcp2_cc_compute_initcwnd(cstat->max_tx_udp_payload_size);
- cc->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100;
+ reno->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100;
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(reno->cc.log, NGTCP2_LOG_EVENT_RCV,
"target_cwnd=%" PRIu64 " max_delivery_rate_sec=%" PRIu64
- " min_rtt=%" PRIu64,
- cc->target_cwnd, cc->max_delivery_rate_sec, cstat->min_rtt);
+ " smoothed_rtt=%" PRIu64,
+ reno->target_cwnd, reno->max_delivery_rate_sec,
+ cstat->smoothed_rtt);
}
}
-void ngtcp2_cc_reno_cc_reset(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_reno_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_reno_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_reno_cc, ccb);
+ ngtcp2_cc_reno *reno = ngtcp2_struct_of(cc, ngtcp2_cc_reno, cc);
(void)cstat;
(void)ts;
- reno_cc_reset(cc);
+ reno_cc_reset(reno);
}
-static void cubic_cc_reset(ngtcp2_cubic_cc *cc) {
- cc->max_delivery_rate_sec = 0;
- cc->target_cwnd = 0;
- cc->w_last_max = 0;
- cc->w_tcp = 0;
- cc->origin_point = 0;
- cc->epoch_start = UINT64_MAX;
- cc->k = 0;
-
- cc->prior.cwnd = 0;
- cc->prior.ssthresh = 0;
- cc->prior.w_last_max = 0;
- cc->prior.w_tcp = 0;
- cc->prior.origin_point = 0;
- cc->prior.epoch_start = UINT64_MAX;
- cc->prior.k = 0;
-
- cc->rtt_sample_count = 0;
- cc->current_round_min_rtt = UINT64_MAX;
- cc->last_round_min_rtt = UINT64_MAX;
- cc->window_end = -1;
+static void cubic_cc_reset(ngtcp2_cc_cubic *cubic) {
+ cubic->max_delivery_rate_sec = 0;
+ cubic->target_cwnd = 0;
+ cubic->w_last_max = 0;
+ cubic->w_tcp = 0;
+ cubic->origin_point = 0;
+ cubic->epoch_start = UINT64_MAX;
+ cubic->k = 0;
+
+ cubic->prior.cwnd = 0;
+ cubic->prior.ssthresh = 0;
+ cubic->prior.w_last_max = 0;
+ cubic->prior.w_tcp = 0;
+ cubic->prior.origin_point = 0;
+ cubic->prior.epoch_start = UINT64_MAX;
+ cubic->prior.k = 0;
+
+ cubic->rtt_sample_count = 0;
+ cubic->current_round_min_rtt = UINT64_MAX;
+ cubic->last_round_min_rtt = UINT64_MAX;
+ cubic->window_end = -1;
}
-void ngtcp2_cubic_cc_init(ngtcp2_cubic_cc *cc, ngtcp2_log *log) {
- cc->ccb.log = log;
- cubic_cc_reset(cc);
+void ngtcp2_cc_cubic_init(ngtcp2_cc_cubic *cubic, ngtcp2_log *log) {
+ memset(cubic, 0, sizeof(*cubic));
+
+ cubic->cc.log = log;
+ cubic->cc.on_pkt_acked = ngtcp2_cc_cubic_cc_on_pkt_acked;
+ cubic->cc.congestion_event = ngtcp2_cc_cubic_cc_congestion_event;
+ cubic->cc.on_spurious_congestion = ngtcp2_cc_cubic_cc_on_spurious_congestion;
+ cubic->cc.on_persistent_congestion =
+ ngtcp2_cc_cubic_cc_on_persistent_congestion;
+ cubic->cc.on_ack_recv = ngtcp2_cc_cubic_cc_on_ack_recv;
+ cubic->cc.on_pkt_sent = ngtcp2_cc_cubic_cc_on_pkt_sent;
+ cubic->cc.new_rtt_sample = ngtcp2_cc_cubic_cc_new_rtt_sample;
+ cubic->cc.reset = ngtcp2_cc_cubic_cc_reset;
+ cubic->cc.event = ngtcp2_cc_cubic_cc_event;
+
+ cubic_cc_reset(cubic);
}
-void ngtcp2_cubic_cc_free(ngtcp2_cubic_cc *cc) { (void)cc; }
-
-int ngtcp2_cc_cubic_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
- const ngtcp2_mem *mem) {
- ngtcp2_cubic_cc *cubic_cc;
-
- cubic_cc = ngtcp2_mem_calloc(mem, 1, sizeof(ngtcp2_cubic_cc));
- if (cubic_cc == NULL) {
- return NGTCP2_ERR_NOMEM;
- }
-
- ngtcp2_cubic_cc_init(cubic_cc, log);
-
- cc->ccb = &cubic_cc->ccb;
- cc->on_pkt_acked = ngtcp2_cc_cubic_cc_on_pkt_acked;
- cc->congestion_event = ngtcp2_cc_cubic_cc_congestion_event;
- cc->on_spurious_congestion = ngtcp2_cc_cubic_cc_on_spurious_congestion;
- cc->on_persistent_congestion = ngtcp2_cc_cubic_cc_on_persistent_congestion;
- cc->on_ack_recv = ngtcp2_cc_cubic_cc_on_ack_recv;
- cc->on_pkt_sent = ngtcp2_cc_cubic_cc_on_pkt_sent;
- cc->new_rtt_sample = ngtcp2_cc_cubic_cc_new_rtt_sample;
- cc->reset = ngtcp2_cc_cubic_cc_reset;
- cc->event = ngtcp2_cc_cubic_cc_event;
-
- return 0;
-}
-
-void ngtcp2_cc_cubic_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem) {
- ngtcp2_cubic_cc *cubic_cc = ngtcp2_struct_of(cc->ccb, ngtcp2_cubic_cc, ccb);
-
- ngtcp2_cubic_cc_free(cubic_cc);
- ngtcp2_mem_free(mem, cubic_cc);
-}
-
-static uint64_t ngtcp2_cbrt(uint64_t n) {
+uint64_t ngtcp2_cbrt(uint64_t n) {
int d;
uint64_t a;
@@ -271,26 +231,23 @@ static uint64_t ngtcp2_cbrt(uint64_t n) {
}
#if defined(_MSC_VER)
-# if defined(_M_X64)
- d = (int)__lzcnt64(n);
-# elif defined(_M_ARM64)
{
unsigned long index;
- d = sizeof(uint64_t) * CHAR_BIT;
+# if defined(_WIN64)
if (_BitScanReverse64(&index, n)) {
- d = d - 1 - index;
+ d = 61 - index;
}
+# else /* !defined(_WIN64) */
+ if (_BitScanReverse(&index, (unsigned int)(n >> 32))) {
+ d = 31 - index;
+ } else {
+ d = 32 + 31 - _BitScanReverse(&index, (unsigned int)n);
+ }
+# endif /* !defined(_WIN64) */
}
-# else
- if ((n >> 32) != 0) {
- d = __lzcnt((unsigned int)(n >> 32));
- } else {
- d = 32 + __lzcnt((unsigned int)n);
- }
-# endif
-#else
+#else /* !defined(_MSC_VER) */
d = __builtin_clzll(n);
-#endif
+#endif /* !defined(_MSC_VER) */
a = 1ULL << ((64 - d) / 3 + 1);
for (; a * a * a > n;) {
@@ -305,19 +262,19 @@ static uint64_t ngtcp2_cbrt(uint64_t n) {
#define NGTCP2_HS_MIN_ETA (4 * NGTCP2_MILLISECONDS)
#define NGTCP2_HS_MAX_ETA (16 * NGTCP2_MILLISECONDS)
-void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt,
ngtcp2_tstamp ts) {
- ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
+ ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
ngtcp2_duration t, eta;
uint64_t target, cwnd_thres;
uint64_t tx, kx, time_delta, delta;
uint64_t add, tcp_add;
uint64_t m;
- if (pkt->pktns_id == NGTCP2_PKTNS_ID_APPLICATION && cc->window_end != -1 &&
- cc->window_end <= pkt->pkt_num) {
- cc->window_end = -1;
+ if (pkt->pktns_id == NGTCP2_PKTNS_ID_APPLICATION && cubic->window_end != -1 &&
+ cubic->window_end <= pkt->pkt_num) {
+ cubic->window_end = -1;
}
if (in_congestion_recovery(cstat, pkt->sent_ts)) {
@@ -326,20 +283,20 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
if (cstat->cwnd < cstat->ssthresh) {
/* slow-start */
- if (cc->target_cwnd == 0 || cc->target_cwnd > cstat->cwnd) {
+ if (cubic->target_cwnd == 0 || cubic->target_cwnd > cstat->cwnd) {
cstat->cwnd += pkt->pktlen;
}
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_RCV,
"pkn=%" PRId64 " acked, slow start cwnd=%" PRIu64,
pkt->pkt_num, cstat->cwnd);
- if (cc->last_round_min_rtt != UINT64_MAX &&
- cc->current_round_min_rtt != UINT64_MAX &&
+ if (cubic->last_round_min_rtt != UINT64_MAX &&
+ cubic->current_round_min_rtt != UINT64_MAX &&
cstat->cwnd >=
NGTCP2_HS_MIN_SSTHRESH * cstat->max_tx_udp_payload_size &&
- cc->rtt_sample_count >= NGTCP2_HS_N_RTT_SAMPLE) {
- eta = cc->last_round_min_rtt / 8;
+ cubic->rtt_sample_count >= NGTCP2_HS_N_RTT_SAMPLE) {
+ eta = cubic->last_round_min_rtt / 8;
if (eta < NGTCP2_HS_MIN_ETA) {
eta = NGTCP2_HS_MIN_ETA;
@@ -347,11 +304,11 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
eta = NGTCP2_HS_MAX_ETA;
}
- if (cc->current_round_min_rtt >= cc->last_round_min_rtt + eta) {
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ if (cubic->current_round_min_rtt >= cubic->last_round_min_rtt + eta) {
+ ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_RCV,
"HyStart++ exit slow start");
- cc->w_last_max = cstat->cwnd;
+ cubic->w_last_max = cstat->cwnd;
cstat->ssthresh = cstat->cwnd;
}
}
@@ -361,32 +318,32 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
/* congestion avoidance */
- if (cc->epoch_start == UINT64_MAX) {
- cc->epoch_start = ts;
- if (cstat->cwnd < cc->w_last_max) {
- cc->k = ngtcp2_cbrt((cc->w_last_max - cstat->cwnd) * 10 / 4 /
- cstat->max_tx_udp_payload_size);
- cc->origin_point = cc->w_last_max;
+ if (cubic->epoch_start == UINT64_MAX) {
+ cubic->epoch_start = ts;
+ if (cstat->cwnd < cubic->w_last_max) {
+ cubic->k = ngtcp2_cbrt((cubic->w_last_max - cstat->cwnd) * 10 / 4 /
+ cstat->max_tx_udp_payload_size);
+ cubic->origin_point = cubic->w_last_max;
} else {
- cc->k = 0;
- cc->origin_point = cstat->cwnd;
+ cubic->k = 0;
+ cubic->origin_point = cstat->cwnd;
}
- cc->w_tcp = cstat->cwnd;
+ cubic->w_tcp = cstat->cwnd;
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_RCV,
"cubic-ca epoch_start=%" PRIu64 " k=%" PRIu64
" origin_point=%" PRIu64,
- cc->epoch_start, cc->k, cc->origin_point);
+ cubic->epoch_start, cubic->k, cubic->origin_point);
- cc->pending_add = 0;
- cc->pending_w_add = 0;
+ cubic->pending_add = 0;
+ cubic->pending_w_add = 0;
}
- t = ts - cc->epoch_start;
+ t = ts - cubic->epoch_start;
tx = (t << 10) / NGTCP2_SECONDS;
- kx = (cc->k << 10);
+ kx = (cubic->k << 10);
if (tx > kx) {
time_delta = tx - kx;
@@ -399,9 +356,19 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
delta >>= 10;
if (tx > kx) {
- target = cc->origin_point + delta;
+ target = cubic->origin_point + delta;
} else {
- target = cc->origin_point - delta;
+ target = cubic->origin_point - delta;
+ }
+
+ cwnd_thres =
+ (target * (((t + cstat->smoothed_rtt) << 10) / NGTCP2_SECONDS)) >> 10;
+ if (cwnd_thres < cstat->cwnd) {
+ target = cstat->cwnd;
+ } else if (2 * cwnd_thres > 3 * cstat->cwnd) {
+ target = cstat->cwnd * 3 / 2;
+ } else {
+ target = cwnd_thres;
}
cwnd_thres =
@@ -415,69 +382,68 @@ void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
}
if (target > cstat->cwnd) {
- m = cc->pending_add +
+ m = cubic->pending_add +
cstat->max_tx_udp_payload_size * (target - cstat->cwnd);
add = m / cstat->cwnd;
- cc->pending_add = m % cstat->cwnd;
+ cubic->pending_add = m % cstat->cwnd;
} else {
- m = cc->pending_add + cstat->max_tx_udp_payload_size;
+ m = cubic->pending_add + cstat->max_tx_udp_payload_size;
add = m / (100 * cstat->cwnd);
- cc->pending_add = m % (100 * cstat->cwnd);
+ cubic->pending_add = m % (100 * cstat->cwnd);
}
- m = cc->pending_w_add + cstat->max_tx_udp_payload_size * pkt->pktlen;
+ m = cubic->pending_w_add + cstat->max_tx_udp_payload_size * pkt->pktlen;
- cc->w_tcp += m / cstat->cwnd;
- cc->pending_w_add = m % cstat->cwnd;
+ cubic->w_tcp += m / cstat->cwnd;
+ cubic->pending_w_add = m % cstat->cwnd;
- if (cc->w_tcp > cstat->cwnd) {
- tcp_add = cstat->max_tx_udp_payload_size * (cc->w_tcp - cstat->cwnd) /
+ if (cubic->w_tcp > cstat->cwnd) {
+ tcp_add = cstat->max_tx_udp_payload_size * (cubic->w_tcp - cstat->cwnd) /
cstat->cwnd;
if (tcp_add > add) {
add = tcp_add;
}
}
- if (cc->target_cwnd == 0 || cc->target_cwnd > cstat->cwnd) {
+ if (cubic->target_cwnd == 0 || cubic->target_cwnd > cstat->cwnd) {
cstat->cwnd += add;
}
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_RCV,
"pkn=%" PRId64 " acked, cubic-ca cwnd=%" PRIu64 " t=%" PRIu64
" k=%" PRIi64 " time_delta=%" PRIu64 " delta=%" PRIu64
" target=%" PRIu64 " w_tcp=%" PRIu64,
- pkt->pkt_num, cstat->cwnd, t, cc->k, time_delta >> 4, delta,
- target, cc->w_tcp);
+ pkt->pkt_num, cstat->cwnd, t, cubic->k, time_delta >> 4,
+ delta, target, cubic->w_tcp);
}
-void ngtcp2_cc_cubic_cc_congestion_event(ngtcp2_cc *ccx,
- ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_cubic_cc_congestion_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp sent_ts,
ngtcp2_tstamp ts) {
- ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
+ ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
uint64_t min_cwnd;
if (in_congestion_recovery(cstat, sent_ts)) {
return;
}
- if (cc->prior.cwnd < cstat->cwnd) {
- cc->prior.cwnd = cstat->cwnd;
- cc->prior.ssthresh = cstat->ssthresh;
- cc->prior.w_last_max = cc->w_last_max;
- cc->prior.w_tcp = cc->w_tcp;
- cc->prior.origin_point = cc->origin_point;
- cc->prior.epoch_start = cc->epoch_start;
- cc->prior.k = cc->k;
+ if (cubic->prior.cwnd < cstat->cwnd) {
+ cubic->prior.cwnd = cstat->cwnd;
+ cubic->prior.ssthresh = cstat->ssthresh;
+ cubic->prior.w_last_max = cubic->w_last_max;
+ cubic->prior.w_tcp = cubic->w_tcp;
+ cubic->prior.origin_point = cubic->origin_point;
+ cubic->prior.epoch_start = cubic->epoch_start;
+ cubic->prior.k = cubic->k;
}
cstat->congestion_recovery_start_ts = ts;
- cc->epoch_start = UINT64_MAX;
- if (cstat->cwnd < cc->w_last_max) {
- cc->w_last_max = cstat->cwnd * 17 / 10 / 2;
+ cubic->epoch_start = UINT64_MAX;
+ if (cstat->cwnd < cubic->w_last_max) {
+ cubic->w_last_max = cstat->cwnd * 17 / 10 / 2;
} else {
- cc->w_last_max = cstat->cwnd;
+ cubic->w_last_max = cstat->cwnd;
}
min_cwnd = 2 * cstat->max_tx_udp_payload_size;
@@ -485,134 +451,136 @@ void ngtcp2_cc_cubic_cc_congestion_event(ngtcp2_cc *ccx,
cstat->ssthresh = ngtcp2_max(cstat->ssthresh, min_cwnd);
cstat->cwnd = cstat->ssthresh;
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_RCV,
"reduce cwnd because of packet loss cwnd=%" PRIu64,
cstat->cwnd);
}
-void ngtcp2_cc_cubic_cc_on_spurious_congestion(ngtcp2_cc *ccx,
+void ngtcp2_cc_cubic_cc_on_spurious_congestion(ngtcp2_cc *cc,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
+ ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
(void)ts;
- if (cstat->cwnd >= cc->prior.cwnd) {
+ if (cstat->cwnd >= cubic->prior.cwnd) {
return;
}
cstat->congestion_recovery_start_ts = UINT64_MAX;
- cstat->cwnd = cc->prior.cwnd;
- cstat->ssthresh = cc->prior.ssthresh;
- cc->w_last_max = cc->prior.w_last_max;
- cc->w_tcp = cc->prior.w_tcp;
- cc->origin_point = cc->prior.origin_point;
- cc->epoch_start = cc->prior.epoch_start;
- cc->k = cc->prior.k;
-
- cc->prior.cwnd = 0;
- cc->prior.ssthresh = 0;
- cc->prior.w_last_max = 0;
- cc->prior.w_tcp = 0;
- cc->prior.origin_point = 0;
- cc->prior.epoch_start = UINT64_MAX;
- cc->prior.k = 0;
-
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ cstat->cwnd = cubic->prior.cwnd;
+ cstat->ssthresh = cubic->prior.ssthresh;
+ cubic->w_last_max = cubic->prior.w_last_max;
+ cubic->w_tcp = cubic->prior.w_tcp;
+ cubic->origin_point = cubic->prior.origin_point;
+ cubic->epoch_start = cubic->prior.epoch_start;
+ cubic->k = cubic->prior.k;
+
+ cubic->prior.cwnd = 0;
+ cubic->prior.ssthresh = 0;
+ cubic->prior.w_last_max = 0;
+ cubic->prior.w_tcp = 0;
+ cubic->prior.origin_point = 0;
+ cubic->prior.epoch_start = UINT64_MAX;
+ cubic->prior.k = 0;
+
+ ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_RCV,
"spurious congestion is detected and congestion state is "
"restored cwnd=%" PRIu64,
cstat->cwnd);
}
-void ngtcp2_cc_cubic_cc_on_persistent_congestion(ngtcp2_cc *ccx,
+void ngtcp2_cc_cubic_cc_on_persistent_congestion(ngtcp2_cc *cc,
ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- (void)ccx;
+ (void)cc;
(void)ts;
cstat->cwnd = 2 * cstat->max_tx_udp_payload_size;
cstat->congestion_recovery_start_ts = UINT64_MAX;
}
-void ngtcp2_cc_cubic_cc_on_ack_recv(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_cubic_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_ack *ack,
ngtcp2_tstamp ts) {
- ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
+ ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
uint64_t target_cwnd, initcwnd;
(void)ack;
(void)ts;
/* TODO Use sliding window for min rtt measurement */
/* TODO Use sliding window */
- cc->max_delivery_rate_sec =
- ngtcp2_max(cc->max_delivery_rate_sec, cstat->delivery_rate_sec);
+ cubic->max_delivery_rate_sec =
+ ngtcp2_max(cubic->max_delivery_rate_sec, cstat->delivery_rate_sec);
- if (cstat->min_rtt != UINT64_MAX && cc->max_delivery_rate_sec) {
+ if (cstat->min_rtt != UINT64_MAX && cubic->max_delivery_rate_sec) {
target_cwnd =
- cc->max_delivery_rate_sec * cstat->smoothed_rtt / NGTCP2_SECONDS;
+ cubic->max_delivery_rate_sec * cstat->smoothed_rtt / NGTCP2_SECONDS;
initcwnd = ngtcp2_cc_compute_initcwnd(cstat->max_tx_udp_payload_size);
- cc->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100;
+ cubic->target_cwnd = ngtcp2_max(initcwnd, target_cwnd) * 289 / 100;
- ngtcp2_log_info(cc->ccb.log, NGTCP2_LOG_EVENT_RCV,
+ ngtcp2_log_info(cubic->cc.log, NGTCP2_LOG_EVENT_RCV,
"target_cwnd=%" PRIu64 " max_delivery_rate_sec=%" PRIu64
- " min_rtt=%" PRIu64,
- cc->target_cwnd, cc->max_delivery_rate_sec, cstat->min_rtt);
+ " smoothed_rtt=%" PRIu64,
+ cubic->target_cwnd, cubic->max_delivery_rate_sec,
+ cstat->smoothed_rtt);
}
}
-void ngtcp2_cc_cubic_cc_on_pkt_sent(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_cubic_cc_on_pkt_sent(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt) {
- ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
+ ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
(void)cstat;
- if (pkt->pktns_id != NGTCP2_PKTNS_ID_APPLICATION || cc->window_end != -1) {
+ if (pkt->pktns_id != NGTCP2_PKTNS_ID_APPLICATION || cubic->window_end != -1) {
return;
}
- cc->window_end = pkt->pkt_num;
- cc->last_round_min_rtt = cc->current_round_min_rtt;
- cc->current_round_min_rtt = UINT64_MAX;
- cc->rtt_sample_count = 0;
+ cubic->window_end = pkt->pkt_num;
+ cubic->last_round_min_rtt = cubic->current_round_min_rtt;
+ cubic->current_round_min_rtt = UINT64_MAX;
+ cubic->rtt_sample_count = 0;
}
-void ngtcp2_cc_cubic_cc_new_rtt_sample(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_cubic_cc_new_rtt_sample(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
+ ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
(void)ts;
- if (cc->window_end == -1) {
+ if (cubic->window_end == -1) {
return;
}
- cc->current_round_min_rtt =
- ngtcp2_min(cc->current_round_min_rtt, cstat->latest_rtt);
- ++cc->rtt_sample_count;
+ cubic->current_round_min_rtt =
+ ngtcp2_min(cubic->current_round_min_rtt, cstat->latest_rtt);
+ ++cubic->rtt_sample_count;
}
-void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts) {
- ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
+ ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
(void)cstat;
(void)ts;
- cubic_cc_reset(cc);
+ cubic_cc_reset(cubic);
}
-void ngtcp2_cc_cubic_cc_event(ngtcp2_cc *ccx, ngtcp2_conn_stat *cstat,
+void ngtcp2_cc_cubic_cc_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_cc_event_type event, ngtcp2_tstamp ts) {
- ngtcp2_cubic_cc *cc = ngtcp2_struct_of(ccx->ccb, ngtcp2_cubic_cc, ccb);
+ ngtcp2_cc_cubic *cubic = ngtcp2_struct_of(cc, ngtcp2_cc_cubic, cc);
ngtcp2_tstamp last_ts;
- if (event != NGTCP2_CC_EVENT_TYPE_TX_START || cc->epoch_start == UINT64_MAX) {
+ if (event != NGTCP2_CC_EVENT_TYPE_TX_START ||
+ cubic->epoch_start == UINT64_MAX) {
return;
}
last_ts = cstat->last_tx_pkt_ts[NGTCP2_PKTNS_ID_APPLICATION];
- if (last_ts == UINT64_MAX || last_ts <= cc->epoch_start) {
+ if (last_ts == UINT64_MAX || last_ts <= cubic->epoch_start) {
return;
}
assert(ts >= last_ts);
- cc->epoch_start += ts - last_ts;
+ cubic->epoch_start += ts - last_ts;
}
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.h b/deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.h
index e8d1b747b8..4e47695032 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.h
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_cc.h
@@ -40,20 +40,6 @@ typedef struct ngtcp2_conn_stat ngtcp2_conn_stat;
/**
* @struct
*
- * :type:`ngtcp2_cc_base` is the base structure of custom congestion
- * control algorithm. It must be the first field of custom congestion
- * controller.
- */
-typedef struct ngtcp2_cc_base {
- /**
- * :member:`log` is ngtcp2 library internal logger.
- */
- ngtcp2_log *log;
-} ngtcp2_cc_base;
-
-/**
- * @struct
- *
* :type:`ngtcp2_cc_pkt` is a convenient structure to include
* acked/lost/sent packet.
*/
@@ -243,15 +229,14 @@ typedef void (*ngtcp2_cc_event)(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
/**
* @struct
*
- * :type:`ngtcp2_cc` is congestion control algorithm interface to
- * allow custom implementation.
+ * :type:`ngtcp2_cc` is congestion control algorithm interface shared
+ * by implementations. All callback functions are optional.
*/
typedef struct ngtcp2_cc {
/**
- * :member:`ccb` is a pointer to :type:`ngtcp2_cc_base` which
- * usually contains a state.
+ * :member:`log` is ngtcp2 library internal logger.
*/
- ngtcp2_cc_base *ccb;
+ ngtcp2_log *log;
/**
* :member:`on_pkt_acked` is a callback function which is called
* when a packet is acknowledged.
@@ -314,22 +299,15 @@ ngtcp2_cc_pkt *ngtcp2_cc_pkt_init(ngtcp2_cc_pkt *pkt, int64_t pkt_num,
ngtcp2_tstamp sent_ts, uint64_t lost,
uint64_t tx_in_flight, int is_app_limited);
-/* ngtcp2_reno_cc is the RENO congestion controller. */
-typedef struct ngtcp2_reno_cc {
- ngtcp2_cc_base ccb;
+/* ngtcp2_cc_reno is the RENO congestion controller. */
+typedef struct ngtcp2_cc_reno {
+ ngtcp2_cc cc;
uint64_t max_delivery_rate_sec;
uint64_t target_cwnd;
uint64_t pending_add;
-} ngtcp2_reno_cc;
-
-int ngtcp2_cc_reno_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
- const ngtcp2_mem *mem);
-
-void ngtcp2_cc_reno_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem);
-
-void ngtcp2_reno_cc_init(ngtcp2_reno_cc *cc, ngtcp2_log *log);
+} ngtcp2_cc_reno;
-void ngtcp2_reno_cc_free(ngtcp2_reno_cc *cc);
+void ngtcp2_cc_reno_init(ngtcp2_cc_reno *reno, ngtcp2_log *log);
void ngtcp2_cc_reno_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt, ngtcp2_tstamp ts);
@@ -348,9 +326,9 @@ void ngtcp2_cc_reno_cc_on_ack_recv(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
void ngtcp2_cc_reno_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_tstamp ts);
-/* ngtcp2_cubic_cc is CUBIC congestion controller. */
-typedef struct ngtcp2_cubic_cc {
- ngtcp2_cc_base ccb;
+/* ngtcp2_cc_cubic is CUBIC congestion controller. */
+typedef struct ngtcp2_cc_cubic {
+ ngtcp2_cc cc;
uint64_t max_delivery_rate_sec;
uint64_t target_cwnd;
uint64_t w_last_max;
@@ -377,16 +355,9 @@ typedef struct ngtcp2_cubic_cc {
int64_t window_end;
uint64_t pending_add;
uint64_t pending_w_add;
-} ngtcp2_cubic_cc;
+} ngtcp2_cc_cubic;
-int ngtcp2_cc_cubic_cc_init(ngtcp2_cc *cc, ngtcp2_log *log,
- const ngtcp2_mem *mem);
-
-void ngtcp2_cc_cubic_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem);
-
-void ngtcp2_cubic_cc_init(ngtcp2_cubic_cc *cc, ngtcp2_log *log);
-
-void ngtcp2_cubic_cc_free(ngtcp2_cubic_cc *cc);
+void ngtcp2_cc_cubic_init(ngtcp2_cc_cubic *cc, ngtcp2_log *log);
void ngtcp2_cc_cubic_cc_on_pkt_acked(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
const ngtcp2_cc_pkt *pkt,
@@ -419,4 +390,6 @@ void ngtcp2_cc_cubic_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
void ngtcp2_cc_cubic_cc_event(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat,
ngtcp2_cc_event_type event, ngtcp2_tstamp ts);
+uint64_t ngtcp2_cbrt(uint64_t n);
+
#endif /* NGTCP2_CC_H */
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.c b/deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.c
index 6e9c41b7e8..2874a5c608 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.c
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.c
@@ -64,11 +64,11 @@ static int conn_local_stream(ngtcp2_conn *conn, int64_t stream_id) {
static int bidi_stream(int64_t stream_id) { return (stream_id & 0x2) == 0; }
/*
- * conn_is_handshake_completed returns nonzero if QUIC handshake has
- * completed.
+ * conn_is_tls_handshake_completed returns nonzero if TLS handshake
+ * has completed and 1 RTT keys are available.
*/
-static int conn_is_handshake_completed(ngtcp2_conn *conn) {
- return (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED) &&
+static int conn_is_tls_handshake_completed(ngtcp2_conn *conn) {
+ return (conn->flags & NGTCP2_CONN_FLAG_TLS_HANDSHAKE_COMPLETED) &&
conn->pktns.crypto.rx.ckm && conn->pktns.crypto.tx.ckm;
}
@@ -270,6 +270,7 @@ static int conn_call_path_validation(ngtcp2_conn *conn, const ngtcp2_pv *pv,
ngtcp2_path_validation_result res) {
int rv;
uint32_t flags = NGTCP2_PATH_VALIDATION_FLAG_NONE;
+ const ngtcp2_path *old_path = NULL;
if (!conn->callbacks.path_validation) {
return 0;
@@ -279,12 +280,18 @@ static int conn_call_path_validation(ngtcp2_conn *conn, const ngtcp2_pv *pv,
flags |= NGTCP2_PATH_VALIDATION_FLAG_PREFERRED_ADDR;
}
- rv = conn->callbacks.path_validation(
- conn, flags, &pv->dcid.ps.path,
- (pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE)
- ? &pv->fallback_dcid.ps.path
- : NULL,
- res, conn->user_data);
+ if (pv->flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE) {
+ old_path = &pv->fallback_dcid.ps.path;
+ }
+
+ if (conn->server && old_path &&
+ (ngtcp2_addr_compare(&pv->dcid.ps.path.remote, &old_path->remote) &
+ (NGTCP2_ADDR_COMPARE_FLAG_ADDR | NGTCP2_ADDR_COMPARE_FLAG_FAMILY))) {
+ flags |= NGTCP2_PATH_VALIDATION_FLAG_NEW_TOKEN;
+ }
+
+ rv = conn->callbacks.path_validation(conn, flags, &pv->dcid.ps.path, old_path,
+ res, conn->user_data);
if (rv != 0) {
return NGTCP2_ERR_CALLBACK_FAILURE;
}
@@ -376,7 +383,7 @@ static int conn_call_dcid_status(ngtcp2_conn *conn,
}
rv = conn->callbacks.dcid_status(
- conn, (int)type, dcid->seq, &dcid->cid,
+ conn, type, dcid->seq, &dcid->cid,
(dcid->flags & NGTCP2_DCID_FLAG_TOKEN_PRESENT) ? dcid->token : NULL,
conn->user_data);
if (rv != 0) {
@@ -564,7 +571,7 @@ static int conn_call_recv_datagram(ngtcp2_conn *conn,
datalen = 0;
}
- if (!conn_is_handshake_completed(conn)) {
+ if (!conn_is_tls_handshake_completed(conn)) {
flags |= NGTCP2_DATAGRAM_FLAG_EARLY;
}
@@ -772,26 +779,6 @@ static void pktns_del(ngtcp2_pktns *pktns, const ngtcp2_mem *mem) {
ngtcp2_mem_free(mem, pktns);
}
-static void cc_del(ngtcp2_cc *cc, ngtcp2_cc_algo cc_algo,
- const ngtcp2_mem *mem) {
- switch (cc_algo) {
- case NGTCP2_CC_ALGO_RENO:
- ngtcp2_cc_reno_cc_free(cc, mem);
- break;
- case NGTCP2_CC_ALGO_CUBIC:
- ngtcp2_cc_cubic_cc_free(cc, mem);
- break;
- case NGTCP2_CC_ALGO_BBR:
- ngtcp2_cc_bbr_cc_free(cc, mem);
- break;
- case NGTCP2_CC_ALGO_BBR2:
- ngtcp2_cc_bbr2_cc_free(cc, mem);
- break;
- default:
- break;
- }
-}
-
static int cid_less(const ngtcp2_ksl_key *lhs, const ngtcp2_ksl_key *rhs) {
return ngtcp2_cid_less(lhs, rhs);
}
@@ -1185,32 +1172,24 @@ static int conn_new(ngtcp2_conn **pconn, const ngtcp2_cid *dcid,
switch (settings->cc_algo) {
case NGTCP2_CC_ALGO_RENO:
- rv = ngtcp2_cc_reno_cc_init(&(*pconn)->cc, &(*pconn)->log, mem);
- if (rv != 0) {
- goto fail_cc_init;
- }
+ ngtcp2_cc_reno_init(&(*pconn)->reno, &(*pconn)->log);
+
break;
case NGTCP2_CC_ALGO_CUBIC:
- rv = ngtcp2_cc_cubic_cc_init(&(*pconn)->cc, &(*pconn)->log, mem);
- if (rv != 0) {
- goto fail_cc_init;
- }
+ ngtcp2_cc_cubic_init(&(*pconn)->cubic, &(*pconn)->log);
+
break;
case NGTCP2_CC_ALGO_BBR:
- rv = ngtcp2_cc_bbr_cc_init(&(*pconn)->cc, &(*pconn)->log, &(*pconn)->cstat,
- &(*pconn)->rst, settings->initial_ts,
- callbacks->rand, &settings->rand_ctx, mem);
- if (rv != 0) {
- goto fail_cc_init;
- }
+ ngtcp2_cc_bbr_init(&(*pconn)->bbr, &(*pconn)->log, &(*pconn)->cstat,
+ &(*pconn)->rst, settings->initial_ts, callbacks->rand,
+ &settings->rand_ctx);
+
break;
case NGTCP2_CC_ALGO_BBR2:
- rv = ngtcp2_cc_bbr2_cc_init(&(*pconn)->cc, &(*pconn)->log, &(*pconn)->cstat,
- &(*pconn)->rst, settings->initial_ts,
- callbacks->rand, &settings->rand_ctx, mem);
- if (rv != 0) {
- goto fail_cc_init;
- }
+ ngtcp2_cc_bbr2_init(&(*pconn)->bbr2, &(*pconn)->log, &(*pconn)->cstat,
+ &(*pconn)->rst, settings->initial_ts, callbacks->rand,
+ &settings->rand_ctx);
+
break;
default:
ngtcp2_unreachable();
@@ -1382,8 +1361,6 @@ fail_pktns_init:
fail_hs_pktns_init:
pktns_del((*pconn)->in_pktns, mem);
fail_in_pktns_init:
- cc_del(&(*pconn)->cc, settings->cc_algo, mem);
-fail_cc_init:
ngtcp2_mem_free(mem, (uint8_t *)(*pconn)->local.settings.token);
fail_token:
ngtcp2_mem_free(mem, (*pconn)->qlog.buf.begin);
@@ -1594,8 +1571,6 @@ void ngtcp2_conn_del(ngtcp2_conn *conn) {
pktns_del(conn->hs_pktns, conn->mem);
pktns_del(conn->in_pktns, conn->mem);
- cc_del(&conn->cc, conn->cc_algo, conn->mem);
-
ngtcp2_mem_free(conn->mem, conn->qlog.buf.begin);
ngtcp2_pmtud_del(conn->pmtud);
@@ -3569,7 +3544,7 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
/* transport parameter is only valid after handshake completion
which means we don't know how many connection ID that remote
peer can accept before handshake completion. */
- if (conn->oscid.datalen && conn_is_handshake_completed(conn)) {
+ if (conn->oscid.datalen && conn_is_tls_handshake_completed(conn)) {
rv = conn_enqueue_new_connection_id(conn);
if (rv != 0) {
return rv;
@@ -4469,7 +4444,8 @@ ngtcp2_ssize ngtcp2_conn_write_single_frame_pkt(
if (((rtb_entry_flags & NGTCP2_RTB_ENTRY_FLAG_ACK_ELICITING) || padded) &&
(!path || ngtcp2_path_eq(&conn->dcid.current.ps.path, path))) {
- if (pi && !(rtb_entry_flags & NGTCP2_RTB_ENTRY_FLAG_PMTUD_PROBE)) {
+ if (pi && (conn->tx.ecn.state == NGTCP2_ECN_STATE_CAPABLE ||
+ !(rtb_entry_flags & NGTCP2_RTB_ENTRY_FLAG_PMTUD_PROBE))) {
conn_handle_tx_ecn(conn, pi, &rtb_entry_flags, pktns, &hd, ts);
}
@@ -4500,8 +4476,7 @@ ngtcp2_ssize ngtcp2_conn_write_single_frame_pkt(
nwrite);
}
}
- } else if (pi && !(rtb_entry_flags & NGTCP2_RTB_ENTRY_FLAG_PMTUD_PROBE) &&
- conn->tx.ecn.state == NGTCP2_ECN_STATE_CAPABLE) {
+ } else if (pi && conn->tx.ecn.state == NGTCP2_ECN_STATE_CAPABLE) {
conn_handle_tx_ecn(conn, pi, NULL, pktns, &hd, ts);
}
@@ -4560,7 +4535,7 @@ static int conn_handshake_remnants_left(ngtcp2_conn *conn) {
ngtcp2_pktns *in_pktns = conn->in_pktns;
ngtcp2_pktns *hs_pktns = conn->hs_pktns;
- return !conn_is_handshake_completed(conn) ||
+ return !conn_is_tls_handshake_completed(conn) ||
(in_pktns && (in_pktns->rtb.num_pto_eliciting ||
ngtcp2_ksl_len(&in_pktns->crypto.tx.frq))) ||
(hs_pktns && (hs_pktns->rtb.num_pto_eliciting ||
@@ -4715,7 +4690,7 @@ static int conn_start_pmtud(ngtcp2_conn *conn) {
assert(!conn->local.settings.no_pmtud);
assert(!conn->pmtud);
- assert(conn_is_handshake_completed(conn));
+ assert(conn_is_tls_handshake_completed(conn));
assert(conn->remote.transport_params);
assert(conn->remote.transport_params->max_udp_payload_size >=
NGTCP2_MAX_UDP_PAYLOAD_SIZE);
@@ -5841,13 +5816,13 @@ static int conn_emit_pending_crypto_data(ngtcp2_conn *conn,
*/
static int conn_recv_connection_close(ngtcp2_conn *conn,
ngtcp2_connection_close *fr) {
- ngtcp2_connection_close_error *ccerr = &conn->rx.ccerr;
+ ngtcp2_ccerr *ccerr = &conn->rx.ccerr;
conn->state = NGTCP2_CS_DRAINING;
if (fr->type == NGTCP2_FRAME_CONNECTION_CLOSE) {
- ccerr->type = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT;
+ ccerr->type = NGTCP2_CCERR_TYPE_TRANSPORT;
} else {
- ccerr->type = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION;
+ ccerr->type = NGTCP2_CCERR_TYPE_APPLICATION;
}
ccerr->error_code = fr->error_code;
ccerr->frame_type = fr->frame_type;
@@ -5859,15 +5834,13 @@ static int conn_recv_connection_close(ngtcp2_conn *conn,
}
if (ccerr->reason == NULL) {
- ccerr->reason = ngtcp2_mem_malloc(
- conn->mem, NGTCP2_CONNECTION_CLOSE_ERROR_MAX_REASONLEN);
+ ccerr->reason = ngtcp2_mem_malloc(conn->mem, NGTCP2_CCERR_MAX_REASONLEN);
if (ccerr->reason == NULL) {
return NGTCP2_ERR_NOMEM;
}
}
- ccerr->reasonlen =
- ngtcp2_min(fr->reasonlen, NGTCP2_CONNECTION_CLOSE_ERROR_MAX_REASONLEN);
+ ccerr->reasonlen = ngtcp2_min(fr->reasonlen, NGTCP2_CCERR_MAX_REASONLEN);
ngtcp2_cpymem((uint8_t *)ccerr->reason, fr->reason, ccerr->reasonlen);
return 0;
@@ -5897,7 +5870,9 @@ static void conn_recv_path_challenge(ngtcp2_conn *conn, const ngtcp2_path *path,
static void conn_reset_congestion_state(ngtcp2_conn *conn, ngtcp2_tstamp ts) {
conn_reset_conn_stat_cc(conn, &conn->cstat);
- conn->cc.reset(&conn->cc, &conn->cstat, ts);
+ if (conn->cc.reset) {
+ conn->cc.reset(&conn->cc, &conn->cstat, ts);
+ }
if (conn->hs_pktns) {
ngtcp2_rtb_reset_cc_state(&conn->hs_pktns->rtb,
@@ -6238,7 +6213,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
/* Receiving Version Negotiation packet after getting Handshake
packet from server is invalid. */
- if (conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) {
+ if (conn->flags & NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED) {
return NGTCP2_ERR_DISCARD_PKT;
}
@@ -6274,7 +6249,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
/* Receiving Retry packet after getting Initial packet from server
is invalid. */
- if (conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) {
+ if (conn->flags & NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED) {
return NGTCP2_ERR_DISCARD_PKT;
}
@@ -6315,7 +6290,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
/* Quoted from spec: if subsequent packets of those types include a
different Source Connection ID, they MUST be discarded. */
- if ((conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) &&
+ if ((conn->flags & NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED) &&
!ngtcp2_cid_eq(&conn->dcid.current.cid, &hd.scid)) {
ngtcp2_log_rx_pkt_hd(&conn->log, &hd);
ngtcp2_log_info(&conn->log, NGTCP2_LOG_EVENT_PKT,
@@ -6333,7 +6308,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
return NGTCP2_ERR_DISCARD_PKT;
}
- if (conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) {
+ if (conn->flags & NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED) {
if (conn->early.ckm) {
ngtcp2_ssize nread2;
/* TODO Avoid to parse header twice. */
@@ -6388,7 +6363,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
return NGTCP2_ERR_DISCARD_PKT;
}
}
- if ((conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) == 0) {
+ if ((conn->flags & NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED) == 0) {
/* Set rcid here so that it is available to callback. If this
packet is discarded later in this function and no packet is
processed in this connection attempt so far, connection
@@ -6572,8 +6547,9 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
switch (hd.type) {
case NGTCP2_PKT_INITIAL:
- if (!conn->server || ((conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED) &&
- !ngtcp2_cid_eq(&conn->rcid, &hd.dcid))) {
+ if (!conn->server ||
+ ((conn->flags & NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED) &&
+ !ngtcp2_cid_eq(&conn->rcid, &hd.dcid))) {
rv = conn_verify_dcid(conn, NULL, &hd);
if (rv != 0) {
if (ngtcp2_err_is_fatal(rv)) {
@@ -6609,8 +6585,8 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
}
if (hd.type == NGTCP2_PKT_INITIAL &&
- !(conn->flags & NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED)) {
- conn->flags |= NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED;
+ !(conn->flags & NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED)) {
+ conn->flags |= NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED;
if (!conn->server) {
conn->dcid.current.cid = hd.scid;
}
@@ -6892,7 +6868,7 @@ static int conn_emit_pending_stream_data(ngtcp2_conn *conn, ngtcp2_strm *strm,
int rv;
uint64_t offset;
uint32_t sdflags;
- int handshake_completed = conn_is_handshake_completed(conn);
+ int handshake_completed = conn_is_tls_handshake_completed(conn);
if (!strm->rx.rob) {
return 0;
@@ -7236,7 +7212,7 @@ static int conn_recv_stream(ngtcp2_conn *conn, const ngtcp2_stream *fr) {
if (fin) {
sdflags |= NGTCP2_STREAM_DATA_FLAG_FIN;
}
- if (!conn_is_handshake_completed(conn)) {
+ if (!conn_is_tls_handshake_completed(conn)) {
sdflags |= NGTCP2_STREAM_DATA_FLAG_EARLY;
}
rv = conn_call_recv_stream_data(conn, strm, sdflags, offset, data,
@@ -9562,7 +9538,7 @@ static int conn_sync_stream_data_limit(ngtcp2_conn *conn) {
static int conn_handshake_completed(ngtcp2_conn *conn) {
int rv;
- conn->flags |= NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED;
+ conn->flags |= NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED;
rv = conn_call_handshake_completed(conn);
if (rv != 0) {
@@ -9731,8 +9707,8 @@ static ngtcp2_ssize conn_read_handshake(ngtcp2_conn *conn,
}
}
- if (conn_is_handshake_completed(conn) &&
- !(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED)) {
+ if (conn_is_tls_handshake_completed(conn) &&
+ !(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) {
rv = conn_handshake_completed(conn);
if (rv != 0) {
return rv;
@@ -9800,7 +9776,7 @@ static ngtcp2_ssize conn_read_handshake(ngtcp2_conn *conn,
conn_discard_initial_state(conn, ts);
}
- if (!conn_is_handshake_completed(conn)) {
+ if (!conn_is_tls_handshake_completed(conn)) {
/* If server hits amplification limit, it cancels loss detection
timer. If server receives a packet from client, the limit is
increased and server can send more. If server has
@@ -10144,7 +10120,7 @@ static ngtcp2_ssize conn_write_handshake(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
if (!conn_handshake_probe_left(conn) && conn_cwnd_is_zero(conn)) {
destlen = 0;
} else {
- if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED)) {
+ if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) {
pending_early_datalen = conn_retry_early_payloadlen(conn);
if (pending_early_datalen) {
write_datalen = pending_early_datalen;
@@ -10162,7 +10138,7 @@ static ngtcp2_ssize conn_write_handshake(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
destlen -= (size_t)nwrite;
}
- if (!conn_is_handshake_completed(conn)) {
+ if (!conn_is_tls_handshake_completed(conn)) {
if (!(conn->flags & NGTCP2_CONN_FLAG_EARLY_DATA_REJECTED)) {
nwrite = conn_retransmit_retry_early(conn, pi, dest, destlen,
NGTCP2_WRITE_PKT_FLAG_NONE, ts);
@@ -10184,6 +10160,10 @@ static ngtcp2_ssize conn_write_handshake(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
return res;
}
+ if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) {
+ return res;
+ }
+
if (!(conn->flags & NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED)) {
return NGTCP2_ERR_REQUIRED_TRANSPORT_PARAM;
}
@@ -10430,16 +10410,16 @@ static ngtcp2_ssize conn_client_write_handshake(ngtcp2_conn *conn,
return spktlen + early_spktlen;
}
-void ngtcp2_conn_handshake_completed(ngtcp2_conn *conn) {
- conn->flags |= NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED;
+void ngtcp2_conn_tls_handshake_completed(ngtcp2_conn *conn) {
+ conn->flags |= NGTCP2_CONN_FLAG_TLS_HANDSHAKE_COMPLETED;
if (conn->server) {
conn->flags |= NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED;
}
}
int ngtcp2_conn_get_handshake_completed(ngtcp2_conn *conn) {
- return conn_is_handshake_completed(conn) &&
- (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED);
+ return conn_is_tls_handshake_completed(conn) &&
+ (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED);
}
int ngtcp2_conn_sched_ack(ngtcp2_conn *conn, ngtcp2_acktr *acktr,
@@ -10939,7 +10919,7 @@ ngtcp2_tstamp ngtcp2_conn_ack_delay_expiry(ngtcp2_conn *conn) {
}
static ngtcp2_tstamp conn_handshake_expiry(ngtcp2_conn *conn) {
- if (conn_is_handshake_completed(conn) ||
+ if (conn_is_tls_handshake_completed(conn) ||
conn->local.settings.handshake_timeout == UINT64_MAX) {
return UINT64_MAX;
}
@@ -11020,7 +11000,7 @@ int ngtcp2_conn_handle_expiry(ngtcp2_conn *conn, ngtcp2_tstamp ts) {
}
}
- if (!conn_is_handshake_completed(conn) &&
+ if (!conn_is_tls_handshake_completed(conn) &&
conn->local.settings.handshake_timeout != UINT64_MAX &&
conn->local.settings.initial_ts +
conn->local.settings.handshake_timeout <=
@@ -12362,11 +12342,9 @@ ngtcp2_ssize ngtcp2_conn_write_application_close_pkt(
return res;
}
-static void
-connection_close_error_init(ngtcp2_connection_close_error *ccerr,
- ngtcp2_connection_close_error_code_type type,
- uint64_t error_code, const uint8_t *reason,
- size_t reasonlen) {
+static void ccerr_init(ngtcp2_ccerr *ccerr, ngtcp2_ccerr_type type,
+ uint64_t error_code, const uint8_t *reason,
+ size_t reasonlen) {
ccerr->type = type;
ccerr->error_code = error_code;
ccerr->frame_type = 0;
@@ -12374,72 +12352,61 @@ connection_close_error_init(ngtcp2_connection_close_error *ccerr,
ccerr->reasonlen = reasonlen;
}
-void ngtcp2_connection_close_error_default(
- ngtcp2_connection_close_error *ccerr) {
- connection_close_error_init(ccerr,
- NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT,
- NGTCP2_NO_ERROR, NULL, 0);
+void ngtcp2_ccerr_default(ngtcp2_ccerr *ccerr) {
+ ccerr_init(ccerr, NGTCP2_CCERR_TYPE_TRANSPORT, NGTCP2_NO_ERROR, NULL, 0);
}
-void ngtcp2_connection_close_error_set_transport_error(
- ngtcp2_connection_close_error *ccerr, uint64_t error_code,
- const uint8_t *reason, size_t reasonlen) {
- connection_close_error_init(ccerr,
- NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT,
- error_code, reason, reasonlen);
+void ngtcp2_ccerr_set_transport_error(ngtcp2_ccerr *ccerr, uint64_t error_code,
+ const uint8_t *reason, size_t reasonlen) {
+ ccerr_init(ccerr, NGTCP2_CCERR_TYPE_TRANSPORT, error_code, reason, reasonlen);
}
-void ngtcp2_connection_close_error_set_transport_error_liberr(
- ngtcp2_connection_close_error *ccerr, int liberr, const uint8_t *reason,
- size_t reasonlen) {
+void ngtcp2_ccerr_set_liberr(ngtcp2_ccerr *ccerr, int liberr,
+ const uint8_t *reason, size_t reasonlen) {
switch (liberr) {
case NGTCP2_ERR_RECV_VERSION_NEGOTIATION:
- connection_close_error_init(
- ccerr,
- NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_VERSION_NEGOTIATION,
- NGTCP2_NO_ERROR, reason, reasonlen);
+ ccerr_init(ccerr, NGTCP2_CCERR_TYPE_VERSION_NEGOTIATION, NGTCP2_NO_ERROR,
+ reason, reasonlen);
return;
case NGTCP2_ERR_IDLE_CLOSE:
- connection_close_error_init(
- ccerr, NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_IDLE_CLOSE,
- NGTCP2_NO_ERROR, reason, reasonlen);
+ ccerr_init(ccerr, NGTCP2_CCERR_TYPE_IDLE_CLOSE, NGTCP2_NO_ERROR, reason,
+ reasonlen);
return;
};
- ngtcp2_connection_close_error_set_transport_error(
+ ngtcp2_ccerr_set_transport_error(
ccerr, ngtcp2_err_infer_quic_transport_error_code(liberr), reason,
reasonlen);
}
-void ngtcp2_connection_close_error_set_transport_error_tls_alert(
- ngtcp2_connection_close_error *ccerr, uint8_t tls_alert,
- const uint8_t *reason, size_t reasonlen) {
- ngtcp2_connection_close_error_set_transport_error(
- ccerr, NGTCP2_CRYPTO_ERROR | tls_alert, reason, reasonlen);
+void ngtcp2_ccerr_set_tls_alert(ngtcp2_ccerr *ccerr, uint8_t tls_alert,
+ const uint8_t *reason, size_t reasonlen) {
+ ngtcp2_ccerr_set_transport_error(ccerr, NGTCP2_CRYPTO_ERROR | tls_alert,
+ reason, reasonlen);
}
-void ngtcp2_connection_close_error_set_application_error(
- ngtcp2_connection_close_error *ccerr, uint64_t error_code,
- const uint8_t *reason, size_t reasonlen) {
- connection_close_error_init(
- ccerr, NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION, error_code,
- reason, reasonlen);
+void ngtcp2_ccerr_set_application_error(ngtcp2_ccerr *ccerr,
+ uint64_t error_code,
+ const uint8_t *reason,
+ size_t reasonlen) {
+ ccerr_init(ccerr, NGTCP2_CCERR_TYPE_APPLICATION, error_code, reason,
+ reasonlen);
}
ngtcp2_ssize ngtcp2_conn_write_connection_close_versioned(
ngtcp2_conn *conn, ngtcp2_path *path, int pkt_info_version,
ngtcp2_pkt_info *pi, uint8_t *dest, size_t destlen,
- const ngtcp2_connection_close_error *ccerr, ngtcp2_tstamp ts) {
+ const ngtcp2_ccerr *ccerr, ngtcp2_tstamp ts) {
(void)pkt_info_version;
switch (ccerr->type) {
- case NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT:
+ case NGTCP2_CCERR_TYPE_TRANSPORT:
return ngtcp2_conn_write_connection_close_pkt(
conn, path, pi, dest, destlen, ccerr->error_code, ccerr->reason,
ccerr->reasonlen, ts);
- case NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION:
+ case NGTCP2_CCERR_TYPE_APPLICATION:
return ngtcp2_conn_write_application_close_pkt(
conn, path, pi, dest, destlen, ccerr->error_code, ccerr->reason,
ccerr->reasonlen, ts);
@@ -13000,7 +12967,7 @@ int ngtcp2_conn_on_loss_detection_timer(ngtcp2_conn *conn, ngtcp2_tstamp ts) {
return 0;
}
- if (!conn->server && !conn_is_handshake_completed(conn)) {
+ if (!conn->server && !conn_is_tls_handshake_completed(conn)) {
if (hs_pktns->crypto.tx.ckm) {
hs_pktns->rtb.probe_pkt_left = 1;
} else {
@@ -13190,7 +13157,7 @@ size_t ngtcp2_conn_get_num_active_dcid(ngtcp2_conn *conn) {
size_t n = 1; /* for conn->dcid.current */
ngtcp2_pv *pv = conn->pv;
- if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED)) {
+ if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) {
return 0;
}
@@ -13227,7 +13194,7 @@ size_t ngtcp2_conn_get_active_dcid(ngtcp2_conn *conn, ngtcp2_cid_token *dest) {
ngtcp2_dcid *dcid;
size_t len, i;
- if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED)) {
+ if (!(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) {
return 0;
}
@@ -13408,10 +13375,6 @@ int ngtcp2_conn_initiate_migration(ngtcp2_conn *conn, const ngtcp2_path *path,
return conn_call_activate_dcid(conn, &pv->dcid);
}
-uint64_t ngtcp2_conn_get_max_local_streams_uni(ngtcp2_conn *conn) {
- return conn->local.uni.max_streams;
-}
-
uint64_t ngtcp2_conn_get_max_data_left(ngtcp2_conn *conn) {
return conn->tx.max_offset - conn->tx.offset;
}
@@ -13460,7 +13423,7 @@ ngtcp2_tstamp ngtcp2_conn_get_idle_expiry(ngtcp2_conn *conn) {
/* TODO Remote max_idle_timeout becomes effective after handshake
completion. */
- if (!conn_is_handshake_completed(conn) ||
+ if (!conn_is_tls_handshake_completed(conn) ||
conn->remote.transport_params->max_idle_timeout == 0 ||
(conn->local.transport_params.max_idle_timeout &&
conn->local.transport_params.max_idle_timeout <
@@ -13474,7 +13437,7 @@ ngtcp2_tstamp ngtcp2_conn_get_idle_expiry(ngtcp2_conn *conn) {
return UINT64_MAX;
}
- trpto = 3 * conn_compute_pto(conn, conn_is_handshake_completed(conn)
+ trpto = 3 * conn_compute_pto(conn, conn_is_tls_handshake_completed(conn)
? &conn->pktns
: conn->hs_pktns);
@@ -13482,8 +13445,9 @@ ngtcp2_tstamp ngtcp2_conn_get_idle_expiry(ngtcp2_conn *conn) {
}
ngtcp2_duration ngtcp2_conn_get_pto(ngtcp2_conn *conn) {
- return conn_compute_pto(
- conn, conn_is_handshake_completed(conn) ? &conn->pktns : conn->hs_pktns);
+ return conn_compute_pto(conn, conn_is_tls_handshake_completed(conn)
+ ? &conn->pktns
+ : conn->hs_pktns);
}
void ngtcp2_conn_set_initial_crypto_ctx(ngtcp2_conn *conn,
@@ -13535,9 +13499,8 @@ void ngtcp2_conn_set_tls_native_handle(ngtcp2_conn *conn,
conn->crypto.tls_native_handle = tls_native_handle;
}
-void ngtcp2_conn_get_connection_close_error(
- ngtcp2_conn *conn, ngtcp2_connection_close_error *ccerr) {
- *ccerr = conn->rx.ccerr;
+const ngtcp2_ccerr *ngtcp2_conn_get_ccerr(ngtcp2_conn *conn) {
+ return &conn->rx.ccerr;
}
void ngtcp2_conn_set_tls_error(ngtcp2_conn *conn, int liberr) {
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.h b/deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.h
index d6be6a9d13..9b3bbfdc75 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.h
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_conn.h
@@ -120,10 +120,10 @@ typedef enum {
packets sent in NGTCP2_ECN_STATE_TESTING period. */
#define NGTCP2_ECN_MAX_NUM_VALIDATION_PKTS 10
-/* NGTCP2_CONNECTION_CLOSE_ERROR_MAX_REASONLEN is the maximum length
- of reason phrase to remember. If the received reason phrase is
- longer than this value, it is truncated. */
-#define NGTCP2_CONNECTION_CLOSE_ERROR_MAX_REASONLEN 1024
+/* NGTCP2_CCERR_MAX_REASONLEN is the maximum length of reason phrase
+ to remember. If the received reason phrase is longer than this
+ value, it is truncated. */
+#define NGTCP2_CCERR_MAX_REASONLEN 1024
/* NGTCP2_WRITE_PKT_FLAG_NONE indicates that no flag is set. */
#define NGTCP2_WRITE_PKT_FLAG_NONE 0x00u
@@ -159,17 +159,17 @@ void ngtcp2_path_challenge_entry_init(ngtcp2_path_challenge_entry *pcent,
/* NGTCP2_CONN_FLAG_NONE indicates that no flag is set. */
#define NGTCP2_CONN_FLAG_NONE 0x00u
-/* NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED is set when TLS stack declares
- that TLS handshake has completed. The condition of this
+/* NGTCP2_CONN_FLAG_TLS_HANDSHAKE_COMPLETED is set when TLS stack
+ declares that TLS handshake has completed. The condition of this
declaration varies between TLS implementations and this flag does
not indicate the completion of QUIC handshake. Some
implementations declare TLS handshake completion as server when
they write off Server Finished and before deriving application rx
secret. */
-#define NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED 0x01u
-/* NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED is set if connection ID is
- negotiated. This is only used for client. */
-#define NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED 0x02u
+#define NGTCP2_CONN_FLAG_TLS_HANDSHAKE_COMPLETED 0x01u
+/* NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED is set when the first
+ Initial packet has successfully been processed. */
+#define NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED 0x02u
/* NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED is set if transport
parameters are received. */
#define NGTCP2_CONN_FLAG_TRANSPORT_PARAM_RECVED 0x04u
@@ -188,9 +188,9 @@ void ngtcp2_path_challenge_entry_init(ngtcp2_path_challenge_entry *pcent,
/* NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED is set when an endpoint
confirmed completion of handshake. */
#define NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED 0x80u
-/* NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED is set when the
- library transitions its state to "post handshake". */
-#define NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED_HANDLED 0x0100u
+/* NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED is set when the library
+ transitions its state to "post handshake". */
+#define NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED 0x0100u
/* NGTCP2_CONN_FLAG_HANDSHAKE_EARLY_RETRANSMIT is set when the early
handshake retransmission has done when server receives overlapping
Initial crypto data. */
@@ -345,6 +345,19 @@ typedef enum ngtcp2_ecn_state {
NGTCP2_ECN_STATE_CAPABLE,
} ngtcp2_ecn_state;
+/* ngtcp2_early_transport_params is the values remembered by client
+ from the previous session. */
+typedef struct ngtcp2_early_transport_params {
+ uint64_t initial_max_streams_bidi;
+ uint64_t initial_max_streams_uni;
+ uint64_t initial_max_stream_data_bidi_local;
+ uint64_t initial_max_stream_data_bidi_remote;
+ uint64_t initial_max_stream_data_uni;
+ uint64_t initial_max_data;
+ uint64_t active_connection_id_limit;
+ uint64_t max_datagram_frame_size;
+} ngtcp2_early_transport_params;
+
ngtcp2_static_ringbuf_def(dcid_bound, NGTCP2_MAX_BOUND_DCID_POOL_SIZE,
sizeof(ngtcp2_dcid));
ngtcp2_static_ringbuf_def(dcid_unused, NGTCP2_MAX_DCID_POOL_SIZE,
@@ -483,7 +496,7 @@ struct ngtcp2_conn {
/* path_challenge stores received PATH_CHALLENGE data. */
ngtcp2_static_ringbuf_path_challenge path_challenge;
/* ccerr is the received connection close error. */
- ngtcp2_connection_close_error ccerr;
+ ngtcp2_ccerr ccerr;
} rx;
struct {
@@ -498,16 +511,7 @@ struct ngtcp2_conn {
ngtcp2_conn_set_early_remote_transport_params(). Server does
not use this field. Server must not set values for these
parameters that are smaller than the remembered values. */
- struct {
- uint64_t initial_max_streams_bidi;
- uint64_t initial_max_streams_uni;
- uint64_t initial_max_stream_data_bidi_local;
- uint64_t initial_max_stream_data_bidi_remote;
- uint64_t initial_max_stream_data_uni;
- uint64_t initial_max_data;
- uint64_t active_connection_id_limit;
- uint64_t max_datagram_frame_size;
- } transport_params;
+ ngtcp2_early_transport_params transport_params;
} early;
struct {
@@ -677,7 +681,13 @@ struct ngtcp2_conn {
ngtcp2_qlog qlog;
ngtcp2_rst rst;
ngtcp2_cc_algo cc_algo;
- ngtcp2_cc cc;
+ union {
+ ngtcp2_cc cc;
+ ngtcp2_cc_reno reno;
+ ngtcp2_cc_cubic cubic;
+ ngtcp2_cc_bbr bbr;
+ ngtcp2_cc_bbr2 bbr2;
+ };
const ngtcp2_mem *mem;
/* idle_ts is the time instant when idle timer started. */
ngtcp2_tstamp idle_ts;
diff --git a/deps/ngtcp2/ngtcp2/lib/ngtcp2_rtb.c b/deps/ngtcp2/ngtcp2/lib/ngtcp2_rtb.c
index 7fb0cc707d..d819a39048 100644
--- a/deps/ngtcp2/ngtcp2/lib/ngtcp2_rtb.c
+++ b/deps/ngtcp2/ngtcp2/lib/ngtcp2_rtb.c
@@ -889,12 +889,14 @@ static void rtb_on_pkt_acked(ngtcp2_rtb *rtb, ngtcp2_rtb_entry *ent,
ngtcp2_rst_update_rate_sample(rtb->rst, ent, ts);
- cc->on_pkt_acked(cc, cstat,
- ngtcp2_cc_pkt_init(&pkt, ent->hd.pkt_num, ent->pktlen,
- rtb->pktns_id, ent->ts, ent->rst.lost,
- ent->rst.tx_in_flight,
- ent->rst.is_app_limited),
- ts);
+ if (cc->on_pkt_acked) {
+ cc->on_pkt_acked(cc, cstat,
+ ngtcp2_cc_pkt_init(&pkt, ent->hd.pkt_num, ent->pktlen,
+ rtb->pktns_id, ent->ts, ent->rst.lost,
+ ent->rst.tx_in_flight,
+ ent->rst.is_app_limited),
+ ts);
+ }
if (!(ent->flags & NGTCP2_RTB_ENTRY_FLAG_PROBE) &&
(ent->flags & NGTCP2_RTB_ENTRY_FLAG_ACK_ELICITING)) {
@@ -932,7 +934,7 @@ static void conn_verify_ecn(ngtcp2_conn *conn, ngtcp2_pktns *pktns,
}
if (fr->type == NGTCP2_FRAME_ACK_ECN) {
- if (largest_acked_sent_ts != UINT64_MAX &&
+ if (cc->congestion_event && largest_acked_sent_ts != UINT64_MAX &&
fr->ecn.ce > pktns->rx.ecn.ack.ce) {
cc->congestion_event(cc, cstat, largest_acked_sent_ts, ts);
}
@@ -1118,7 +1120,9 @@ ngtcp2_ssize ngtcp2_rtb_recv_ack(ngtcp2_rtb *rtb, const ngtcp2_ack *fr,
rtb->rst->lost += cc_ack.bytes_lost;
cc_ack.largest_acked_sent_ts = largest_acked_sent_ts;
- cc->on_ack_recv(cc, cstat, &cc_ack, ts);
+ if (cc->on_ack_recv) {
+ cc->on_ack_recv(cc, cstat, &cc_ack, ts);
+ }
return num_acked;
@@ -1292,7 +1296,9 @@ static int rtb_detect_lost_pkt(ngtcp2_rtb *rtb, uint64_t *ppkt_lost,
break;
}
- cc->congestion_event(cc, cstat, latest_ts, ts);
+ if (cc->congestion_event) {
+ cc->congestion_event(cc, cstat, latest_ts, ts);
+ }
loss_window = latest_ts - oldest_ts;
/* Persistent congestion situation is only evaluated for app
@@ -1316,7 +1322,9 @@ static int rtb_detect_lost_pkt(ngtcp2_rtb *rtb, uint64_t *ppkt_lost,
cstat->rttvar = conn->local.settings.initial_rtt / 2;
cstat->first_rtt_sample_ts = UINT64_MAX;
- cc->on_persistent_congestion(cc, cstat, ts);
+ if (cc->on_persistent_congestion) {
+ cc->on_persistent_congestion(cc, cstat, ts);
+ }
}
}