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