We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / net / tools / quic / quic_server.h
blob6ff8c53066c55593f5c661fd552c9c181a66a268
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.
8 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_H_
9 #define NET_TOOLS_QUIC_QUIC_SERVER_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/ip_endpoint.h"
14 #include "net/quic/crypto/quic_crypto_server_config.h"
15 #include "net/quic/quic_config.h"
16 #include "net/quic/quic_connection_helper.h"
17 #include "net/quic/quic_framer.h"
18 #include "net/tools/epoll_server/epoll_server.h"
19 #include "net/tools/quic/quic_default_packet_writer.h"
21 namespace net {
22 namespace tools {
24 namespace test {
25 class QuicServerPeer;
26 } // namespace test
28 class ProcessPacketInterface;
29 class QuicDispatcher;
30 class QuicPacketReader;
32 class QuicServer : public EpollCallbackInterface {
33 public:
34 QuicServer();
35 QuicServer(const QuicConfig& config,
36 const QuicVersionVector& supported_versions);
38 ~QuicServer() override;
40 // Start listening on the specified address.
41 bool Listen(const IPEndPoint& address);
43 // Wait up to 50ms, and handle any events which occur.
44 void WaitForEvents();
46 // Server deletion is imminent. Start cleaning up the epoll server.
47 void Shutdown();
49 // From EpollCallbackInterface
50 void OnRegistration(EpollServer* eps, int fd, int event_mask) override {}
51 void OnModification(int fd, int event_mask) override {}
52 void OnEvent(int fd, EpollEvent* event) override;
53 void OnUnregistration(int fd, bool replaced) override {}
55 // Reads a number of packets from the given fd, and then passes them off to
56 // the QuicDispatcher. Returns true if some packets are read, false
57 // otherwise.
58 // If packets_dropped is non-null, the socket is configured to track
59 // dropped packets, and some packets are read, it will be set to the number of
60 // dropped packets.
61 static bool ReadAndDispatchPackets(int fd, int port,
62 ProcessPacketInterface* processor,
63 QuicPacketCount* packets_dropped);
64 // Same as ReadAndDispatchPackets, only does one packet at a time.
65 static bool ReadAndDispatchSinglePacket(int fd, int port,
66 ProcessPacketInterface* processor,
67 QuicPacketCount* packets_dropped);
69 void OnShutdown(EpollServer* eps, int fd) override {}
71 void SetStrikeRegisterNoStartupPeriod() {
72 crypto_config_.set_strike_register_no_startup_period();
75 // SetProofSource sets the ProofSource that will be used to verify the
76 // server's certificate, and takes ownership of |source|.
77 void SetProofSource(ProofSource* source) {
78 crypto_config_.SetProofSource(source);
81 bool overflow_supported() { return overflow_supported_; }
83 QuicPacketCount packets_dropped() { return packets_dropped_; }
85 int port() { return port_; }
87 protected:
88 virtual QuicDefaultPacketWriter* CreateWriter(int fd);
90 virtual QuicDispatcher* CreateQuicDispatcher();
92 const QuicConfig& config() const { return config_; }
93 const QuicCryptoServerConfig& crypto_config() const {
94 return crypto_config_;
96 const QuicVersionVector& supported_versions() const {
97 return supported_versions_;
99 EpollServer* epoll_server() { return &epoll_server_; }
101 QuicDispatcher* dispatcher() { return dispatcher_.get(); }
103 private:
104 friend class net::tools::test::QuicServerPeer;
106 // Initialize the internal state of the server.
107 void Initialize();
109 // Accepts data from the framer and demuxes clients to sessions.
110 scoped_ptr<QuicDispatcher> dispatcher_;
111 // Frames incoming packets and hands them to the dispatcher.
112 EpollServer epoll_server_;
114 // The port the server is listening on.
115 int port_;
117 // Listening connection. Also used for outbound client communication.
118 int fd_;
120 // If overflow_supported_ is true this will be the number of packets dropped
121 // during the lifetime of the server. This may overflow if enough packets
122 // are dropped.
123 QuicPacketCount packets_dropped_;
125 // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped
126 // because the socket would otherwise overflow.
127 bool overflow_supported_;
129 // If true, use recvmmsg for reading.
130 bool use_recvmmsg_;
132 // config_ contains non-crypto parameters that are negotiated in the crypto
133 // handshake.
134 QuicConfig config_;
135 // crypto_config_ contains crypto parameters for the handshake.
136 QuicCryptoServerConfig crypto_config_;
138 // This vector contains QUIC versions which we currently support.
139 // This should be ordered such that the highest supported version is the first
140 // element, with subsequent elements in descending order (versions can be
141 // skipped as necessary).
142 QuicVersionVector supported_versions_;
144 scoped_ptr<QuicPacketReader> packet_reader_;
146 DISALLOW_COPY_AND_ASSIGN(QuicServer);
149 } // namespace tools
150 } // namespace net
152 #endif // NET_TOOLS_QUIC_QUIC_SERVER_H_