1 1.1 christos /* 2 1.1 christos * Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos #ifndef OSSL_QUIC_ENGINE_H 10 1.1.1.2 christos #define OSSL_QUIC_ENGINE_H 11 1.1 christos 12 1.1.1.2 christos #include <openssl/ssl.h> 13 1.1 christos 14 1.1.1.2 christos #include "internal/quic_predef.h" 15 1.1.1.2 christos #include "internal/quic_port.h" 16 1.1.1.2 christos #include "internal/thread_arch.h" 17 1.1 christos 18 1.1.1.2 christos #ifndef OPENSSL_NO_QUIC 19 1.1 christos 20 1.1 christos /* 21 1.1 christos * QUIC Engine 22 1.1 christos * =========== 23 1.1 christos * 24 1.1 christos * A QUIC Engine (QUIC_ENGINE) represents an event processing domain for the 25 1.1 christos * purposes of QUIC and contains zero or more subsidiary QUIC_PORT instances 26 1.1 christos * (each of which currently represents a UDP socket), each of which in turn 27 1.1 christos * contains zero or more subsidiary QUIC_CHANNEL instances, each of which 28 1.1 christos * represents a single QUIC connection. All QUIC_PORT instances must belong 29 1.1 christos * to a QUIC_ENGINE. 30 1.1 christos * 31 1.1 christos * TODO(QUIC FUTURE): Currently a QUIC_PORT belongs to a single QUIC_CHANNEL. 32 1.1 christos * This will cease to be the case once connection migration and/or multipath is 33 1.1 christos * implemented, so in future a channel might be associated with multiple ports. 34 1.1 christos * 35 1.1 christos * A QUIC engine is the root object in a QUIC event domain, and is responsible 36 1.1 christos * for managing event processing for all QUIC ports and channels (e.g. timeouts, 37 1.1 christos * clock management, the QUIC_REACTOR instance, etc.). 38 1.1 christos */ 39 1.1 christos typedef struct quic_engine_args_st { 40 1.1.1.2 christos OSSL_LIB_CTX *libctx; 41 1.1.1.2 christos const char *propq; 42 1.1 christos 43 1.1 christos /* 44 1.1 christos * This must be a mutex the lifetime of which will exceed that of the engine 45 1.1 christos * and all ports and channels. The instantiator of the engine is responsible 46 1.1 christos * for providing a mutex as this makes it easier to handle instantiation and 47 1.1 christos * teardown of channels in situations potentially requiring locking. 48 1.1 christos * 49 1.1 christos * Note that this is a MUTEX not a RWLOCK as it needs to be an OS mutex for 50 1.1 christos * compatibility with an OS's condition variable wait API, whereas RWLOCK 51 1.1 christos * may, depending on the build configuration, be implemented using an OS's 52 1.1 christos * mutex primitive or using its RW mutex primitive. 53 1.1 christos */ 54 1.1.1.2 christos CRYPTO_MUTEX *mutex; 55 1.1 christos 56 1.1 christos /* Flags to pass when initialising the reactor. */ 57 1.1.1.2 christos uint64_t reactor_flags; 58 1.1 christos } QUIC_ENGINE_ARGS; 59 1.1 christos 60 1.1 christos QUIC_ENGINE *ossl_quic_engine_new(const QUIC_ENGINE_ARGS *args); 61 1.1 christos 62 1.1 christos void ossl_quic_engine_free(QUIC_ENGINE *qeng); 63 1.1 christos 64 1.1 christos /* 65 1.1 christos * Create a port which is a child of the engine. args->engine shall be NULL. 66 1.1 christos */ 67 1.1 christos QUIC_PORT *ossl_quic_engine_create_port(QUIC_ENGINE *qeng, 68 1.1.1.2 christos const QUIC_PORT_ARGS *args); 69 1.1 christos 70 1.1 christos /* Gets the mutex used by the engine. */ 71 1.1 christos CRYPTO_MUTEX *ossl_quic_engine_get0_mutex(QUIC_ENGINE *qeng); 72 1.1 christos 73 1.1 christos /* Gets the current time. */ 74 1.1 christos OSSL_TIME ossl_quic_engine_get_time(QUIC_ENGINE *qeng); 75 1.1 christos 76 1.1 christos /* 77 1.1 christos * Some use cases really need actual time rather than "fake" time. Convert a 78 1.1 christos * fake time into a real time. If tm is before the current fake time then the 79 1.1 christos * current time is returned. 80 1.1 christos */ 81 1.1 christos OSSL_TIME ossl_quic_engine_make_real_time(QUIC_ENGINE *qeng, OSSL_TIME tm); 82 1.1 christos 83 1.1 christos /* Override the callback for getting the current time */ 84 1.1 christos void ossl_quic_engine_set_time_cb(QUIC_ENGINE *qeng, 85 1.1.1.2 christos OSSL_TIME (*now_cb)(void *arg), 86 1.1.1.2 christos void *now_cb_arg); 87 1.1 christos 88 1.1 christos /* For testing use. While enabled, ticking is not performed. */ 89 1.1 christos void ossl_quic_engine_set_inhibit_tick(QUIC_ENGINE *qeng, int inhibit); 90 1.1 christos 91 1.1 christos /* Gets the reactor which can be used to tick/poll on the port. */ 92 1.1 christos QUIC_REACTOR *ossl_quic_engine_get0_reactor(QUIC_ENGINE *qeng); 93 1.1 christos 94 1.1 christos OSSL_LIB_CTX *ossl_quic_engine_get0_libctx(QUIC_ENGINE *qeng); 95 1.1 christos const char *ossl_quic_engine_get0_propq(QUIC_ENGINE *qeng); 96 1.1 christos 97 1.1 christos /* 98 1.1 christos * Look through all the engine's ports and determine if any of them have had a 99 1.1 christos * BIO changed. If so, update the blocking support detection data in the 100 1.1 christos * QUIC_REACTOR. If force is 1, always do the update even if nothing seems 101 1.1 christos * to have changed. 102 1.1 christos */ 103 1.1 christos void ossl_quic_engine_update_poll_descriptors(QUIC_ENGINE *qeng, int force); 104 1.1 christos 105 1.1.1.2 christos #endif 106 1.1 christos 107 1.1 christos #endif 108