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/file_util.h" | |
wtc
2014/06/18 02:04:47
It doesn't seem necessary to include "base/file_ut
dmziegler
2014/06/18 20:13:41
Removed.
| |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "net/base/io_buffer.h" | |
13 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.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_framer.h" |
wtc
2014/06/18 02:04:47
It doesn't seem necessary to include "net/quic/qui
dmziegler
2014/06/18 20:13:41
Removed.
| |
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(); | |
33 QuicServer(const QuicConfig& config, | 34 QuicServer(const QuicConfig& config, |
34 const QuicVersionVector& supported_versions, | 35 const QuicVersionVector& supported_versions, |
35 uint32 server_initial_flow_control_receive_window); | 36 uint32 server_initial_flow_control_receive_window); |
36 | 37 |
37 virtual ~QuicServer(); | 38 virtual ~QuicServer(); |
38 | 39 |
39 // Start listening on the specified address. | 40 // Start listening on the specified address. |
40 bool Listen(const IPEndPoint& address); | 41 bool Listen(const IPEndPoint& address); |
41 | 42 |
42 // Wait up to 50ms, and handle any events which occur. | 43 // Server deletion is imminent. Start cleaning up. |
43 void WaitForEvents(); | |
44 | |
45 // Server deletion is imminent. Start cleaning up the epoll server. | |
46 void Shutdown(); | 44 void Shutdown(); |
47 | 45 |
48 // From EpollCallbackInterface | 46 void OnReadComplete(int result); |
wtc
2014/06/18 02:04:47
Document this method.
dmziegler
2014/06/18 20:13:41
Done.
| |
49 virtual void OnRegistration(EpollServer* eps, | |
50 int fd, | |
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 {} | |
55 | 47 |
56 // Reads a packet from the given fd, and then passes it off to | 48 // Start reading on the socket. After each asynchronous read, OnReadComplete |
57 // the QuicDispatcher. Returns true if a packet is read, false | 49 // will call StartReading again. |
58 // otherwise. | 50 void StartReading(); |
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 | |
61 // dropped packets. | |
62 static bool ReadAndDispatchSinglePacket(int fd, int port, | |
63 QuicDispatcher* dispatcher, | |
64 uint32* packets_dropped); | |
65 | |
66 virtual void OnShutdown(EpollServer* eps, int fd) OVERRIDE {} | |
67 | 51 |
68 void SetStrikeRegisterNoStartupPeriod() { | 52 void SetStrikeRegisterNoStartupPeriod() { |
69 crypto_config_.set_strike_register_no_startup_period(); | 53 crypto_config_.set_strike_register_no_startup_period(); |
70 } | 54 } |
71 | 55 |
72 // SetProofSource sets the ProofSource that will be used to verify the | 56 // SetProofSource sets the ProofSource that will be used to verify the |
73 // server's certificate, and takes ownership of |source|. | 57 // server's certificate, and takes ownership of |source|. |
74 void SetProofSource(ProofSource* source) { | 58 void SetProofSource(ProofSource* source) { |
75 crypto_config_.SetProofSource(source); | 59 crypto_config_.SetProofSource(source); |
76 } | 60 } |
77 | 61 |
78 bool overflow_supported() { return overflow_supported_; } | |
79 | |
80 uint32 packets_dropped() { return packets_dropped_; } | |
81 | |
82 int port() { return port_; } | |
83 | |
84 private: | 62 private: |
85 friend class net::tools::test::QuicServerPeer; | 63 friend class net::test::QuicServerPeer; |
86 | 64 |
87 // Initialize the internal state of the server. | 65 // Initialize the internal state of the server. |
88 void Initialize(); | 66 void Initialize(); |
89 | 67 |
90 // Accepts data from the framer and demuxes clients to sessions. | 68 // Accepts data from the framer and demuxes clients to sessions. |
91 scoped_ptr<QuicDispatcher> dispatcher_; | 69 scoped_ptr<QuicDispatcher> dispatcher_; |
92 // Frames incoming packets and hands them to the dispatcher. | |
93 EpollServer epoll_server_; | |
94 | 70 |
95 // The port the server is listening on. | 71 QuicClock clock_; |
96 int port_; | |
97 | 72 |
98 // Listening connection. Also used for outbound client communication. | 73 QuicConnectionHelperInterface* helper_; |
99 int fd_; | |
100 | 74 |
101 // If overflow_supported_ is true this will be the number of packets dropped | 75 // Listening connection. Also used for outbound client communication. |
wtc
2014/06/18 02:04:47
"Listening connection" seems wrong. I think this s
dmziegler
2014/06/18 20:13:41
Done.
| |
102 // during the lifetime of the server. This may overflow if enough packets | 76 scoped_ptr<UDPServerSocket> socket_; |
103 // are dropped. | |
104 uint32 packets_dropped_; | |
105 | |
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_; | |
109 | |
110 // If true, use recvmmsg for reading. | |
111 bool use_recvmmsg_; | |
112 | 77 |
113 // config_ contains non-crypto parameters that are negotiated in the crypto | 78 // config_ contains non-crypto parameters that are negotiated in the crypto |
114 // handshake. | 79 // handshake. |
115 QuicConfig config_; | 80 QuicConfig config_; |
116 // crypto_config_ contains crypto parameters for the handshake. | 81 // crypto_config_ contains crypto parameters for the handshake. |
117 QuicCryptoServerConfig crypto_config_; | 82 QuicCryptoServerConfig crypto_config_; |
118 | 83 |
119 // This vector contains QUIC versions which we currently support. | 84 // This vector contains QUIC versions which we currently support. |
120 // This should be ordered such that the highest supported version is the first | 85 // This should be ordered such that the highest supported version is the first |
121 // element, with subsequent elements in descending order (versions can be | 86 // element, with subsequent elements in descending order (versions can be |
122 // skipped as necessary). | 87 // skipped as necessary). |
123 QuicVersionVector supported_versions_; | 88 QuicVersionVector supported_versions_; |
124 | 89 |
125 // Size of flow control receive window to advertise to clients on new | 90 // Size of flow control receive window to advertise to clients on new |
126 // connections. | 91 // connections. |
127 uint32 server_initial_flow_control_receive_window_; | 92 uint32 server_initial_flow_control_receive_window_; |
128 | 93 |
94 IPEndPoint server_address_; | |
wtc
2014/06/18 02:04:46
Add a comment. Perhaps adapting the original comme
dmziegler
2014/06/18 20:13:41
Done.
| |
95 | |
96 bool read_pending_; | |
97 | |
98 int synchronous_read_count_; | |
99 | |
100 scoped_refptr<IOBufferWithSize> read_buffer_; | |
101 | |
102 IPEndPoint read_addr_; | |
103 | |
104 base::WeakPtrFactory<QuicServer> weak_factory_; | |
wtc
2014/06/18 02:04:47
Except for weak_factory_, all the new data members
dmziegler
2014/06/18 20:13:41
Done.
| |
105 | |
129 DISALLOW_COPY_AND_ASSIGN(QuicServer); | 106 DISALLOW_COPY_AND_ASSIGN(QuicServer); |
130 }; | 107 }; |
131 | 108 |
132 } // namespace tools | |
133 } // namespace net | 109 } // namespace net |
134 | 110 |
135 #endif // NET_TOOLS_QUIC_QUIC_SERVER_H_ | 111 #endif // NET_QUIC_QUIC_SERVER_H_ |
OLD | NEW |