| 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_SIMPLE_CLIENT_H_ | 8 #ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ |
| 9 #define NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ | 9 #define NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 class QuicChromiumAlarmFactory; | 31 class QuicChromiumAlarmFactory; |
| 32 class QuicChromiumConnectionHelper; | 32 class QuicChromiumConnectionHelper; |
| 33 class UDPClientSocket; | 33 class UDPClientSocket; |
| 34 | 34 |
| 35 | 35 |
| 36 namespace test { | 36 namespace test { |
| 37 class QuicClientPeer; | 37 class QuicClientPeer; |
| 38 } // namespace test | 38 } // namespace test |
| 39 | 39 |
| 40 class QuicSimpleClient : public QuicClientBase, | 40 class QuicSimpleClient : public QuicClientBase, |
| 41 public QuicSpdyStream::Visitor, | |
| 42 public QuicChromiumPacketReader::Visitor { | 41 public QuicChromiumPacketReader::Visitor { |
| 43 public: | 42 public: |
| 44 class ResponseListener { | 43 class ResponseListener { |
| 45 public: | 44 public: |
| 46 ResponseListener() {} | 45 ResponseListener() {} |
| 47 virtual ~ResponseListener() {} | 46 virtual ~ResponseListener() {} |
| 48 virtual void OnCompleteResponse(QuicStreamId id, | 47 virtual void OnCompleteResponse(QuicStreamId id, |
| 49 const HttpResponseHeaders& response_headers, | 48 const HttpResponseHeaders& response_headers, |
| 50 const std::string& response_body) = 0; | 49 const std::string& response_body) = 0; |
| 51 }; | 50 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 77 // Connect(), but callers are responsible for making sure the crypto handshake | 76 // Connect(), but callers are responsible for making sure the crypto handshake |
| 78 // completes. | 77 // completes. |
| 79 void StartConnect(); | 78 void StartConnect(); |
| 80 | 79 |
| 81 // Disconnects from the QUIC server. | 80 // Disconnects from the QUIC server. |
| 82 void Disconnect(); | 81 void Disconnect(); |
| 83 | 82 |
| 84 // Sends an HTTP request and does not wait for response before returning. | 83 // Sends an HTTP request and does not wait for response before returning. |
| 85 void SendRequest(const SpdyHeaderBlock& headers, | 84 void SendRequest(const SpdyHeaderBlock& headers, |
| 86 base::StringPiece body, | 85 base::StringPiece body, |
| 87 bool fin); | 86 bool fin) override; |
| 88 | 87 |
| 89 // Sends an HTTP request and waits for response before returning. | 88 // Sends an HTTP request and waits for response before returning. |
| 90 void SendRequestAndWaitForResponse(const SpdyHeaderBlock& headers, | 89 void SendRequestAndWaitForResponse(const SpdyHeaderBlock& headers, |
| 91 base::StringPiece body, | 90 base::StringPiece body, |
| 92 bool fin); | 91 bool fin); |
| 93 | 92 |
| 94 // Sends a request simple GET for each URL in |args|, and then waits for | 93 // Sends a request simple GET for each URL in |args|, and then waits for |
| 95 // each to complete. | 94 // each to complete. |
| 96 void SendRequestsAndWaitForResponse( | 95 void SendRequestsAndWaitForResponse( |
| 97 const base::CommandLine::StringVector& url_list); | 96 const base::CommandLine::StringVector& url_list); |
| 98 | 97 |
| 99 // Migrate to a new socket during an active connection. | 98 // Migrate to a new socket during an active connection. |
| 100 bool MigrateSocket(const IPAddress& new_host); | 99 bool MigrateSocket(const IPAddress& new_host); |
| 101 | 100 |
| 102 // QuicChromiumPacketReader::Visitor | 101 // QuicChromiumPacketReader::Visitor |
| 103 void OnReadError(int result, const DatagramClientSocket* socket) override; | 102 void OnReadError(int result, const DatagramClientSocket* socket) override; |
| 104 bool OnPacket(const QuicReceivedPacket& packet, | 103 bool OnPacket(const QuicReceivedPacket& packet, |
| 105 IPEndPoint local_address, | 104 IPEndPoint local_address, |
| 106 IPEndPoint peer_address) override; | 105 IPEndPoint peer_address) override; |
| 107 | 106 |
| 108 // QuicSpdyStream::Visitor | 107 // QuicSpdyStream::Visitor |
| 109 void OnClose(QuicSpdyStream* stream) override; | 108 void OnClose(QuicSpdyStream* stream) override; |
| 110 | 109 |
| 111 // If the crypto handshake has not yet been confirmed, adds the data to the | |
| 112 // queue of data to resend if the client receives a stateless reject. | |
| 113 // Otherwise, deletes the data. | |
| 114 void MaybeAddQuicDataToResend( | |
| 115 std::unique_ptr<QuicDataToResend> data_to_resend); | |
| 116 | |
| 117 void set_bind_to_address(const IPAddress& address) { | 110 void set_bind_to_address(const IPAddress& address) { |
| 118 bind_to_address_ = address; | 111 bind_to_address_ = address; |
| 119 } | 112 } |
| 120 | 113 |
| 121 const IPAddress& bind_to_address() const { return bind_to_address_; } | 114 const IPAddress& bind_to_address() const { return bind_to_address_; } |
| 122 | 115 |
| 123 void set_local_port(int local_port) { local_port_ = local_port; } | 116 void set_local_port(int local_port) { local_port_ = local_port; } |
| 124 | 117 |
| 125 const IPEndPoint& server_address() const { return server_address_; } | 118 const IPEndPoint& server_address() const { return server_address_; } |
| 126 | 119 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 138 const std::string& latest_response_body() const; | 131 const std::string& latest_response_body() const; |
| 139 | 132 |
| 140 protected: | 133 protected: |
| 141 virtual QuicChromiumAlarmFactory* CreateQuicAlarmFactory(); | 134 virtual QuicChromiumAlarmFactory* CreateQuicAlarmFactory(); |
| 142 virtual QuicChromiumConnectionHelper* CreateQuicConnectionHelper(); | 135 virtual QuicChromiumConnectionHelper* CreateQuicConnectionHelper(); |
| 143 virtual QuicPacketWriter* CreateQuicPacketWriter(); | 136 virtual QuicPacketWriter* CreateQuicPacketWriter(); |
| 144 | 137 |
| 145 private: | 138 private: |
| 146 friend class net::test::QuicClientPeer; | 139 friend class net::test::QuicClientPeer; |
| 147 | 140 |
| 148 // Specific QuicClient class for storing data to resend. | |
| 149 class ClientQuicDataToResend : public QuicDataToResend { | |
| 150 public: | |
| 151 // Takes ownership of |headers|. | |
| 152 ClientQuicDataToResend(std::unique_ptr<SpdyHeaderBlock> headers, | |
| 153 base::StringPiece body, | |
| 154 bool fin, | |
| 155 QuicSimpleClient* client) | |
| 156 : QuicDataToResend(std::move(headers), body, fin), client_(client) { | |
| 157 DCHECK(client); | |
| 158 } | |
| 159 | |
| 160 ~ClientQuicDataToResend() override {} | |
| 161 | |
| 162 void Resend() override; | |
| 163 | |
| 164 private: | |
| 165 QuicSimpleClient* client_; | |
| 166 | |
| 167 DISALLOW_COPY_AND_ASSIGN(ClientQuicDataToResend); | |
| 168 }; | |
| 169 | |
| 170 // Used during initialization: creates the UDP socket FD, sets socket options, | 141 // Used during initialization: creates the UDP socket FD, sets socket options, |
| 171 // and binds the socket to our address. | 142 // and binds the socket to our address. |
| 172 bool CreateUDPSocket(); | 143 bool CreateUDPSocket(); |
| 173 | 144 |
| 174 // Read a UDP packet and hand it to the framer. | 145 // Read a UDP packet and hand it to the framer. |
| 175 bool ReadAndProcessPacket(); | 146 bool ReadAndProcessPacket(); |
| 176 | 147 |
| 177 void StartPacketReaderIfNotStarted(); | 148 void StartPacketReaderIfNotStarted(); |
| 178 | 149 |
| 179 // Used by |helper_| to time alarms. | 150 // Used by |helper_| to time alarms. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 210 | 181 |
| 211 // If true, store the latest response code, headers, and body. | 182 // If true, store the latest response code, headers, and body. |
| 212 bool store_response_; | 183 bool store_response_; |
| 213 // HTTP response code from most recent response. | 184 // HTTP response code from most recent response. |
| 214 size_t latest_response_code_; | 185 size_t latest_response_code_; |
| 215 // HTTP headers from most recent response. | 186 // HTTP headers from most recent response. |
| 216 std::string latest_response_headers_; | 187 std::string latest_response_headers_; |
| 217 // Body of most recent response. | 188 // Body of most recent response. |
| 218 std::string latest_response_body_; | 189 std::string latest_response_body_; |
| 219 | 190 |
| 220 // Keeps track of any data that must be resent upon a subsequent successful | |
| 221 // connection, in case the client receives a stateless reject. | |
| 222 std::vector<std::unique_ptr<QuicDataToResend>> data_to_resend_on_connect_; | |
| 223 | |
| 224 // The log used for the sockets. | 191 // The log used for the sockets. |
| 225 NetLog net_log_; | 192 NetLog net_log_; |
| 226 | 193 |
| 227 std::unique_ptr<QuicChromiumPacketReader> packet_reader_; | 194 std::unique_ptr<QuicChromiumPacketReader> packet_reader_; |
| 228 | 195 |
| 229 bool packet_reader_started_; | 196 bool packet_reader_started_; |
| 230 | 197 |
| 231 base::WeakPtrFactory<QuicSimpleClient> weak_factory_; | 198 base::WeakPtrFactory<QuicSimpleClient> weak_factory_; |
| 232 | 199 |
| 233 DISALLOW_COPY_AND_ASSIGN(QuicSimpleClient); | 200 DISALLOW_COPY_AND_ASSIGN(QuicSimpleClient); |
| 234 }; | 201 }; |
| 235 | 202 |
| 236 } // namespace net | 203 } // namespace net |
| 237 | 204 |
| 238 #endif // NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ | 205 #endif // NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ |
| OLD | NEW |