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