QUIC CHANNEL, PORT: Abstract time retrieval
[openssl.git] / include / internal / quic_port.h
1 /*
2  * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 #ifndef OSSL_QUIC_PORT_H
10 # define OSSL_QUIC_PORT_H
11
12 # include <openssl/ssl.h>
13 # include "internal/quic_types.h"
14 # include "internal/quic_reactor.h"
15 # include "internal/quic_demux.h"
16 # include "internal/thread_arch.h"
17
18 # ifndef OPENSSL_NO_QUIC
19
20 /*
21  * QUIC Port
22  * =========
23  *
24  * A QUIC Port (QUIC_PORT) represents a single UDP network socket and contains
25  * zero or more subsidiary QUIC_CHANNEL instances, each of which represents a
26  * single QUIC connection. All QUIC_CHANNEL instances must belong to a
27  * QUIC_PORT.
28  */
29 typedef struct quic_port_args_st {
30     /* All channels in a QUIC event domain share the same (libctx, propq). */
31     OSSL_LIB_CTX    *libctx;
32     const char      *propq;
33
34     /*
35      * This must be a mutex the lifetime of which will exceed that of the port
36      * and all channels. The instantiator of the port is responsible for
37      * providing a mutex as this makes it easier to handle instantiation and
38      * teardown of channels in situations potentially requiring locking.
39      *
40      * Note that this is a MUTEX not a RWLOCK as it needs to be an OS mutex for
41      * compatibility with an OS's condition variable wait API, whereas RWLOCK
42      * may, depending on the build configuration, be implemented using an OS's
43      * mutex primitive or using its RW mutex primitive.
44      */
45     CRYPTO_MUTEX    *mutex;
46
47     /*
48      * Optional function pointer to use to retrieve the current time. If NULL,
49      * ossl_time_now() is used.
50      */
51     OSSL_TIME       (*now_cb)(void *arg);
52     void            *now_cb_arg;
53 } QUIC_PORT_ARGS;
54
55 typedef struct quic_port_st QUIC_PORT;
56
57 QUIC_PORT *ossl_quic_port_new(const QUIC_PORT_ARGS *args);
58
59 void ossl_quic_port_free(QUIC_PORT *port);
60
61 /*
62  * Queries and Accessors
63  * =====================
64  */
65
66 /* Gets/sets the underlying network read and write BIO. */
67 BIO *ossl_quic_port_get_net_rbio(QUIC_PORT *port);
68 BIO *ossl_quic_port_get_net_wbio(QUIC_PORT *port);
69 int ossl_quic_port_set_net_rbio(QUIC_PORT *port, BIO *net_rbio);
70 int ossl_quic_port_set_net_wbio(QUIC_PORT *port, BIO *net_wbio);
71
72 int ossl_quic_port_update_poll_descriptors(QUIC_PORT *port);
73
74 /* Gets the reactor which can be used to tick/poll on the port. */
75 QUIC_REACTOR *ossl_quic_port_get0_reactor(QUIC_PORT *port);
76
77 /* Gets the demuxer belonging to the port. */
78 QUIC_DEMUX *ossl_quic_port_get0_demux(QUIC_PORT *port);
79
80 /* Gets the mutex used by the port. */
81 CRYPTO_MUTEX *ossl_quic_port_get0_mutex(QUIC_PORT *port);
82
83 /* Gets the current time. */
84 OSSL_TIME ossl_quic_port_get_time(QUIC_PORT *port);
85
86 # endif
87
88 #endif