apiref.rst revision 8ae5ecb4
1API Reference 2============= 3 4.. highlight:: c 5 6Preliminaries 7------------- 8 9All declarations are in :file:`lsquic.h`, so it is enough to 10 11:: 12 13 #incluide <lsquic.h> 14 15in each source file. 16 17 18Library Version 19--------------- 20 21LSQUIC follows the following versioning model. The version number 22has the form MAJOR.MINOR.PATCH, where 23 24- MAJOR changes when a large redesign occurs; 25- MINOR changes when an API change or another significant change occurs; and 26- PATCH changes when a bug is fixed or another small, API-compatible change occurs. 27 28QUIC Versions 29------------- 30 31LSQUIC supports two types of QUIC protocol: Google QUIC and IETF QUIC. The 32former will at some point become obsolete, while the latter is still being 33developed by the IETF. Both types are included in a single enum: 34 35.. type:: enum lsquic_version 36 37 .. member:: LSQVER_043 38 39 Google QUIC version Q043 40 41 .. member:: LSQVER_046 42 43 Google QUIC version Q046 44 45 .. member:: LSQVER_050 46 47 Google QUIC version Q050 48 49 .. member:: LSQVER_ID27 50 51 IETF QUIC version ID (Internet-Draft) 27 52 53 .. member:: LSQVER_ID28 54 55 IETF QUIC version ID 28 56 57 .. member:: N_LSQVER 58 59 Special value indicating the number of versions in the enum. It 60 may be used as argument to :func:`lsquic_engine_connect()`. 61 62Several version lists (as bitmasks) are defined in :file:`lsquic.h`: 63 64.. macro:: LSQUIC_SUPPORTED_VERSIONS 65 66List of all supported versions. 67 68.. macro:: LSQUIC_FORCED_TCID0_VERSIONS 69 70List of versions in which the server never includes CID in short packets. 71 72.. macro:: LSQUIC_EXPERIMENTAL_VERSIONS 73 74Experimental versions. 75 76.. macro: LSQUIC_DEPRECATED_VERSIONS 77 78Deprecated versions. 79 80.. macro:: LSQUIC_GQUIC_HEADER_VERSIONS 81 82Versions that have Google QUIC-like headers. Only Q043 remains in this 83list. 84 85.. macro:: LSQUIC_IETF_VERSIONS 86 87IETF QUIC versions. 88 89.. macro:: LSQUIC_IETF_DRAFT_VERSIONS 90 91IETF QUIC *draft* versions. When IETF QUIC v1 is released, it will not 92be included in this list. 93 94LSQUIC Types 95------------ 96 97LSQUIC declares several types used by many of its public functions. They are: 98 99.. type:: lsquic_engine_t 100 101 Instance of LSQUIC engine. 102 103.. type:: lsquic_conn_t 104 105 QUIC connection. 106 107.. type:: lsquic_stream_t 108 109 QUIC stream. 110 111.. type:: lsquic_stream_id_t 112 113 Stream ID. 114 115.. type:: lsquic_conn_ctx_t 116 117 Connection context. This is the return value of :func:`on_new_conn()`. 118 To LSQUIC, this is just an opaque pointer. User code is expected to 119 use it for its own purposes. 120 121.. type:: lsquic_stream_ctx_t 122 123 Stream context. This is the return value of :func:`on_new_stream()`. 124 To LSQUIC, this is just an opaque pointer. User code is expected to 125 use it for its own purposes. 126 127.. type:: lsquic_http_headers_t 128 129 HTTP headers 130 131Library Initialization 132---------------------- 133 134Before using the library, internal structures must be initialized using 135the global initialization function: 136 137:: 138 139 if (0 == lsquic_global_init(LSQUIC_GLOBAL_CLIENT|LSQUIC_GLOBAL_SERVER)) 140 /* OK, do something useful */ 141 ; 142 143This call only needs to be made once. Afterwards, any number of LSQUIC 144engines may be instantiated. 145 146After a process is done using LSQUIC, it should clean up: 147 148:: 149 150 lsquic_global_cleanup(); 151 152Logging 153------- 154 155.. type:: struct lsquic_logger_if 156 157 .. member:: int (*log_buf)(void *logger_ctx, const char *buf, size_t len) 158 159.. function:: void lsquic_logger_init (const struct lsquic_logger_if *logger_if, void *logger_ctx, enum lsquic_logger_timestamp_style) 160 161 Call this if you want to do something with LSQUIC log messages, as they are thrown out by default. 162 163.. function:: int lsquic_set_log_level (const char *log_level) 164 165 Set log level for all LSQUIC modules. 166 167 :param log_level: Acceptable values are debug, info, notice, warning, error, alert, emerg, crit (case-insensitive). 168 :return: 0 on success or -1 on failure (invalid log level). 169 170.. function:: int lsquic_logger_lopt (const char *log_specs) 171 172 Set log level for a particular module or several modules. 173 174 :param log_specs: 175 176 One or more "module=level" specifications serapated by comma. 177 For example, "event=debug,engine=info". See `List of Log Modules`_ 178 179Engine Instantiation and Destruction 180------------------------------------ 181 182To use the library, an instance of the ``struct lsquic_engine`` needs to be 183created: 184 185.. function:: lsquic_engine_t *lsquic_engine_new (unsigned flags, const struct lsquic_engine_api *api) 186 187 Create a new engine. 188 189 :param flags: This is is a bitmask of ``LSENG_SERVER``` and ``LSENG_HTTP``. 190 :param api: Pointer to an initialized :type:`lsquic_engine_api`. 191 192 The engine can be instantiated either in server mode (when ``LSENG_SERVER`` 193 is set) or client mode. If you need both server and client in your program, 194 create two engines (or as many as you'd like). 195 196 Specifying ``LSENG_HTTP`` flag enables the HTTP functionality: HTTP/2-like 197 for Google QUIC connections and HTTP/3 functionality for IETF QUIC 198 connections. 199 200.. function:: void lsquic_engine_cooldown (lsquic_engine_t *engine) 201 202 This function closes all mini connections and marks all full connections 203 as going away. In server mode, this also causes the engine to stop 204 creating new connections. 205 206.. function:: void lsquic_engine_destroy (lsquic_engine_t *engine) 207 208 Destroy engine and all its resources. 209 210Engine Callbacks 211---------------- 212 213``struct lsquic_engine_api`` contains a few mandatory members and several 214optional members. 215 216.. type:: struct lsquic_engine_api 217 218 .. member:: const struct lsquic_stream_if *ea_stream_if 219 .. member:: void *ea_stream_if_ctx 220 221 ``ea_stream_if`` is mandatory. This structure contains pointers 222 to callbacks that handle connections and stream events. 223 224 .. member:: lsquic_packets_out_f ea_packets_out 225 .. member:: void *ea_packets_out_ctx 226 227 ``ea_packets_out`` is used by the engine to send packets. 228 229 .. member:: const struct lsquic_engine_settings *ea_settings 230 231 If ``ea_settings`` is set to NULL, the engine uses default settings 232 (see :func:`lsquic_engine_init_settings()`) 233 234 .. member:: lsquic_lookup_cert_f ea_lookup_cert 235 .. member:: void *ea_cert_lu_ctx 236 237 Look up certificate. Mandatory in server mode. 238 239 .. member:: struct ssl_ctx_st * (*ea_get_ssl_ctx)(void *peer_ctx) 240 241 Get SSL_CTX associated with a peer context. Mandatory in server 242 mode. This is use for default values for SSL instantiation. 243 244 .. member:: const struct lsquic_hset_if *ea_hsi_if 245 .. member:: void *ea_hsi_ctx 246 247 Optional header set interface. If not specified, the incoming headers 248 are converted to HTTP/1.x format and are read from stream and have to 249 be parsed again. 250 251 .. member:: const struct lsquic_shared_hash_if *ea_shi 252 .. member:: void *ea_shi_ctx 253 254 Shared hash interface can be used to share state between several 255 processes of a single QUIC server. 256 257 .. member:: const struct lsquic_packout_mem_if *ea_pmi 258 .. member:: void *ea_pmi_ctx 259 260 Optional set of functions to manage memory allocation for outgoing 261 packets. 262 263 .. member:: lsquic_cids_update_f ea_new_scids 264 .. member:: lsquic_cids_update_f ea_live_scids 265 .. member:: lsquic_cids_update_f ea_old_scids 266 .. member:: void *ea_cids_update_ctx 267 268 In a multi-process setup, it may be useful to observe the CID 269 lifecycle. This optional set of callbacks makes it possible. 270 271.. _apiref-engine-settings: 272 273Engine Settings 274--------------- 275 276Engine behavior can be controlled by several settings specified in the 277settings structure: 278 279.. type:: struct lsquic_engine_settings 280 281 .. member:: unsigned es_versions 282 283 This is a bit mask wherein each bit corresponds to a value in 284 :type:`lsquic_version`. Client starts negotiating with the highest 285 version and goes down. Server supports either of the versions 286 specified here. This setting applies to both Google and IETF QUIC. 287 288 The default value is :macro:`LSQUIC_DF_VERSIONS`. 289 290 .. member:: unsigned es_cfcw 291 292 Initial default connection flow control window. 293 294 In server mode, per-connection values may be set lower than 295 this if resources are scarce. 296 297 Do not set es_cfcw and es_sfcw lower than :macro:`LSQUIC_MIN_FCW`. 298 299 .. member:: unsigned es_sfcw 300 301 Initial default stream flow control window. 302 303 In server mode, per-connection values may be set lower than 304 this if resources are scarce. 305 306 Do not set es_cfcw and es_sfcw lower than :macro:`LSQUIC_MIN_FCW`. 307 308 .. member:: unsigned es_max_cfcw 309 310 This value is used to specify maximum allowed value connection flow 311 control window is allowed to reach due to window auto-tuning. By 312 default, this value is zero, which means that CFCW is not allowed 313 to increase from its initial value. 314 315 .. member:: unsigned es_max_sfcw 316 317 This value is used to specify maximum allowed value stream flow 318 control window is allowed to reach due to window auto-tuning. By 319 default, this value is zero, which means that CFCW is not allowed 320 to increase from its initial value. 321 322 .. member:: unsigned es_max_streams_in 323 324 Maximum incoming streams, a.k.a. MIDS. 325 326 Google QUIC only. 327 328 .. member:: unsigned long es_handshake_to 329 330 Handshake timeout in microseconds. 331 332 For client, this can be set to an arbitrary value (zero turns the 333 timeout off). 334 335 For server, this value is limited to about 16 seconds. Do not set 336 it to zero. 337 338 Defaults to :macro:`LSQUIC_DF_HANDSHAKE_TO`. 339 340 .. member:: unsigned long es_idle_conn_to 341 342 Idle connection timeout, a.k.a ICSL, in microseconds; GQUIC only. 343 344 Defaults to :macro:`LSQUIC_DF_IDLE_CONN_TO` 345 346 .. member:: int es_silent_close 347 348 SCLS (silent close) 349 350 .. member:: unsigned es_max_header_list_size 351 352 This corresponds to SETTINGS_MAX_HEADER_LIST_SIZE 353 (:rfc:`7540#section-6.5.2`). 0 means no limit. Defaults 354 to :func:`LSQUIC_DF_MAX_HEADER_LIST_SIZE`. 355 356 .. member:: const char *es_ua 357 358 UAID -- User-Agent ID. Defaults to :macro:`LSQUIC_DF_UA`. 359 360 Google QUIC only. 361 362 363 More parameters for server 364 365 .. member:: unsigned es_max_inchoate 366 367 Maximum number of incoming connections in inchoate state. (In 368 other words, maximum number of mini connections.) 369 370 This is only applicable in server mode. 371 372 Defaults to :macro:`LSQUIC_DF_MAX_INCHOATE`. 373 374 .. member:: int es_support_push 375 376 Setting this value to 0 means that 377 378 For client: 379 380 1. we send a SETTINGS frame to indicate that we do not support server 381 push; and 382 2. all incoming pushed streams get reset immediately. 383 384 (For maximum effect, set es_max_streams_in to 0.) 385 386 For server: 387 388 1. :func:`lsquic_conn_push_stream()` will return -1. 389 390 .. member:: int es_support_tcid0 391 392 If set to true value, the server will not include connection ID in 393 outgoing packets if client's CHLO specifies TCID=0. 394 395 For client, this means including TCID=0 into CHLO message. Note that 396 in this case, the engine tracks connections by the 397 (source-addr, dest-addr) tuple, thereby making it necessary to create 398 a socket for each connection. 399 400 This option has no effect in Q046, as the server never includes 401 CIDs in the short packets. 402 403 The default is :func:`LSQUIC_DF_SUPPORT_TCID0`. 404 405 .. member:: int es_support_nstp 406 407 Q037 and higher support "No STOP_WAITING frame" mode. When set, the 408 client will send NSTP option in its Client Hello message and will not 409 sent STOP_WAITING frames, while ignoring incoming STOP_WAITING frames, 410 if any. Note that if the version negotiation happens to downgrade the 411 client below Q037, this mode will *not* be used. 412 413 This option does not affect the server, as it must support NSTP mode 414 if it was specified by the client. 415 416 Defaults to :macro:`LSQUIC_DF_SUPPORT_NSTP`. 417 418 .. member:: int es_honor_prst 419 420 If set to true value, the library will drop connections when it 421 receives corresponding Public Reset packet. The default is to 422 ignore these packets. 423 424 .. member:: int es_send_prst 425 426 If set to true value, the library will send Public Reset packets 427 in response to incoming packets with unknown Connection IDs. 428 429 The default is :macro:`LSQUIC_DF_SEND_PRST`. 430 431 .. member:: unsigned es_progress_check 432 433 A non-zero value enables internal checks that identify suspected 434 infinite loops in user `on_read` and `on_write` callbacks 435 and break them. An infinite loop may occur if user code keeps 436 on performing the same operation without checking status, e.g. 437 reading from a closed stream etc. 438 439 The value of this parameter is as follows: should a callback return 440 this number of times in a row without making progress (that is, 441 reading, writing, or changing stream state), loop break will occur. 442 443 The defaut value is :macro:`LSQUIC_DF_PROGRESS_CHECK`. 444 445 .. member:: int es_rw_once 446 447 A non-zero value make stream dispatch its read-write events once 448 per call. 449 450 When zero, read and write events are dispatched until the stream 451 is no longer readable or writeable, respectively, or until the 452 user signals unwillingness to read or write using 453 :func:`lsquic_stream_wantread()` or :func:`lsquic_stream_wantwrite()` 454 or shuts down the stream. 455 456 The default value is :macro:`LSQUIC_DF_RW_ONCE`. 457 458 .. member:: unsigned es_proc_time_thresh 459 460 If set, this value specifies that number of microseconds that 461 :func:`lsquic_engine_process_conns()` and 462 :func:`lsquic_engine_send_unsent_packets()` are allowed to spend 463 before returning. 464 465 This is not an exact science and the connections must make 466 progress, so the deadline is checked after all connections get 467 a chance to tick (in the case of :func:`lsquic_engine_process_conns())` 468 and at least one batch of packets is sent out. 469 470 When processing function runs out of its time slice, immediate 471 calls to :func:`lsquic_engine_has_unsent_packets()` return false. 472 473 The default value is :func:`LSQUIC_DF_PROC_TIME_THRESH`. 474 475 .. member:: int es_pace_packets 476 477 If set to true, packet pacing is implemented per connection. 478 479 The default value is :func:`LSQUIC_DF_PACE_PACKETS`. 480 481 .. member:: unsigned es_clock_granularity 482 483 Clock granularity information is used by the pacer. The value 484 is in microseconds; default is :func:`LSQUIC_DF_CLOCK_GRANULARITY`. 485 486 .. member:: unsigned es_init_max_data 487 488 Initial max data. 489 490 This is a transport parameter. 491 492 Depending on the engine mode, the default value is either 493 :macro:`LSQUIC_DF_INIT_MAX_DATA_CLIENT` or 494 :macro:`LSQUIC_DF_INIT_MAX_DATA_SERVER`. 495 496 IETF QUIC only. 497 498 .. member:: unsigned es_init_max_stream_data_bidi_remote 499 500 Initial max stream data. 501 502 This is a transport parameter. 503 504 Depending on the engine mode, the default value is either 505 :macro:`LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_REMOTE_CLIENT` or 506 :macro:`LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_REMOTE_SERVER`. 507 508 IETF QUIC only. 509 510 .. member:: unsigned es_init_max_stream_data_bidi_local 511 512 Initial max stream data. 513 514 This is a transport parameter. 515 516 Depending on the engine mode, the default value is either 517 :macro:`LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_LOCAL_CLIENT` or 518 :macro:`LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_LOCAL_SERVER`. 519 520 IETF QUIC only. 521 522 .. member:: unsigned es_init_max_stream_data_uni 523 524 Initial max stream data for unidirectional streams initiated 525 by remote endpoint. 526 527 This is a transport parameter. 528 529 Depending on the engine mode, the default value is either 530 :macro:`LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_CLIENT` or 531 :macro:`LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_SERVER`. 532 533 IETF QUIC only. 534 535 .. member:: unsigned es_init_max_streams_bidi 536 537 Maximum initial number of bidirectional stream. 538 539 This is a transport parameter. 540 541 Default value is :macro:`LSQUIC_DF_INIT_MAX_STREAMS_BIDI`. 542 543 IETF QUIC only. 544 545 .. member:: unsigned es_init_max_streams_uni 546 547 Maximum initial number of unidirectional stream. 548 549 This is a transport parameter. 550 551 Default value is :macro:`LSQUIC_DF_INIT_MAX_STREAMS_UNI_CLIENT` or 552 :macro:`LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_SERVER`. 553 554 IETF QUIC only. 555 556 .. member:: unsigned es_idle_timeout 557 558 Idle connection timeout. 559 560 This is a transport parameter. 561 562 (Note: `es_idle_conn_to` is not reused because it is in microseconds, 563 which, I now realize, was not a good choice. Since it will be 564 obsoleted some time after the switchover to IETF QUIC, we do not 565 have to keep on using strange units.) 566 567 Default value is :macro:`LSQUIC_DF_IDLE_TIMEOUT`. 568 569 Maximum value is 600 seconds. 570 571 IETF QUIC only. 572 573 .. member:: unsigned es_ping_period 574 575 Ping period. If set to non-zero value, the connection will generate and 576 send PING frames in the absence of other activity. 577 578 By default, the server does not send PINGs and the period is set to zero. 579 The client's defaut value is :macro:`LSQUIC_DF_PING_PERIOD`. 580 581 IETF QUIC only. 582 583 .. member:: unsigned es_scid_len 584 585 Source Connection ID length. Valid values are 0 through 20, inclusive. 586 587 Default value is :macro:`LSQUIC_DF_SCID_LEN`. 588 589 IETF QUIC only. 590 591 .. member:: unsigned es_scid_iss_rate 592 593 Source Connection ID issuance rate. This field is measured in CIDs 594 per minute. Using value 0 indicates that there is no rate limit for 595 CID issuance. 596 597 Default value is :macro:`LSQUIC_DF_SCID_ISS_RATE`. 598 599 IETF QUIC only. 600 601 .. member:: unsigned es_qpack_dec_max_size 602 603 Maximum size of the QPACK dynamic table that the QPACK decoder will 604 use. 605 606 The default is :macro:`LSQUIC_DF_QPACK_DEC_MAX_SIZE`. 607 608 IETF QUIC only. 609 610 .. member:: unsigned es_qpack_dec_max_blocked 611 612 Maximum number of blocked streams that the QPACK decoder is willing 613 to tolerate. 614 615 The default is :macro:`LSQUIC_DF_QPACK_DEC_MAX_BLOCKED`. 616 617 IETF QUIC only. 618 619 .. member:: unsigned es_qpack_enc_max_size 620 621 Maximum size of the dynamic table that the encoder is willing to use. 622 The actual size of the dynamic table will not exceed the minimum of 623 this value and the value advertized by peer. 624 625 The default is :macro:`LSQUIC_DF_QPACK_ENC_MAX_SIZE`. 626 627 IETF QUIC only. 628 629 .. member:: unsigned es_qpack_enc_max_blocked 630 631 Maximum number of blocked streams that the QPACK encoder is willing 632 to risk. The actual number of blocked streams will not exceed the 633 minimum of this value and the value advertized by peer. 634 635 The default is :macro:`LSQUIC_DF_QPACK_ENC_MAX_BLOCKED`. 636 637 IETF QUIC only. 638 639 .. member:: int es_ecn 640 641 Enable ECN support. 642 643 The default is :macro:`LSQUIC_DF_ECN` 644 645 IETF QUIC only. 646 647 .. member:: int es_allow_migration 648 649 Allow peer to migrate connection. 650 651 The default is :macro:`LSQUIC_DF_ALLOW_MIGRATION` 652 653 IETF QUIC only. 654 655 .. member:: unsigned es_cc_algo 656 657 Congestion control algorithm to use. 658 659 - 0: Use default (:macro:`LSQUIC_DF_CC_ALGO)` 660 - 1: Cubic 661 - 2: BBR 662 663 IETF QUIC only. 664 665 .. member:: int es_ql_bits 666 667 Use QL loss bits. Allowed values are: 668 669 - 0: Do not use loss bits 670 - 1: Allow loss bits 671 - 2: Allow and send loss bits 672 673 Default value is :macro:`LSQUIC_DF_QL_BITS` 674 675 .. member:: int es_spin 676 677 Enable spin bit. Allowed values are 0 and 1. 678 679 Default value is :macro:`LSQUIC_DF_SPIN` 680 681 .. member:: int es_delayed_acks 682 683 Enable delayed ACKs extension. Allowed values are 0 and 1. 684 685 **Warning**: this is an experimental feature. Using it will most likely 686 lead to degraded performance. 687 688 Default value is :macro:`LSQUIC_DF_DELAYED_ACKS` 689 690 .. member:: int es_timestamps 691 692 Enable timestamps extension. Allowed values are 0 and 1. 693 694 Default value is @ref LSQUIC_DF_TIMESTAMPS 695 696 .. member:: unsigned short es_max_udp_payload_size_rx 697 698 Maximum packet size we are willing to receive. This is sent to 699 peer in transport parameters: the library does not enforce this 700 limit for incoming packets. 701 702 If set to zero, limit is not set. 703 704 Default value is :macro:`LSQUIC_DF_MAX_UDP_PAYLOAD_SIZE_RX` 705 706 .. member:: unsigned es_noprogress_timeout 707 708 No progress timeout. 709 710 If connection does not make progress for this number of seconds, the 711 connection is dropped. Here, progress is defined as user streams 712 being written to or read from. 713 714 If this value is zero, this timeout is disabled. 715 716 Default value is :macro:`LSQUIC_DF_NOPROGRESS_TIMEOUT_SERVER` in server 717 mode and :macro:`LSQUIC_DF_NOPROGRESS_TIMEOUT_CLIENT` in client mode. 718 719To initialize the settings structure to library defaults, use the following 720convenience function: 721 722.. function:: lsquic_engine_init_settings (struct lsquic_engine_settings *, unsigned flags) 723 724 ``flags`` is a bitmask of ``LSENG_SERVER`` and ``LSENG_HTTP`` 725 726After doing this, change just the settings you'd like. To check whether 727the values are correct, another convenience function is provided: 728 729.. function:: lsquic_engine_check_settings (const struct lsquic_engine_settings *, unsigned flags, char *err_buf, size_t err_buf_sz) 730 731 Check settings for errors. Return 0 if settings are OK, -1 otherwise. 732 733 If `err_buf` and `err_buf_sz` are set, an error string is written to the 734 buffers. 735 736The following macros in :file:`lsquic.h` specify default values: 737 738*Note that, despite our best efforts, documentation may accidentally get 739out of date. Please check your :file:`lsquic.h` for actual values.* 740 741.. macro:: LSQUIC_MIN_FCW 742 743 Minimum flow control window is set to 16 KB for both client and server. 744 This means we can send up to this amount of data before handshake gets 745 completed. 746 747.. macro:: LSQUIC_DF_VERSIONS 748 749 By default, deprecated and experimental versions are not included. 750 751.. macro:: LSQUIC_DF_CFCW_SERVER 752.. macro:: LSQUIC_DF_CFCW_CLIENT 753.. macro:: LSQUIC_DF_SFCW_SERVER 754.. macro:: LSQUIC_DF_SFCW_CLIENT 755.. macro:: LSQUIC_DF_MAX_STREAMS_IN 756 757.. macro:: LSQUIC_DF_INIT_MAX_DATA_SERVER 758.. macro:: LSQUIC_DF_INIT_MAX_DATA_CLIENT 759.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_REMOTE_SERVER 760.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_LOCAL_SERVER 761.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_REMOTE_CLIENT 762.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_LOCAL_CLIENT 763.. macro:: LSQUIC_DF_INIT_MAX_STREAMS_BIDI 764.. macro:: LSQUIC_DF_INIT_MAX_STREAMS_UNI_CLIENT 765.. macro:: LSQUIC_DF_INIT_MAX_STREAMS_UNI_SERVER 766.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_CLIENT 767.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_SERVER 768 769.. macro:: LSQUIC_DF_IDLE_TIMEOUT 770 771 Default idle connection timeout is 30 seconds. 772 773.. macro:: LSQUIC_DF_PING_PERIOD 774 775 Default ping period is 15 seconds. 776 777.. macro:: LSQUIC_DF_HANDSHAKE_TO 778 779 Default handshake timeout is 10,000,000 microseconds (10 seconds). 780 781.. macro:: LSQUIC_DF_IDLE_CONN_TO 782 783 Default idle connection timeout is 30,000,000 microseconds. 784 785.. macro:: LSQUIC_DF_SILENT_CLOSE 786 787 By default, connections are closed silenty when they time out (no 788 CONNECTION_CLOSE frame is sent). 789 790.. macro:: LSQUIC_DF_MAX_HEADER_LIST_SIZE 791 792 Default value of maximum header list size. If set to non-zero value, 793 SETTINGS_MAX_HEADER_LIST_SIZE will be sent to peer after handshake is 794 completed (assuming the peer supports this setting frame type). 795 796.. macro:: LSQUIC_DF_UA 797 798 Default value of UAID (user-agent ID). 799 800.. macro:: LSQUIC_DF_MAX_INCHOATE 801 802 Default is 1,000,000. 803 804.. macro:: LSQUIC_DF_SUPPORT_NSTP 805 806 NSTP is not used by default. 807 808.. macro:: LSQUIC_DF_SUPPORT_PUSH 809 810 Push promises are supported by default. 811 812.. macro:: LSQUIC_DF_SUPPORT_TCID0 813 814 Support for TCID=0 is enabled by default. 815 816.. macro:: LSQUIC_DF_HONOR_PRST 817 818 By default, LSQUIC ignores Public Reset packets. 819 820.. macro:: LSQUIC_DF_SEND_PRST 821 822 By default, LSQUIC will not send Public Reset packets in response to 823 packets that specify unknown connections. 824 825.. macro:: LSQUIC_DF_PROGRESS_CHECK 826 827 By default, infinite loop checks are turned on. 828 829.. macro:: LSQUIC_DF_RW_ONCE 830 831 By default, read/write events are dispatched in a loop. 832 833.. macro:: LSQUIC_DF_PROC_TIME_THRESH 834 835 By default, the threshold is not enabled. 836 837.. macro:: LSQUIC_DF_PACE_PACKETS 838 839 By default, packets are paced 840 841.. macro:: LSQUIC_DF_CLOCK_GRANULARITY 842 843 Default clock granularity is 1000 microseconds. 844 845.. macro:: LSQUIC_DF_SCID_LEN 8 846 847 The default value is 8 for simplicity and speed. 848 849.. macro:: LSQUIC_DF_SCID_ISS_RATE 850 851 The default value is 60 CIDs per minute. 852 853.. macro:: LSQUIC_DF_QPACK_DEC_MAX_BLOCKED 854 855 Default value is 100. 856 857.. macro:: LSQUIC_DF_QPACK_DEC_MAX_SIZE 858 859 Default value is 4,096 bytes. 860 861.. macro:: LSQUIC_DF_QPACK_ENC_MAX_BLOCKED 862 863 Default value is 100. 864 865.. macro:: LSQUIC_DF_QPACK_ENC_MAX_SIZE 866 867 Default value is 4,096 bytes. 868 869.. macro:: LSQUIC_DF_ECN 870 871 ECN is disabled by default. 872 873.. macro:: LSQUIC_DF_ALLOW_MIGRATION 874 875 Allow migration by default. 876 877.. macro:: LSQUIC_DF_QL_BITS 878 879 Use QL loss bits by default. 880 881.. macro:: LSQUIC_DF_SPIN 882 883 Turn spin bit on by default. 884 885.. macro:: LSQUIC_DF_CC_ALGO 886 887 Use Cubic by default. 888 889.. macro:: LSQUIC_DF_DELAYED_ACKS 890 891 Delayed ACKs are off by default. 892 893.. macro:: LSQUIC_DF_MAX_UDP_PAYLOAD_SIZE_RX 894 895 By default, incoming packet size is not limited. 896 897.. macro:: LSQUIC_DF_NOPROGRESS_TIMEOUT_SERVER 898 899 By default, drop no-progress connections after 60 seconds on the server. 900 901.. macro:: LSQUIC_DF_NOPROGRESS_TIMEOUT_CLIENT 902 903 By default, do not use no-progress timeout on the client. 904 905Receiving Packets 906----------------- 907 908Incoming packets are supplied to the engine using :func:`lsquic_engine_packet_in()`. 909It is up to the engine to decide what do to with the packet. It can find an existing 910connection and dispatch the packet there, create a new connection (in server mode), or 911schedule a version negotiation or stateless reset packet. 912 913.. function:: int lsquic_engine_packet_in (lsquic_engine_t *engine, const unsigned char *data, size_t size, const struct sockaddr *local, const struct sockaddr *peer, void *peer_ctx, int ecn) 914 915 Pass incoming packet to the QUIC engine. This function can be called 916 more than once in a row. After you add one or more packets, call 917 :func:`lsquic_engine_process_conns()` to schedule outgoing packets, if any. 918 919 :param engine: Engine instance. 920 :param data: Pointer to UDP datagram payload. 921 :param size: Size of UDP datagram. 922 :param local: Local address. 923 :param peer: Peer address. 924 :param peer_ctx: Peer context. 925 :param ecn: ECN marking associated with this UDP datagram. 926 927 :return: 928 929 - ``0``: Packet was processed by a real connection. 930 - ``1``: Packet was handled successfully, but not by a connection. 931 This may happen with version negotiation and public reset 932 packets as well as some packets that may be ignored. 933 - ``-1``: Some error occurred. Possible reasons are invalid packet 934 size or failure to allocate memory. 935 936.. function:: int lsquic_engine_earliest_adv_tick (lsquic_engine_t *engine, int *diff) 937 938 Returns true if there are connections to be processed, false otherwise. 939 940 :param engine: 941 942 Engine instance. 943 944 :param diff: 945 946 If the function returns a true value, the pointed to integer is set to the 947 difference between the earliest advisory tick time and now. 948 If the former is in the past, this difference is negative. 949 950 :return: 951 952 True if there are connections to be processed, false otherwise. 953 954Sending Packets 955--------------- 956 957User specifies a callback :type:`lsquic_packets_out_f` in :type:`lsquic_engine_api` 958that the library uses to send packets. 959 960.. type:: struct lsquic_out_spec 961 962 This structure describes an outgoing packet. 963 964 .. member:: struct iovec *iov 965 966 A vector with payload. 967 968 .. member:: size_t iovlen 969 970 Vector length. 971 972 .. member:: const struct sockaddr *local_sa 973 974 Local address. 975 976 .. member:: const struct sockaddr *dest_sa 977 978 Destination address. 979 980 .. member:: void *peer_ctx 981 982 Peer context associated with the local address. 983 984 .. member:: int ecn 985 986 ECN: Valid values are 0 - 3. See :rfc:`3168`. 987 988 ECN may be set by IETF QUIC connections if ``es_ecn`` is set. 989 990.. type: typedef int (*lsquic_packets_out_f)(void *packets_out_ctx, const struct lsquic_out_spec *out_spec, unsigned n_packets_out) 991 992 Returns number of packets successfully sent out or -1 on error. -1 should 993 only be returned if no packets were sent out. If -1 is returned or if the 994 return value is smaller than ``n_packets_out``, this indicates that sending 995 of packets is not possible. 996 997 If not all packets could be sent out, then: 998 999 - errno is examined. If it is not EAGAIN or EWOULDBLOCK, the connection 1000 whose packet caused the error is closed forthwith. 1001 - No packets are attempted to be sent out until :func:`lsquic_engine_send_unsent_packets()` 1002 is called. 1003 1004.. function:: void lsquic_engine_process_conns (lsquic_engine_t *engine) 1005 1006 Process tickable connections. This function must be called often enough so 1007 that packets and connections do not expire. The preferred method of doing 1008 so is by using :func:`lsquic_engine_earliest_adv_tick()`. 1009 1010.. function:: int lsquic_engine_has_unsent_packets (lsquic_engine_t *engine) 1011 1012 Returns true if engine has some unsent packets. This happens if 1013 ``ea_packets_out()`` could not send everything out. 1014 1015.. function:: void lsquic_engine_send_unsent_packets (lsquic_engine_t *engine) 1016 1017 Send out as many unsent packets as possibe: until we are out of unsent 1018 packets or until ``ea_packets_out()`` fails. 1019 1020 If ``ea_packets_out()`` cannot send all packets, this function must be 1021 called to signify that sending of packets is possible again. 1022 1023Stream Callback Interface 1024------------------------- 1025 1026The stream callback interface structure lists the callbacks used by 1027the engine to communicate with the user code: 1028 1029.. type:: struct lsquic_stream_if 1030 1031 .. member:: lsquic_conn_ctx_t *(*on_new_conn)(void *stream_if_ctx, 1032 lsquic_conn_t *); 1033 1034 Called when a new connection has been created. In server mode, 1035 this means that the handshake has been successful. In client mode, 1036 on the other hand, this callback is called as soon as connection 1037 object is created inside the engine, but before the handshake is 1038 done. 1039 1040 The return value is the connection context associated with this 1041 connection. Use :func:`lsquic_conn_get_ctx()` to get back this 1042 context. It is OK for this function to return NULL. 1043 1044 This callback is mandatory. 1045 1046 .. member:: void (*on_conn_closed)(lsquic_conn_t *) 1047 1048 Connection is closed. 1049 1050 This callback is mandatory. 1051 1052 .. member:: lsquic_stream_ctx_t * (*on_new_stream)(void *stream_if_ctx, lsquic_stream_t *) 1053 1054 If you need to initiate a connection, call lsquic_conn_make_stream(). 1055 This will cause `on_new_stream` callback to be called when appropriate 1056 (this operation is delayed when maximum number of outgoing streams is 1057 reached). 1058 1059 If connection is going away, this callback may be called with the 1060 second parameter set to NULL. 1061 1062 The return value is the stream context associated with the stream. 1063 A pointer to it is passed to `on_read()`, `on_write()`, and `on_close()` 1064 callbacks. It is OK for this function to return NULL. 1065 1066 This callback is mandatory. 1067 1068 .. member:: void (*on_read) (lsquic_stream_t *s, lsquic_stream_ctx_t *h) 1069 1070 Stream is readable: either there are bytes to be read or an error 1071 is ready to be collected. 1072 1073 This callback is mandatory. 1074 1075 .. member:: void (*on_write) (lsquic_stream_t *s, lsquic_stream_ctx_t *h) 1076 1077 Stream is writeable. 1078 1079 This callback is mandatory. 1080 1081 .. member:: void (*on_close) (lsquic_stream_t *s, lsquic_stream_ctx_t *h) 1082 1083 After this callback returns, the stream is no longer accessible. This is 1084 a good time to clean up the stream context. 1085 1086 This callback is mandatory. 1087 1088 .. member:: void (*on_hsk_done)(lsquic_conn_t *c, enum lsquic_hsk_status s) 1089 1090 When handshake is completed, this callback is called. 1091 1092 This callback is optional. 1093 1094 .. member:: void (*on_goaway_received)(lsquic_conn_t *) 1095 1096 This is called when our side received GOAWAY frame. After this, 1097 new streams should not be created. 1098 1099 This callback is optional. 1100 1101 .. member:: void (*on_new_token)(lsquic_conn_t *c, const unsigned char *token, size_t token_size) 1102 1103 When client receives a token in NEW_TOKEN frame, this callback is called. 1104 1105 This callback is optional. 1106 1107 .. member:: void (*on_zero_rtt_info)(lsquic_conn_t *c, const unsigned char *, size_t) 1108 1109 This callback lets client record information needed to 1110 perform a zero-RTT handshake next time around. 1111 1112 This callback is optional. 1113 1114Creating Connections 1115-------------------- 1116 1117In server mode, the connections are created by the library based on incoming 1118packets. After handshake is completed, the library calls :func:`on_new_conn()` 1119callback. 1120 1121In client mode, a new connection is created by 1122 1123.. function:: lsquic_conn_t * lsquic_engine_connect (lsquic_engine_t *engine, enum lsquic_version version, const struct sockaddr *local_sa, const struct sockaddr *peer_sa, void *peer_ctx, lsquic_conn_ctx_t *conn_ctx, const char *sni, unsigned short max_udp_payload_size, const unsigned char *zero_rtt, size_t zero_rtt_len, const unsigned char *token, size_t token_sz) 1124 1125 :param engine: Engine to use. 1126 1127 :param version: 1128 1129 To let the engine specify QUIC version, use N_LSQVER. If zero-rtt info is 1130 supplied, version is picked from there instead. 1131 1132 :param local_sa: 1133 1134 Local address. 1135 1136 :param peer_sa: 1137 1138 Address of the server. 1139 1140 :param peer_ctx: 1141 1142 Context associated with the connection. This is what gets passed to TODO. 1143 1144 :param conn_ctx: 1145 1146 Connection context can be set early using this parameter. Useful if 1147 you need the connection context to be available in `on_conn_new()`. 1148 Note that that callback's return value replaces the connection 1149 context set here. 1150 1151 :param sni: 1152 1153 The SNI is required for Google QUIC connections; it is optional for 1154 IETF QUIC and may be set to NULL. 1155 1156 :param max_udp_payload_size: 1157 1158 Maximum packet size. If set to zero, it is inferred based on `peer_sa` 1159 and `version`. 1160 1161 :param zero_rtt: 1162 1163 Pointer to previously saved zero-RTT data needed for TLS resumption. 1164 May be NULL. 1165 1166 :param zero_rtt_len: 1167 1168 Size of zero-RTT data. 1169 1170 :param token: 1171 1172 Pointer to previously received token to include in the Initial 1173 packet. Tokens are used by IETF QUIC to pre-validate client 1174 connections, potentially avoiding a retry. 1175 1176 See ``on_new_token`` callback in :type:`lsquic_stream_if`: 1177 1178 May be NULL. 1179 1180 :param token_sz: 1181 1182 Size of data pointed to by ``token``. 1183 1184Closing Connections 1185------------------- 1186 1187.. function:: void lsquic_conn_going_away (lsquic_conn_t *conn) 1188 1189 Mark connection as going away: send GOAWAY frame and do not accept 1190 any more incoming streams, nor generate streams of our own. 1191 1192 Only applicable to HTTP/3 and GQUIC connections. Otherwise a no-op. 1193 1194.. function:: void lsquic_conn_close (lsquic_conn_t *conn) 1195 1196 This closes the connection. ``on_conn_closed()`` and ``on_close()`` callbacks will be called. 1197 1198Creating Streams 1199---------------- 1200 1201Similar to connections, streams are created by the library in server mode; they 1202correspond to requests. In client mode, a new stream is created by 1203 1204.. function:: void lsquic_conn_make_stream (lsquic_conn_t *) 1205 1206 Create a new request stream. This causes :member:`on_new_stream()` callback 1207 to be called. If creating more requests is not permitted at the moment 1208 (due to number of concurrent streams limit), stream creation is registered 1209 as "pending" and the stream is created later when number of streams dips 1210 under the limit again. Any number of pending streams can be created. 1211 Use :func:`lsquic_conn_n_pending_streams()` and 1212 :func:`lsquic_conn_cancel_pending_streams()` to manage pending streams. 1213 1214 If connection is going away, :func:`on_new_stream()` is called with the 1215 stream parameter set to NULL. 1216 1217Stream Events 1218------------- 1219 1220To register or unregister an interest in a read or write event, use the 1221following functions: 1222 1223.. function:: int lsquic_stream_wantread (lsquic_stream_t *stream, int want) 1224 1225 :param stream: Stream to read from. 1226 :param want: Boolean value indicating whether the caller wants to read 1227 from stream. 1228 :return: Previous value of ``want`` or ``-1`` if the stream has already 1229 been closed for reading. 1230 1231 A stream becomes readable if there is was an error: for example, the 1232 peer may have reset the stream. In this case, reading from the stream 1233 will return an error. 1234 1235.. function:: int lsquic_stream_wantwrite (lsquic_stream_t *stream, int want) 1236 1237 :param stream: Stream to write to. 1238 :param want: Boolean value indicating whether the caller wants to write 1239 to stream. 1240 :return: Previous value of ``want`` or ``-1`` if the stream has already 1241 been closed for writing. 1242 1243Reading From Streams 1244-------------------- 1245 1246.. function:: ssize_t lsquic_stream_read (lsquic_stream_t *stream, unsigned char *buf, size_t sz) 1247 1248 :param stream: Stream to read from. 1249 :param buf: Buffer to copy data to. 1250 :param sz: Size of the buffer. 1251 :return: Number of bytes read, zero if EOS has been reached, or -1 on error. 1252 1253 Read up to ``sz`` bytes from ``stream`` into buffer ``buf``. 1254 1255 ``-1`` is returned on error, in which case ``errno`` is set: 1256 1257 - ``EBADF``: The stream is closed. 1258 - ``ECONNRESET``: The stream has been reset. 1259 - ``EWOULDBLOCK``: There is no data to be read. 1260 1261.. function:: ssize_t lsquic_stream_readv (lsquic_stream_t *stream, const struct iovec *vec, int iovcnt) 1262 1263 :param stream: Stream to read from. 1264 :param vec: Array of ``iovec`` structures. 1265 :param iovcnt: Number of elements in ``vec``. 1266 :return: Number of bytes read, zero if EOS has been reached, or -1 on error. 1267 1268 Similar to :func:`lsquic_stream_read()`, but reads data into a vector. 1269 1270.. function:: ssize_t lsquic_stream_readf (lsquic_stream_t *stream, size_t (*readf)(void *ctx, const unsigned char *buf, size_t len, int fin), void *ctx) 1271 1272 :param stream: Stream to read from. 1273 1274 :param readf: 1275 1276 The callback takes four parameters: 1277 1278 - Pointer to user-supplied context; 1279 - Pointer to the data; 1280 - Data size (can be zero); and 1281 - Indicator whether the FIN follows the data. 1282 1283 The callback returns number of bytes processed. If this number is zero 1284 or is smaller than ``len``, reading from stream stops. 1285 1286 :param ctx: Context pointer passed to ``readf``. 1287 1288 This function allows user-supplied callback to read the stream contents. 1289 It is meant to be used for zero-copy stream processing. 1290 1291 Return value and errors are same as in :func:`lsquic_stream_read()`. 1292 1293Writing To Streams 1294------------------ 1295 1296.. function:: ssize_t lsquic_stream_write (lsquic_stream_t *stream, const void *buf, size_t len) 1297 1298 :param stream: Stream to write to. 1299 :param buf: Buffer to copy data from. 1300 :param len: Number of bytes to copy. 1301 :return: Number of bytes written -- which may be smaller than ``len`` -- or a negative 1302 value when an error occurs. 1303 1304 Write ``len`` bytes to the stream. Returns number of bytes written, which 1305 may be smaller that ``len``. 1306 1307 A negative return value indicates a serious error (the library is likely 1308 to have aborted the connection because of it). 1309 1310.. function:: ssize_t lsquic_stream_writev (lsquic_stream_t *s, const struct iovec *vec, int count) 1311 1312 Like :func:`lsquic_stream_write()`, but read data from a vector. 1313 1314.. type:: struct lsquic_reader 1315 1316 Used as argument to :func:`lsquic_stream_writef()`. 1317 1318 .. member:: size_t (*lsqr_read) (void *lsqr_ctx, void *buf, size_t count) 1319 1320 :param lsqr_ctx: Pointer to user-specified context. 1321 :param buf: Memory location to write to. 1322 :param count: Size of available memory pointed to by ``buf``. 1323 :return: 1324 1325 Number of bytes written. This is not a ``ssize_t`` because 1326 the read function is not supposed to return an error. If an error 1327 occurs in the read function (for example, when reading from a file 1328 fails), it is supposed to deal with the error itself. 1329 1330 .. member:: size_t (*lsqr_size) (void *lsqr_ctx) 1331 1332 Return number of bytes remaining in the reader. 1333 1334 .. member:: void *lsqr_ctx 1335 1336 Context pointer passed both to ``lsqr_read()`` and to ``lsqr_size()``. 1337 1338.. function:: ssize_t lsquic_stream_writef (lsquic_stream_t *stream, struct lsquic_reader *reader) 1339 1340 :param stream: Stream to write to. 1341 :param reader: Reader to read from. 1342 :return: Number of bytes written or -1 on error. 1343 1344 Write to stream using :type:`lsquic_reader`. This is the most generic of 1345 the write functions -- :func:`lsquic_stream_write()` and 1346 :func:`lsquic_stream_writev()` utilize the same mechanism. 1347 1348.. function:: int lsquic_stream_flush (lsquic_stream_t *stream) 1349 1350 :param stream: Stream to flush. 1351 :return: 0 on success and -1 on failure. 1352 1353 Flush any buffered data. This triggers packetizing even a single byte 1354 into a separate frame. Flushing a closed stream is an error. 1355 1356Closing Streams 1357--------------- 1358 1359Streams can be closed for reading, writing, or both. 1360``on_close()`` callback is called at some point after a stream is closed 1361for both reading and writing, 1362 1363.. function:: int lsquic_stream_shutdown (lsquic_stream_t *stream, int how) 1364 1365 :param stream: Stream to shut down. 1366 :param how: 1367 1368 This parameter specifies what do to. Allowed values are: 1369 1370 - 0: Stop reading. 1371 - 1: Stop writing. 1372 - 2: Stop both reading and writing. 1373 1374 :return: 0 on success or -1 on failure. 1375 1376.. function:: int lsquic_stream_close (lsquic_stream_t *stream) 1377 1378 :param stream: Stream to close. 1379 :return: 0 on success or -1 on failure. 1380 1381Sending HTTP Headers 1382-------------------- 1383 1384.. type:: struct lsxpack_header 1385 1386This type is defined in _lsxpack_header.h_. See that header file for 1387more information. 1388 1389 .. member:: char *buf 1390 1391 the buffer for headers 1392 1393 .. member:: const char *name_ptr 1394 1395 the name pointer can be optionally set for encoding 1396 1397 .. member:: uint32_t name_hash 1398 1399 hash value for name 1400 1401 .. member:: uint32_t nameval_hash 1402 1403 hash value for name + value 1404 1405 .. member:: lsxpack_strlen_t name_offset 1406 1407 the offset for name in the buffer 1408 1409 .. member:: lsxpack_strlen_t name_len 1410 1411 the length of name 1412 1413 .. member:: lsxpack_strlen_t val_offset 1414 1415 the offset for value in the buffer 1416 1417 .. member:: lsxpack_strlen_t val_len 1418 1419 the length of value 1420 1421 .. member:: uint16_t chain_next_idx 1422 1423 mainly for cookie value chain 1424 1425 .. member:: uint8_t hpack_index 1426 1427 HPACK static table index 1428 1429 .. member:: uint8_t qpack_index 1430 1431 QPACK static table index 1432 1433 .. member:: uint8_t app_index 1434 1435 APP header index 1436 1437 .. member:: enum lsxpack_flag flags:8 1438 1439 combination of lsxpack_flag 1440 1441 .. member:: uint8_t indexed_type 1442 1443 control to disable index or not 1444 1445 .. member:: uint8_t dec_overhead 1446 1447 num of extra bytes written to decoded buffer 1448 1449.. type:: lsquic_http_headers_t 1450 1451 .. member:: int count 1452 1453 Number of headers in ``headers``. 1454 1455 .. member:: struct lsxpack_header *headers 1456 1457 Pointer to an array of HTTP headers. 1458 1459 HTTP header list structure. Contains a list of HTTP headers. 1460 1461.. function:: int lsquic_stream_send_headers (lsquic_stream_t *stream, const lsquic_http_headers_t *headers, int eos) 1462 1463 :param stream: 1464 1465 Stream to send headers on. 1466 1467 :param headers: 1468 1469 Headers to send. 1470 1471 :param eos: 1472 1473 Boolean value to indicate whether these headers constitute the whole 1474 HTTP message. 1475 1476 :return: 1477 1478 0 on success or -1 on error. 1479 1480Receiving HTTP Headers 1481---------------------- 1482 1483If ``ea_hsi_if`` is not set in :type:`lsquic_engine_api`, the library will translate 1484HPACK- and QPACK-encoded headers into HTTP/1.x-like headers and prepend them to the 1485stream. To the stream-reading function, it will look as if a standard HTTP/1.x 1486message. 1487 1488Alternatively, you can specify header-processing set of functions and manage header 1489fields yourself. In that case, the header set must be "read" from the stream via 1490:func:`lsquic_stream_get_hset()`. 1491 1492.. type:: struct lsquic_hset_if 1493 1494 .. member:: void * (*hsi_create_header_set)(void *hsi_ctx, lsquic_stream_t *stream, int is_push_promise) 1495 1496 :param hsi_ctx: User context. This is the pointer specifed in ``ea_hsi_ctx``. 1497 :param stream: Stream with which the header set is associated. May be set 1498 to NULL in server mode. 1499 :param is_push_promise: Boolean value indicating whether this header set is 1500 for a push promise. 1501 :return: Pointer to user-defined header set object. 1502 1503 Create a new header set. This object is (and must be) fetched from a 1504 stream by calling :func:`lsquic_stream_get_hset()` before the stream can 1505 be read. 1506 1507 .. member:: struct lsxpack_header * (*hsi_prepare_decode)(void *hdr_set, struct lsxpack_header *hdr, size_t space) 1508 1509 Return a header set prepared for decoding. If ``hdr`` is NULL, this 1510 means return a new structure with at least ``space`` bytes available 1511 in the decoder buffer. On success, a newly prepared header is 1512 returned. 1513 1514 If ``hdr`` is not NULL, it means there was not enough decoder buffer 1515 and it must be increased to at least ``space`` bytes. ``buf``, ``val_len``, 1516 and ``name_offset`` member of the ``hdr`` structure may change. On 1517 success, the return value is the same as ``hdr``. 1518 1519 If NULL is returned, the space cannot be allocated. 1520 1521 .. member:: int (*hsi_process_header)(void *hdr_set, struct lsxpack_header *hdr) 1522 1523 Process new header. 1524 1525 :param hdr_set: 1526 1527 Header set to add the new header field to. This is the object 1528 returned by ``hsi_create_header_set()``. 1529 1530 :param hdr: 1531 1532 The header returned by @ref ``hsi_prepare_decode()``. 1533 1534 :return: 1535 1536 Return 0 on success, a positive value if a header error occured, 1537 or a negative value on any other error. A positive return value 1538 will result in cancellation of associated stream. A negative return 1539 value will result in connection being aborted. 1540 1541 .. member:: void (*hsi_discard_header_set)(void *hdr_set) 1542 1543 :param hdr_set: Header set to discard. 1544 1545 Discard header set. This is called for unclaimed header sets and 1546 header sets that had an error. 1547 1548 .. member:: enum lsquic_hsi_flag hsi_flags 1549 1550 These flags specify properties of decoded headers passed to 1551 ``hsi_process_header()``. This is only applicable to QPACK headers; 1552 HPACK library header properties are based on compilation, not 1553 run-time, options. 1554 1555.. function:: void * lsquic_stream_get_hset (lsquic_stream_t *stream) 1556 1557 :param stream: Stream to fetch header set from. 1558 1559 :return: Header set associated with the stream. 1560 1561 Get header set associated with the stream. The header set is created by 1562 ``hsi_create_header_set()`` callback. After this call, the ownership of 1563 the header set is transferred to the caller. 1564 1565 This call must precede calls to :func:`lsquic_stream_read()`, 1566 :func:`lsquic_stream_readv()`, and :func:`lsquic_stream_readf()`. 1567 1568 If the optional header set interface is not specified, 1569 this function returns NULL. 1570 1571Push Promises 1572------------- 1573 1574.. function:: int lsquic_conn_push_stream (lsquic_conn_t *conn, void *hdr_set, lsquic_stream_t *stream, const lsquic_http_headers_t *headers) 1575 1576 :return: 1577 1578 - 0: Stream pushed successfully. 1579 - 1: Stream push failed because it is disabled or because we hit 1580 stream limit or connection is going away. 1581 - -1: Stream push failed because of an internal error. 1582 1583 A server may push a stream. This call creates a new stream in reference 1584 to stream ``stream``. It will behave as if the client made a request: it will 1585 trigger ``on_new_stream()`` event and it can be used as a regular client-initiated stream. 1586 1587 ``hdr_set`` must be set. It is passed as-is to :func:`lsquic_stream_get_hset()`. 1588 1589.. function:: int lsquic_conn_is_push_enabled (lsquic_conn_t *conn) 1590 1591 :return: Boolean value indicating whether push promises are enabled. 1592 1593 Only makes sense in server mode: the client cannot push a stream and this 1594 function always returns false in client mode. 1595 1596.. function: int lsquic_stream_is_pushed (const lsquic_stream_t *stream) 1597 1598 :return: Boolean value indicating whether this is a pushed stream. 1599 1600.. function:: int lsquic_stream_refuse_push (lsquic_stream_t *stream) 1601 1602 Refuse pushed stream. Call it from ``on_new_stream()``. No need to 1603 call :func:`lsquic_stream_close()` after this. ``on_close()`` will be called. 1604 1605.. function:: int lsquic_stream_push_info (const lsquic_stream_t *stream, lsquic_stream_id_t *ref_stream_id, void **hdr_set) 1606 1607 Get information associated with pushed stream 1608 1609 :param ref_stream_id: Stream ID in response to which push promise was sent. 1610 :param hdr_set: Header set. This object was passed to or generated by :func:`lsquic_conn_push_stream()`. 1611 1612 :return: 0 on success and -1 if this is not a pushed stream. 1613 1614Stream Priorities 1615----------------- 1616 1617.. function:: unsigned lsquic_stream_priority (const lsquic_stream_t *stream) 1618 1619 Return current priority of the stream. 1620 1621.. function:: int lsquic_stream_set_priority (lsquic_stream_t *stream, unsigned priority) 1622 1623 Set stream priority. Valid priority values are 1 through 256, inclusive. 1624 1625 :return: 0 on success of -1 on failure (this happens if priority value is invalid). 1626 1627Miscellaneous Engine Functions 1628------------------------------ 1629 1630.. function:: unsigned lsquic_engine_quic_versions (const lsquic_engine_t *engine) 1631 1632 Return the list of QUIC versions (as bitmask) this engine instance supports. 1633 1634.. function:: unsigned lsquic_engine_count_attq (lsquic_engine_t *engine, int from_now) 1635 1636 Return number of connections whose advisory tick time is before current 1637 time plus ``from_now`` microseconds from now. ``from_now`` can be negative. 1638 1639Miscellaneous Connection Functions 1640---------------------------------- 1641 1642.. function:: enum lsquic_version lsquic_conn_quic_version (const lsquic_conn_t *conn) 1643 1644 Get QUIC version used by the connection. 1645 1646 If version has not yet been negotiated (can happen in client mode), ``-1`` is 1647 returned. 1648 1649.. function:: const lsquic_cid_t * lsquic_conn_id (const lsquic_conn_t *conn) 1650 1651 Get connection ID. 1652 1653.. function:: lsquic_engine_t * lsquic_conn_get_engine (lsquic_conn_t *conn) 1654 1655 Get pointer to the engine. 1656 1657.. function:: int lsquic_conn_get_sockaddr (lsquic_conn_t *conn, const struct sockaddr **local, const struct sockaddr **peer) 1658 1659 Get current (last used) addresses associated with the current path 1660 used by the connection. 1661 1662.. function:: struct stack_st_X509 * lsquic_conn_get_server_cert_chain (lsquic_conn_t *conn) 1663 1664 Get certificate chain returned by the server. This can be used for 1665 server certificate verification. 1666 1667 The caller releases the stack using sk_X509_free(). 1668 1669.. function:: lsquic_conn_ctx_t * lsquic_conn_get_ctx (const lsquic_conn_t *conn) 1670 1671 Get user-supplied context associated with the connection. 1672 1673.. function:: void lsquic_conn_set_ctx (lsquic_conn_t *conn, lsquic_conn_ctx_t *ctx) 1674 1675 Set user-supplied context associated with the connection. 1676 1677.. function:: void * lsquic_conn_get_peer_ctx (lsquic_conn_t *conn, const struct sockaddr *local_sa) 1678 1679 Get peer context associated with the connection and local address. 1680 1681.. function:: enum LSQUIC_CONN_STATUS lsquic_conn_status (lsquic_conn_t *conn, char *errbuf, size_t bufsz) 1682 1683 Get connection status. 1684 1685Miscellaneous Stream Functions 1686------------------------------ 1687 1688.. function:: unsigned lsquic_conn_n_avail_streams (const lsquic_conn_t *conn) 1689 1690 Return max allowed outbound streams less current outbound streams. 1691 1692.. function:: unsigned lsquic_conn_n_pending_streams (const lsquic_conn_t *conn) 1693 1694 Return number of delayed streams currently pending. 1695 1696.. function:: unsigned lsquic_conn_cancel_pending_streams (lsquic_conn_t *, unsigned n) 1697 1698 Cancel ``n`` pending streams. Returns new number of pending streams. 1699 1700.. function:: lsquic_conn_t * lsquic_stream_conn (const lsquic_stream_t *stream) 1701 1702 Get a pointer to the connection object. Use it with connection functions. 1703 1704.. function:: int lsquic_stream_is_rejected (const lsquic_stream_t *stream) 1705 1706 Returns true if this stream was rejected, false otherwise. Use this as 1707 an aid to distinguish between errors. 1708 1709Other Functions 1710--------------- 1711 1712.. function:: enum lsquic_version lsquic_str2ver (const char *str, size_t len) 1713 1714 Translate string QUIC version to LSQUIC QUIC version representation. 1715 1716.. function:: enum lsquic_version lsquic_alpn2ver (const char *alpn, size_t len) 1717 1718 Translate ALPN (e.g. "h3", "h3-23", "h3-Q046") to LSQUIC enum. 1719 1720Miscellaneous Types 1721------------------- 1722 1723.. type:: struct lsquic_shared_hash_if 1724 1725 The shared hash interface is used to share data between multiple LSQUIC instances. 1726 1727 .. member:: int (*shi_insert)(void *shi_ctx, void *key, unsigned key_sz, void *data, unsigned data_sz, time_t expiry) 1728 1729 :param shi_ctx: 1730 1731 Shared memory context pointer 1732 1733 :param key: 1734 1735 Key data. 1736 1737 :param key_sz: 1738 1739 Key size. 1740 1741 :param data: 1742 1743 Pointer to the data to store. 1744 1745 :param data_sz: 1746 1747 Data size. 1748 1749 :param expiry: When this item expires. If you want your item to never expire, set this to zero. 1750 1751 :return: 0 on success, -1 on failure. 1752 1753 If inserted successfully, ``free()`` will be called on ``data`` and ``key`` 1754 pointer when the element is deleted, whether due to expiration 1755 or explicit deletion. 1756 1757 .. member:: int (*shi_delete)(void *shi_ctx, const void *key, unsigned key_sz) 1758 1759 Delete item from shared hash 1760 1761 :return: 0 on success, -1 on failure. 1762 1763 .. member:: int (*shi_lookup)(void *shi_ctx, const void *key, unsigned key_sz, void **data, unsigned *data_sz) 1764 1765 :param shi_ctx: 1766 1767 Shared memory context pointer 1768 1769 :param key: 1770 1771 Key data. 1772 1773 :param key_sz: 1774 1775 Key size. 1776 1777 :param data: 1778 1779 Pointer to set to the result. 1780 1781 :param data_sz: 1782 1783 Pointer to the data size. 1784 1785 :return: 1786 1787 - ``1``: found. 1788 - ``0``: not found. 1789 - ``-1``: error (perhaps not enough room in ``data`` if copy was attempted). 1790 1791 The implementation may choose to copy the object into buffer pointed 1792 to by ``data``, so you should have it ready. 1793 1794.. type:: struct lsquic_packout_mem_if 1795 1796 The packet out memory interface is used by LSQUIC to get buffers to 1797 which outgoing packets will be written before they are passed to 1798 :member:`lsquic_engine_api.ea_packets_out` callback. 1799 1800 If not specified, malloc() and free() are used. 1801 1802 .. member:: void * (*pmi_allocate) (void *pmi_ctx, void *conn_ctx, unsigned short sz, char is_ipv6) 1803 1804 Allocate buffer for sending. 1805 1806 .. member:: void (*pmi_release) (void *pmi_ctx, void *conn_ctx, void *buf, char is_ipv6) 1807 1808 This function is used to release the allocated buffer after it is 1809 sent via ``ea_packets_out()``. 1810 1811 .. member:: void (*pmi_return) (void *pmi_ctx, void *conn_ctx, void *buf, char is_ipv6) 1812 1813 If allocated buffer is not going to be sent, return it to the 1814 caller using this function. 1815 1816.. type:: typedef void (*lsquic_cids_update_f)(void *ctx, void **peer_ctx, const lsquic_cid_t *cids, unsigned n_cids) 1817 1818 :param ctx: 1819 1820 Context associated with the CID lifecycle callbacks (ea_cids_update_ctx). 1821 1822 :param peer_ctx: 1823 1824 Array of peer context pointers. 1825 1826 :param cids: 1827 1828 Array of connection IDs. 1829 1830 :param n_cids: 1831 1832 Number of elements in the peer context pointer and connection ID arrays. 1833 1834.. type:: struct lsquic_keylog_if 1835 1836 SSL keylog interface. 1837 1838 .. member:: void * (*kli_open) (void *keylog_ctx, lsquic_conn_t *conn) 1839 1840 Return keylog handle or NULL if no key logging is desired. 1841 1842 .. member:: void (*kli_log_line) (void *handle, const char *line) 1843 1844 Log line. The first argument is the pointer returned by ``kli_open()``. 1845 1846 .. member:: void (*kli_close) (void *handle) 1847 1848 Close handle. 1849 1850.. type:: enum lsquic_logger_timestamp_style 1851 1852 Enumerate timestamp styles supported by LSQUIC logger mechanism. 1853 1854 .. member:: LLTS_NONE 1855 1856 No timestamp is generated. 1857 1858 .. member:: LLTS_HHMMSSMS 1859 1860 The timestamp consists of 24 hours, minutes, seconds, and milliseconds. Example: 13:43:46.671 1861 1862 .. member:: LLTS_YYYYMMDD_HHMMSSMS 1863 1864 Like above, plus date, e.g: 2017-03-21 13:43:46.671 1865 1866 .. member:: LLTS_CHROMELIKE 1867 1868 This is Chrome-like timestamp used by proto-quic. The timestamp 1869 includes month, date, hours, minutes, seconds, and microseconds. 1870 1871 Example: 1223/104613.946956 (instead of 12/23 10:46:13.946956). 1872 1873 This is to facilitate reading two logs side-by-side. 1874 1875 .. member:: LLTS_HHMMSSUS 1876 1877 The timestamp consists of 24 hours, minutes, seconds, and microseconds. Example: 13:43:46.671123 1878 1879 .. member:: LLTS_YYYYMMDD_HHMMSSUS 1880 1881 Date and time using microsecond resolution, e.g: 2017-03-21 13:43:46.671123 1882 1883.. type:: enum LSQUIC_CONN_STATUS 1884 1885 .. member:: LSCONN_ST_HSK_IN_PROGRESS 1886 .. member:: LSCONN_ST_CONNECTED 1887 .. member:: LSCONN_ST_HSK_FAILURE 1888 .. member:: LSCONN_ST_GOING_AWAY 1889 .. member:: LSCONN_ST_TIMED_OUT 1890 .. member:: LSCONN_ST_RESET 1891 1892 If es_honor_prst is not set, the connection will never get public 1893 reset packets and this flag will not be set. 1894 1895 .. member:: LSCONN_ST_USER_ABORTED 1896 .. member:: LSCONN_ST_ERROR 1897 .. member:: LSCONN_ST_CLOSED 1898 .. member:: LSCONN_ST_PEER_GOING_AWAY 1899 1900.. type:: enum lsquic_hsi_flag 1901 1902 These flags are ORed together to specify properties of 1903 :type:`lsxpack_header` passed to :member:`lsquic_hset_if.hsi_process_header`. 1904 1905 .. member:: LSQUIC_HSI_HTTP1X 1906 1907 Turn HTTP/1.x mode on or off. In this mode, decoded name and value 1908 pair are separated by ``": "`` and ``"\r\n"`` is appended to the end 1909 of the string. By default, this mode is off. 1910 1911 .. member:: LSQUIC_HSI_HASH_NAME 1912 1913 Include name hash into lsxpack_header. 1914 1915 .. member:: LSQUIC_HSI_HASH_NAMEVAL 1916 1917 Include nameval hash into lsxpack_header. 1918 1919Global Variables 1920---------------- 1921 1922.. var:: const char *const lsquic_ver2str[N_LSQVER] 1923 1924 Convert LSQUIC version to human-readable string 1925 1926List of Log Modules 1927------------------- 1928 1929The following log modules are defined: 1930 1931- *alarmset*: Alarm processing. 1932- *bbr*: BBR congestion controller. 1933- *bw-sampler*: Bandwidth sampler (used by BBR). 1934- *cfcw*: Connection flow control window. 1935- *conn*: Connection. 1936- *crypto*: Low-level Google QUIC cryptography tracing. 1937- *cubic*: Cubic congestion controller. 1938- *di*: "Data In" handler (storing incoming data before it is read). 1939- *eng-hist*: Engine history. 1940- *engine*: Engine. 1941- *event*: Cross-module significant events. 1942- *frame-reader*: Reader of the HEADERS stream in Google QUIC. 1943- *frame-writer*: Writer of the HEADERS stream in Google QUIC. 1944- *handshake*: Handshake and packet encryption and decryption. 1945- *hcsi-reader*: Reader of the HTTP/3 control stream. 1946- *hcso-writer*: Writer of the HTTP/3 control stream. 1947- *headers*: HEADERS stream (Google QUIC). 1948- *hsk-adapter*: 1949- *http1x*: Header conversion to HTTP/1.x. 1950- *logger*: Logger. 1951- *mini-conn*: Mini connection. 1952- *pacer*: Pacer. 1953- *parse*: Parsing. 1954- *prq*: PRQ stands for Packet Request Queue. This logs scheduling 1955 and sending packets not associated with a connection: version 1956 negotiation and stateless resets. 1957- *purga*: CID purgatory. 1958- *qdec-hdl*: QPACK decoder stream handler. 1959- *qenc-hdl*: QPACK encoder stream handler. 1960- *qlog*: QLOG output. At the moment, it is out of date. 1961- *qpack-dec*: QPACK decoder. 1962- *qpack-enc*: QPACK encoder. 1963- *rechist*: Receive history. 1964- *sendctl*: Send controller. 1965- *sfcw*: Stream flow control window. 1966- *spi*: Stream priority iterator. 1967- *stream*: Stream operation. 1968- *tokgen*: Token generation and validation. 1969- *trapa*: Transport parameter processing. 1970