lsquic_engine_public.h revision fcbdf653
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_engine_public.h -- Engine's "public interface"
4 *
5 * This structure is used to bundle things in engine that connections
6 * need.  This way, the space per mini connection is one pointer instead
7 * of several.
8 */
9
10#ifndef LSQUIC_ENGINE_PUBLIC_H
11#define LSQUIC_ENGINE_PUBLIC_H 1
12
13struct lsquic_cid;
14struct lsquic_conn;
15struct lsquic_engine;
16struct stack_st_X509;
17struct lsquic_hash;
18struct lsquic_stream_if;
19struct ssl_ctx_st;
20struct crand;
21struct evp_aead_ctx_st;
22struct lsquic_server_config;
23struct sockaddr;
24
25enum warning_type
26{
27    WT_ACKPARSE_MINI,
28    WT_ACKPARSE_FULL,
29    WT_NO_POISON,
30    N_WARNING_TYPES,
31};
32
33#define WARNING_INTERVAL (24ULL * 3600ULL * 1000000ULL)
34
35struct lsquic_engine_public {
36    struct lsquic_mm                enp_mm;
37    struct lsquic_engine_settings   enp_settings;
38    struct token_generator         *enp_tokgen;
39    lsquic_lookup_cert_f            enp_lookup_cert;
40    void                           *enp_cert_lu_ctx;
41    struct ssl_ctx_st *           (*enp_get_ssl_ctx)(void *peer_ctx,
42                                                     const struct sockaddr *);
43    const struct lsquic_shared_hash_if
44                                   *enp_shi;
45    void                           *enp_shi_ctx;
46    lsquic_time_t                   enp_last_warning[N_WARNING_TYPES];
47    const struct lsquic_stream_if  *enp_stream_if;
48    void                           *enp_stream_if_ctx;
49    const struct lsquic_hset_if    *enp_hsi_if;
50    void                           *enp_hsi_ctx;
51    void                          (*enp_generate_scid)(struct lsquic_conn *,
52                                            struct lsquic_cid *, unsigned);
53    int                           (*enp_verify_cert)(void *verify_ctx,
54                                            struct stack_st_X509 *chain);
55    void                           *enp_verify_ctx;
56    const struct lsquic_packout_mem_if
57                                   *enp_pmi;
58    void                           *enp_pmi_ctx;
59    const struct lsquic_keylog_if  *enp_kli;
60    void                           *enp_kli_ctx;
61    struct lsquic_engine           *enp_engine;
62    struct lsquic_hash             *enp_srst_hash;
63    enum {
64        ENPUB_PROC  = (1 << 0), /* Being processed by one of the user-facing
65                                 * functions.
66                                 */
67        ENPUB_CAN_SEND = (1 << 1),
68        ENPUB_HTTP  = (1 << 2), /* Engine in HTTP mode */
69    }                               enp_flags;
70    unsigned char                   enp_ver_tags_buf[ sizeof(lsquic_ver_tag_t) * N_LSQVER ];
71    unsigned                        enp_ver_tags_len;
72    struct crand                   *enp_crand;
73    struct evp_aead_ctx_st         *enp_retry_aead_ctx;
74    unsigned char                  *enp_alpn;   /* May be set if not HTTP */
75    /* es_noprogress_timeout converted to microseconds for speed */
76    lsquic_time_t                   enp_noprog_timeout;
77    lsquic_time_t                   enp_mtu_probe_timer;
78    /* Certs used by gQUIC server: */
79    struct lsquic_hash             *enp_compressed_server_certs;
80    struct lsquic_hash             *enp_server_certs;
81    /* gQUIC server configuration: */
82    struct lsquic_server_config    *enp_server_config;
83    /* Serialized subset of server engine transport parameters that is used
84     * as SSL QUIC context.  0 is for version <= LSQVER_ID27, 1 is for others.
85     */
86    unsigned char                   enp_quic_ctx_buf[2][200];
87    unsigned                        enp_quic_ctx_sz[2];
88#if LSQUIC_CONN_STATS
89    struct batch_size_stats {
90        unsigned    min, max,   /* Minimum and maximum batch sizes */
91                    count;      /* Number of batches sent */
92        float       avg;        /* Average batch size */
93    }                               enp_batch_size_stats;
94#endif
95};
96
97/* Put connection onto the Tickable Queue if it is not already on it.  If
98 * connection is being destroyed, this is a no-op.
99 */
100void
101lsquic_engine_add_conn_to_tickable (struct lsquic_engine_public *,
102                                                        lsquic_conn_t *);
103
104/* Put connection onto Advisory Tick Time  Queue if it is not already on it.
105 */
106void
107lsquic_engine_add_conn_to_attq (struct lsquic_engine_public *enpub,
108                                lsquic_conn_t *, lsquic_time_t, unsigned why);
109
110void
111lsquic_engine_retire_cid (struct lsquic_engine_public *,
112    struct lsquic_conn *, unsigned cce_idx, lsquic_time_t now,
113    lsquic_time_t drain_time);
114
115int
116lsquic_engine_add_cid (struct lsquic_engine_public *,
117                              struct lsquic_conn *, unsigned cce_idx);
118
119struct lsquic_conn *
120lsquic_engine_find_conn (const struct lsquic_engine_public *pub,
121                         const lsquic_cid_t *cid);
122
123#endif
124