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.
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_framer.h"
17 #include "net/tools/epoll_server/epoll_server.h"
18 #include "net/tools/quic/quic_dispatcher.h"
30 class QuicServer : public EpollCallbackInterface {
33 QuicServer(const QuicConfig& config,
34 const QuicVersionVector& supported_versions,
35 uint32 server_initial_flow_control_receive_window);
37 virtual ~QuicServer();
39 // Start listening on the specified address.
40 bool Listen(const IPEndPoint& address);
42 // Wait up to 50ms, and handle any events which occur.
45 // Server deletion is imminent. Start cleaning up the epoll server.
48 // From EpollCallbackInterface
49 virtual void OnRegistration(EpollServer* eps,
51 int event_mask) OVERRIDE {}
52 virtual void OnModification(int fd, int event_mask) OVERRIDE {}
53 virtual void OnEvent(int fd, EpollEvent* event) OVERRIDE;
54 virtual void OnUnregistration(int fd, bool replaced) OVERRIDE {}
56 // Reads a packet from the given fd, and then passes it off to
57 // the QuicDispatcher. Returns true if a packet is read, false
59 // If packets_dropped is non-null, the socket is configured to track
60 // dropped packets, and some packets are read, it will be set to the number of
62 static bool ReadAndDispatchSinglePacket(int fd, int port,
63 QuicDispatcher* dispatcher,
64 uint32* packets_dropped);
66 virtual void OnShutdown(EpollServer* eps, int fd) OVERRIDE {}
68 void SetStrikeRegisterNoStartupPeriod() {
69 crypto_config_.set_strike_register_no_startup_period();
72 // SetProofSource sets the ProofSource that will be used to verify the
73 // server's certificate, and takes ownership of |source|.
74 void SetProofSource(ProofSource* source) {
75 crypto_config_.SetProofSource(source);
78 bool overflow_supported() { return overflow_supported_; }
80 uint32 packets_dropped() { return packets_dropped_; }
82 int port() { return port_; }
85 friend class net::tools::test::QuicServerPeer;
87 // Initialize the internal state of the server.
90 // Accepts data from the framer and demuxes clients to sessions.
91 scoped_ptr<QuicDispatcher> dispatcher_;
92 // Frames incoming packets and hands them to the dispatcher.
93 EpollServer epoll_server_;
95 // The port the server is listening on.
98 // Listening connection. Also used for outbound client communication.
101 // If overflow_supported_ is true this will be the number of packets dropped
102 // during the lifetime of the server. This may overflow if enough packets
104 uint32 packets_dropped_;
106 // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped
107 // because the socket would otherwise overflow.
108 bool overflow_supported_;
110 // If true, use recvmmsg for reading.
113 // config_ contains non-crypto parameters that are negotiated in the crypto
116 // crypto_config_ contains crypto parameters for the handshake.
117 QuicCryptoServerConfig crypto_config_;
119 // This vector contains QUIC versions which we currently support.
120 // This should be ordered such that the highest supported version is the first
121 // element, with subsequent elements in descending order (versions can be
122 // skipped as necessary).
123 QuicVersionVector supported_versions_;
125 // Size of flow control receive window to advertise to clients on new
127 uint32 server_initial_flow_control_receive_window_;
129 DISALLOW_COPY_AND_ASSIGN(QuicServer);
135 #endif // NET_TOOLS_QUIC_QUIC_SERVER_H_