| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 base class for the toy client, which connects to a specified port and sends | 5 // A base class for the toy client, which connects to a specified port and sends |
| 6 // QUIC request to that endpoint. | 6 // QUIC request to that endpoint. |
| 7 | 7 |
| 8 #ifndef NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_ | 8 #ifndef NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_ |
| 9 #define NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_ | 9 #define NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_ |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
| 16 #include "net/log/net_log.h" | 16 #include "net/log/net_log.h" |
| 17 #include "net/quic/crypto/crypto_handshake.h" | 17 #include "net/quic/crypto/crypto_handshake.h" |
| 18 #include "net/quic/crypto/quic_crypto_client_config.h" | 18 #include "net/quic/crypto/quic_crypto_client_config.h" |
| 19 #include "net/quic/quic_alarm_factory.h" |
| 19 #include "net/quic/quic_bandwidth.h" | 20 #include "net/quic/quic_bandwidth.h" |
| 20 #include "net/quic/quic_client_push_promise_index.h" | 21 #include "net/quic/quic_client_push_promise_index.h" |
| 21 #include "net/quic/quic_config.h" | 22 #include "net/quic/quic_config.h" |
| 22 #include "net/quic/quic_connection.h" | 23 #include "net/quic/quic_connection.h" |
| 23 #include "net/quic/quic_packet_writer.h" | 24 #include "net/quic/quic_packet_writer.h" |
| 24 #include "net/quic/quic_protocol.h" | 25 #include "net/quic/quic_protocol.h" |
| 25 #include "net/tools/quic/quic_client_session.h" | 26 #include "net/tools/quic/quic_client_session.h" |
| 26 #include "net/tools/quic/quic_spdy_client_stream.h" | 27 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 27 | 28 |
| 28 namespace net { | 29 namespace net { |
| 29 | 30 |
| 30 class ProofVerifier; | 31 class ProofVerifier; |
| 31 class QuicServerId; | 32 class QuicServerId; |
| 32 | 33 |
| 33 class QuicClientBase { | 34 class QuicClientBase { |
| 34 public: | 35 public: |
| 35 QuicClientBase(const QuicServerId& server_id, | 36 QuicClientBase(const QuicServerId& server_id, |
| 36 const QuicVersionVector& supported_versions, | 37 const QuicVersionVector& supported_versions, |
| 37 const QuicConfig& config, | 38 const QuicConfig& config, |
| 38 QuicConnectionHelperInterface* helper, | 39 QuicConnectionHelperInterface* helper, |
| 40 QuicAlarmFactory* alarm_factory, |
| 39 ProofVerifier* proof_verifier); | 41 ProofVerifier* proof_verifier); |
| 40 | 42 |
| 41 ~QuicClientBase(); | 43 ~QuicClientBase(); |
| 42 | 44 |
| 43 // Initializes the client to create a connection. Should be called exactly | 45 // Initializes the client to create a connection. Should be called exactly |
| 44 // once before calling StartConnect or Connect. Returns true if the | 46 // once before calling StartConnect or Connect. Returns true if the |
| 45 // initialization succeeds, false otherwise. | 47 // initialization succeeds, false otherwise. |
| 46 virtual bool Initialize(); | 48 virtual bool Initialize(); |
| 47 | 49 |
| 48 // Returns true if the crypto handshake has yet to establish encryption. | 50 // Returns true if the crypto handshake has yet to establish encryption. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // Returns the next server-designated ConnectionId from the cached config for | 176 // Returns the next server-designated ConnectionId from the cached config for |
| 175 // |server_id_|, if it exists. Otherwise, returns 0. | 177 // |server_id_|, if it exists. Otherwise, returns 0. |
| 176 QuicConnectionId GetNextServerDesignatedConnectionId(); | 178 QuicConnectionId GetNextServerDesignatedConnectionId(); |
| 177 | 179 |
| 178 // Generates a new, random connection ID (as opposed to a server-designated | 180 // Generates a new, random connection ID (as opposed to a server-designated |
| 179 // connection ID). | 181 // connection ID). |
| 180 virtual QuicConnectionId GenerateNewConnectionId(); | 182 virtual QuicConnectionId GenerateNewConnectionId(); |
| 181 | 183 |
| 182 QuicConnectionHelperInterface* helper() { return helper_.get(); } | 184 QuicConnectionHelperInterface* helper() { return helper_.get(); } |
| 183 | 185 |
| 186 QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); } |
| 187 |
| 184 void set_num_sent_client_hellos(int num_sent_client_hellos) { | 188 void set_num_sent_client_hellos(int num_sent_client_hellos) { |
| 185 num_sent_client_hellos_ = num_sent_client_hellos; | 189 num_sent_client_hellos_ = num_sent_client_hellos; |
| 186 } | 190 } |
| 187 | 191 |
| 188 void set_num_stateless_rejects_received(int num_stateless_rejects_received) { | 192 void set_num_stateless_rejects_received(int num_stateless_rejects_received) { |
| 189 num_stateless_rejects_received_ = num_stateless_rejects_received; | 193 num_stateless_rejects_received_ = num_stateless_rejects_received; |
| 190 } | 194 } |
| 191 | 195 |
| 192 private: | 196 private: |
| 193 // |server_id_| is a tuple (hostname, port, is_https) of the server. | 197 // |server_id_| is a tuple (hostname, port, is_https) of the server. |
| 194 QuicServerId server_id_; | 198 QuicServerId server_id_; |
| 195 | 199 |
| 196 // config_ and crypto_config_ contain configuration and cached state about | 200 // config_ and crypto_config_ contain configuration and cached state about |
| 197 // servers. | 201 // servers. |
| 198 QuicConfig config_; | 202 QuicConfig config_; |
| 199 QuicCryptoClientConfig crypto_config_; | 203 QuicCryptoClientConfig crypto_config_; |
| 200 | 204 |
| 201 // Helper to be used by created connections. Needs to outlive |session_|. | 205 // Helper to be used by created connections. Needs to outlive |session_|. |
| 202 std::unique_ptr<QuicConnectionHelperInterface> helper_; | 206 std::unique_ptr<QuicConnectionHelperInterface> helper_; |
| 203 | 207 |
| 208 // Helper to be used by created connections. Needs to outlive |session_|. |
| 209 std::unique_ptr<QuicAlarmFactory> alarm_factory_; |
| 210 |
| 204 // Writer used to actually send packets to the wire. Needs to outlive | 211 // Writer used to actually send packets to the wire. Needs to outlive |
| 205 // |session_|. | 212 // |session_|. |
| 206 std::unique_ptr<QuicPacketWriter> writer_; | 213 std::unique_ptr<QuicPacketWriter> writer_; |
| 207 | 214 |
| 208 // Session which manages streams. | 215 // Session which manages streams. |
| 209 std::unique_ptr<QuicClientSession> session_; | 216 std::unique_ptr<QuicClientSession> session_; |
| 210 | 217 |
| 211 // This vector contains QUIC versions which we currently support. | 218 // This vector contains QUIC versions which we currently support. |
| 212 // This should be ordered such that the highest supported version is the first | 219 // This should be ordered such that the highest supported version is the first |
| 213 // element, with subsequent elements in descending order (versions can be | 220 // element, with subsequent elements in descending order (versions can be |
| (...skipping 27 matching lines...) Expand all Loading... |
| 241 bool connected_or_attempting_connect_; | 248 bool connected_or_attempting_connect_; |
| 242 | 249 |
| 243 QuicClientPushPromiseIndex push_promise_index_; | 250 QuicClientPushPromiseIndex push_promise_index_; |
| 244 | 251 |
| 245 DISALLOW_COPY_AND_ASSIGN(QuicClientBase); | 252 DISALLOW_COPY_AND_ASSIGN(QuicClientBase); |
| 246 }; | 253 }; |
| 247 | 254 |
| 248 } // namespace net | 255 } // namespace net |
| 249 | 256 |
| 250 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_ | 257 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_ |
| OLD | NEW |