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