Raise an error on syscall failure in tls_retry_write_records
[openssl.git] / include / internal / quic_tserver.h
1 /*
2  * Copyright 2022 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
10 #ifndef OSSL_QUIC_TSERVER_H
11 # define OSSL_QUIC_TSERVER_H
12
13 # include <openssl/ssl.h>
14 # include "internal/quic_stream.h"
15
16 # ifndef OPENSSL_NO_QUIC
17
18 /*
19  * QUIC Test Server Module
20  * =======================
21  *
22  * This implements a QUIC test server. Since full QUIC server support is not yet
23  * implemented this server is limited in features and scope. It exists to
24  * provide a target for our QUIC client to talk to for testing purposes.
25  *
26  * A given QUIC test server instance supports only one client at a time.
27  *
28  * Note that this test server is not suitable for production use because it does
29  * not implement address verification, anti-amplification or retry logic.
30  */
31 typedef struct quic_tserver_st QUIC_TSERVER;
32
33 typedef struct quic_tserver_args_st {
34     OSSL_LIB_CTX *libctx;
35     const char *propq;
36     BIO *net_rbio, *net_wbio;
37 } QUIC_TSERVER_ARGS;
38
39 QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args,
40                                     const char *certfile, const char *keyfile);
41
42 void ossl_quic_tserver_free(QUIC_TSERVER *srv);
43
44 /* Advances the state machine. */
45 int ossl_quic_tserver_tick(QUIC_TSERVER *srv);
46
47 /* Returns 1 if we have a (non-terminated) client. */
48 int ossl_quic_tserver_is_connected(QUIC_TSERVER *srv);
49
50 /*
51  * Attempts to read from stream 0. Writes the number of bytes read to
52  * *bytes_read and returns 1 on success. If no bytes are available, 0 is written
53  * to *bytes_read and 1 is returned (this is considered a success case).
54  *
55  * Returns 0 if connection is not currently active. If the receive part of
56  * the stream has reached the end of stream condition, returns 0; call
57  * ossl_quic_tserver_has_read_ended() to identify this condition.
58  */
59 int ossl_quic_tserver_read(QUIC_TSERVER *srv,
60                            unsigned char *buf,
61                            size_t buf_len,
62                            size_t *bytes_read);
63
64 /*
65  * Returns 1 if the read part of the stream has ended normally.
66  */
67 int ossl_quic_tserver_has_read_ended(QUIC_TSERVER *srv);
68
69 /*
70  * Attempts to write to stream 0. Writes the number of bytes consumed to
71  * *bytes_written and returns 1 on success. If there is no space currently
72  * available to write any bytes, 0 is written to *consumed and 1 is returned
73  * (this is considered a success case).
74  *
75  * Note that unlike libssl public APIs, this API always works in a 'partial
76  * write' mode.
77  *
78  * Returns 0 if connection is not currently active.
79  */
80 int ossl_quic_tserver_write(QUIC_TSERVER *srv,
81                             const unsigned char *buf,
82                             size_t buf_len,
83                             size_t *bytes_written);
84
85 /*
86  * Signals normal end of the stream.
87  */
88 int ossl_quic_tserver_conclude(QUIC_TSERVER *srv);
89
90 # endif
91
92 #endif