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