blob: 3661b7a1c8e7ecfbf08683ae4dc35942777d58f2 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_SERVER_H_
6#define QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_SERVER_H_
7
8#include "net/third_party/quiche/src/quic/core/quic_dispatcher.h"
9#include "net/third_party/quiche/src/quic/core/quic_session.h"
10#include "net/third_party/quiche/src/quic/tools/quic_server.h"
11#include "net/third_party/quiche/src/quic/tools/quic_simple_server_backend.h"
12#include "net/third_party/quiche/src/quic/tools/quic_simple_server_session.h"
13#include "net/third_party/quiche/src/quic/tools/quic_simple_server_stream.h"
14
15namespace quic {
16
17namespace test {
18
19// A test server which enables easy creation of custom QuicServerSessions
20//
21// Eventually this may be extended to allow custom QuicConnections etc.
22class QuicTestServer : public QuicServer {
23 public:
24 // Factory for creating QuicServerSessions.
25 class SessionFactory {
26 public:
27 virtual ~SessionFactory() {}
28
29 // Returns a new session owned by the caller.
30 virtual QuicServerSessionBase* CreateSession(
31 const QuicConfig& config,
32 QuicConnection* connection,
33 QuicSession::Visitor* visitor,
34 QuicCryptoServerStream::Helper* helper,
35 const QuicCryptoServerConfig* crypto_config,
36 QuicCompressedCertsCache* compressed_certs_cache,
37 QuicSimpleServerBackend* quic_simple_server_backend) = 0;
38 };
39
40 // Factory for creating QuicSimpleServerStreams.
41 class StreamFactory {
42 public:
43 virtual ~StreamFactory() {}
44
45 // Returns a new stream owned by the caller.
46 virtual QuicSimpleServerStream* CreateStream(
47 QuicStreamId id,
48 QuicSpdySession* session,
49 QuicSimpleServerBackend* quic_simple_server_backend) = 0;
50 };
51
52 class CryptoStreamFactory {
53 public:
54 virtual ~CryptoStreamFactory() {}
55
56 // Returns a new QuicCryptoServerStreamBase owned by the caller
57 virtual QuicCryptoServerStreamBase* CreateCryptoStream(
58 const QuicCryptoServerConfig* crypto_config,
59 QuicServerSessionBase* session) = 0;
60 };
61
62 QuicTestServer(std::unique_ptr<ProofSource> proof_source,
63 QuicSimpleServerBackend* quic_simple_server_backend);
64 QuicTestServer(std::unique_ptr<ProofSource> proof_source,
65 const QuicConfig& config,
66 const ParsedQuicVersionVector& supported_versions,
67 QuicSimpleServerBackend* quic_simple_server_backend);
68 QuicTestServer(std::unique_ptr<ProofSource> proof_source,
69 const QuicConfig& config,
70 const ParsedQuicVersionVector& supported_versions,
71 QuicSimpleServerBackend* quic_simple_server_backend,
dschinazi8ff74822019-05-28 16:37:20 -070072 uint8_t expected_server_connection_id_length);
QUICHE teama6ef0a62019-03-07 20:34:33 -050073
74 // Create a custom dispatcher which creates custom sessions.
75 QuicDispatcher* CreateQuicDispatcher() override;
76
77 // Sets a custom session factory, owned by the caller, for easy custom
78 // session logic. This is incompatible with setting a stream factory or a
79 // crypto stream factory.
80 void SetSessionFactory(SessionFactory* factory);
81
82 // Sets a custom stream factory, owned by the caller, for easy custom
83 // stream logic. This is incompatible with setting a session factory.
84 void SetSpdyStreamFactory(StreamFactory* factory);
85
86 // Sets a custom crypto stream factory, owned by the caller, for easy custom
87 // crypto logic. This is incompatible with setting a session factory.
88 void SetCryptoStreamFactory(CryptoStreamFactory* factory);
89};
90
91// Useful test sessions for the QuicTestServer.
92
93// Test session which sends a GOAWAY immedaitely on creation, before crypto
94// credentials have even been established.
95class ImmediateGoAwaySession : public QuicSimpleServerSession {
96 public:
97 ImmediateGoAwaySession(const QuicConfig& config,
98 QuicConnection* connection,
99 QuicSession::Visitor* visitor,
100 QuicCryptoServerStream::Helper* helper,
101 const QuicCryptoServerConfig* crypto_config,
102 QuicCompressedCertsCache* compressed_certs_cache,
103 QuicSimpleServerBackend* quic_simple_server_backend);
104
105 // Override to send GoAway.
106 void OnStreamFrame(const QuicStreamFrame& frame) override;
107};
108
109} // namespace test
110
111} // namespace quic
112
113#endif // QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_SERVER_H_