apiref.rst revision 0bd32030
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_ID24 50 51 IETF QUIC version ID (Internet-Draft) 24 52 53 .. member:: LSQVER_ID25 54 55 IETF QUIC version ID 25 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 679To initialize the settings structure to library defaults, use the following 680convenience function: 681 682.. function:: lsquic_engine_init_settings (struct lsquic_engine_settings *, unsigned flags) 683 684 ``flags`` is a bitmask of ``LSENG_SERVER`` and ``LSENG_HTTP`` 685 686After doing this, change just the settings you'd like. To check whether 687the values are correct, another convenience function is provided: 688 689.. function:: lsquic_engine_check_settings (const struct lsquic_engine_settings *, unsigned flags, char *err_buf, size_t err_buf_sz) 690 691 Check settings for errors. Return 0 if settings are OK, -1 otherwise. 692 693 If `err_buf` and `err_buf_sz` are set, an error string is written to the 694 buffers. 695 696The following macros in :file:`lsquic.h` specify default values: 697 698*Note that, despite our best efforts, documentation may accidentally get 699out of date. Please check your :file:`lsquic.h` for actual values.* 700 701.. macro:: LSQUIC_MIN_FCW 702 703 Minimum flow control window is set to 16 KB for both client and server. 704 This means we can send up to this amount of data before handshake gets 705 completed. 706 707.. macro:: LSQUIC_DF_VERSIONS 708 709 By default, deprecated and experimental versions are not included. 710 711.. macro:: LSQUIC_DF_CFCW_SERVER 712.. macro:: LSQUIC_DF_CFCW_CLIENT 713.. macro:: LSQUIC_DF_SFCW_SERVER 714.. macro:: LSQUIC_DF_SFCW_CLIENT 715.. macro:: LSQUIC_DF_MAX_STREAMS_IN 716 717.. macro:: LSQUIC_DF_INIT_MAX_DATA_SERVER 718.. macro:: LSQUIC_DF_INIT_MAX_DATA_CLIENT 719.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_REMOTE_SERVER 720.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_LOCAL_SERVER 721.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_REMOTE_CLIENT 722.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_LOCAL_CLIENT 723.. macro:: LSQUIC_DF_INIT_MAX_STREAMS_BIDI 724.. macro:: LSQUIC_DF_INIT_MAX_STREAMS_UNI_CLIENT 725.. macro:: LSQUIC_DF_INIT_MAX_STREAMS_UNI_SERVER 726.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_CLIENT 727.. macro:: LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_SERVER 728 729.. macro:: LSQUIC_DF_IDLE_TIMEOUT 730 731 Default idle connection timeout is 30 seconds. 732 733.. macro:: LSQUIC_DF_PING_PERIOD 734 735 Default ping period is 15 seconds. 736 737.. macro:: LSQUIC_DF_HANDSHAKE_TO 738 739 Default handshake timeout is 10,000,000 microseconds (10 seconds). 740 741.. macro:: LSQUIC_DF_IDLE_CONN_TO 742 743 Default idle connection timeout is 30,000,000 microseconds. 744 745.. macro:: LSQUIC_DF_SILENT_CLOSE 746 747 By default, connections are closed silenty when they time out (no 748 CONNECTION_CLOSE frame is sent). 749 750.. macro:: LSQUIC_DF_MAX_HEADER_LIST_SIZE 751 752 Default value of maximum header list size. If set to non-zero value, 753 SETTINGS_MAX_HEADER_LIST_SIZE will be sent to peer after handshake is 754 completed (assuming the peer supports this setting frame type). 755 756.. macro:: LSQUIC_DF_UA 757 758 Default value of UAID (user-agent ID). 759 760.. macro:: LSQUIC_DF_MAX_INCHOATE 761 762 Default is 1,000,000. 763 764.. macro:: LSQUIC_DF_SUPPORT_NSTP 765 766 NSTP is not used by default. 767 768.. macro:: LSQUIC_DF_SUPPORT_PUSH 769 770 Push promises are supported by default. 771 772.. macro:: LSQUIC_DF_SUPPORT_TCID0 773 774 Support for TCID=0 is enabled by default. 775 776.. macro:: LSQUIC_DF_HONOR_PRST 777 778 By default, LSQUIC ignores Public Reset packets. 779 780.. macro:: LSQUIC_DF_SEND_PRST 781 782 By default, LSQUIC will not send Public Reset packets in response to 783 packets that specify unknown connections. 784 785.. macro:: LSQUIC_DF_PROGRESS_CHECK 786 787 By default, infinite loop checks are turned on. 788 789.. macro:: LSQUIC_DF_RW_ONCE 790 791 By default, read/write events are dispatched in a loop. 792 793.. macro:: LSQUIC_DF_PROC_TIME_THRESH 794 795 By default, the threshold is not enabled. 796 797.. macro:: LSQUIC_DF_PACE_PACKETS 798 799 By default, packets are paced 800 801.. macro:: LSQUIC_DF_CLOCK_GRANULARITY 802 803 Default clock granularity is 1000 microseconds. 804 805.. macro:: LSQUIC_DF_SCID_LEN 8 806 807 The default value is 8 for simplicity and speed. 808 809.. macro:: LSQUIC_DF_SCID_ISS_RATE 810 811 The default value is 60 CIDs per minute. 812 813.. macro:: LSQUIC_DF_QPACK_DEC_MAX_BLOCKED 814 815 Default value is 100. 816 817.. macro:: LSQUIC_DF_QPACK_DEC_MAX_SIZE 818 819 Default value is 4,096 bytes. 820 821.. macro:: LSQUIC_DF_QPACK_ENC_MAX_BLOCKED 822 823 Default value is 100. 824 825.. macro:: LSQUIC_DF_QPACK_ENC_MAX_SIZE 826 827 Default value is 4,096 bytes. 828 829.. macro:: LSQUIC_DF_ECN 830 831 ECN is disabled by default. 832 833.. macro:: LSQUIC_DF_ALLOW_MIGRATION 834 835 Allow migration by default. 836 837.. macro:: LSQUIC_DF_QL_BITS 838 839 Use QL loss bits by default. 840 841.. macro:: LSQUIC_DF_SPIN 842 843 Turn spin bit on by default. 844 845.. macro:: LSQUIC_DF_CC_ALGO 846 847 Use Cubic by default. 848 849Receiving Packets 850----------------- 851 852Incoming packets are supplied to the engine using :func:`lsquic_engine_packet_in()`. 853It is up to the engine to decide what do to with the packet. It can find an existing 854connection and dispatch the packet there, create a new connection (in server mode), or 855schedule a version negotiation or stateless reset packet. 856 857.. 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) 858 859 Pass incoming packet to the QUIC engine. This function can be called 860 more than once in a row. After you add one or more packets, call 861 :func:`lsquic_engine_process_conns()` to schedule outgoing packets, if any. 862 863 :param engine: Engine instance. 864 :param data: Pointer to UDP datagram payload. 865 :param size: Size of UDP datagram. 866 :param local: Local address. 867 :param peer: Peer address. 868 :param peer_ctx: Peer context. 869 :param ecn: ECN marking associated with this UDP datagram. 870 871 :return: 872 873 - ``0``: Packet was processed by a real connection. 874 - ``1``: Packet was handled successfully, but not by a connection. 875 This may happen with version negotiation and public reset 876 packets as well as some packets that may be ignored. 877 - ``-1``: Some error occurred. Possible reasons are invalid packet 878 size or failure to allocate memory. 879 880.. function:: int lsquic_engine_earliest_adv_tick (lsquic_engine_t *engine, int *diff) 881 882 Returns true if there are connections to be processed, false otherwise. 883 884 :param engine: 885 886 Engine instance. 887 888 :param diff: 889 890 If the function returns a true value, the pointed to integer is set to the 891 difference between the earliest advisory tick time and now. 892 If the former is in the past, this difference is negative. 893 894 :return: 895 896 True if there are connections to be processed, false otherwise. 897 898Sending Packets 899--------------- 900 901User specifies a callback :type:`lsquic_packets_out_f` in :type:`lsquic_engine_api` 902that the library uses to send packets. 903 904.. type:: struct lsquic_out_spec 905 906 This structure describes an outgoing packet. 907 908 .. member:: struct iovec *iov 909 910 A vector with payload. 911 912 .. member:: size_t iovlen 913 914 Vector length. 915 916 .. member:: const struct sockaddr *local_sa 917 918 Local address. 919 920 .. member:: const struct sockaddr *dest_sa 921 922 Destination address. 923 924 .. member:: void *peer_ctx 925 926 Peer context associated with the local address. 927 928 .. member:: int ecn 929 930 ECN: Valid values are 0 - 3. See RFC 3168. 931 932 ECN may be set by IETF QUIC connections if ``es_ecn`` is set. 933 934.. type: typedef int (*lsquic_packets_out_f)(void *packets_out_ctx, const struct lsquic_out_spec *out_spec, unsigned n_packets_out) 935 936 Returns number of packets successfully sent out or -1 on error. -1 should 937 only be returned if no packets were sent out. If -1 is returned or if the 938 return value is smaller than ``n_packets_out``, this indicates that sending 939 of packets is not possible. 940 941 If not all packets could be sent out, then: 942 943 - errno is examined. If it is not EAGAIN or EWOULDBLOCK, the connection 944 whose packet caused the error is closed forthwith. 945 - No packets are attempted to be sent out until :func:`lsquic_engine_send_unsent_packets()` 946 is called. 947 948.. function:: void lsquic_engine_process_conns (lsquic_engine_t *engine) 949 950 Process tickable connections. This function must be called often enough so 951 that packets and connections do not expire. The preferred method of doing 952 so is by using :func:`lsquic_engine_earliest_adv_tick()`. 953 954.. function:: int lsquic_engine_has_unsent_packets (lsquic_engine_t *engine) 955 956 Returns true if engine has some unsent packets. This happens if 957 ``ea_packets_out()`` could not send everything out. 958 959.. function:: void lsquic_engine_send_unsent_packets (lsquic_engine_t *engine) 960 961 Send out as many unsent packets as possibe: until we are out of unsent 962 packets or until ``ea_packets_out()`` fails. 963 964 If ``ea_packets_out()`` cannot send all packets, this function must be 965 called to signify that sending of packets is possible again. 966 967Stream Callback Interface 968------------------------- 969 970The stream callback interface structure lists the callbacks used by 971the engine to communicate with the user code: 972 973.. type:: struct lsquic_stream_if 974 975 .. member:: lsquic_conn_ctx_t *(*on_new_conn)(void *stream_if_ctx, 976 lsquic_conn_t *); 977 978 Called when a new connection has been created. In server mode, 979 this means that the handshake has been successful. In client mode, 980 on the other hand, this callback is called as soon as connection 981 object is created inside the engine, but before the handshake is 982 done. 983 984 The return value is the connection context associated with this 985 connection. Use :func:`lsquic_conn_get_ctx()` to get back this 986 context. It is OK for this function to return NULL. 987 988 This callback is mandatory. 989 990 .. member:: void (*on_conn_closed)(lsquic_conn_t *) 991 992 Connection is closed. 993 994 This callback is mandatory. 995 996 .. member:: lsquic_stream_ctx_t * (*on_new_stream)(void *stream_if_ctx, lsquic_stream_t *) 997 998 If you need to initiate a connection, call lsquic_conn_make_stream(). 999 This will cause `on_new_stream` callback to be called when appropriate 1000 (this operation is delayed when maximum number of outgoing streams is 1001 reached). 1002 1003 If connection is going away, this callback may be called with the 1004 second parameter set to NULL. 1005 1006 The return value is the stream context associated with the stream. 1007 A pointer to it is passed to `on_read()`, `on_write()`, and `on_close()` 1008 callbacks. It is OK for this function to return NULL. 1009 1010 This callback is mandatory. 1011 1012 .. member:: void (*on_read) (lsquic_stream_t *s, lsquic_stream_ctx_t *h) 1013 1014 Stream is readable: either there are bytes to be read or an error 1015 is ready to be collected. 1016 1017 This callback is mandatory. 1018 1019 .. member:: void (*on_write) (lsquic_stream_t *s, lsquic_stream_ctx_t *h) 1020 1021 Stream is writeable. 1022 1023 This callback is mandatory. 1024 1025 .. member:: void (*on_close) (lsquic_stream_t *s, lsquic_stream_ctx_t *h) 1026 1027 After this callback returns, the stream is no longer accessible. This is 1028 a good time to clean up the stream context. 1029 1030 This callback is mandatory. 1031 1032 .. member:: void (*on_hsk_done)(lsquic_conn_t *c, enum lsquic_hsk_status s) 1033 1034 When handshake is completed, this callback is called. 1035 1036 This callback is optional. 1037 1038 .. member:: void (*on_goaway_received)(lsquic_conn_t *) 1039 1040 This is called when our side received GOAWAY frame. After this, 1041 new streams should not be created. 1042 1043 This callback is optional. 1044 1045 .. member:: void (*on_new_token)(lsquic_conn_t *c, const unsigned char *token, size_t token_size) 1046 1047 When client receives a token in NEW_TOKEN frame, this callback is called. 1048 1049 This callback is optional. 1050 1051 .. member:: void (*on_zero_rtt_info)(lsquic_conn_t *c, const unsigned char *, size_t) 1052 1053 This callback lets client record information needed to 1054 perform a zero-RTT handshake next time around. 1055 1056 This callback is optional. 1057 1058Creating Connections 1059-------------------- 1060 1061In server mode, the connections are created by the library based on incoming 1062packets. After handshake is completed, the library calls :func:`on_new_conn()` 1063callback. 1064 1065In client mode, a new connection is created by 1066 1067.. 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) 1068 1069 :param engine: Engine to use. 1070 1071 :param version: 1072 1073 To let the engine specify QUIC version, use N_LSQVER. If zero-rtt info is 1074 supplied, version is picked from there instead. 1075 1076 :param local_sa: 1077 1078 Local address. 1079 1080 :param peer_sa: 1081 1082 Address of the server. 1083 1084 :param peer_ctx: 1085 1086 Context associated with the connection. This is what gets passed to TODO. 1087 1088 :param conn_ctx: 1089 1090 Connection context can be set early using this parameter. Useful if 1091 you need the connection context to be available in `on_conn_new()`. 1092 Note that that callback's return value replaces the connection 1093 context set here. 1094 1095 :param sni: 1096 1097 The SNI is required for Google QUIC connections; it is optional for 1098 IETF QUIC and may be set to NULL. 1099 1100 :param max_packet_size: 1101 1102 Maximum packet size. If set to zero, it is inferred based on `peer_sa` 1103 and `version`. 1104 1105 :param zero_rtt: 1106 1107 Pointer to previously saved zero-RTT data needed for TLS resumption. 1108 May be NULL. 1109 1110 :param zero_rtt_len: 1111 1112 Size of zero-RTT data. 1113 1114 :param token: 1115 1116 Pointer to previously received token to include in the Initial 1117 packet. Tokens are used by IETF QUIC to pre-validate client 1118 connections, potentially avoiding a retry. 1119 1120 See ``on_new_token`` callback in :type:`lsquic_stream_if`: 1121 1122 May be NULL. 1123 1124 :param token_sz: 1125 1126 Size of data pointed to by ``token``. 1127 1128Closing Connections 1129------------------- 1130 1131.. function:: void lsquic_conn_going_away (lsquic_conn_t *conn) 1132 1133 Mark connection as going away: send GOAWAY frame and do not accept 1134 any more incoming streams, nor generate streams of our own. 1135 1136 In the server mode, of course, we can call this function just fine in both 1137 Google and IETF QUIC. 1138 1139 In client mode, calling this function in for an IETF QUIC connection does 1140 not do anything, as the client MUST NOT send GOAWAY frames. 1141 1142.. function:: void lsquic_conn_close (lsquic_conn_t *conn) 1143 1144 This closes the connection. ``on_conn_closed()`` and ``on_close()`` callbacks will be called. 1145 1146Creating Streams 1147---------------- 1148 1149Similar to connections, streams are created by the library in server mode; they 1150correspond to requests. In client mode, a new stream is created by 1151 1152.. function:: void lsquic_conn_make_stream (lsquic_conn_t *) 1153 1154 Create a new request stream. This causes :member:`on_new_stream()` callback 1155 to be called. If creating more requests is not permitted at the moment 1156 (due to number of concurrent streams limit), stream creation is registered 1157 as "pending" and the stream is created later when number of streams dips 1158 under the limit again. Any number of pending streams can be created. 1159 Use :func:`lsquic_conn_n_pending_streams()` and 1160 :func:`lsquic_conn_cancel_pending_streams()` to manage pending streams. 1161 1162 If connection is going away, :func:`on_new_stream()` is called with the 1163 stream parameter set to NULL. 1164 1165Stream Events 1166------------- 1167 1168To register or unregister an interest in a read or write event, use the 1169following functions: 1170 1171.. function:: int lsquic_stream_wantread (lsquic_stream_t *stream, int want) 1172 1173 :param stream: Stream to read from. 1174 :param want: Boolean value indicating whether the caller wants to read 1175 from stream. 1176 :return: Previous value of ``want`` or ``-1`` if the stream has already 1177 been closed for reading. 1178 1179 A stream becomes readable if there is was an error: for example, the 1180 peer may have reset the stream. In this case, reading from the stream 1181 will return an error. 1182 1183.. function:: int lsquic_stream_wantwrite (lsquic_stream_t *stream, int want) 1184 1185 :param stream: Stream to write to. 1186 :param want: Boolean value indicating whether the caller wants to write 1187 to stream. 1188 :return: Previous value of ``want`` or ``-1`` if the stream has already 1189 been closed for writing. 1190 1191Reading From Streams 1192-------------------- 1193 1194.. function:: ssize_t lsquic_stream_read (lsquic_stream_t *stream, unsigned char *buf, size_t sz) 1195 1196 :param stream: Stream to read from. 1197 :param buf: Buffer to copy data to. 1198 :param sz: Size of the buffer. 1199 :return: Number of bytes read, zero if EOS has been reached, or -1 on error. 1200 1201 Read up to ``sz`` bytes from ``stream`` into buffer ``buf``. 1202 1203 ``-1`` is returned on error, in which case ``errno`` is set: 1204 1205 - ``EBADF``: The stream is closed. 1206 - ``ECONNRESET``: The stream has been reset. 1207 - ``EWOULDBLOCK``: There is no data to be read. 1208 1209.. function:: ssize_t lsquic_stream_readv (lsquic_stream_t *stream, const struct iovec *vec, int iovcnt) 1210 1211 :param stream: Stream to read from. 1212 :param vec: Array of ``iovec`` structures. 1213 :param iovcnt: Number of elements in ``vec``. 1214 :return: Number of bytes read, zero if EOS has been reached, or -1 on error. 1215 1216 Similar to :func:`lsquic_stream_read()`, but reads data into a vector. 1217 1218.. 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) 1219 1220 :param stream: Stream to read from. 1221 1222 :param readf: 1223 1224 The callback takes four parameters: 1225 1226 - Pointer to user-supplied context; 1227 - Pointer to the data; 1228 - Data size (can be zero); and 1229 - Indicator whether the FIN follows the data. 1230 1231 The callback returns number of bytes processed. If this number is zero 1232 or is smaller than ``len``, reading from stream stops. 1233 1234 :param ctx: Context pointer passed to ``readf``. 1235 1236 This function allows user-supplied callback to read the stream contents. 1237 It is meant to be used for zero-copy stream processing. 1238 1239 Return value and errors are same as in :func:`lsquic_stream_read()`. 1240 1241Writing To Streams 1242------------------ 1243 1244.. function:: ssize_t lsquic_stream_write (lsquic_stream_t *stream, const void *buf, size_t len) 1245 1246 :param stream: Stream to write to. 1247 :param buf: Buffer to copy data from. 1248 :param len: Number of bytes to copy. 1249 :return: Number of bytes written -- which may be smaller than ``len`` -- or a negative 1250 value when an error occurs. 1251 1252 Write ``len`` bytes to the stream. Returns number of bytes written, which 1253 may be smaller that ``len``. 1254 1255 A negative return value indicates a serious error (the library is likely 1256 to have aborted the connection because of it). 1257 1258.. function:: ssize_t lsquic_stream_writev (lsquic_stream_t *s, const struct iovec *vec, int count) 1259 1260 Like :func:`lsquic_stream_write()`, but read data from a vector. 1261 1262.. type:: struct lsquic_reader 1263 1264 Used as argument to :func:`lsquic_stream_writef()`. 1265 1266 .. member:: size_t (*lsqr_read) (void *lsqr_ctx, void *buf, size_t count) 1267 1268 :param lsqr_ctx: Pointer to user-specified context. 1269 :param buf: Memory location to write to. 1270 :param count: Size of available memory pointed to by ``buf``. 1271 :return: 1272 1273 Number of bytes written. This is not a ``ssize_t`` because 1274 the read function is not supposed to return an error. If an error 1275 occurs in the read function (for example, when reading from a file 1276 fails), it is supposed to deal with the error itself. 1277 1278 .. member:: size_t (*lsqr_size) (void *lsqr_ctx) 1279 1280 Return number of bytes remaining in the reader. 1281 1282 .. member:: void *lsqr_ctx 1283 1284 Context pointer passed both to ``lsqr_read()`` and to ``lsqr_size()``. 1285 1286.. function:: ssize_t lsquic_stream_writef (lsquic_stream_t *stream, struct lsquic_reader *reader) 1287 1288 :param stream: Stream to write to. 1289 :param reader: Reader to read from. 1290 :return: Number of bytes written or -1 on error. 1291 1292 Write to stream using :type:`lsquic_reader`. This is the most generic of 1293 the write functions -- :func:`lsquic_stream_write()` and 1294 :func:`lsquic_stream_writev()` utilize the same mechanism. 1295 1296.. function:: int lsquic_stream_flush (lsquic_stream_t *stream) 1297 1298 :param stream: Stream to flush. 1299 :return: 0 on success and -1 on failure. 1300 1301 Flush any buffered data. This triggers packetizing even a single byte 1302 into a separate frame. Flushing a closed stream is an error. 1303 1304Closing Streams 1305--------------- 1306 1307Streams can be closed for reading, writing, or both. 1308``on_close()`` callback is called at some point after a stream is closed 1309for both reading and writing, 1310 1311.. function:: int lsquic_stream_shutdown (lsquic_stream_t *stream, int how) 1312 1313 :param stream: Stream to shut down. 1314 :param how: 1315 1316 This parameter specifies what do to. Allowed values are: 1317 1318 - 0: Stop reading. 1319 - 1: Stop writing. 1320 - 2: Stop both reading and writing. 1321 1322 :return: 0 on success or -1 on failure. 1323 1324.. function:: int lsquic_stream_close (lsquic_stream_t *stream) 1325 1326 :param stream: Stream to close. 1327 :return: 0 on success or -1 on failure. 1328 1329Sending HTTP Headers 1330-------------------- 1331 1332.. type:: lsquic_http_header_t 1333 1334 .. member:: struct iovec name 1335 1336 Header name. 1337 1338 .. member:: struct iovec value 1339 1340 Header value. 1341 1342 HTTP header structure. Contains header name and value. 1343 1344.. type:: lsquic_http_headers_t 1345 1346 .. member:: int count 1347 1348 Number of headers in ``headers``. 1349 1350 .. member:: lsquic_http_header_t *headers 1351 1352 Pointer to an array of HTTP headers. 1353 1354 HTTP header list structure. Contains a list of HTTP headers in key/value pairs. 1355 1356.. function:: int lsquic_stream_send_headers (lsquic_stream_t *stream, const lsquic_http_headers_t *headers, int eos) 1357 1358 :param stream: 1359 1360 Stream to send headers on. 1361 1362 :param headers: 1363 1364 Headers to send. 1365 1366 :param eos: 1367 1368 Boolean value to indicate whether these headers constitute the whole 1369 HTTP message. 1370 1371 :return: 1372 1373 0 on success or -1 on error. 1374 1375Receiving HTTP Headers 1376---------------------- 1377 1378If ``ea_hsi_if`` is not set in :type:`lsquic_engine_api`, the library will translate 1379HPACK- and QPACK-encoded headers into HTTP/1.x-like headers and prepend them to the 1380stream. To the stream-reading function, it will look as if a standard HTTP/1.x 1381message. 1382 1383Alternatively, you can specify header-processing set of functions and manage header 1384fields yourself. In that case, the header set must be "read" from the stream via 1385:func:`lsquic_stream_get_hset()`. 1386 1387.. type:: struct lsquic_hset_if 1388 1389 .. member:: void * (*hsi_create_header_set)(void *hsi_ctx, int is_push_promise) 1390 1391 :param hsi_ctx: User context. This is the pointer specifed in ``ea_hsi_ctx``. 1392 :param is_push_promise: Boolean value indicating whether this header set is 1393 for a push promise. 1394 :return: Pointer to user-defined header set object. 1395 1396 Create a new header set. This object is (and must be) fetched from a 1397 stream by calling :func:`lsquic_stream_get_hset()` before the stream can 1398 be read. 1399 1400 .. 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) 1401 1402 :param hdr_set: 1403 1404 Header set to add the new header field to. This is the object 1405 returned by ``hsi_create_header_set()``. 1406 1407 :param name_idx: 1408 1409 This value is set to the index in either the HPACK or QPACK static table 1410 whose entry's name element matches ``name``. The values are as follows: 1411 1412 - if there is no such match, this value is zero; 1413 - if HPACK is used, the value is between 1 and 61; and 1414 - if QPACK is used, the value is 62+ (subtract 62 to get the QPACK 1415 static table index). 1416 1417 :param name: 1418 1419 Header field name. If NULL, this means that no more header are going to be 1420 added to the set. 1421 1422 :param name_len: 1423 1424 Header field name length. 1425 1426 :param value: 1427 1428 Header field value. 1429 1430 :param value_len: 1431 1432 Header field value length. 1433 1434 :return: 1435 1436 0 on success, non-zero on failure. The latter is treated as a stream 1437 error: the associated stream is reset. See :type:`lsquic_header_status` 1438 for detailed error listing. 1439 1440 .. member:: void (*hsi_discard_header_set)(void *hdr_set) 1441 1442 :param hdr_set: Header set to discard. 1443 1444 Discard header set. This is called for unclaimed header sets and 1445 header sets that had an error. 1446 1447.. function:: void * lsquic_stream_get_hset (lsquic_stream_t *stream) 1448 1449 :param stream: Stream to fetch header set from. 1450 1451 :return: Header set associated with the stream. 1452 1453 Get header set associated with the stream. The header set is created by 1454 ``hsi_create_header_set()`` callback. After this call, the ownership of 1455 the header set is trasnferred to the caller. 1456 1457 This call must precede calls to :func:`lsquic_stream_read()`, 1458 :func:`lsquic_stream_readv()`, and :func:`lsquic_stream_readf()`. 1459 1460 If the optional header set interface is not specified, 1461 this function returns NULL. 1462 1463Push Promises 1464------------- 1465 1466.. 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) 1467 1468 :return: 1469 1470 - 0: Stream pushed successfully. 1471 - 1: Stream push failed because it is disabled or because we hit 1472 stream limit or connection is going away. 1473 - -1: Stream push failed because of an internal error. 1474 1475 A server may push a stream. This call creates a new stream in reference 1476 to stream ``stream``. It will behave as if the client made a request: it will 1477 trigger ``on_new_stream()`` event and it can be used as a regular client-initiated stream. 1478 1479 If ``hdr_set`` is not set, it is generated by using ``ea_hsi_if`` callbacks (if set). 1480 In either case, the header set object belongs to the connection. The 1481 user is not to free this object until ``hsi_discard_header_set()`` is 1482 called. 1483 1484.. function:: int lsquic_conn_is_push_enabled (lsquic_conn_t *conn) 1485 1486 :return: Boolean value indicating whether push promises are enabled. 1487 1488 Only makes sense in server mode: the client cannot push a stream and this 1489 function always returns false in client mode. 1490 1491.. function: int lsquic_stream_is_pushed (const lsquic_stream_t *stream) 1492 1493 :return: Boolean value indicating whether this is a pushed stream. 1494 1495.. function:: int lsquic_stream_refuse_push (lsquic_stream_t *stream) 1496 1497 Refuse pushed stream. Call it from ``on_new_stream()``. No need to 1498 call :func:`lsquic_stream_close()` after this. ``on_close()`` will be called. 1499 1500.. function:: int lsquic_stream_push_info (const lsquic_stream_t *stream, lsquic_stream_id_t *ref_stream_id, void **hdr_set) 1501 1502 Get information associated with pushed stream 1503 1504 :param ref_stream_id: Stream ID in response to which push promise was sent. 1505 :param hdr_set: Header set. This object was passed to or generated by :func:`lsquic_conn_push_stream()`. 1506 1507 :return: 0 on success and -1 if this is not a pushed stream. 1508 1509Stream Priorities 1510----------------- 1511 1512.. function:: unsigned lsquic_stream_priority (const lsquic_stream_t *stream) 1513 1514 Return current priority of the stream. 1515 1516.. function:: int lsquic_stream_set_priority (lsquic_stream_t *stream, unsigned priority) 1517 1518 Set stream priority. Valid priority values are 1 through 256, inclusive. 1519 1520 :return: 0 on success of -1 on failure (this happens if priority value is invalid). 1521 1522Miscellaneous Engine Functions 1523------------------------------ 1524 1525.. function:: unsigned lsquic_engine_quic_versions (const lsquic_engine_t *engine) 1526 1527 Return the list of QUIC versions (as bitmask) this engine instance supports. 1528 1529.. function:: unsigned lsquic_engine_count_attq (lsquic_engine_t *engine, int from_now) 1530 1531 Return number of connections whose advisory tick time is before current 1532 time plus ``from_now`` microseconds from now. ``from_now`` can be negative. 1533 1534Miscellaneous Connection Functions 1535---------------------------------- 1536 1537.. function:: enum lsquic_version lsquic_conn_quic_version (const lsquic_conn_t *conn) 1538 1539 Get QUIC version used by the connection. 1540 1541 If version has not yet been negotiated (can happen in client mode), ``-1`` is 1542 returned. 1543 1544.. function:: const lsquic_cid_t * lsquic_conn_id (const lsquic_conn_t *conn) 1545 1546 Get connection ID. 1547 1548.. function:: lsquic_engine_t * lsquic_conn_get_engine (lsquic_conn_t *conn) 1549 1550 Get pointer to the engine. 1551 1552.. function:: int lsquic_conn_get_sockaddr (lsquic_conn_t *conn, const struct sockaddr **local, const struct sockaddr **peer) 1553 1554 Get current (last used) addresses associated with the current path 1555 used by the connection. 1556 1557.. function:: struct stack_st_X509 * lsquic_conn_get_server_cert_chain (lsquic_conn_t *conn) 1558 1559 Get certificate chain returned by the server. This can be used for 1560 server certificate verification. 1561 1562 The caller releases the stack using sk_X509_free(). 1563 1564.. function:: lsquic_conn_ctx_t * lsquic_conn_get_ctx (const lsquic_conn_t *conn) 1565 1566 Get user-supplied context associated with the connection. 1567 1568.. function:: void lsquic_conn_set_ctx (lsquic_conn_t *conn, lsquic_conn_ctx_t *ctx) 1569 1570 Set user-supplied context associated with the connection. 1571 1572.. function:: void * lsquic_conn_get_peer_ctx (lsquic_conn_t *conn, const struct sockaddr *local_sa) 1573 1574 Get peer context associated with the connection and local address. 1575 1576.. function:: enum LSQUIC_CONN_STATUS lsquic_conn_status (lsquic_conn_t *conn, char *errbuf, size_t bufsz) 1577 1578 Get connection status. 1579 1580Miscellaneous Stream Functions 1581------------------------------ 1582 1583.. function:: unsigned lsquic_conn_n_avail_streams (const lsquic_conn_t *conn) 1584 1585 Return max allowed outbound streams less current outbound streams. 1586 1587.. function:: unsigned lsquic_conn_n_pending_streams (const lsquic_conn_t *conn) 1588 1589 Return number of delayed streams currently pending. 1590 1591.. function:: unsigned lsquic_conn_cancel_pending_streams (lsquic_conn_t *, unsigned n) 1592 1593 Cancel ``n`` pending streams. Returns new number of pending streams. 1594 1595.. function:: lsquic_conn_t * lsquic_stream_conn (const lsquic_stream_t *stream) 1596 1597 Get a pointer to the connection object. Use it with connection functions. 1598 1599.. function:: int lsquic_stream_is_rejected (const lsquic_stream_t *stream) 1600 1601 Returns true if this stream was rejected, false otherwise. Use this as 1602 an aid to distinguish between errors. 1603 1604Other Functions 1605--------------- 1606 1607.. function:: enum lsquic_version lsquic_str2ver (const char *str, size_t len) 1608 1609 Translate string QUIC version to LSQUIC QUIC version representation. 1610 1611.. function:: enum lsquic_version lsquic_alpn2ver (const char *alpn, size_t len) 1612 1613 Translate ALPN (e.g. "h3", "h3-23", "h3-Q046") to LSQUIC enum. 1614 1615Miscellaneous Types 1616------------------- 1617 1618.. type:: struct lsquic_shared_hash_if 1619 1620 The shared hash interface is used to share data between multiple LSQUIC instances. 1621 1622 .. member:: int (*shi_insert)(void *shi_ctx, void *key, unsigned key_sz, void *data, unsigned data_sz, time_t expiry) 1623 1624 :param shi_ctx: 1625 1626 Shared memory context pointer 1627 1628 :param key: 1629 1630 Key data. 1631 1632 :param key_sz: 1633 1634 Key size. 1635 1636 :param data: 1637 1638 Pointer to the data to store. 1639 1640 :param data_sz: 1641 1642 Data size. 1643 1644 :param expiry: When this item expires. If you want your item to never expire, set this to zero. 1645 1646 :return: 0 on success, -1 on failure. 1647 1648 If inserted successfully, ``free()`` will be called on ``data`` and ``key`` 1649 pointer when the element is deleted, whether due to expiration 1650 or explicit deletion. 1651 1652 .. member:: int (*shi_delete)(void *shi_ctx, const void *key, unsigned key_sz) 1653 1654 Delete item from shared hash 1655 1656 :return: 0 on success, -1 on failure. 1657 1658 .. member:: int (*shi_lookup)(void *shi_ctx, const void *key, unsigned key_sz, void **data, unsigned *data_sz) 1659 1660 :param shi_ctx: 1661 1662 Shared memory context pointer 1663 1664 :param key: 1665 1666 Key data. 1667 1668 :param key_sz: 1669 1670 Key size. 1671 1672 :param data: 1673 1674 Pointer to set to the result. 1675 1676 :param data_sz: 1677 1678 Pointer to the data size. 1679 1680 :return: 1681 1682 - ``1``: found. 1683 - ``0``: not found. 1684 - ``-1``: error (perhaps not enough room in ``data`` if copy was attempted). 1685 1686 The implementation may choose to copy the object into buffer pointed 1687 to by ``data``, so you should have it ready. 1688 1689.. type:: struct lsquic_packout_mem_if 1690 1691 The packet out memory interface is used by LSQUIC to get buffers to 1692 which outgoing packets will be written before they are passed to 1693 :member:`lsquic_engine_api.ea_packets_out` callback. 1694 1695 If not specified, malloc() and free() are used. 1696 1697 .. member:: void * (*pmi_allocate) (void *pmi_ctx, void *conn_ctx, unsigned short sz, char is_ipv6) 1698 1699 Allocate buffer for sending. 1700 1701 .. member:: void (*pmi_release) (void *pmi_ctx, void *conn_ctx, void *buf, char is_ipv6) 1702 1703 This function is used to release the allocated buffer after it is 1704 sent via ``ea_packets_out()``. 1705 1706 .. member:: void (*pmi_return) (void *pmi_ctx, void *conn_ctx, void *buf, char is_ipv6) 1707 1708 If allocated buffer is not going to be sent, return it to the 1709 caller using this function. 1710 1711.. type:: typedef void (*lsquic_cids_update_f)(void *ctx, void **peer_ctx, const lsquic_cid_t *cids, unsigned n_cids) 1712 1713 :param ctx: 1714 1715 Context associated with the CID lifecycle callbacks (ea_cids_update_ctx). 1716 1717 :param peer_ctx: 1718 1719 Array of peer context pointers. 1720 1721 :param cids: 1722 1723 Array of connection IDs. 1724 1725 :param n_cids: 1726 1727 Number of elements in the peer context pointer and connection ID arrays. 1728 1729.. type:: struct lsquic_keylog_if 1730 1731 SSL keylog interface. 1732 1733 .. member:: void * (*kli_open) (void *keylog_ctx, lsquic_conn_t *conn) 1734 1735 Return keylog handle or NULL if no key logging is desired. 1736 1737 .. member:: void (*kli_log_line) (void *handle, const char *line) 1738 1739 Log line. The first argument is the pointer returned by ``kli_open()``. 1740 1741 .. member:: void (*kli_close) (void *handle) 1742 1743 Close handle. 1744 1745.. type:: enum lsquic_header_status 1746 1747 When headers are processed, various errors may occur. They are listed 1748 in this enum. 1749 1750 .. member:: LSQUIC_HDR_OK 1751 1752 Header was processed OK. 1753 1754 .. member:: LSQUIC_HDR_ERR_DUPLICATE_PSDO_HDR 1755 1756 Duplicate pseudo-header 1757 1758 .. member:: LSQUIC_HDR_ERR_INCOMPL_REQ_PSDO_HDR 1759 1760 Not all request pseudo-headers are present 1761 1762 .. member:: LSQUIC_HDR_ERR_UNNEC_REQ_PSDO_HDR 1763 1764 Unnecessary request pseudo-header present in the response 1765 1766 .. member:: LSQUIC_HDR_ERR_BAD_REQ_HEADER 1767 1768 Prohibited header in request 1769 1770 .. member:: LSQUIC_HDR_ERR_INCOMPL_RESP_PSDO_HDR 1771 1772 Not all response pseudo-headers are present 1773 1774 .. member:: LSQUIC_HDR_ERR_UNNEC_RESP_PSDO_HDR 1775 1776 Unnecessary response pseudo-header present in the response. 1777 1778 .. member:: LSQUIC_HDR_ERR_UNKNOWN_PSDO_HDR 1779 1780 Unknown pseudo-header 1781 1782 .. member:: LSQUIC_HDR_ERR_UPPERCASE_HEADER 1783 1784 Uppercase letter in header 1785 1786 .. member:: LSQUIC_HDR_ERR_MISPLACED_PSDO_HDR 1787 1788 Misplaced pseudo-header 1789 1790 .. member:: LSQUIC_HDR_ERR_MISSING_PSDO_HDR 1791 1792 Missing pseudo-header 1793 1794 .. member:: LSQUIC_HDR_ERR_HEADERS_TOO_LARGE 1795 1796 Header or headers are too large 1797 1798 .. member:: LSQUIC_HDR_ERR_NOMEM 1799 1800 Cannot allocate any more memory. 1801 1802.. type:: enum lsquic_logger_timestamp_style 1803 1804 Enumerate timestamp styles supported by LSQUIC logger mechanism. 1805 1806 .. member:: LLTS_NONE 1807 1808 No timestamp is generated. 1809 1810 .. member:: LLTS_HHMMSSMS 1811 1812 The timestamp consists of 24 hours, minutes, seconds, and milliseconds. Example: 13:43:46.671 1813 1814 .. member:: LLTS_YYYYMMDD_HHMMSSMS 1815 1816 Like above, plus date, e.g: 2017-03-21 13:43:46.671 1817 1818 .. member:: LLTS_CHROMELIKE 1819 1820 This is Chrome-like timestamp used by proto-quic. The timestamp 1821 includes month, date, hours, minutes, seconds, and microseconds. 1822 1823 Example: 1223/104613.946956 (instead of 12/23 10:46:13.946956). 1824 1825 This is to facilitate reading two logs side-by-side. 1826 1827 .. member:: LLTS_HHMMSSUS 1828 1829 The timestamp consists of 24 hours, minutes, seconds, and microseconds. Example: 13:43:46.671123 1830 1831 .. member:: LLTS_YYYYMMDD_HHMMSSUS 1832 1833 Date and time using microsecond resolution, e.g: 2017-03-21 13:43:46.671123 1834 1835.. type:: enum LSQUIC_CONN_STATUS 1836 1837 .. member:: LSCONN_ST_HSK_IN_PROGRESS 1838 .. member:: LSCONN_ST_CONNECTED 1839 .. member:: LSCONN_ST_HSK_FAILURE 1840 .. member:: LSCONN_ST_GOING_AWAY 1841 .. member:: LSCONN_ST_TIMED_OUT 1842 .. member:: LSCONN_ST_RESET 1843 1844 If es_honor_prst is not set, the connection will never get public 1845 reset packets and this flag will not be set. 1846 1847 .. member:: LSCONN_ST_USER_ABORTED 1848 .. member:: LSCONN_ST_ERROR 1849 .. member:: LSCONN_ST_CLOSED 1850 .. member:: LSCONN_ST_PEER_GOING_AWAY 1851 1852Global Variables 1853---------------- 1854 1855.. var:: const char *const lsquic_ver2str[N_LSQVER] 1856 1857 Convert LSQUIC version to human-readable string 1858 1859List of Log Modules 1860------------------- 1861 1862The following log modules are defined: 1863 1864- *alarmset*: Alarm processing. 1865- *bbr*: BBR congestion controller. 1866- *bw-sampler*: Bandwidth sampler (used by BBR). 1867- *cfcw*: Connection flow control window. 1868- *conn*: Connection. 1869- *crypto*: Low-level Google QUIC cryptography tracing. 1870- *cubic*: Cubic congestion controller. 1871- *di*: "Data In" handler (storing incoming data before it is read). 1872- *eng-hist*: Engine history. 1873- *engine*: Engine. 1874- *event*: Cross-module significant events. 1875- *frame-reader*: Reader of the HEADERS stream in Google QUIC. 1876- *frame-writer*: Writer of the HEADERS stream in Google QUIC. 1877- *handshake*: Handshake and packet encryption and decryption. 1878- *hcsi-reader*: Reader of the HTTP/3 control stream. 1879- *hcso-writer*: Writer of the HTTP/3 control stream. 1880- *headers*: HEADERS stream (Google QUIC). 1881- *hsk-adapter*: 1882- *http1x*: Header conversion to HTTP/1.x. 1883- *logger*: Logger. 1884- *mini-conn*: Mini connection. 1885- *pacer*: Pacer. 1886- *parse*: Parsing. 1887- *prq*: PRQ stands for Packet Request Queue. This logs scheduling 1888 and sending packets not associated with a connection: version 1889 negotiation and stateless resets. 1890- *purga*: CID purgatory. 1891- *qdec-hdl*: QPACK decoder stream handler. 1892- *qenc-hdl*: QPACK encoder stream handler. 1893- *qlog*: QLOG output. At the moment, it is out of date. 1894- *qpack-dec*: QPACK decoder. 1895- *qpack-enc*: QPACK encoder. 1896- *rechist*: Receive history. 1897- *sendctl*: Send controller. 1898- *sfcw*: Stream flow control window. 1899- *spi*: Stream priority iterator. 1900- *stream*: Stream operation. 1901- *tokgen*: Token generation and validation. 1902- *trapa*: Transport parameter processing. 1903