OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // A toy server, which listens on a specified address for QUIC traffic and | 5 // A toy server, which listens on a specified address for QUIC traffic and |
6 // handles incoming responses. | 6 // handles incoming responses. |
7 | 7 |
8 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_H_ | 8 #ifndef NET_QUIC_QUIC_SERVER_H_ |
9 #define NET_TOOLS_QUIC_QUIC_SERVER_H_ | 9 #define NET_QUIC_QUIC_SERVER_H_ |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "net/base/io_buffer.h" | |
13 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
15 #include "net/base/net_log.h" | |
14 #include "net/quic/crypto/quic_crypto_server_config.h" | 16 #include "net/quic/crypto/quic_crypto_server_config.h" |
17 #include "net/quic/quic_clock.h" | |
15 #include "net/quic/quic_config.h" | 18 #include "net/quic/quic_config.h" |
16 #include "net/quic/quic_framer.h" | 19 #include "net/quic/quic_connection_helper.h" |
17 #include "net/tools/epoll_server/epoll_server.h" | |
18 #include "net/tools/quic/quic_dispatcher.h" | |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 | 22 |
22 namespace tools { | |
23 | 23 |
24 namespace test { | 24 namespace test { |
25 class QuicServerPeer; | 25 class QuicServerPeer; |
26 } // namespace test | 26 } // namespace test |
27 | 27 |
28 class QuicConnectionHelperInterface; | |
28 class QuicDispatcher; | 29 class QuicDispatcher; |
30 class UDPServerSocket; | |
29 | 31 |
30 class QuicServer : public EpollCallbackInterface { | 32 class NET_EXPORT_PRIVATE QuicServer { |
31 public: | 33 public: |
32 QuicServer(); | 34 QuicServer(); |
wtc
2014/06/23 23:12:16
You said you will leave the default QuicServer con
dmziegler
2014/06/24 00:08:52
It's only declared -- yes, that was a mistake.
| |
33 QuicServer(const QuicConfig& config, | 35 QuicServer(const QuicConfig& config, |
34 const QuicVersionVector& supported_versions); | 36 const QuicVersionVector& supported_versions); |
35 | 37 |
36 virtual ~QuicServer(); | 38 virtual ~QuicServer(); |
37 | 39 |
38 // Start listening on the specified address. | 40 // Start listening on the specified address. Returns an error code. |
39 bool Listen(const IPEndPoint& address); | 41 int Listen(const IPEndPoint& address); |
40 | 42 |
41 // Wait up to 50ms, and handle any events which occur. | 43 // Server deletion is imminent. Start cleaning up. |
42 void WaitForEvents(); | |
43 | |
44 // Server deletion is imminent. Start cleaning up the epoll server. | |
45 void Shutdown(); | 44 void Shutdown(); |
46 | 45 |
47 // From EpollCallbackInterface | 46 // Start reading on the socket. On asynchronous reads, this registers |
48 virtual void OnRegistration(EpollServer* eps, | 47 // OnReadComplete as the callback, which will then call StartReading again. |
49 int fd, | 48 void StartReading(); |
50 int event_mask) OVERRIDE {} | |
51 virtual void OnModification(int fd, int event_mask) OVERRIDE {} | |
52 virtual void OnEvent(int fd, EpollEvent* event) OVERRIDE; | |
53 virtual void OnUnregistration(int fd, bool replaced) OVERRIDE {} | |
54 | 49 |
55 // Reads a packet from the given fd, and then passes it off to | 50 // Called on reads that complete asynchronously. Dispatches the packet and |
56 // the QuicDispatcher. Returns true if a packet is read, false | 51 // continues the read loop. |
57 // otherwise. | 52 void OnReadComplete(int result); |
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 ReadAndDispatchSinglePacket(int fd, int port, | |
62 QuicDispatcher* dispatcher, | |
63 uint32* packets_dropped); | |
64 | |
65 virtual void OnShutdown(EpollServer* eps, int fd) OVERRIDE {} | |
66 | 53 |
67 void SetStrikeRegisterNoStartupPeriod() { | 54 void SetStrikeRegisterNoStartupPeriod() { |
68 crypto_config_.set_strike_register_no_startup_period(); | 55 crypto_config_.set_strike_register_no_startup_period(); |
69 } | 56 } |
70 | 57 |
71 // SetProofSource sets the ProofSource that will be used to verify the | 58 // SetProofSource sets the ProofSource that will be used to verify the |
72 // server's certificate, and takes ownership of |source|. | 59 // server's certificate, and takes ownership of |source|. |
73 void SetProofSource(ProofSource* source) { | 60 void SetProofSource(ProofSource* source) { |
74 crypto_config_.SetProofSource(source); | 61 crypto_config_.SetProofSource(source); |
75 } | 62 } |
76 | 63 |
77 bool overflow_supported() { return overflow_supported_; } | |
78 | |
79 uint32 packets_dropped() { return packets_dropped_; } | |
80 | |
81 int port() { return port_; } | |
82 | |
83 protected: | |
84 virtual QuicDispatcher* CreateQuicDispatcher(); | |
85 | |
86 const QuicConfig& config() const { return config_; } | |
87 const QuicCryptoServerConfig& crypto_config() const { | |
88 return crypto_config_; | |
89 } | |
90 const QuicVersionVector& supported_versions() const { | |
91 return supported_versions_; | |
92 } | |
93 EpollServer* epoll_server() { return &epoll_server_; } | |
94 | |
95 private: | 64 private: |
96 friend class net::tools::test::QuicServerPeer; | 65 friend class net::test::QuicServerPeer; |
97 | 66 |
98 // Initialize the internal state of the server. | 67 // Initialize the internal state of the server. |
99 void Initialize(); | 68 void Initialize(); |
100 | 69 |
101 // Accepts data from the framer and demuxes clients to sessions. | 70 // Accepts data from the framer and demuxes clients to sessions. |
102 scoped_ptr<QuicDispatcher> dispatcher_; | 71 scoped_ptr<QuicDispatcher> dispatcher_; |
103 // Frames incoming packets and hands them to the dispatcher. | |
104 EpollServer epoll_server_; | |
105 | 72 |
106 // The port the server is listening on. | 73 // Used by the helper_ to time alarms. |
107 int port_; | 74 QuicClock clock_; |
108 | 75 |
109 // Listening connection. Also used for outbound client communication. | 76 // Used to manage the message loop. |
110 int fd_; | 77 QuicConnectionHelper helper_; |
111 | 78 |
112 // If overflow_supported_ is true this will be the number of packets dropped | 79 // Listening socket. Also used for outbound client communication. |
113 // during the lifetime of the server. This may overflow if enough packets | 80 scoped_ptr<UDPServerSocket> socket_; |
114 // are dropped. | |
115 uint32 packets_dropped_; | |
116 | |
117 // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped | |
118 // because the socket would otherwise overflow. | |
119 bool overflow_supported_; | |
120 | |
121 // If true, use recvmmsg for reading. | |
122 bool use_recvmmsg_; | |
123 | 81 |
124 // config_ contains non-crypto parameters that are negotiated in the crypto | 82 // config_ contains non-crypto parameters that are negotiated in the crypto |
125 // handshake. | 83 // handshake. |
126 QuicConfig config_; | 84 QuicConfig config_; |
127 // crypto_config_ contains crypto parameters for the handshake. | 85 // crypto_config_ contains crypto parameters for the handshake. |
128 QuicCryptoServerConfig crypto_config_; | 86 QuicCryptoServerConfig crypto_config_; |
129 | 87 |
130 // This vector contains QUIC versions which we currently support. | 88 // This vector contains QUIC versions which we currently support. |
131 // This should be ordered such that the highest supported version is the first | 89 // This should be ordered such that the highest supported version is the first |
132 // element, with subsequent elements in descending order (versions can be | 90 // element, with subsequent elements in descending order (versions can be |
133 // skipped as necessary). | 91 // skipped as necessary). |
134 QuicVersionVector supported_versions_; | 92 QuicVersionVector supported_versions_; |
135 | 93 |
136 // Size of flow control receive window to advertise to clients on new | 94 // The address that the server listens on. |
137 // connections. | 95 IPEndPoint server_address_; |
138 uint32 server_initial_flow_control_receive_window_; | 96 |
97 // Keeps track of whether a read is currently in flight, after which | |
98 // OnReadComplete will be called. | |
99 bool read_pending_; | |
100 | |
101 // The number of iterations of the read loop that have completed synchronously | |
102 // and without posting a new task to the message loop. | |
103 int synchronous_read_count_; | |
104 | |
105 // The target buffer of the current read. | |
106 scoped_refptr<IOBufferWithSize> read_buffer_; | |
107 | |
108 // The source address of the current read. | |
109 IPEndPoint client_address_; | |
110 | |
111 // The log to use for the socket. | |
112 NetLog net_log_; | |
113 | |
114 base::WeakPtrFactory<QuicServer> weak_factory_; | |
139 | 115 |
140 DISALLOW_COPY_AND_ASSIGN(QuicServer); | 116 DISALLOW_COPY_AND_ASSIGN(QuicServer); |
141 }; | 117 }; |
142 | 118 |
143 } // namespace tools | |
144 } // namespace net | 119 } // namespace net |
145 | 120 |
146 #endif // NET_TOOLS_QUIC_QUIC_SERVER_H_ | 121 #endif // NET_QUIC_QUIC_SERVER_H_ |
OLD | NEW |