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