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 <string> | 11 #include <string> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "net/quic/core/crypto/crypto_handshake.h" | 14 #include "net/quic/core/crypto/crypto_handshake.h" |
15 #include "net/quic/core/quic_client_push_promise_index.h" | 15 #include "net/quic/core/quic_client_push_promise_index.h" |
16 #include "net/quic/core/quic_config.h" | 16 #include "net/quic/core/quic_config.h" |
17 #include "net/quic/platform/api/quic_socket_address.h" | 17 #include "net/quic/platform/api/quic_socket_address.h" |
| 18 #include "net/quic/platform/api/quic_string_piece.h" |
18 #include "net/tools/quic/quic_client_session.h" | 19 #include "net/tools/quic/quic_client_session.h" |
19 #include "net/tools/quic/quic_spdy_client_stream.h" | 20 #include "net/tools/quic/quic_spdy_client_stream.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 class ProofVerifier; | 24 class ProofVerifier; |
24 class QuicServerId; | 25 class QuicServerId; |
25 | 26 |
26 class QuicClientBase : public QuicClientPushPromiseIndex::Delegate, | 27 class QuicClientBase : public QuicClientPushPromiseIndex::Delegate, |
27 public QuicSpdyStream::Visitor { | 28 public QuicSpdyStream::Visitor { |
(...skipping 12 matching lines...) Expand all Loading... |
40 // receipt of a stateless reject. Recall that the client API allows callers | 41 // receipt of a stateless reject. Recall that the client API allows callers |
41 // to optimistically send data to the server prior to handshake-confirmation. | 42 // to optimistically send data to the server prior to handshake-confirmation. |
42 // If the client subsequently receives a stateless reject, it must tear down | 43 // If the client subsequently receives a stateless reject, it must tear down |
43 // its existing session, create a new session, and resend all previously sent | 44 // its existing session, create a new session, and resend all previously sent |
44 // data. It uses these objects to keep track of all the sent data, and to | 45 // data. It uses these objects to keep track of all the sent data, and to |
45 // resend the data upon a subsequent connection. | 46 // resend the data upon a subsequent connection. |
46 class QuicDataToResend { | 47 class QuicDataToResend { |
47 public: | 48 public: |
48 // |headers| may be null, since it's possible to send data without headers. | 49 // |headers| may be null, since it's possible to send data without headers. |
49 QuicDataToResend(std::unique_ptr<SpdyHeaderBlock> headers, | 50 QuicDataToResend(std::unique_ptr<SpdyHeaderBlock> headers, |
50 base::StringPiece body, | 51 QuicStringPiece body, |
51 bool fin); | 52 bool fin); |
52 | 53 |
53 virtual ~QuicDataToResend(); | 54 virtual ~QuicDataToResend(); |
54 | 55 |
55 // Must be overridden by specific classes with the actual method for | 56 // Must be overridden by specific classes with the actual method for |
56 // re-sending data. | 57 // re-sending data. |
57 virtual void Resend() = 0; | 58 virtual void Resend() = 0; |
58 | 59 |
59 protected: | 60 protected: |
60 std::unique_ptr<SpdyHeaderBlock> headers_; | 61 std::unique_ptr<SpdyHeaderBlock> headers_; |
61 base::StringPiece body_; | 62 QuicStringPiece body_; |
62 bool fin_; | 63 bool fin_; |
63 | 64 |
64 private: | 65 private: |
65 DISALLOW_COPY_AND_ASSIGN(QuicDataToResend); | 66 DISALLOW_COPY_AND_ASSIGN(QuicDataToResend); |
66 }; | 67 }; |
67 | 68 |
68 QuicClientBase(const QuicServerId& server_id, | 69 QuicClientBase(const QuicServerId& server_id, |
69 const QuicVersionVector& supported_versions, | 70 const QuicVersionVector& supported_versions, |
70 const QuicConfig& config, | 71 const QuicConfig& config, |
71 QuicConnectionHelperInterface* helper, | 72 QuicConnectionHelperInterface* helper, |
(...skipping 22 matching lines...) Expand all Loading... |
94 // Disconnects from the QUIC server. | 95 // Disconnects from the QUIC server. |
95 void Disconnect(); | 96 void Disconnect(); |
96 | 97 |
97 // Returns true if the crypto handshake has yet to establish encryption. | 98 // Returns true if the crypto handshake has yet to establish encryption. |
98 // Returns false if encryption is active (even if the server hasn't confirmed | 99 // Returns false if encryption is active (even if the server hasn't confirmed |
99 // the handshake) or if the connection has been closed. | 100 // the handshake) or if the connection has been closed. |
100 bool EncryptionBeingEstablished(); | 101 bool EncryptionBeingEstablished(); |
101 | 102 |
102 // Sends an HTTP request and does not wait for response before returning. | 103 // Sends an HTTP request and does not wait for response before returning. |
103 void SendRequest(const SpdyHeaderBlock& headers, | 104 void SendRequest(const SpdyHeaderBlock& headers, |
104 base::StringPiece body, | 105 QuicStringPiece body, |
105 bool fin); | 106 bool fin); |
106 | 107 |
107 // Sends an HTTP request and waits for response before returning. | 108 // Sends an HTTP request and waits for response before returning. |
108 void SendRequestAndWaitForResponse(const SpdyHeaderBlock& headers, | 109 void SendRequestAndWaitForResponse(const SpdyHeaderBlock& headers, |
109 base::StringPiece body, | 110 QuicStringPiece body, |
110 bool fin); | 111 bool fin); |
111 | 112 |
112 // Sends a request simple GET for each URL in |url_list|, and then waits for | 113 // Sends a request simple GET for each URL in |url_list|, and then waits for |
113 // each to complete. | 114 // each to complete. |
114 void SendRequestsAndWaitForResponse(const std::vector<std::string>& url_list); | 115 void SendRequestsAndWaitForResponse(const std::vector<std::string>& url_list); |
115 | 116 |
116 // Returns a newly created QuicSpdyClientStream, owned by the | 117 // Returns a newly created QuicSpdyClientStream, owned by the |
117 // QuicSimpleClient. | 118 // QuicSimpleClient. |
118 virtual QuicSpdyClientStream* CreateClientStream(); | 119 virtual QuicSpdyClientStream* CreateClientStream(); |
119 | 120 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 QuicConnectionId GetNextServerDesignatedConnectionId(); | 315 QuicConnectionId GetNextServerDesignatedConnectionId(); |
315 | 316 |
316 // Generates a new, random connection ID (as opposed to a server-designated | 317 // Generates a new, random connection ID (as opposed to a server-designated |
317 // connection ID). | 318 // connection ID). |
318 virtual QuicConnectionId GenerateNewConnectionId(); | 319 virtual QuicConnectionId GenerateNewConnectionId(); |
319 | 320 |
320 // If the crypto handshake has not yet been confirmed, adds the data to the | 321 // If the crypto handshake has not yet been confirmed, adds the data to the |
321 // queue of data to resend if the client receives a stateless reject. | 322 // queue of data to resend if the client receives a stateless reject. |
322 // Otherwise, deletes the data. | 323 // Otherwise, deletes the data. |
323 void MaybeAddDataToResend(const SpdyHeaderBlock& headers, | 324 void MaybeAddDataToResend(const SpdyHeaderBlock& headers, |
324 base::StringPiece body, | 325 QuicStringPiece body, |
325 bool fin); | 326 bool fin); |
326 | 327 |
327 void ClearDataToResend(); | 328 void ClearDataToResend(); |
328 | 329 |
329 void ResendSavedData(); | 330 void ResendSavedData(); |
330 | 331 |
331 void AddPromiseDataToResend(const SpdyHeaderBlock& headers, | 332 void AddPromiseDataToResend(const SpdyHeaderBlock& headers, |
332 base::StringPiece body, | 333 QuicStringPiece body, |
333 bool fin); | 334 bool fin); |
334 | 335 |
335 QuicConnectionHelperInterface* helper() { return helper_.get(); } | 336 QuicConnectionHelperInterface* helper() { return helper_.get(); } |
336 | 337 |
337 QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); } | 338 QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); } |
338 | 339 |
339 void set_num_sent_client_hellos(int num_sent_client_hellos) { | 340 void set_num_sent_client_hellos(int num_sent_client_hellos) { |
340 num_sent_client_hellos_ = num_sent_client_hellos; | 341 num_sent_client_hellos_ = num_sent_client_hellos; |
341 } | 342 } |
342 | 343 |
343 void set_num_stateless_rejects_received(int num_stateless_rejects_received) { | 344 void set_num_stateless_rejects_received(int num_stateless_rejects_received) { |
344 num_stateless_rejects_received_ = num_stateless_rejects_received; | 345 num_stateless_rejects_received_ = num_stateless_rejects_received; |
345 } | 346 } |
346 | 347 |
347 private: | 348 private: |
348 // Specific QuicClient class for storing data to resend. | 349 // Specific QuicClient class for storing data to resend. |
349 class ClientQuicDataToResend : public QuicDataToResend { | 350 class ClientQuicDataToResend : public QuicDataToResend { |
350 public: | 351 public: |
351 ClientQuicDataToResend(std::unique_ptr<SpdyHeaderBlock> headers, | 352 ClientQuicDataToResend(std::unique_ptr<SpdyHeaderBlock> headers, |
352 base::StringPiece body, | 353 QuicStringPiece body, |
353 bool fin, | 354 bool fin, |
354 QuicClientBase* client) | 355 QuicClientBase* client) |
355 : QuicDataToResend(std::move(headers), body, fin), client_(client) { | 356 : QuicDataToResend(std::move(headers), body, fin), client_(client) { |
356 DCHECK(headers_); | 357 DCHECK(headers_); |
357 DCHECK(client); | 358 DCHECK(client); |
358 } | 359 } |
359 | 360 |
360 ~ClientQuicDataToResend() override {} | 361 ~ClientQuicDataToResend() override {} |
361 | 362 |
362 void Resend() override; | 363 void Resend() override; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 std::vector<std::unique_ptr<QuicDataToResend>> data_to_resend_on_connect_; | 458 std::vector<std::unique_ptr<QuicDataToResend>> data_to_resend_on_connect_; |
458 | 459 |
459 std::unique_ptr<ClientQuicDataToResend> push_promise_data_to_resend_; | 460 std::unique_ptr<ClientQuicDataToResend> push_promise_data_to_resend_; |
460 | 461 |
461 DISALLOW_COPY_AND_ASSIGN(QuicClientBase); | 462 DISALLOW_COPY_AND_ASSIGN(QuicClientBase); |
462 }; | 463 }; |
463 | 464 |
464 } // namespace net | 465 } // namespace net |
465 | 466 |
466 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_ | 467 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_ |
OLD | NEW |