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