1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov/*
350aadb33SDmitri Tikhonov * lsquic_engine_public.h -- Engine's "public interface"
450aadb33SDmitri Tikhonov *
55392f7a3SLiteSpeed Tech * This structure is used to bundle things in engine that connections
65392f7a3SLiteSpeed Tech * need.  This way, the space per mini connection is one pointer instead
75392f7a3SLiteSpeed Tech * of several.
850aadb33SDmitri Tikhonov */
950aadb33SDmitri Tikhonov
1050aadb33SDmitri Tikhonov#ifndef LSQUIC_ENGINE_PUBLIC_H
1150aadb33SDmitri Tikhonov#define LSQUIC_ENGINE_PUBLIC_H 1
1250aadb33SDmitri Tikhonov
13b62ec17fSDmitri Tikhonovstruct lsquic_cid;
1450aadb33SDmitri Tikhonovstruct lsquic_conn;
1550aadb33SDmitri Tikhonovstruct lsquic_engine;
167f2bd84cSDmitri Tikhonovstruct stack_st_X509;
175392f7a3SLiteSpeed Techstruct lsquic_hash;
185392f7a3SLiteSpeed Techstruct lsquic_stream_if;
195392f7a3SLiteSpeed Techstruct ssl_ctx_st;
2010c41073SDmitri Tikhonovstruct crand;
219fc12041SDmitri Tikhonovstruct evp_aead_ctx_st;
222f4629f2SDmitri Tikhonovstruct lsquic_server_config;
23fcbdf653SDmitri Tikhonovstruct sockaddr;
245392f7a3SLiteSpeed Tech
255392f7a3SLiteSpeed Techenum warning_type
265392f7a3SLiteSpeed Tech{
275392f7a3SLiteSpeed Tech    WT_ACKPARSE_MINI,
285392f7a3SLiteSpeed Tech    WT_ACKPARSE_FULL,
29de46bf2fSDmitri Tikhonov    WT_NO_POISON,
305392f7a3SLiteSpeed Tech    N_WARNING_TYPES,
315392f7a3SLiteSpeed Tech};
325392f7a3SLiteSpeed Tech
335392f7a3SLiteSpeed Tech#define WARNING_INTERVAL (24ULL * 3600ULL * 1000000ULL)
3450aadb33SDmitri Tikhonov
3550aadb33SDmitri Tikhonovstruct lsquic_engine_public {
3650aadb33SDmitri Tikhonov    struct lsquic_mm                enp_mm;
3750aadb33SDmitri Tikhonov    struct lsquic_engine_settings   enp_settings;
385392f7a3SLiteSpeed Tech    struct token_generator         *enp_tokgen;
395392f7a3SLiteSpeed Tech    lsquic_lookup_cert_f            enp_lookup_cert;
405392f7a3SLiteSpeed Tech    void                           *enp_cert_lu_ctx;
41fcbdf653SDmitri Tikhonov    struct ssl_ctx_st *           (*enp_get_ssl_ctx)(void *peer_ctx,
42fcbdf653SDmitri Tikhonov                                                     const struct sockaddr *);
435392f7a3SLiteSpeed Tech    const struct lsquic_shared_hash_if
445392f7a3SLiteSpeed Tech                                   *enp_shi;
455392f7a3SLiteSpeed Tech    void                           *enp_shi_ctx;
465392f7a3SLiteSpeed Tech    lsquic_time_t                   enp_last_warning[N_WARNING_TYPES];
475392f7a3SLiteSpeed Tech    const struct lsquic_stream_if  *enp_stream_if;
485392f7a3SLiteSpeed Tech    void                           *enp_stream_if_ctx;
493b55e6aeSDmitri Tikhonov    const struct lsquic_hset_if    *enp_hsi_if;
503b55e6aeSDmitri Tikhonov    void                           *enp_hsi_ctx;
51c2faf032SDmitri Tikhonov    void                          (*enp_generate_scid)(void *,
52c2faf032SDmitri Tikhonov                        struct lsquic_conn *, struct lsquic_cid *, unsigned);
53c2faf032SDmitri Tikhonov    void                           *enp_gen_scid_ctx;
547f2bd84cSDmitri Tikhonov    int                           (*enp_verify_cert)(void *verify_ctx,
557f2bd84cSDmitri Tikhonov                                            struct stack_st_X509 *chain);
567f2bd84cSDmitri Tikhonov    void                           *enp_verify_ctx;
5750aadb33SDmitri Tikhonov    const struct lsquic_packout_mem_if
5850aadb33SDmitri Tikhonov                                   *enp_pmi;
5950aadb33SDmitri Tikhonov    void                           *enp_pmi_ctx;
6050aadb33SDmitri Tikhonov    struct lsquic_engine           *enp_engine;
615392f7a3SLiteSpeed Tech    struct lsquic_hash             *enp_srst_hash;
6250aadb33SDmitri Tikhonov    enum {
6350aadb33SDmitri Tikhonov        ENPUB_PROC  = (1 << 0), /* Being processed by one of the user-facing
6450aadb33SDmitri Tikhonov                                 * functions.
6550aadb33SDmitri Tikhonov                                 */
66c44946ecSDmitri Tikhonov        ENPUB_CAN_SEND = (1 << 1),
67fa4561dcSDmitri Tikhonov        ENPUB_HTTP  = (1 << 2), /* Engine in HTTP mode */
6850aadb33SDmitri Tikhonov    }                               enp_flags;
695392f7a3SLiteSpeed Tech    unsigned char                   enp_ver_tags_buf[ sizeof(lsquic_ver_tag_t) * N_LSQVER ];
705392f7a3SLiteSpeed Tech    unsigned                        enp_ver_tags_len;
7110c41073SDmitri Tikhonov    struct crand                   *enp_crand;
729fc12041SDmitri Tikhonov    struct evp_aead_ctx_st         *enp_retry_aead_ctx;
73fa4561dcSDmitri Tikhonov    unsigned char                  *enp_alpn;   /* May be set if not HTTP */
748ae5ecb4SDmitri Tikhonov    /* es_noprogress_timeout converted to microseconds for speed */
758ae5ecb4SDmitri Tikhonov    lsquic_time_t                   enp_noprog_timeout;
76b8fa6195SDmitri Tikhonov    lsquic_time_t                   enp_mtu_probe_timer;
772f4629f2SDmitri Tikhonov    /* Certs used by gQUIC server: */
782f4629f2SDmitri Tikhonov    struct lsquic_hash             *enp_compressed_server_certs;
792f4629f2SDmitri Tikhonov    struct lsquic_hash             *enp_server_certs;
802f4629f2SDmitri Tikhonov    /* gQUIC server configuration: */
812f4629f2SDmitri Tikhonov    struct lsquic_server_config    *enp_server_config;
8204f8f447SDmitri Tikhonov    /* Serialized subset of server engine transport parameters that is used
8304f8f447SDmitri Tikhonov     * as SSL QUIC context.  0 is for version <= LSQVER_ID27, 1 is for others.
8404f8f447SDmitri Tikhonov     */
8504f8f447SDmitri Tikhonov    unsigned char                   enp_quic_ctx_buf[2][200];
8604f8f447SDmitri Tikhonov    unsigned                        enp_quic_ctx_sz[2];
87758aff32SDmitri Tikhonov#if LSQUIC_CONN_STATS
88758aff32SDmitri Tikhonov    struct batch_size_stats {
89758aff32SDmitri Tikhonov        unsigned    min, max,   /* Minimum and maximum batch sizes */
90758aff32SDmitri Tikhonov                    count;      /* Number of batches sent */
91758aff32SDmitri Tikhonov        float       avg;        /* Average batch size */
92758aff32SDmitri Tikhonov    }                               enp_batch_size_stats;
93758aff32SDmitri Tikhonov#endif
9450aadb33SDmitri Tikhonov};
9550aadb33SDmitri Tikhonov
96e8bd737dSDmitri Tikhonov/* Put connection onto the Tickable Queue if it is not already on it.  If
9750aadb33SDmitri Tikhonov * connection is being destroyed, this is a no-op.
9850aadb33SDmitri Tikhonov */
9950aadb33SDmitri Tikhonovvoid
100e8bd737dSDmitri Tikhonovlsquic_engine_add_conn_to_tickable (struct lsquic_engine_public *,
101e8bd737dSDmitri Tikhonov                                                        lsquic_conn_t *);
10250aadb33SDmitri Tikhonov
10350aadb33SDmitri Tikhonov/* Put connection onto Advisory Tick Time  Queue if it is not already on it.
10450aadb33SDmitri Tikhonov */
10550aadb33SDmitri Tikhonovvoid
10650aadb33SDmitri Tikhonovlsquic_engine_add_conn_to_attq (struct lsquic_engine_public *enpub,
1070adf085aSDmitri Tikhonov                                lsquic_conn_t *, lsquic_time_t, unsigned why);
10850aadb33SDmitri Tikhonov
1095392f7a3SLiteSpeed Techvoid
1105392f7a3SLiteSpeed Techlsquic_engine_retire_cid (struct lsquic_engine_public *,
1114580fab7SDmitri Tikhonov    struct lsquic_conn *, unsigned cce_idx, lsquic_time_t now,
1124580fab7SDmitri Tikhonov    lsquic_time_t drain_time);
1135392f7a3SLiteSpeed Tech
1145392f7a3SLiteSpeed Techint
1155392f7a3SLiteSpeed Techlsquic_engine_add_cid (struct lsquic_engine_public *,
1165392f7a3SLiteSpeed Tech                              struct lsquic_conn *, unsigned cce_idx);
1175392f7a3SLiteSpeed Tech
1185392f7a3SLiteSpeed Techstruct lsquic_conn *
1195392f7a3SLiteSpeed Techlsquic_engine_find_conn (const struct lsquic_engine_public *pub,
1205392f7a3SLiteSpeed Tech                         const lsquic_cid_t *cid);
1215392f7a3SLiteSpeed Tech
12250aadb33SDmitri Tikhonov#endif
123