Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / tools / quic / quic_server.h
blob56b9e4da8503c7e3a573d7407411af089546f4b7
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 // A toy server, which listens on a specified address for QUIC traffic and
6 // handles incoming responses.
7 //
8 // Note that this server is intended to verify correctness of the client and is
9 // in no way expected to be performant.
11 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_H_
12 #define NET_TOOLS_QUIC_QUIC_SERVER_H_
14 #include "base/basictypes.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "net/base/ip_endpoint.h"
17 #include "net/quic/crypto/quic_crypto_server_config.h"
18 #include "net/quic/quic_config.h"
19 #include "net/quic/quic_connection_helper.h"
20 #include "net/quic/quic_framer.h"
21 #include "net/tools/epoll_server/epoll_server.h"
22 #include "net/tools/quic/quic_default_packet_writer.h"
24 namespace net {
25 namespace tools {
27 namespace test {
28 class QuicServerPeer;
29 } // namespace test
31 class ProcessPacketInterface;
32 class QuicDispatcher;
33 class QuicPacketReader;
35 class QuicServer : public EpollCallbackInterface {
36 public:
37 QuicServer();
38 QuicServer(const QuicConfig& config,
39 const QuicVersionVector& supported_versions);
41 ~QuicServer() override;
43 // Start listening on the specified address.
44 bool Listen(const IPEndPoint& address);
46 // Wait up to 50ms, and handle any events which occur.
47 void WaitForEvents();
49 // Server deletion is imminent. Start cleaning up the epoll server.
50 void Shutdown();
52 // From EpollCallbackInterface
53 void OnRegistration(EpollServer* eps, int fd, int event_mask) override {}
54 void OnModification(int fd, int event_mask) override {}
55 void OnEvent(int fd, EpollEvent* event) override;
56 void OnUnregistration(int fd, bool replaced) override {}
58 void OnShutdown(EpollServer* eps, int fd) override {}
60 void SetStrikeRegisterNoStartupPeriod() {
61 crypto_config_.set_strike_register_no_startup_period();
64 // SetProofSource sets the ProofSource that will be used to verify the
65 // server's certificate, and takes ownership of |source|.
66 void SetProofSource(ProofSource* source) {
67 crypto_config_.SetProofSource(source);
70 bool overflow_supported() { return overflow_supported_; }
72 QuicPacketCount packets_dropped() { return packets_dropped_; }
74 int port() { return port_; }
76 protected:
77 virtual QuicDefaultPacketWriter* CreateWriter(int fd);
79 virtual QuicDispatcher* CreateQuicDispatcher();
81 const QuicConfig& config() const { return config_; }
82 const QuicCryptoServerConfig& crypto_config() const {
83 return crypto_config_;
85 const QuicVersionVector& supported_versions() const {
86 return supported_versions_;
88 EpollServer* epoll_server() { return &epoll_server_; }
90 QuicDispatcher* dispatcher() { return dispatcher_.get(); }
92 private:
93 friend class net::tools::test::QuicServerPeer;
95 // Initialize the internal state of the server.
96 void Initialize();
98 // Accepts data from the framer and demuxes clients to sessions.
99 scoped_ptr<QuicDispatcher> dispatcher_;
100 // Frames incoming packets and hands them to the dispatcher.
101 EpollServer epoll_server_;
103 // The port the server is listening on.
104 int port_;
106 // Listening connection. Also used for outbound client communication.
107 int fd_;
109 // If overflow_supported_ is true this will be the number of packets dropped
110 // during the lifetime of the server. This may overflow if enough packets
111 // are dropped.
112 QuicPacketCount packets_dropped_;
114 // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped
115 // because the socket would otherwise overflow.
116 bool overflow_supported_;
118 // If true, use recvmmsg for reading.
119 bool use_recvmmsg_;
121 // config_ contains non-crypto parameters that are negotiated in the crypto
122 // handshake.
123 QuicConfig config_;
124 // crypto_config_ contains crypto parameters for the handshake.
125 QuicCryptoServerConfig crypto_config_;
127 // This vector contains QUIC versions which we currently support.
128 // This should be ordered such that the highest supported version is the first
129 // element, with subsequent elements in descending order (versions can be
130 // skipped as necessary).
131 QuicVersionVector supported_versions_;
133 scoped_ptr<QuicPacketReader> packet_reader_;
135 DISALLOW_COPY_AND_ASSIGN(QuicServer);
138 } // namespace tools
139 } // namespace net
141 #endif // NET_TOOLS_QUIC_QUIC_SERVER_H_