changeset 12: |
c520966de7fa |
author: |
ellis <ellis@rwest.io> |
date: |
Mon, 15 May 2023 21:40:24 -0400 |
permissions: |
-rw-r--r-- |
description: |
added quiche.h and some ui work |
1 // Copyright (C) 2018-2019, Cloudflare, Inc. 2 // All rights reserved. 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are 8 // * Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 11 // * Redistributions in binary form must reproduce the above copyright 12 // notice, this list of conditions and the following disclaimer in the 13 // documentation and/or other materials provided with the distribution. 15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 17 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 19 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 #if defined(__cplusplus) 38 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) 43 #include <sys/socket.h> 48 #include <sys/types.h> 52 #define ssize_t SSIZE_T 55 // QUIC transport API. 58 // The current QUIC wire version. 59 #define QUICHE_PROTOCOL_VERSION 0x00000001 61 // The maximum length of a connection ID. 62 #define QUICHE_MAX_CONN_ID_LEN 20 64 // The minimum length of Initial packets sent by a client. 65 #define QUICHE_MIN_CLIENT_INITIAL_LEN 1200 68 // There is no more work to do. 71 // The provided buffer is too short. 72 QUICHE_ERR_BUFFER_TOO_SHORT = -2, 74 // The provided packet cannot be parsed because its version is unknown. 75 QUICHE_ERR_UNKNOWN_VERSION = -3, 77 // The provided packet cannot be parsed because it contains an invalid 79 QUICHE_ERR_INVALID_FRAME = -4, 81 // The provided packet cannot be parsed. 82 QUICHE_ERR_INVALID_PACKET = -5, 84 // The operation cannot be completed because the connection is in an 86 QUICHE_ERR_INVALID_STATE = -6, 88 // The operation cannot be completed because the stream is in an 90 QUICHE_ERR_INVALID_STREAM_STATE = -7, 92 // The peer's transport params cannot be parsed. 93 QUICHE_ERR_INVALID_TRANSPORT_PARAM = -8, 95 // A cryptographic operation failed. 96 QUICHE_ERR_CRYPTO_FAIL = -9, 98 // The TLS handshake failed. 99 QUICHE_ERR_TLS_FAIL = -10, 101 // The peer violated the local flow control limits. 102 QUICHE_ERR_FLOW_CONTROL = -11, 104 // The peer violated the local stream limits. 105 QUICHE_ERR_STREAM_LIMIT = -12, 107 // The specified stream was stopped by the peer. 108 QUICHE_ERR_STREAM_STOPPED = -15, 110 // The specified stream was reset by the peer. 111 QUICHE_ERR_STREAM_RESET = -16, 113 // The received data exceeds the stream's final size. 114 QUICHE_ERR_FINAL_SIZE = -13, 116 // Error in congestion control. 117 QUICHE_ERR_CONGESTION_CONTROL = -14, 119 // Too many identifiers were provided. 120 QUICHE_ERR_ID_LIMIT = -17, 122 // Not enough available identifiers. 123 QUICHE_ERR_OUT_OF_IDENTIFIERS = -18, 125 // Error in key update. 126 QUICHE_ERR_KEY_UPDATE = -19, 129 // Returns a human readable string with the quiche version number. 130 const char *quiche_version(void); 132 // Enables logging. |cb| will be called with log messages 133 int quiche_enable_debug_logging(void (*cb)(const char *line, void *argp), 136 // Stores configuration shared between multiple connections. 137 typedef struct quiche_config quiche_config; 139 // Creates a config object with the given version. 140 quiche_config *quiche_config_new(uint32_t version); 142 // Configures the given certificate chain. 143 int quiche_config_load_cert_chain_from_pem_file(quiche_config *config, 146 // Configures the given private key. 147 int quiche_config_load_priv_key_from_pem_file(quiche_config *config, 150 // Specifies a file where trusted CA certificates are stored for the purposes of certificate verification. 151 int quiche_config_load_verify_locations_from_file(quiche_config *config, 154 // Specifies a directory where trusted CA certificates are stored for the purposes of certificate verification. 155 int quiche_config_load_verify_locations_from_directory(quiche_config *config, 158 // Configures whether to verify the peer's certificate. 159 void quiche_config_verify_peer(quiche_config *config, bool v); 161 // Configures whether to send GREASE. 162 void quiche_config_grease(quiche_config *config, bool v); 164 // Enables logging of secrets. 165 void quiche_config_log_keys(quiche_config *config); 167 // Enables sending or receiving early data. 168 void quiche_config_enable_early_data(quiche_config *config); 170 // Configures the list of supported application protocols. 171 int quiche_config_set_application_protos(quiche_config *config, 172 const uint8_t *protos, 175 // Sets the `max_idle_timeout` transport parameter, in milliseconds, default is 177 void quiche_config_set_max_idle_timeout(quiche_config *config, uint64_t v); 179 // Sets the `max_udp_payload_size transport` parameter. 180 void quiche_config_set_max_recv_udp_payload_size(quiche_config *config, size_t v); 182 // Sets the maximum outgoing UDP payload size. 183 void quiche_config_set_max_send_udp_payload_size(quiche_config *config, size_t v); 185 // Sets the `initial_max_data` transport parameter. 186 void quiche_config_set_initial_max_data(quiche_config *config, uint64_t v); 188 // Sets the `initial_max_stream_data_bidi_local` transport parameter. 189 void quiche_config_set_initial_max_stream_data_bidi_local(quiche_config *config, uint64_t v); 191 // Sets the `initial_max_stream_data_bidi_remote` transport parameter. 192 void quiche_config_set_initial_max_stream_data_bidi_remote(quiche_config *config, uint64_t v); 194 // Sets the `initial_max_stream_data_uni` transport parameter. 195 void quiche_config_set_initial_max_stream_data_uni(quiche_config *config, uint64_t v); 197 // Sets the `initial_max_streams_bidi` transport parameter. 198 void quiche_config_set_initial_max_streams_bidi(quiche_config *config, uint64_t v); 200 // Sets the `initial_max_streams_uni` transport parameter. 201 void quiche_config_set_initial_max_streams_uni(quiche_config *config, uint64_t v); 203 // Sets the `ack_delay_exponent` transport parameter. 204 void quiche_config_set_ack_delay_exponent(quiche_config *config, uint64_t v); 206 // Sets the `max_ack_delay` transport parameter. 207 void quiche_config_set_max_ack_delay(quiche_config *config, uint64_t v); 209 // Sets the `disable_active_migration` transport parameter. 210 void quiche_config_set_disable_active_migration(quiche_config *config, bool v); 212 enum quiche_cc_algorithm { 218 // Sets the congestion control algorithm used. 219 void quiche_config_set_cc_algorithm(quiche_config *config, enum quiche_cc_algorithm algo); 221 // Configures whether to use HyStart++. 222 void quiche_config_enable_hystart(quiche_config *config, bool v); 224 // Configures whether to enable pacing (enabled by default). 225 void quiche_config_enable_pacing(quiche_config *config, bool v); 227 // Configures max pacing rate to be used. 228 void quiche_config_set_max_pacing_rate(quiche_config *config, uint64_t v); 230 // Configures whether to enable receiving DATAGRAM frames. 231 void quiche_config_enable_dgram(quiche_config *config, bool enabled, 232 size_t recv_queue_len, 233 size_t send_queue_len); 235 // Sets the maximum connection window. 236 void quiche_config_set_max_connection_window(quiche_config *config, uint64_t v); 238 // Sets the maximum stream window. 239 void quiche_config_set_max_stream_window(quiche_config *config, uint64_t v); 241 // Sets the limit of active connection IDs. 242 void quiche_config_set_active_connection_id_limit(quiche_config *config, uint64_t v); 244 // Sets the initial stateless reset token. |v| must contain 16 bytes, otherwise the behaviour is undefined. 245 void quiche_config_set_stateless_reset_token(quiche_config *config, const uint8_t *v); 247 // Frees the config object. 248 void quiche_config_free(quiche_config *config); 250 // Extracts version, type, source / destination connection ID and address 251 // verification token from the packet in |buf|. 252 int quiche_header_info(const uint8_t *buf, size_t buf_len, size_t dcil, 253 uint32_t *version, uint8_t *type, 254 uint8_t *scid, size_t *scid_len, 255 uint8_t *dcid, size_t *dcid_len, 256 uint8_t *token, size_t *token_len); 258 // A QUIC connection. 259 typedef struct quiche_conn quiche_conn; 261 // Creates a new server-side connection. 262 quiche_conn *quiche_accept(const uint8_t *scid, size_t scid_len, 263 const uint8_t *odcid, size_t odcid_len, 264 const struct sockaddr *local, size_t local_len, 265 const struct sockaddr *peer, size_t peer_len, 266 quiche_config *config); 268 // Creates a new client-side connection. 269 quiche_conn *quiche_connect(const char *server_name, 270 const uint8_t *scid, size_t scid_len, 271 const struct sockaddr *local, size_t local_len, 272 const struct sockaddr *peer, size_t peer_len, 273 quiche_config *config); 275 // Writes a version negotiation packet. 276 ssize_t quiche_negotiate_version(const uint8_t *scid, size_t scid_len, 277 const uint8_t *dcid, size_t dcid_len, 278 uint8_t *out, size_t out_len); 280 // Writes a retry packet. 281 ssize_t quiche_retry(const uint8_t *scid, size_t scid_len, 282 const uint8_t *dcid, size_t dcid_len, 283 const uint8_t *new_scid, size_t new_scid_len, 284 const uint8_t *token, size_t token_len, 285 uint32_t version, uint8_t *out, size_t out_len); 287 // Returns true if the given protocol version is supported. 288 bool quiche_version_is_supported(uint32_t version); 290 quiche_conn *quiche_conn_new_with_tls(const uint8_t *scid, size_t scid_len, 291 const uint8_t *odcid, size_t odcid_len, 292 const struct sockaddr *local, size_t local_len, 293 const struct sockaddr *peer, size_t peer_len, 294 quiche_config *config, void *ssl, 297 // Enables keylog to the specified file path. Returns true on success. 298 bool quiche_conn_set_keylog_path(quiche_conn *conn, const char *path); 300 // Enables keylog to the specified file descriptor. Unix only. 301 void quiche_conn_set_keylog_fd(quiche_conn *conn, int fd); 303 // Enables qlog to the specified file path. Returns true on success. 304 bool quiche_conn_set_qlog_path(quiche_conn *conn, const char *path, 305 const char *log_title, const char *log_desc); 307 // Enables qlog to the specified file descriptor. Unix only. 308 void quiche_conn_set_qlog_fd(quiche_conn *conn, int fd, const char *log_title, 309 const char *log_desc); 311 // Configures the given session for resumption. 312 int quiche_conn_set_session(quiche_conn *conn, const uint8_t *buf, size_t buf_len); 315 // The remote address the packet was received from. 316 struct sockaddr *from; 319 // The local address the packet was received on. 324 // Processes QUIC packets received from the peer. 325 ssize_t quiche_conn_recv(quiche_conn *conn, uint8_t *buf, size_t buf_len, 326 const quiche_recv_info *info); 329 // The local address the packet should be sent from. 330 struct sockaddr_storage from; 333 // The remote address the packet should be sent to. 334 struct sockaddr_storage to; 337 // The time to send the packet out. 341 // Writes a single QUIC packet to be sent to the peer. 342 ssize_t quiche_conn_send(quiche_conn *conn, uint8_t *out, size_t out_len, 343 quiche_send_info *out_info); 345 // Returns the size of the send quantum, in bytes. 346 size_t quiche_conn_send_quantum(const quiche_conn *conn); 348 // Reads contiguous data from a stream. 349 ssize_t quiche_conn_stream_recv(quiche_conn *conn, uint64_t stream_id, 350 uint8_t *out, size_t buf_len, bool *fin); 352 // Writes data to a stream. 353 ssize_t quiche_conn_stream_send(quiche_conn *conn, uint64_t stream_id, 354 const uint8_t *buf, size_t buf_len, bool fin); 356 // The side of the stream to be shut down. 357 enum quiche_shutdown { 358 QUICHE_SHUTDOWN_READ = 0, 359 QUICHE_SHUTDOWN_WRITE = 1, 362 // Sets the priority for a stream. 363 int quiche_conn_stream_priority(quiche_conn *conn, uint64_t stream_id, 364 uint8_t urgency, bool incremental); 366 // Shuts down reading or writing from/to the specified stream. 367 int quiche_conn_stream_shutdown(quiche_conn *conn, uint64_t stream_id, 368 enum quiche_shutdown direction, uint64_t err); 370 // Returns the stream's send capacity in bytes. 371 ssize_t quiche_conn_stream_capacity(const quiche_conn *conn, uint64_t stream_id); 373 // Returns true if the stream has data that can be read. 374 bool quiche_conn_stream_readable(const quiche_conn *conn, uint64_t stream_id); 376 // Returns the next stream that has data to read, or -1 if no such stream is 378 int64_t quiche_conn_stream_readable_next(quiche_conn *conn); 380 // Returns true if the stream has enough send capacity. 382 // On error a value lower than 0 is returned. 383 int quiche_conn_stream_writable(quiche_conn *conn, uint64_t stream_id, size_t len); 385 // Returns the next stream that can be written to, or -1 if no such stream is 387 int64_t quiche_conn_stream_writable_next(quiche_conn *conn); 389 // Returns true if all the data has been read from the specified stream. 390 bool quiche_conn_stream_finished(const quiche_conn *conn, uint64_t stream_id); 392 typedef struct quiche_stream_iter quiche_stream_iter; 394 // Returns an iterator over streams that have outstanding data to read. 395 quiche_stream_iter *quiche_conn_readable(const quiche_conn *conn); 397 // Returns an iterator over streams that can be written to. 398 quiche_stream_iter *quiche_conn_writable(const quiche_conn *conn); 400 // Returns the maximum possible size of egress UDP payloads. 401 size_t quiche_conn_max_send_udp_payload_size(const quiche_conn *conn); 403 // Returns the amount of time until the next timeout event, in nanoseconds. 404 uint64_t quiche_conn_timeout_as_nanos(const quiche_conn *conn); 406 // Returns the amount of time until the next timeout event, in milliseconds. 407 uint64_t quiche_conn_timeout_as_millis(const quiche_conn *conn); 409 // Processes a timeout event. 410 void quiche_conn_on_timeout(quiche_conn *conn); 412 // Closes the connection with the given error and reason. 413 int quiche_conn_close(quiche_conn *conn, bool app, uint64_t err, 414 const uint8_t *reason, size_t reason_len); 416 // Returns a string uniquely representing the connection. 417 void quiche_conn_trace_id(const quiche_conn *conn, const uint8_t **out, size_t *out_len); 419 // Returns the source connection ID. 420 void quiche_conn_source_id(const quiche_conn *conn, const uint8_t **out, size_t *out_len); 422 // Returns the destination connection ID. 423 void quiche_conn_destination_id(const quiche_conn *conn, const uint8_t **out, size_t *out_len); 425 // Returns the negotiated ALPN protocol. 426 void quiche_conn_application_proto(const quiche_conn *conn, const uint8_t **out, 429 // Returns the peer's leaf certificate (if any) as a DER-encoded buffer. 430 void quiche_conn_peer_cert(const quiche_conn *conn, const uint8_t **out, size_t *out_len); 432 // Returns the serialized cryptographic session for the connection. 433 void quiche_conn_session(const quiche_conn *conn, const uint8_t **out, size_t *out_len); 435 // Returns true if the connection handshake is complete. 436 bool quiche_conn_is_established(const quiche_conn *conn); 438 // Returns true if the connection has a pending handshake that has progressed 439 // enough to send or receive early data. 440 bool quiche_conn_is_in_early_data(const quiche_conn *conn); 442 // Returns whether there is stream or DATAGRAM data available to read. 443 bool quiche_conn_is_readable(const quiche_conn *conn); 445 // Returns true if the connection is draining. 446 bool quiche_conn_is_draining(const quiche_conn *conn); 448 // Returns the number of bidirectional streams that can be created 449 // before the peer's stream count limit is reached. 450 uint64_t quiche_conn_peer_streams_left_bidi(const quiche_conn *conn); 452 // Returns the number of unidirectional streams that can be created 453 // before the peer's stream count limit is reached. 454 uint64_t quiche_conn_peer_streams_left_uni(const quiche_conn *conn); 456 // Returns true if the connection is closed. 457 bool quiche_conn_is_closed(const quiche_conn *conn); 459 // Returns true if the connection was closed due to the idle timeout. 460 bool quiche_conn_is_timed_out(const quiche_conn *conn); 462 // Returns true if a connection error was received, and updates the provided 463 // parameters accordingly. 464 bool quiche_conn_peer_error(const quiche_conn *conn, 466 uint64_t *error_code, 467 const uint8_t **reason, 470 // Returns true if a connection error was queued or sent, and updates the provided 471 // parameters accordingly. 472 bool quiche_conn_local_error(const quiche_conn *conn, 474 uint64_t *error_code, 475 const uint8_t **reason, 478 // Initializes the stream's application data. 480 // Stream data can only be initialized once. Additional calls to this method 483 // Note that the application is responsible for freeing the data. 484 int quiche_conn_stream_init_application_data(quiche_conn *conn, 488 // Returns the stream's application data, if any was initialized. 489 void *quiche_conn_stream_application_data(quiche_conn *conn, uint64_t stream_id); 491 // Fetches the next stream from the given iterator. Returns false if there are 492 // no more elements in the iterator. 493 bool quiche_stream_iter_next(quiche_stream_iter *iter, uint64_t *stream_id); 495 // Frees the given stream iterator object. 496 void quiche_stream_iter_free(quiche_stream_iter *iter); 499 // The number of QUIC packets received on this connection. 502 // The number of QUIC packets sent on this connection. 505 // The number of QUIC packets that were lost. 508 // The number of sent QUIC packets with retransmitted data. 511 // The number of sent bytes. 514 // The number of received bytes. 517 // The number of bytes lost. 520 // The number of stream bytes retransmitted. 521 uint64_t stream_retrans_bytes; 523 // The number of known paths for the connection. 526 // The maximum idle timeout. 527 uint64_t peer_max_idle_timeout; 529 // The maximum UDP payload size. 530 uint64_t peer_max_udp_payload_size; 532 // The initial flow control maximum data for the connection. 533 uint64_t peer_initial_max_data; 535 // The initial flow control maximum data for local bidirectional streams. 536 uint64_t peer_initial_max_stream_data_bidi_local; 538 // The initial flow control maximum data for remote bidirectional streams. 539 uint64_t peer_initial_max_stream_data_bidi_remote; 541 // The initial flow control maximum data for unidirectional streams. 542 uint64_t peer_initial_max_stream_data_uni; 544 // The initial maximum bidirectional streams. 545 uint64_t peer_initial_max_streams_bidi; 547 // The initial maximum unidirectional streams. 548 uint64_t peer_initial_max_streams_uni; 550 // The ACK delay exponent. 551 uint64_t peer_ack_delay_exponent; 553 // The max ACK delay. 554 uint64_t peer_max_ack_delay; 556 // Whether active migration is disabled. 557 bool peer_disable_active_migration; 559 // The active connection ID limit. 560 uint64_t peer_active_conn_id_limit; 562 // DATAGRAM frame extension parameter, if any. 563 ssize_t peer_max_datagram_frame_size; 566 // Collects and returns statistics about the connection. 567 void quiche_conn_stats(const quiche_conn *conn, quiche_stats *out); 570 // The local address used by this path. 571 struct sockaddr_storage local_addr; 572 socklen_t local_addr_len; 574 // The peer address seen by this path. 575 struct sockaddr_storage peer_addr; 576 socklen_t peer_addr_len; 578 // The validation state of the path. 579 ssize_t validation_state; 581 // Whether this path is active. 584 // The number of QUIC packets received on this path. 587 // The number of QUIC packets sent on this path. 590 // The number of QUIC packets that were lost on this path. 593 // The number of sent QUIC packets with retransmitted data on this path. 596 // The estimated round-trip time of the path (in nanoseconds). 599 // The size of the path's congestion window in bytes. 602 // The number of sent bytes on this path. 605 // The number of received bytes on this path. 608 // The number of bytes lost on this path. 611 // The number of stream bytes retransmitted on this path. 612 uint64_t stream_retrans_bytes; 614 // The current PMTU for the path. 617 // The most recent data delivery rate estimate in bytes/s. 618 uint64_t delivery_rate; 622 // Collects and returns statistics about the specified path for the connection. 624 // The `idx` argument represent the path's index (also see the `paths_count` 625 // field of `quiche_stats`). 626 int quiche_conn_path_stats(const quiche_conn *conn, size_t idx, quiche_path_stats *out); 628 // Returns whether or not this is a server-side connection. 629 bool quiche_conn_is_server(const quiche_conn *conn); 631 // Returns the maximum DATAGRAM payload that can be sent. 632 ssize_t quiche_conn_dgram_max_writable_len(const quiche_conn *conn); 634 // Returns the length of the first stored DATAGRAM. 635 ssize_t quiche_conn_dgram_recv_front_len(const quiche_conn *conn); 637 // Returns the number of items in the DATAGRAM receive queue. 638 ssize_t quiche_conn_dgram_recv_queue_len(const quiche_conn *conn); 640 // Returns the total size of all items in the DATAGRAM receive queue. 641 ssize_t quiche_conn_dgram_recv_queue_byte_size(const quiche_conn *conn); 643 // Returns the number of items in the DATAGRAM send queue. 644 ssize_t quiche_conn_dgram_send_queue_len(const quiche_conn *conn); 646 // Returns the total size of all items in the DATAGRAM send queue. 647 ssize_t quiche_conn_dgram_send_queue_byte_size(const quiche_conn *conn); 649 // Reads the first received DATAGRAM. 650 ssize_t quiche_conn_dgram_recv(quiche_conn *conn, uint8_t *buf, 653 // Sends data in a DATAGRAM frame. 654 ssize_t quiche_conn_dgram_send(quiche_conn *conn, const uint8_t *buf, 657 // Purges queued outgoing DATAGRAMs matching the predicate. 658 void quiche_conn_dgram_purge_outgoing(quiche_conn *conn, 659 bool (*f)(uint8_t *, size_t)); 661 // Schedule an ack-eliciting packet on the active path. 662 ssize_t quiche_conn_send_ack_eliciting(quiche_conn *conn); 664 // Schedule an ack-eliciting packet on the specified path. 665 ssize_t quiche_conn_send_ack_eliciting_on_path(quiche_conn *conn, 666 const struct sockaddr *local, size_t local_len, 667 const struct sockaddr *peer, size_t peer_len); 669 // Frees the connection object. 670 void quiche_conn_free(quiche_conn *conn); 676 // List of ALPN tokens of supported HTTP/3 versions. 677 #define QUICHE_H3_APPLICATION_PROTOCOL "\x02h3\x05h3-29\x05h3-28\x05h3-27" 679 enum quiche_h3_error { 680 // There is no error or no work to do 681 QUICHE_H3_ERR_DONE = -1, 683 // The provided buffer is too short. 684 QUICHE_H3_ERR_BUFFER_TOO_SHORT = -2, 686 // Internal error in the HTTP/3 stack. 687 QUICHE_H3_ERR_INTERNAL_ERROR = -3, 689 // Endpoint detected that the peer is exhibiting behavior that causes. 691 QUICHE_H3_ERR_EXCESSIVE_LOAD = -4, 693 // Stream ID or Push ID greater that current maximum was 694 // used incorrectly, such as exceeding a limit, reducing a limit, 696 QUICHE_H3_ERR_ID_ERROR= -5, 698 // The endpoint detected that its peer created a stream that it will not 700 QUICHE_H3_ERR_STREAM_CREATION_ERROR = -6, 702 // A required critical stream was closed. 703 QUICHE_H3_ERR_CLOSED_CRITICAL_STREAM = -7, 705 // No SETTINGS frame at beginning of control stream. 706 QUICHE_H3_ERR_MISSING_SETTINGS = -8, 708 // A frame was received which is not permitted in the current state. 709 QUICHE_H3_ERR_FRAME_UNEXPECTED = -9, 711 // Frame violated layout or size rules. 712 QUICHE_H3_ERR_FRAME_ERROR = -10, 714 // QPACK Header block decompression failure. 715 QUICHE_H3_ERR_QPACK_DECOMPRESSION_FAILED = -11, 717 // -12 was previously used for TransportError, skip it 719 // The underlying QUIC stream (or connection) doesn't have enough capacity 720 // for the operation to complete. The application should retry later on. 721 QUICHE_H3_ERR_STREAM_BLOCKED = -13, 723 // Error in the payload of a SETTINGS frame. 724 QUICHE_H3_ERR_SETTINGS_ERROR = -14, 726 // Server rejected request. 727 QUICHE_H3_ERR_REQUEST_REJECTED = -15, 729 // Request or its response cancelled. 730 QUICHE_H3_ERR_REQUEST_CANCELLED = -16, 732 // Client's request stream terminated without containing a full-formed 734 QUICHE_H3_ERR_REQUEST_INCOMPLETE = -17, 736 // An HTTP message was malformed and cannot be processed. 737 QUICHE_H3_ERR_MESSAGE_ERROR = -18, 739 // The TCP connection established in response to a CONNECT request was 740 // reset or abnormally closed. 741 QUICHE_H3_ERR_CONNECT_ERROR = -19, 743 // The requested operation cannot be served over HTTP/3. Peer should retry 745 QUICHE_H3_ERR_VERSION_FALLBACK = -20, 747 // The following QUICHE_H3_TRANSPORT_ERR_* errors are propagated 748 // from the QUIC transport layer. 750 // See QUICHE_ERR_DONE. 751 QUICHE_H3_TRANSPORT_ERR_DONE = QUICHE_ERR_DONE - 1000, 753 // See QUICHE_ERR_BUFFER_TOO_SHORT. 754 QUICHE_H3_TRANSPORT_ERR_BUFFER_TOO_SHORT = QUICHE_ERR_BUFFER_TOO_SHORT - 1000, 756 // See QUICHE_ERR_UNKNOWN_VERSION. 757 QUICHE_H3_TRANSPORT_ERR_UNKNOWN_VERSION = QUICHE_ERR_UNKNOWN_VERSION - 1000, 759 // See QUICHE_ERR_INVALID_FRAME. 760 QUICHE_H3_TRANSPORT_ERR_INVALID_FRAME = QUICHE_ERR_INVALID_FRAME - 1000, 762 // See QUICHE_ERR_INVALID_PACKET. 763 QUICHE_H3_TRANSPORT_ERR_INVALID_PACKET = QUICHE_ERR_INVALID_PACKET - 1000, 765 // See QUICHE_ERR_INVALID_STATE. 766 QUICHE_H3_TRANSPORT_ERR_INVALID_STATE = QUICHE_ERR_INVALID_STATE - 1000, 768 // See QUICHE_ERR_INVALID_STREAM_STATE. 769 QUICHE_H3_TRANSPORT_ERR_INVALID_STREAM_STATE = QUICHE_ERR_INVALID_STREAM_STATE - 1000, 771 // See QUICHE_ERR_INVALID_TRANSPORT_PARAM. 772 QUICHE_H3_TRANSPORT_ERR_INVALID_TRANSPORT_PARAM = QUICHE_ERR_INVALID_TRANSPORT_PARAM - 1000, 774 // See QUICHE_ERR_CRYPTO_FAIL. 775 QUICHE_H3_TRANSPORT_ERR_CRYPTO_FAIL = QUICHE_ERR_CRYPTO_FAIL - 1000, 777 // See QUICHE_ERR_TLS_FAIL. 778 QUICHE_H3_TRANSPORT_ERR_TLS_FAIL = QUICHE_ERR_TLS_FAIL - 1000, 780 // See QUICHE_ERR_FLOW_CONTROL. 781 QUICHE_H3_TRANSPORT_ERR_FLOW_CONTROL = QUICHE_ERR_FLOW_CONTROL - 1000, 783 // See QUICHE_ERR_STREAM_LIMIT. 784 QUICHE_H3_TRANSPORT_ERR_STREAM_LIMIT = QUICHE_ERR_STREAM_LIMIT - 1000, 786 // See QUICHE_ERR_STREAM_STOPPED. 787 QUICHE_H3_TRANSPORT_ERR_STREAM_STOPPED = QUICHE_ERR_STREAM_STOPPED - 1000, 789 // See QUICHE_ERR_STREAM_RESET. 790 QUICHE_H3_TRANSPORT_ERR_STREAM_RESET = QUICHE_ERR_STREAM_RESET - 1000, 792 // See QUICHE_ERR_FINAL_SIZE. 793 QUICHE_H3_TRANSPORT_ERR_FINAL_SIZE = QUICHE_ERR_FINAL_SIZE - 1000, 795 // See QUICHE_ERR_CONGESTION_CONTROL. 796 QUICHE_H3_TRANSPORT_ERR_CONGESTION_CONTROL = QUICHE_ERR_CONGESTION_CONTROL - 1000, 798 // See QUICHE_ERR_ID_LIMIT. 799 QUICHE_H3_TRANSPORT_ERR_ID_LIMIT = QUICHE_ERR_ID_LIMIT - 1000, 801 // See QUICHE_ERR_OUT_OF_IDENTIFIERS. 802 QUICHE_H3_TRANSPORT_ERR_OUT_OF_IDENTIFIERS = QUICHE_ERR_OUT_OF_IDENTIFIERS - 1000, 804 // See QUICHE_ERR_KEY_UPDATE. 805 QUICHE_H3_TRANSPORT_ERR_KEY_UPDATE = QUICHE_ERR_KEY_UPDATE - 1000, 808 // Stores configuration shared between multiple connections. 809 typedef struct quiche_h3_config quiche_h3_config; 811 // Creates an HTTP/3 config object with default settings values. 812 quiche_h3_config *quiche_h3_config_new(void); 814 // Sets the `SETTINGS_MAX_FIELD_SECTION_SIZE` setting. 815 void quiche_h3_config_set_max_field_section_size(quiche_h3_config *config, uint64_t v); 817 // Sets the `SETTINGS_QPACK_MAX_TABLE_CAPACITY` setting. 818 void quiche_h3_config_set_qpack_max_table_capacity(quiche_h3_config *config, uint64_t v); 820 // Sets the `SETTINGS_QPACK_BLOCKED_STREAMS` setting. 821 void quiche_h3_config_set_qpack_blocked_streams(quiche_h3_config *config, uint64_t v); 823 // Sets the `SETTINGS_ENABLE_CONNECT_PROTOCOL` setting. 824 void quiche_h3_config_enable_extended_connect(quiche_h3_config *config, bool enabled); 826 // Frees the HTTP/3 config object. 827 void quiche_h3_config_free(quiche_h3_config *config); 829 // An HTTP/3 connection. 830 typedef struct quiche_h3_conn quiche_h3_conn; 832 // Creates a new server-side connection. 833 quiche_h3_conn *quiche_h3_accept(quiche_conn *quiche_conn, 834 quiche_h3_config *config); 836 // Creates a new HTTP/3 connection using the provided QUIC connection. 837 quiche_h3_conn *quiche_h3_conn_new_with_transport(quiche_conn *quiche_conn, 838 quiche_h3_config *config); 840 enum quiche_h3_event_type { 841 QUICHE_H3_EVENT_HEADERS, 842 QUICHE_H3_EVENT_DATA, 843 QUICHE_H3_EVENT_FINISHED, 844 QUICHE_H3_EVENT_DATAGRAM, 845 QUICHE_H3_EVENT_GOAWAY, 846 QUICHE_H3_EVENT_RESET, 847 QUICHE_H3_EVENT_PRIORITY_UPDATE, 850 typedef struct quiche_h3_event quiche_h3_event; 852 // Processes HTTP/3 data received from the peer. 853 int64_t quiche_h3_conn_poll(quiche_h3_conn *conn, quiche_conn *quic_conn, 854 quiche_h3_event **ev); 856 // Returns the type of the event. 857 enum quiche_h3_event_type quiche_h3_event_type(quiche_h3_event *ev); 859 // Iterates over the headers in the event. 861 // The `cb` callback will be called for each header in `ev`. `cb` should check 862 // the validity of pseudo-headers and headers. If `cb` returns any value other 863 // than `0`, processing will be interrupted and the value is returned to the 865 int quiche_h3_event_for_each_header(quiche_h3_event *ev, 866 int (*cb)(uint8_t *name, size_t name_len, 867 uint8_t *value, size_t value_len, 871 // Iterates over the peer's HTTP/3 settings. 873 // The `cb` callback will be called for each setting in `conn`. 874 // If `cb` returns any value other than `0`, processing will be interrupted and 875 // the value is returned to the caller. 876 int quiche_h3_for_each_setting(quiche_h3_conn *conn, 877 int (*cb)(uint64_t identifier, 878 uint64_t value, void *argp), 881 // Check whether data will follow the headers on the stream. 882 bool quiche_h3_event_headers_has_body(quiche_h3_event *ev); 884 // Check whether or not extended connection is enabled by the peer 885 bool quiche_h3_extended_connect_enabled_by_peer(quiche_h3_conn *conn); 887 // Frees the HTTP/3 event object. 888 void quiche_h3_event_free(quiche_h3_event *ev); 894 const uint8_t *value; 898 // Extensible Priorities parameters. 902 } quiche_h3_priority; 904 // Sends an HTTP/3 request. 905 int64_t quiche_h3_send_request(quiche_h3_conn *conn, quiche_conn *quic_conn, 906 quiche_h3_header *headers, size_t headers_len, 909 // Sends an HTTP/3 response on the specified stream with default priority. 910 int quiche_h3_send_response(quiche_h3_conn *conn, quiche_conn *quic_conn, 911 uint64_t stream_id, quiche_h3_header *headers, 912 size_t headers_len, bool fin); 914 // Sends an HTTP/3 response on the specified stream with specified priority. 915 int quiche_h3_send_response_with_priority(quiche_h3_conn *conn, 916 quiche_conn *quic_conn, uint64_t stream_id, 917 quiche_h3_header *headers, size_t headers_len, 918 quiche_h3_priority *priority, bool fin); 920 // Sends an HTTP/3 body chunk on the given stream. 921 ssize_t quiche_h3_send_body(quiche_h3_conn *conn, quiche_conn *quic_conn, 922 uint64_t stream_id, uint8_t *body, size_t body_len, 925 // Reads request or response body data into the provided buffer. 926 ssize_t quiche_h3_recv_body(quiche_h3_conn *conn, quiche_conn *quic_conn, 927 uint64_t stream_id, uint8_t *out, size_t out_len); 929 // Try to parse an Extensible Priority field value. 930 int quiche_h3_parse_extensible_priority(uint8_t *priority, 932 quiche_h3_priority *parsed); 934 /// Sends a PRIORITY_UPDATE frame on the control stream with specified 935 /// request stream ID and priority. 936 int quiche_h3_send_priority_update_for_request(quiche_h3_conn *conn, 937 quiche_conn *quic_conn, 939 quiche_h3_priority *priority); 941 // Take the last received PRIORITY_UPDATE frame for a stream. 943 // The `cb` callback will be called once. `cb` should check the validity of 944 // priority field value contents. If `cb` returns any value other than `0`, 945 // processing will be interrupted and the value is returned to the caller. 946 int quiche_h3_take_last_priority_update(quiche_h3_conn *conn, 947 uint64_t prioritized_element_id, 948 int (*cb)(uint8_t *priority_field_value, 949 uint64_t priority_field_value_len, 953 // Returns whether the peer enabled HTTP/3 DATAGRAM frame support. 954 bool quiche_h3_dgram_enabled_by_peer(quiche_h3_conn *conn, 955 quiche_conn *quic_conn); 957 // Writes data to the DATAGRAM send queue. 958 ssize_t quiche_h3_send_dgram(quiche_h3_conn *conn, quiche_conn *quic_conn, 959 uint64_t flow_id, uint8_t *data, size_t data_len); 961 // Reads data from the DATAGRAM receive queue. 962 ssize_t quiche_h3_recv_dgram(quiche_h3_conn *conn, quiche_conn *quic_conn, 963 uint64_t *flow_id, size_t *flow_id_len, 964 uint8_t *out, size_t out_len); 966 // Frees the HTTP/3 connection object. 967 void quiche_h3_conn_free(quiche_h3_conn *conn); 969 #if defined(__cplusplus)