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 <stddef.h> | 11 #include <stddef.h> |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
19 #include "net/base/ip_endpoint.h" | 19 #include "net/base/ip_endpoint.h" |
20 #include "net/quic/quic_config.h" | 20 #include "net/quic/quic_config.h" |
21 #include "net/quic/quic_spdy_stream.h" | 21 #include "net/quic/quic_spdy_stream.h" |
22 #include "net/tools/balsa/balsa_headers.h" | 22 #include "net/tools/balsa/balsa_headers.h" |
23 #include "net/tools/epoll_server/epoll_server.h" | 23 #include "net/tools/epoll_server/epoll_server.h" |
24 #include "net/tools/quic/quic_client_base.h" | 24 #include "net/tools/quic/quic_client_base.h" |
| 25 #include "net/tools/quic/quic_process_packet_interface.h" |
25 | 26 |
26 namespace net { | 27 namespace net { |
27 | 28 |
28 class QuicServerId; | 29 class QuicServerId; |
29 | 30 |
30 namespace tools { | 31 namespace tools { |
31 | 32 |
32 class QuicEpollConnectionHelper; | 33 class QuicEpollConnectionHelper; |
| 34 class QuicPacketReader; |
33 | 35 |
34 namespace test { | 36 namespace test { |
35 class QuicClientPeer; | 37 class QuicClientPeer; |
36 } // namespace test | 38 } // namespace test |
37 | 39 |
38 class QuicClient : public QuicClientBase, | 40 class QuicClient : public QuicClientBase, |
39 public EpollCallbackInterface, | 41 public EpollCallbackInterface, |
40 public QuicSpdyStream::Visitor { | 42 public QuicSpdyStream::Visitor, |
| 43 public ProcessPacketInterface { |
41 public: | 44 public: |
42 class ResponseListener { | 45 class ResponseListener { |
43 public: | 46 public: |
44 ResponseListener() {} | 47 ResponseListener() {} |
45 virtual ~ResponseListener() {} | 48 virtual ~ResponseListener() {} |
46 virtual void OnCompleteResponse(QuicStreamId id, | 49 virtual void OnCompleteResponse(QuicStreamId id, |
47 const BalsaHeaders& response_headers, | 50 const BalsaHeaders& response_headers, |
48 const std::string& response_body) = 0; | 51 const std::string& response_body) = 0; |
49 }; | 52 }; |
50 | 53 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 response_listener_.reset(listener); | 170 response_listener_.reset(listener); |
168 } | 171 } |
169 | 172 |
170 void set_store_response(bool val) { store_response_ = val; } | 173 void set_store_response(bool val) { store_response_ = val; } |
171 | 174 |
172 size_t latest_response_code() const; | 175 size_t latest_response_code() const; |
173 const std::string& latest_response_headers() const; | 176 const std::string& latest_response_headers() const; |
174 const std::string& latest_response_body() const; | 177 const std::string& latest_response_body() const; |
175 const std::string& latest_response_trailers() const; | 178 const std::string& latest_response_trailers() const; |
176 | 179 |
| 180 // Implements ProcessPacketInterface. This will be called for each received |
| 181 // packet. |
| 182 void ProcessPacket(const IPEndPoint& self_address, |
| 183 const IPEndPoint& peer_address, |
| 184 const QuicEncryptedPacket& packet) override; |
| 185 |
177 protected: | 186 protected: |
178 virtual QuicPacketWriter* CreateQuicPacketWriter(); | 187 virtual QuicPacketWriter* CreateQuicPacketWriter(); |
| 188 virtual QuicPacketReader* CreateQuicPacketReader(); |
179 | 189 |
180 virtual int ReadPacket(char* buffer, | 190 virtual int ReadPacket(char* buffer, |
181 int buffer_len, | 191 int buffer_len, |
182 IPEndPoint* server_address, | 192 IPEndPoint* server_address, |
183 IPAddressNumber* client_ip); | 193 IPAddressNumber* client_ip); |
184 | 194 |
185 // If |fd| is an open UDP socket, unregister and close it. Otherwise, do | 195 // If |fd| is an open UDP socket, unregister and close it. Otherwise, do |
186 // nothing. | 196 // nothing. |
187 virtual void CleanUpUDPSocket(int fd); | 197 virtual void CleanUpUDPSocket(int fd); |
188 | 198 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // Used during initialization: creates the UDP socket FD, sets socket options, | 234 // Used during initialization: creates the UDP socket FD, sets socket options, |
225 // and binds the socket to our address. | 235 // and binds the socket to our address. |
226 bool CreateUDPSocket(); | 236 bool CreateUDPSocket(); |
227 | 237 |
228 // Actually clean up |fd|. | 238 // Actually clean up |fd|. |
229 void CleanUpUDPSocketImpl(int fd); | 239 void CleanUpUDPSocketImpl(int fd); |
230 | 240 |
231 // Read a UDP packet and hand it to the framer. | 241 // Read a UDP packet and hand it to the framer. |
232 bool ReadAndProcessPacket(); | 242 bool ReadAndProcessPacket(); |
233 | 243 |
| 244 // Read available UDP packets up to kNumPacketsPerReadCall |
| 245 // and hand them to the connection. |
| 246 // TODO(rtenneti): Add support for ReadAndProcessPackets(). |
| 247 // bool ReadAndProcessPackets(); |
| 248 |
234 // Address of the server. | 249 // Address of the server. |
235 const IPEndPoint server_address_; | 250 const IPEndPoint server_address_; |
236 | 251 |
237 // If initialized, the address to bind to. | 252 // If initialized, the address to bind to. |
238 IPAddressNumber bind_to_address_; | 253 IPAddressNumber bind_to_address_; |
239 // Local port to bind to. Initialize to 0. | 254 // Local port to bind to. Initialize to 0. |
240 int local_port_; | 255 int local_port_; |
241 | 256 |
242 // Listens for events on the client socket. | 257 // Listens for events on the client socket. |
243 EpollServer* epoll_server_; | 258 EpollServer* epoll_server_; |
(...skipping 27 matching lines...) Expand all Loading... |
271 // HTTP/2 trailers from most recent response. | 286 // HTTP/2 trailers from most recent response. |
272 std::string latest_response_trailers_; | 287 std::string latest_response_trailers_; |
273 | 288 |
274 // Keeps track of any data sent before the handshake. | 289 // Keeps track of any data sent before the handshake. |
275 std::vector<QuicDataToResend*> data_sent_before_handshake_; | 290 std::vector<QuicDataToResend*> data_sent_before_handshake_; |
276 | 291 |
277 // Once the client receives a stateless reject, keeps track of any data that | 292 // Once the client receives a stateless reject, keeps track of any data that |
278 // must be resent upon a subsequent successful connection. | 293 // must be resent upon a subsequent successful connection. |
279 std::vector<QuicDataToResend*> data_to_resend_on_connect_; | 294 std::vector<QuicDataToResend*> data_to_resend_on_connect_; |
280 | 295 |
| 296 // Point to a QuicPacketReader object on the heap. The reader allocates more |
| 297 // space than allowed on the stack. |
| 298 // |
| 299 // TODO(rtenneti): Chromium code doesn't use |packet_reader_|. Add support for |
| 300 // QuicPacketReader |
| 301 QuicPacketReader* packet_reader_; |
| 302 |
281 DISALLOW_COPY_AND_ASSIGN(QuicClient); | 303 DISALLOW_COPY_AND_ASSIGN(QuicClient); |
282 }; | 304 }; |
283 | 305 |
284 } // namespace tools | 306 } // namespace tools |
285 } // namespace net | 307 } // namespace net |
286 | 308 |
287 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ | 309 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ |
OLD | NEW |