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 client, which connects to a specified port and sends QUIC | 5 // A toy client, which connects to a specified port and sends QUIC |
6 // request to that endpoint. | 6 // request to that endpoint. |
7 | 7 |
8 #ifndef NET_TOOLS_QUIC_QUIC_CLIENT_H_ | 8 #ifndef NET_TOOLS_QUIC_QUIC_CLIENT_H_ |
9 #define NET_TOOLS_QUIC_QUIC_CLIENT_H_ | 9 #define NET_TOOLS_QUIC_QUIC_CLIENT_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
17 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
18 #include "net/quic/quic_config.h" | 18 #include "net/quic/quic_config.h" |
19 #include "net/quic/quic_data_stream.h" | 19 #include "net/quic/quic_data_stream.h" |
20 #include "net/tools/balsa/balsa_headers.h" | 20 #include "net/tools/balsa/balsa_headers.h" |
21 #include "net/tools/epoll_server/epoll_server.h" | 21 #include "net/tools/epoll_server/epoll_server.h" |
22 #include "net/tools/quic/quic_client_base.h" | 22 #include "net/tools/quic/quic_client_base.h" |
| 23 #include "net/tools/quic/quic_packet_reader.h" |
23 | 24 |
24 namespace net { | 25 namespace net { |
25 | 26 |
26 class QuicServerId; | 27 class QuicServerId; |
27 | 28 |
28 namespace tools { | 29 namespace tools { |
29 | 30 |
30 class QuicEpollConnectionHelper; | 31 class QuicEpollConnectionHelper; |
31 | 32 |
32 namespace test { | 33 namespace test { |
33 class QuicClientPeer; | 34 class QuicClientPeer; |
34 } // namespace test | 35 } // namespace test |
35 | 36 |
36 class QuicClient : public QuicClientBase, | 37 class QuicClient : public QuicClientBase, |
37 public EpollCallbackInterface, | 38 public EpollCallbackInterface, |
38 public QuicDataStream::Visitor { | 39 public QuicDataStream::Visitor, |
| 40 public ProcessPacketInterface { |
39 public: | 41 public: |
40 class ResponseListener { | 42 class ResponseListener { |
41 public: | 43 public: |
42 ResponseListener() {} | 44 ResponseListener() {} |
43 virtual ~ResponseListener() {} | 45 virtual ~ResponseListener() {} |
44 virtual void OnCompleteResponse(QuicStreamId id, | 46 virtual void OnCompleteResponse(QuicStreamId id, |
45 const BalsaHeaders& response_headers, | 47 const BalsaHeaders& response_headers, |
46 const std::string& response_body) = 0; | 48 const std::string& response_body) = 0; |
47 }; | 49 }; |
48 | 50 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void set_response_listener(ResponseListener* listener) { | 160 void set_response_listener(ResponseListener* listener) { |
159 response_listener_.reset(listener); | 161 response_listener_.reset(listener); |
160 } | 162 } |
161 | 163 |
162 void set_store_response(bool val) { store_response_ = val; } | 164 void set_store_response(bool val) { store_response_ = val; } |
163 | 165 |
164 size_t latest_response_code() const; | 166 size_t latest_response_code() const; |
165 const std::string& latest_response_headers() const; | 167 const std::string& latest_response_headers() const; |
166 const std::string& latest_response_body() const; | 168 const std::string& latest_response_body() const; |
167 | 169 |
| 170 // Implements ProcessPacketInterface. This will be called for each received |
| 171 // packet. |
| 172 void ProcessPacket(const IPEndPoint& self_address, |
| 173 const IPEndPoint& peer_address, |
| 174 const QuicEncryptedPacket& packet) override; |
| 175 |
168 protected: | 176 protected: |
169 virtual QuicEpollConnectionHelper* CreateQuicConnectionHelper(); | 177 virtual QuicEpollConnectionHelper* CreateQuicConnectionHelper(); |
170 virtual QuicPacketWriter* CreateQuicPacketWriter(); | 178 virtual QuicPacketWriter* CreateQuicPacketWriter(); |
| 179 virtual QuicPacketReader* CreateQuicPacketReader(); |
171 | 180 |
172 virtual int ReadPacket(char* buffer, | 181 virtual int ReadPacket(char* buffer, |
173 int buffer_len, | 182 int buffer_len, |
174 IPEndPoint* server_address, | 183 IPEndPoint* server_address, |
175 IPAddressNumber* client_ip); | 184 IPAddressNumber* client_ip); |
176 | 185 |
177 EpollServer* epoll_server() { return epoll_server_; } | 186 EpollServer* epoll_server() { return epoll_server_; } |
178 | 187 |
179 // If the socket has been created, then unregister and close() the FD. | 188 // If the socket has been created, then unregister and close() the FD. |
180 virtual void CleanUpUDPSocket(); | 189 virtual void CleanUpUDPSocket(); |
(...skipping 27 matching lines...) Expand all Loading... |
208 // Used during initialization: creates the UDP socket FD, sets socket options, | 217 // Used during initialization: creates the UDP socket FD, sets socket options, |
209 // and binds the socket to our address. | 218 // and binds the socket to our address. |
210 bool CreateUDPSocket(); | 219 bool CreateUDPSocket(); |
211 | 220 |
212 // Actually clean up the socket. | 221 // Actually clean up the socket. |
213 void CleanUpUDPSocketImpl(); | 222 void CleanUpUDPSocketImpl(); |
214 | 223 |
215 // Read a UDP packet and hand it to the framer. | 224 // Read a UDP packet and hand it to the framer. |
216 bool ReadAndProcessPacket(); | 225 bool ReadAndProcessPacket(); |
217 | 226 |
| 227 // Read available UDP packets up to kNumPacketsPerReadCall |
| 228 // and hand them to the connection. |
| 229 bool ReadAndProcessPackets(); |
| 230 |
218 // Address of the server. | 231 // Address of the server. |
219 const IPEndPoint server_address_; | 232 const IPEndPoint server_address_; |
220 | 233 |
221 // Address of the client if the client is connected to the server. | 234 // Address of the client if the client is connected to the server. |
222 IPEndPoint client_address_; | 235 IPEndPoint client_address_; |
223 | 236 |
224 // If initialized, the address to bind to. | 237 // If initialized, the address to bind to. |
225 IPAddressNumber bind_to_address_; | 238 IPAddressNumber bind_to_address_; |
226 // Local port to bind to. Initialize to 0. | 239 // Local port to bind to. Initialize to 0. |
227 int local_port_; | 240 int local_port_; |
(...skipping 29 matching lines...) Expand all Loading... |
257 // Body of most recent response. | 270 // Body of most recent response. |
258 std::string latest_response_body_; | 271 std::string latest_response_body_; |
259 | 272 |
260 // Keeps track of any data sent before the handshake. | 273 // Keeps track of any data sent before the handshake. |
261 std::vector<QuicDataToResend*> data_sent_before_handshake_; | 274 std::vector<QuicDataToResend*> data_sent_before_handshake_; |
262 | 275 |
263 // Once the client receives a stateless reject, keeps track of any data that | 276 // Once the client receives a stateless reject, keeps track of any data that |
264 // must be resent upon a subsequent successful connection. | 277 // must be resent upon a subsequent successful connection. |
265 std::vector<QuicDataToResend*> data_to_resend_on_connect_; | 278 std::vector<QuicDataToResend*> data_to_resend_on_connect_; |
266 | 279 |
| 280 // Point to a QuicPacketReader object on the heap. The reader allocates more |
| 281 // space than allowed on the stack. |
| 282 scoped_ptr<QuicPacketReader> packet_reader_; |
| 283 |
267 DISALLOW_COPY_AND_ASSIGN(QuicClient); | 284 DISALLOW_COPY_AND_ASSIGN(QuicClient); |
268 }; | 285 }; |
269 | 286 |
270 } // namespace tools | 287 } // namespace tools |
271 } // namespace net | 288 } // namespace net |
272 | 289 |
273 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ | 290 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ |
OLD | NEW |