]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/internal/quic_tserver.h
Enable QUIC test server to find out the termination reason
[thirdparty/openssl.git] / include / internal / quic_tserver.h
CommitLineData
51a168b8
HL
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"
149a8e6c 15# include "internal/quic_channel.h"
51a168b8
HL
16
17# ifndef OPENSSL_NO_QUIC
18
19/*
20 * QUIC Test Server Module
21 * =======================
22 *
23 * This implements a QUIC test server. Since full QUIC server support is not yet
24 * implemented this server is limited in features and scope. It exists to
25 * provide a target for our QUIC client to talk to for testing purposes.
26 *
27 * A given QUIC test server instance supports only one client at a time.
28 *
29 * Note that this test server is not suitable for production use because it does
30 * not implement address verification, anti-amplification or retry logic.
31 */
32typedef struct quic_tserver_st QUIC_TSERVER;
33
34typedef struct quic_tserver_args_st {
35 OSSL_LIB_CTX *libctx;
36 const char *propq;
37 BIO *net_rbio, *net_wbio;
38} QUIC_TSERVER_ARGS;
39
4e3a55fd
MC
40QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args,
41 const char *certfile, const char *keyfile);
51a168b8
HL
42
43void ossl_quic_tserver_free(QUIC_TSERVER *srv);
44
14e31409
MC
45/* Set mutator callbacks for test framework support */
46int ossl_quic_tserver_set_mutator(QUIC_TSERVER *srv,
47 ossl_mutate_packet_cb mutatecb,
48 ossl_finish_mutate_cb finishmutatecb,
49 void *mutatearg);
50
51a168b8
HL
51/* Advances the state machine. */
52int ossl_quic_tserver_tick(QUIC_TSERVER *srv);
53
54/* Returns 1 if we have a (non-terminated) client. */
55int ossl_quic_tserver_is_connected(QUIC_TSERVER *srv);
56
adef87a2 57/* Returns 1 if the server is in any terminating or terminated state */
149a8e6c
MC
58int ossl_quic_tserver_is_term_any(QUIC_TSERVER *srv,
59 QUIC_TERMINATE_CAUSE *cause);
adef87a2 60
149a8e6c
MC
61/* Returns 1 if the server is in a terminated state */
62int ossl_quic_tserver_is_terminated(QUIC_TSERVER *srv,
63 QUIC_TERMINATE_CAUSE *cause);
51a168b8
HL
64/*
65 * Attempts to read from stream 0. Writes the number of bytes read to
66 * *bytes_read and returns 1 on success. If no bytes are available, 0 is written
67 * to *bytes_read and 1 is returned (this is considered a success case).
68 *
a9979965
HL
69 * Returns 0 if connection is not currently active. If the receive part of
70 * the stream has reached the end of stream condition, returns 0; call
71 * ossl_quic_tserver_has_read_ended() to identify this condition.
51a168b8
HL
72 */
73int ossl_quic_tserver_read(QUIC_TSERVER *srv,
74 unsigned char *buf,
75 size_t buf_len,
76 size_t *bytes_read);
77
a9979965
HL
78/*
79 * Returns 1 if the read part of the stream has ended normally.
80 */
81int ossl_quic_tserver_has_read_ended(QUIC_TSERVER *srv);
82
51a168b8
HL
83/*
84 * Attempts to write to stream 0. Writes the number of bytes consumed to
091f532e
HL
85 * *bytes_written and returns 1 on success. If there is no space currently
86 * available to write any bytes, 0 is written to *consumed and 1 is returned
87 * (this is considered a success case).
51a168b8
HL
88 *
89 * Note that unlike libssl public APIs, this API always works in a 'partial
90 * write' mode.
91 *
92 * Returns 0 if connection is not currently active.
93 */
94int ossl_quic_tserver_write(QUIC_TSERVER *srv,
95 const unsigned char *buf,
96 size_t buf_len,
97 size_t *bytes_written);
98
a9979965
HL
99/*
100 * Signals normal end of the stream.
101 */
102int ossl_quic_tserver_conclude(QUIC_TSERVER *srv);
103
51a168b8
HL
104# endif
105
106#endif