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 "quiche/quic/core/crypto/proof_source.h" 9 #include "quiche/quic/tools/quic_simple_server_backend.h" 10 #include "quiche/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, 27 std::unique_ptr<ProofSource> proof_source, 28 const ParsedQuicVersionVector& supported_versions) = 0; 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_ 64