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