summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/quiche/src/quic/tools/quic_toy_server.h
blob: 6168b3f038d2e96de85efe39a1adae77d08516d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef QUICHE_QUIC_TOOLS_QUIC_TOY_SERVER_H_
#define QUICHE_QUIC_TOOLS_QUIC_TOY_SERVER_H_

#include "net/third_party/quiche/src/quic/core/crypto/proof_source.h"
#include "net/third_party/quiche/src/quic/tools/quic_simple_server_backend.h"
#include "net/third_party/quiche/src/quic/tools/quic_spdy_server_base.h"

namespace quic {

// A binary wrapper for QuicServer.  It listens forever on --port
// (default 6121) until it's killed or ctrl-cd to death.
class QuicToyServer {
 public:
  // A factory for creating QuicSpdyServerBase instances.
  class ServerFactory {
   public:
    virtual ~ServerFactory() = default;

    // Creates a QuicSpdyServerBase instance using |backend| for generating
    // responses, and |proof_source| for certificates.
    virtual std::unique_ptr<QuicSpdyServerBase> CreateServer(
        QuicSimpleServerBackend* backend,
        std::unique_ptr<ProofSource> proof_source,
        const ParsedQuicVersionVector& supported_versions) = 0;
  };

  // A facotry for creating QuicSimpleServerBackend instances.
  class BackendFactory {
   public:
    virtual ~BackendFactory() = default;

    // Creates a new backend.
    virtual std::unique_ptr<QuicSimpleServerBackend> CreateBackend() = 0;
  };

  // A factory for creating QuicMemoryCacheBackend instances, configured
  // to load files from disk, if necessary.
  class MemoryCacheBackendFactory : public BackendFactory {
   public:
    std::unique_ptr<quic::QuicSimpleServerBackend> CreateBackend() override;
  };

  // Constructs a new toy server that will use |server_factory| to create the
  // actual QuicSpdyServerBase instance.
  QuicToyServer(BackendFactory* backend_factory, ServerFactory* server_factory);

  // Connects to the QUIC server based on the various flags defined in the
  // .cc file, listends for requests and sends the responses. Returns 1 on
  // failure and does not return otherwise.
  int Start();

 private:
  BackendFactory* backend_factory_;  // Unowned.
  ServerFactory* server_factory_;    // Unowned.
};

}  // namespace quic

#endif  // QUICHE_QUIC_TOOLS_QUIC_TOY_SERVER_H_