rch | 034c98c | 2019-05-17 15:46:09 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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_TOOLS_QUIC_TOY_SERVER_H_ |
| 6 | #define QUICHE_QUIC_TOOLS_QUIC_TOY_SERVER_H_ |
| 7 | |
| 8 | #include "net/third_party/quiche/src/quic/core/crypto/proof_source.h" |
| 9 | #include "net/third_party/quiche/src/quic/tools/quic_simple_server_backend.h" |
| 10 | #include "net/third_party/quiche/src/quic/tools/quic_spdy_server_base.h" |
| 11 | |
| 12 | namespace quic { |
| 13 | |
| 14 | // A binary wrapper for QuicServer. It listens forever on --port |
| 15 | // (default 6121) until it's killed or ctrl-cd to death. |
| 16 | class QuicToyServer { |
| 17 | public: |
| 18 | // A factory for creating QuicSpdyServerBase instances. |
| 19 | class ServerFactory { |
| 20 | public: |
| 21 | virtual ~ServerFactory() = default; |
| 22 | |
| 23 | // Creates a QuicSpdyServerBase instance using |backend| for generating |
| 24 | // responses, and |proof_source| for certificates. |
| 25 | virtual std::unique_ptr<QuicSpdyServerBase> CreateServer( |
| 26 | QuicSimpleServerBackend* backend, |
dschinazi | c5589bd | 2019-09-12 14:50:11 -0700 | [diff] [blame] | 27 | std::unique_ptr<ProofSource> proof_source, |
| 28 | const ParsedQuicVersionVector& supported_versions) = 0; |
rch | 034c98c | 2019-05-17 15:46:09 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | // A facotry for creating QuicSimpleServerBackend instances. |
| 32 | class BackendFactory { |
| 33 | public: |
| 34 | virtual ~BackendFactory() = default; |
| 35 | |
| 36 | // Creates a new backend. |
| 37 | virtual std::unique_ptr<QuicSimpleServerBackend> CreateBackend() = 0; |
| 38 | }; |
| 39 | |
| 40 | // A factory for creating QuicMemoryCacheBackend instances, configured |
| 41 | // to load files from disk, if necessary. |
| 42 | class MemoryCacheBackendFactory : public BackendFactory { |
| 43 | public: |
| 44 | std::unique_ptr<quic::QuicSimpleServerBackend> CreateBackend() override; |
| 45 | }; |
| 46 | |
| 47 | // Constructs a new toy server that will use |server_factory| to create the |
| 48 | // actual QuicSpdyServerBase instance. |
| 49 | QuicToyServer(BackendFactory* backend_factory, ServerFactory* server_factory); |
| 50 | |
| 51 | // Connects to the QUIC server based on the various flags defined in the |
| 52 | // .cc file, listends for requests and sends the responses. Returns 1 on |
| 53 | // failure and does not return otherwise. |
| 54 | int Start(); |
| 55 | |
| 56 | private: |
| 57 | BackendFactory* backend_factory_; // Unowned. |
| 58 | ServerFactory* server_factory_; // Unowned. |
| 59 | }; |
| 60 | |
| 61 | } // namespace quic |
| 62 | |
| 63 | #endif // QUICHE_QUIC_TOOLS_QUIC_TOY_SERVER_H_ |