Release 2.2.0: server included, ID-22 supported (#76)

This commit is contained in:
LiteSpeed Tech 2019-09-11 11:27:58 -04:00 committed by GitHub
parent 8cba36d873
commit 5392f7a3b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
221 changed files with 113761 additions and 4563 deletions

View file

@ -23,9 +23,9 @@ struct sockaddr;
extern "C" {
#endif
#define LSQUIC_MAJOR_VERSION 1
#define LSQUIC_MINOR_VERSION 21
#define LSQUIC_PATCH_VERSION 2
#define LSQUIC_MAJOR_VERSION 2
#define LSQUIC_MINOR_VERSION 2
#define LSQUIC_PATCH_VERSION 0
/**
* Engine flags:
@ -49,7 +49,9 @@ enum lsquic_version
{
/** Q035. This is the first version to be supported by LSQUIC. */
LSQVER_035,
/* Support for this version has been removed. The comment remains to
* document the changes.
*/
/*
* Q037. This version is like Q035, except the way packet hashes are
@ -101,7 +103,9 @@ enum lsquic_version
* Q044. IETF-like packet headers are used. Frames are the same as
* in Q043. Server never includes CIDs in short packets.
*/
LSQVER_044,
/* Support for this version has been removed. The comment remains to
* document the changes.
*/
/**
* Q046. Use IETF Draft-17 compatible packet headers.
@ -120,27 +124,41 @@ enum lsquic_version
#define LSQUIC_EXPERIMENTAL_Q098 0
#endif
/**
* IETF QUIC Draft-22
*/
LSQVER_ID22,
/**
* Special version to trigger version negotiation.
* [draft-ietf-quic-transport-11], Section 3.
*/
LSQVER_VERNEG,
N_LSQVER
};
/**
* We currently support versions 35, 39, 43, 44, and 46.
* We currently support versions 39, 43, 46, and IETF Draft-22
* @see lsquic_version
*/
#define LSQUIC_SUPPORTED_VERSIONS ((1 << N_LSQVER) - 1)
#define LSQUIC_EXPERIMENTAL_VERSIONS (0 \
| LSQUIC_EXPERIMENTAL_Q098)
#define LSQUIC_DEPRECATED_VERSIONS 0
#define LSQUIC_GQUIC_HEADER_VERSIONS ( \
(1 << LSQVER_035) | (1 << LSQVER_039) | (1 << LSQVER_043))
/**
* List of versions in which the server never includes CID in short packets.
*/
#define LSQUIC_FORCED_TCID0_VERSIONS ((1 << LSQVER_044) | (1 << LSQVER_046))
#define LSQUIC_FORCED_TCID0_VERSIONS (1 << LSQVER_046)
#define LSQUIC_EXPERIMENTAL_VERSIONS ( \
(1 << LSQVER_VERNEG) | LSQUIC_EXPERIMENTAL_Q098)
#define LSQUIC_DEPRECATED_VERSIONS 0
#define LSQUIC_GQUIC_HEADER_VERSIONS ((1 << LSQVER_039) | (1 << LSQVER_043))
#define LSQUIC_IETF_VERSIONS ((1 << LSQVER_ID22) | (1 << LSQVER_VERNEG))
#define LSQUIC_IETF_DRAFT_VERSIONS ((1 << LSQVER_ID22) | (1 << LSQVER_VERNEG))
enum lsquic_hsk_status
{
@ -156,6 +174,11 @@ enum lsquic_hsk_status
* The handshake succeeded with 0-RTT.
*/
LSQ_HSK_0RTT_OK,
/**
* The handshake failed because of 0-RTT (early data rejected). Retry
* the connection without 0-RTT.
*/
LSQ_HSK_0RTT_FAIL,
};
/**
@ -192,6 +215,7 @@ struct lsquic_stream_if {
void (*on_read) (lsquic_stream_t *s, lsquic_stream_ctx_t *h);
void (*on_write) (lsquic_stream_t *s, lsquic_stream_ctx_t *h);
void (*on_close) (lsquic_stream_t *s, lsquic_stream_ctx_t *h);
/* This callback in only called in client mode */
/**
* When handshake is completed, this callback is called. `ok' is set
* to true if handshake was successful; otherwise, `ok' is set to
@ -200,8 +224,31 @@ struct lsquic_stream_if {
* This callback is optional.
*/
void (*on_hsk_done)(lsquic_conn_t *c, enum lsquic_hsk_status s);
/**
* When server sends a token in NEW_TOKEN frame, this callback is called.
* The callback is optional.
*/
void (*on_new_token)(lsquic_conn_t *c, const unsigned char *token,
size_t token_size);
/**
* This optional callback lets client record information needed to
* perform a zero-RTT handshake next time around.
*/
void (*on_zero_rtt_info)(lsquic_conn_t *c, const unsigned char *, size_t);
};
struct ssl_ctx_st;
struct ssl_st;
/**
* QUIC engine in server role needs access to certificates. This is
* accomplished by providing a callback and a context to the engine
* constructor.
*/
typedef struct ssl_ctx_st * (*lsquic_lookup_cert_f)(
void *lsquic_cert_lookup_ctx, const struct sockaddr *local, const char *sni);
/**
* Minimum flow control window is set to 16 KB for both client and server.
* This means we can send up to this amount of data before handshake gets
@ -226,12 +273,36 @@ struct lsquic_stream_if {
#define LSQUIC_DF_SFCW_CLIENT (6 * 1024 * 1024)
#define LSQUIC_DF_MAX_STREAMS_IN 100
/* IQUIC uses different names for these: */
#define LSQUIC_DF_INIT_MAX_DATA_SERVER LSQUIC_DF_CFCW_SERVER
#define LSQUIC_DF_INIT_MAX_DATA_CLIENT LSQUIC_DF_CFCW_CLIENT
#define LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_REMOTE_SERVER LSQUIC_DF_SFCW_SERVER
#define LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_LOCAL_SERVER 0
#define LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_REMOTE_CLIENT 0
#define LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_LOCAL_CLIENT LSQUIC_DF_SFCW_CLIENT
#define LSQUIC_DF_INIT_MAX_STREAMS_BIDI LSQUIC_DF_MAX_STREAMS_IN
#define LSQUIC_DF_INIT_MAX_STREAMS_UNI_CLIENT 100
#define LSQUIC_DF_INIT_MAX_STREAMS_UNI_SERVER 3
/* XXX What's a good value here? */
#define LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_CLIENT (32 * 1024)
#define LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_SERVER (12 * 1024)
/**
* Default idle connection time in seconds.
*/
#define LSQUIC_DF_IDLE_TIMEOUT 30
/**
* Default ping period in seconds.
*/
#define LSQUIC_DF_PING_PERIOD 15
/**
* Default handshake timeout in microseconds.
*/
#define LSQUIC_DF_HANDSHAKE_TO (10 * 1000 * 1000)
#define LSQUIC_DF_IDLE_CONN_TO (30 * 1000 * 1000)
#define LSQUIC_DF_IDLE_CONN_TO (LSQUIC_DF_IDLE_TIMEOUT * 1000 * 1000)
#define LSQUIC_DF_SILENT_CLOSE 1
/** Default value of maximum header list size. If set to non-zero value,
@ -249,11 +320,18 @@ struct lsquic_stream_if {
#define LSQUIC_DF_SUPPORT_SREJ_CLIENT 0 /* TODO: client support */
/** Do not use NSTP by default */
#define LSQUIC_DF_SUPPORT_NSTP 0
/** TODO: IETF QUIC clients do not support push */
#define LSQUIC_DF_SUPPORT_PUSH 1
#define LSQUIC_DF_SUPPORT_TCID0 0
#define LSQUIC_DF_SUPPORT_TCID0 1
/** By default, LSQUIC ignores Public Reset packets. */
#define LSQUIC_DF_HONOR_PRST 0
/**
* By default, LSQUIC will not send Public Reset packets in response to
* packets that specify unknown connections.
*/
#define LSQUIC_DF_SEND_PRST 0
/** By default, infinite loop checks are turned on */
#define LSQUIC_DF_PROGRESS_CHECK 1000
@ -269,6 +347,32 @@ struct lsquic_stream_if {
/** Default clock granularity is 1000 microseconds */
#define LSQUIC_DF_CLOCK_GRANULARITY 1000
/** The default value is 8 for simplicity */
#define LSQUIC_DF_SCID_LEN 8
/** The default value is 60 CIDs per minute */
#define LSQUIC_DF_SCID_ISS_RATE 60
#define LSQUIC_DF_QPACK_DEC_MAX_BLOCKED 100
#define LSQUIC_DF_QPACK_DEC_MAX_SIZE 4096
#define LSQUIC_DF_QPACK_ENC_MAX_BLOCKED 100
#define LSQUIC_DF_QPACK_ENC_MAX_SIZE 4096
/** ECN is enabled by default */
#define LSQUIC_DF_ECN 1
/**
* The default number of the priority placeholders is higher than the
* recommended value of 16 to give the clients even more freedom.
*/
#define LSQUIC_DF_H3_PLACEHOLDERS 50
/** Allow migration by default */
#define LSQUIC_DF_ALLOW_MIGRATION 1
/* 1: Cubic; 2: BBR */
#define LSQUIC_DF_CC_ALGO 1
struct lsquic_engine_settings {
/**
* This is a bit mask wherein each bit corresponds to a value in
@ -276,6 +380,8 @@ struct lsquic_engine_settings {
* version and goes down. Server supports either of the versions
* specified here.
*
* This setting applies to both Google and IETF QUIC.
*
* @see lsquic_version
*/
unsigned es_versions;
@ -325,10 +431,12 @@ struct lsquic_engine_settings {
* For client, this can be set to an arbitrary value (zero turns the
* timeout off).
*
* For server, this value is limited to about 16 seconds. Do not set
* it to zero.
*/
unsigned long es_handshake_to;
/** ICSL in microseconds */
/** ICSL in microseconds; GQUIC only */
unsigned long es_idle_conn_to;
/** SCLS (silent close) */
@ -344,10 +452,20 @@ struct lsquic_engine_settings {
/** UAID -- User-Agent ID. Defaults to @ref LSQUIC_DF_UA. */
const char *es_ua;
/**
* More parameters for server
*/
uint64_t es_sttl; /* SCFG TTL in seconds */
uint32_t es_pdmd; /* One fixed value X509 */
uint32_t es_aead; /* One fixed value AESG */
uint32_t es_kexs; /* One fixed value C255 */
/* Maximum number of incoming connections in inchoate state. This is
* only applicable in server mode.
*/
unsigned es_max_inchoate;
/**
* Support SREJ: for client side, this means supporting server's SREJ
* responses (this does not work yet) and for server side, this means
@ -364,6 +482,8 @@ struct lsquic_engine_settings {
* b) All incoming pushed streams get reset immediately.
* (For maximum effect, set es_max_streams_in to 0.)
*
* For server:
* lsquic_conn_push_stream() will return -1.
*/
int es_support_push;
@ -376,7 +496,7 @@ struct lsquic_engine_settings {
* (source-addr, dest-addr) tuple, thereby making it necessary to create
* a socket for each connection.
*
* This option has no effect in Q044 or Q046, as the server never includes
* This option has no effect in Q046, as the server never includes
* CIDs in the short packets.
*
* The default is @ref LSQUIC_DF_SUPPORT_TCID0.
@ -402,6 +522,13 @@ struct lsquic_engine_settings {
*/
int es_honor_prst;
/**
* If set to true value, the library will send Public Reset packets
* in response to incoming packets with unknown Connection IDs.
* The default is @ref LSQUIC_DF_SEND_PRST.
*/
int es_send_prst;
/**
* A non-zero value enables internal checks that identify suspected
* infinite loops in user @ref on_read and @ref on_write callbacks
@ -461,6 +588,169 @@ struct lsquic_engine_settings {
* is in microseconds; default is @ref LSQUIC_DF_CLOCK_GRANULARITY.
*/
unsigned es_clock_granularity;
/* The following settings are specific to IETF QUIC. */
/* vvvvvvvvvvv */
/**
* Initial max data.
*
* This is a transport parameter.
*
* Depending on the engine mode, the default value is either
* @ref LSQUIC_DF_INIT_MAX_DATA_CLIENT or
* @ref LSQUIC_DF_INIT_MAX_DATA_SERVER.
*/
unsigned es_init_max_data;
/**
* Initial max stream data.
*
* This is a transport parameter.
*
* Depending on the engine mode, the default value is either
* @ref LSQUIC_DF_INIT_MAX_STREAM_DATA_CLIENT or
* @ref LSQUIC_DF_INIT_MAX_STREAM_DATA_BIDI_REMOTE_SERVER.
*/
unsigned es_init_max_stream_data_bidi_remote;
unsigned es_init_max_stream_data_bidi_local;
/**
* Initial max stream data for unidirectional streams initiated
* by remote endpoint.
*
* This is a transport parameter.
*
* Depending on the engine mode, the default value is either
* @ref LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_CLIENT or
* @ref LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_SERVER.
*/
unsigned es_init_max_stream_data_uni;
/**
* Maximum initial number of bidirectional stream.
*
* This is a transport parameter.
*
* Default value is @ref LSQUIC_DF_INIT_MAX_STREAMS_BIDI.
*/
unsigned es_init_max_streams_bidi;
/**
* Maximum initial number of unidirectional stream.
*
* This is a transport parameter.
*
* Default value is @ref LSQUIC_DF_INIT_MAX_STREAMS_UNI_CLIENT or
* @ref LSQUIC_DF_INIT_MAX_STREAM_DATA_UNI_SERVER.
*/
unsigned es_init_max_streams_uni;
/**
* Idle connection timeout.
*
* This is a transport parameter.
*
* (Note: es_idle_conn_to is not reused because it is in microseconds,
* which, I now realize, was not a good choice. Since it will be
* obsoleted some time after the switchover to IETF QUIC, we do not
* have to keep on using strange units.)
*
* Default value is @ref LSQUIC_DF_IDLE_TIMEOUT.
*
* Maximum value is 600 seconds.
*/
unsigned es_idle_timeout;
/**
* Ping period. If set to non-zero value, the connection will generate and
* send PING frames in the absence of other activity.
*
* By default, the server does not send PINGs and the period is set to zero.
* The client's defaut value is @ref LSQUIC_DF_PING_PERIOD.
*/
unsigned es_ping_period;
/**
* Source Connection ID length. Only applicable to the IETF QUIC
* versions. Valid values are 4 through 18, inclusive.
*
* Default value is @ref LSQUIC_DF_SCID_LEN.
*/
unsigned es_scid_len;
/**
* Source Connection ID issuance rate. Only applicable to the IETF QUIC
* versions. This field is measured in CIDs per minute. Using value 0
* indicates that there is no rate limit for CID issuance.
*
* Default value is @ref LSQUIC_DF_SCID_ISS_RATE.
*/
unsigned es_scid_iss_rate;
/**
* Maximum size of the QPACK dynamic table that the QPACK decoder will
* use.
*
* The default is @ref LSQUIC_DF_QPACK_DEC_MAX_SIZE.
*/
unsigned es_qpack_dec_max_size;
/**
* Maximum number of blocked streams that the QPACK decoder is willing
* to tolerate.
*
* The default is @ref LSQUIC_DF_QPACK_DEC_MAX_BLOCKED.
*/
unsigned es_qpack_dec_max_blocked;
/**
* Maximum size of the dynamic table that the encoder is willing to use.
* The actual size of the dynamic table will not exceed the minimum of
* this value and the value advertized by peer.
*
* The default is @ref LSQUIC_DF_QPACK_ENC_MAX_SIZE.
*/
unsigned es_qpack_enc_max_size;
/**
* Maximum number of blocked streams that the QPACK encoder is willing
* to risk. The actual number of blocked streams will not exceed the
* minimum of this value and the value advertized by peer.
*
* The default is @ref LSQUIC_DF_QPACK_ENC_MAX_BLOCKED.
*/
unsigned es_qpack_enc_max_blocked;
/**
* Enable ECN support.
*
* The default is @ref LSQUIC_DF_ECN
*/
int es_ecn;
/**
* Number of HTTP/3 priorify placeholders.
*
* The default is @ref LSQUIC_DF_H3_PLACEHOLDERS
*/
unsigned es_h3_placeholders;
/**
* Allow peer to migrate connection.
*
* The default is @ref LSQUIC_DF_ALLOW_MIGRATION
*/
int es_allow_migration;
/**
* Congestion control algorithm to use.
*
* 0: Use default (@ref LSQUIC_DF_CC_ALGO)
* 1: Cubic
* 2: BBR
*/
unsigned es_cc_algo;
};
/* Initialize `settings' to default values */
@ -491,11 +781,12 @@ lsquic_engine_check_settings (const struct lsquic_engine_settings *settings,
struct lsquic_out_spec
{
const unsigned char *buf;
size_t sz;
struct iovec *iov;
size_t iovlen;
const struct sockaddr *local_sa;
const struct sockaddr *dest_sa;
void *peer_ctx;
int ecn; /* Valid values are 0 - 3. See RFC 3168 */
};
/**
@ -511,6 +802,41 @@ typedef int (*lsquic_packets_out_f)(
unsigned n_packets_out
);
/**
* The shared hash interface is used to share data between multiple LSQUIC
* instances.
*/
struct lsquic_shared_hash_if
{
/**
* If you want your item to never expire, set `expiry' to zero.
* Returns 0 on success, -1 on failure.
*
* If inserted successfully, `free()' will be called on `data' and 'key'
* pointer when the element is deleted, whether due to expiration
* or explicit deletion.
*/
int (*shi_insert)(void *shi_ctx, void *key, unsigned key_sz,
void *data, unsigned data_sz, time_t expiry);
/**
* Returns 0 on success, -1 on failure.
*/
int (*shi_delete)(void *shi_ctx, const void *key, unsigned key_sz);
/**
* `data' is pointed to the result and `data_sz' is set to the
* object size. The implementation may choose to copy the object
* into buffer pointed to by `data', so you should have it ready.
*
* @retval 1 found.
* @retval 0 not found.
* @retval -1 error (perhaps not enough room in `data' if copy was
* attempted).
*/
int (*shi_lookup)(void *shi_ctx, const void *key, unsigned key_sz,
void **data, unsigned *data_sz);
};
/**
* The packet out memory interface is used by LSQUIC to get buffers to
* which outgoing packets will be written before they are passed to
@ -539,6 +865,9 @@ struct lsquic_packout_mem_if
char is_ipv6);
};
typedef void (*lsquic_cids_update_f)(void *ctx, void **peer_ctx,
const lsquic_cid_t *cids, unsigned n_cids);
struct stack_st_X509;
/**
@ -554,7 +883,8 @@ enum lsquic_header_status
LSQUIC_HDR_ERR_INCOMPL_REQ_PSDO_HDR,
/** Unnecessary request pseudo-header present in the response */
LSQUIC_HDR_ERR_UNNEC_REQ_PSDO_HDR,
LSQUIC_HDR_ERR_BAD_REQ_HEADER = LSQUIC_HDR_ERR_UNNEC_REQ_PSDO_HDR,
/** Prohibited header in request */
LSQUIC_HDR_ERR_BAD_REQ_HEADER,
/** Not all response pseudo-headers are present */
LSQUIC_HDR_ERR_INCOMPL_RESP_PSDO_HDR,
/** Unnecessary response pseudo-header present in the response. */
@ -590,9 +920,12 @@ struct lsquic_hset_if
* `hdr_set' is the header set object returned by
* @ref hsi_create_header_set().
*
* `name_idx' is set to the index in the HPACK static table whose entry's
* name element matches `name'. If there is no such match, `name_idx' is
* set to zero.
* `name_idx' is set to the index in either the HPACK or QPACK static table
* whose entry's name element matches `name'. The values are as follows:
* - if there is no such match, `name_idx' is set to zero;
* - if HPACK is used, the value is between 1 and 61; and
* - if QPACK is used, the value is 62+ (subtract 62 to get the QPACK
* static table index).
*
* If `name' is NULL, this means that no more header are going to be
* added to the set.
@ -608,6 +941,26 @@ struct lsquic_hset_if
void (*hsi_discard_header_set)(void *hdr_set);
};
/**
* SSL keylog interface.
*/
struct lsquic_keylog_if
{
/** Return keylog handle or NULL if no key logging is desired */
void * (*kli_open) (void *keylog_ctx, lsquic_conn_t *);
/**
* Log line. The first argument is the pointer returned by
* @ref kli_open.
*/
void (*kli_log_line) (void *handle, const char *line);
/**
* Close handle.
*/
void (*kli_close) (void *handle);
};
/* TODO: describe this important data structure */
typedef struct lsquic_engine_api
{
@ -616,11 +969,27 @@ typedef struct lsquic_engine_api
void *ea_stream_if_ctx;
lsquic_packets_out_f ea_packets_out;
void *ea_packets_out_ctx;
lsquic_lookup_cert_f ea_lookup_cert;
void *ea_cert_lu_ctx;
struct ssl_ctx_st * (*ea_get_ssl_ctx)(void *peer_ctx);
/**
* Shared hash interface is optional. If set to zero, performance of
* multiple LSQUIC instances will be degraded.
*/
const struct lsquic_shared_hash_if *ea_shi;
void *ea_shi_ctx;
/**
* Memory interface is optional.
*/
const struct lsquic_packout_mem_if *ea_pmi;
void *ea_pmi_ctx;
/**
* Optional interface to report new and old source connection IDs.
*/
lsquic_cids_update_f ea_new_scids;
lsquic_cids_update_f ea_live_scids;
lsquic_cids_update_f ea_old_scids;
void *ea_cids_update_ctx;
/**
* Function to verify server certificate. The chain contains at least
* one element. The first element in the chain is the server
@ -650,6 +1019,12 @@ typedef struct lsquic_engine_api
*/
void /* FILE, really */ *ea_stats_fh;
#endif
/**
* Optional SSL key logging interface.
*/
const struct lsquic_keylog_if *ea_keylog_if;
void *ea_keylog_ctx;
} lsquic_engine_api_t;
/**
@ -672,7 +1047,9 @@ lsquic_engine_connect (lsquic_engine_t *, const struct sockaddr *local_sa,
const struct sockaddr *peer_sa,
void *peer_ctx, lsquic_conn_ctx_t *conn_ctx,
const char *hostname, unsigned short max_packet_size,
const unsigned char *zero_rtt, size_t zero_rtt_len);
const unsigned char *zero_rtt, size_t zero_rtt_len,
/** Resumption token: optional */
const unsigned char *token, size_t token_sz);
/**
* Pass incoming packet to the QUIC engine. This function can be called
@ -681,6 +1058,10 @@ lsquic_engine_connect (lsquic_engine_t *, const struct sockaddr *local_sa,
*
* @retval 0 Packet was processed by a real connection.
*
* @retval 1 Packet was handled successfully, but not by a connection.
* This may happen with version negotiation and public reset
* packets as well as some packets that may be ignored.
*
* @retval -1 Some error occurred. Possible reasons are invalid packet
* size or failure to allocate memory.
*/
@ -688,7 +1069,7 @@ int
lsquic_engine_packet_in (lsquic_engine_t *,
const unsigned char *packet_in_data, size_t packet_in_size,
const struct sockaddr *sa_local, const struct sockaddr *sa_peer,
void *peer_ctx);
void *peer_ctx, int ecn);
/**
* Process tickable connections. This function must be called often enough so
@ -722,7 +1103,8 @@ lsquic_engine_destroy (lsquic_engine_t *);
unsigned
lsquic_conn_n_avail_streams (const lsquic_conn_t *);
void lsquic_conn_make_stream(lsquic_conn_t *);
void
lsquic_conn_make_stream (lsquic_conn_t *);
/** Return number of delayed streams currently pending */
unsigned
@ -735,21 +1117,48 @@ lsquic_conn_cancel_pending_streams (lsquic_conn_t *, unsigned n);
/**
* Mark connection as going away: send GOAWAY frame and do not accept
* any more incoming streams, nor generate streams of our own.
*
* In the server mode, of course, we can call this function just fine in both
* Google and IETF QUIC.
*
* In client mode, calling this function in for an IETF QUIC connection does
* not do anything, as the client MUST NOT send GOAWAY frames.
* See [draft-ietf-quic-http-17] Section 4.2.7.
*/
void
lsquic_conn_going_away(lsquic_conn_t *conn);
lsquic_conn_going_away (lsquic_conn_t *);
/**
* This forces connection close. on_conn_closed and on_close callbacks
* will be called.
*/
void lsquic_conn_close(lsquic_conn_t *conn);
void
lsquic_conn_close (lsquic_conn_t *);
int lsquic_stream_wantread(lsquic_stream_t *s, int is_want);
ssize_t lsquic_stream_read(lsquic_stream_t *s, void *buf, size_t len);
ssize_t lsquic_stream_readv(lsquic_stream_t *s, const struct iovec *,
int iovcnt);
/**
* This function allows user-supplied callback to read the stream contents.
* It is meant to be used for zero-copy stream processing.
*/
ssize_t
lsquic_stream_readf (lsquic_stream_t *s,
/**
* The callback takes four parameters:
* - Pointer to user-supplied context;
* - Pointer to the data;
* - Data size (can be zero); and
* - Indicator whether the FIN follows the data.
*
* The callback returns number of bytes processed. If this number is zero
* or is smaller than `len', reading from stream stops.
*/
size_t (*readf)(void *ctx, const unsigned char *buf, size_t len, int fin),
void *ctx);
int lsquic_stream_wantwrite(lsquic_stream_t *s, int is_want);
/**
@ -838,7 +1247,33 @@ int lsquic_stream_send_headers(lsquic_stream_t *s,
void *
lsquic_stream_get_hset (lsquic_stream_t *);
int lsquic_conn_is_push_enabled(lsquic_conn_t *c);
/**
* A server may push a stream. This call creates a new stream in reference
* to stream `s'. It will behave as if the client made a request: it will
* trigger on_new_stream() event and it can be used as a regular client-
* initiated stream.
*
* If `hdr_set' is not set, it is generated by using `ea_hsi_if' callbacks.
* In either case, the header set object belongs to the connection. The
* user is not to free this object until (@ref hsi_discard_header_set) is
* called.
*
* @retval 0 Stream pushed successfully.
* @retval 1 Stream push failed because it is disabled or because we hit
* stream limit or connection is going away.
* @retval -1 Stream push failed because of an internal error.
*/
int
lsquic_conn_push_stream (lsquic_conn_t *c, void *hdr_set, lsquic_stream_t *s,
const struct iovec* url, const struct iovec* authority,
const lsquic_http_headers_t *headers);
/**
* Only makes sense in server mode: the client cannot push a stream and this
* function always returns false in client mode.
*/
int
lsquic_conn_is_push_enabled (lsquic_conn_t *);
/** Possible values for how are 0, 1, and 2. See shutdown(2). */
int lsquic_stream_shutdown(lsquic_stream_t *s, int how);
@ -857,16 +1292,8 @@ int lsquic_stream_close(lsquic_stream_t *s);
struct stack_st_X509 *
lsquic_conn_get_server_cert_chain (lsquic_conn_t *);
/**
* Get server config zero_rtt from the encryption session.
* Returns the number of bytes written to the zero_rtt.
*/
ssize_t
lsquic_conn_get_zero_rtt(const lsquic_conn_t *,
unsigned char *zero_rtt, size_t zero_rtt_len);
/** Returns ID of the stream */
uint32_t
lsquic_stream_id_t
lsquic_stream_id (const lsquic_stream_t *s);
/**
@ -880,6 +1307,13 @@ lsquic_stream_get_ctx (const lsquic_stream_t *s);
int
lsquic_stream_is_pushed (const lsquic_stream_t *s);
/**
* Returns true if this stream was rejected, false otherwise. Use this as
* an aid to distinguish between errors.
*/
int
lsquic_stream_is_rejected (const lsquic_stream_t *s);
/**
* Refuse pushed stream. Call it from @ref on_new_stream.
*
@ -902,8 +1336,8 @@ lsquic_stream_refuse_push (lsquic_stream_t *s);
* @retval -1 This is not a pushed stream.
*/
int
lsquic_stream_push_info (const lsquic_stream_t *, uint32_t *ref_stream_id,
void **hdr_set);
lsquic_stream_push_info (const lsquic_stream_t *,
lsquic_stream_id_t *ref_stream_id, void **hdr_set);
/** Return current priority of the stream */
unsigned lsquic_stream_priority (const lsquic_stream_t *s);
@ -923,21 +1357,22 @@ int lsquic_stream_set_priority (lsquic_stream_t *s, unsigned priority);
lsquic_conn_t * lsquic_stream_conn(const lsquic_stream_t *s);
lsquic_stream_t *
lsquic_conn_get_stream_by_id (lsquic_conn_t *c, uint32_t stream_id);
lsquic_conn_get_stream_by_id (lsquic_conn_t *c, lsquic_stream_id_t stream_id);
/** Get connection ID */
lsquic_cid_t
const lsquic_cid_t *
lsquic_conn_id (const lsquic_conn_t *c);
/** Get pointer to the engine */
lsquic_engine_t *
lsquic_conn_get_engine (lsquic_conn_t *c);
int lsquic_conn_get_sockaddr(const lsquic_conn_t *c,
int
lsquic_conn_get_sockaddr(lsquic_conn_t *c,
const struct sockaddr **local, const struct sockaddr **peer);
struct lsquic_logger_if {
int (*vprintf)(void *logger_ctx, const char *fmt, va_list args);
int (*log_buf)(void *logger_ctx, const char *buf, size_t len);
};
/**
@ -1058,31 +1493,98 @@ lsquic_global_cleanup (void);
enum lsquic_version
lsquic_conn_quic_version (const lsquic_conn_t *c);
/* Return keysize or -1 on error */
int
lsquic_conn_crypto_keysize (const lsquic_conn_t *c);
/* Return algorithm keysize or -1 on error */
int
lsquic_conn_crypto_alg_keysize (const lsquic_conn_t *c);
enum lsquic_crypto_ver
{
LSQ_CRY_QUIC,
LSQ_CRY_TLSv13,
};
enum lsquic_crypto_ver
lsquic_conn_crypto_ver (const lsquic_conn_t *c);
/* Return cipher or NULL on error */
const char *
lsquic_conn_crypto_cipher (const lsquic_conn_t *c);
/** Translate string QUIC version to LSQUIC QUIC version representation */
enum lsquic_version
lsquic_str2ver (const char *str, size_t len);
/**
* This function closes all mini connections and marks all full connection
* as going away. In server mode, this also causes the engine to stop
* creating new connections.
*/
void
lsquic_engine_cooldown (lsquic_engine_t *);
struct ssl_st *
lsquic_hsk_getssl(lsquic_conn_t *conn);
/**
* Get user-supplied context associated with the connection.
*/
lsquic_conn_ctx_t *
lsquic_conn_get_ctx (const lsquic_conn_t *c);
lsquic_conn_get_ctx (const lsquic_conn_t *);
/**
* Set user-supplied context associated with the connection.
*/
void lsquic_conn_set_ctx (lsquic_conn_t *c, lsquic_conn_ctx_t *h);
void
lsquic_conn_set_ctx (lsquic_conn_t *, lsquic_conn_ctx_t *);
/**
* Get peer context associated with the connection.
*/
void *lsquic_conn_get_peer_ctx( const lsquic_conn_t *lconn);
void *
lsquic_conn_get_peer_ctx (lsquic_conn_t *, const struct sockaddr *local_sa);
/**
* Abort connection.
*/
void
lsquic_conn_abort (lsquic_conn_t *c);
lsquic_conn_abort (lsquic_conn_t *);
/**
* Helper function: convert list of versions as specified in the argument
* bitmask to string that can be included as argument to "v=" part of the
* Alt-Svc header.
*
* For example (1<<LSQVER_037)|(1<<LSQVER_038) => "37,38"
*
* This is only applicable to Google QUIC versions.
*/
const char *
lsquic_get_alt_svc_versions (unsigned versions);
/**
* Return a NULL-terminated list of HTTP/3 ALPNs, e.g "h3-17", "h3-18", "h3".
*/
const char *const *
lsquic_get_h3_alpns (unsigned versions);
/**
* Returns true if provided buffer could be a valid handshake-stage packet,
* false otherwise. Do not call this function if a connection has already
* been established: it will return incorrect result.
*/
int
lsquic_is_valid_hs_packet (lsquic_engine_t *, const unsigned char *, size_t);
/**
* Parse cid from packet stored in `buf' and store it to `cid'. Returns 0
* on success and -1 on failure.
*/
int
lsquic_cid_from_packet (const unsigned char *, size_t bufsz, lsquic_cid_t *cid);
/**
* Returns true if there are connections to be processed, false otherwise.