Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: net/tools/quic/quic_client_base.h

Issue 2368183003: Move QuicClient::ClientQuicDataToResend from QuicClient to QuicClientBase. (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/quic_client.cc ('k') | net/tools/quic/quic_client_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 13 matching lines...) Expand all
24 #include "net/quic/core/quic_packet_writer.h" 24 #include "net/quic/core/quic_packet_writer.h"
25 #include "net/quic/core/quic_protocol.h" 25 #include "net/quic/core/quic_protocol.h"
26 #include "net/tools/quic/quic_client_session.h" 26 #include "net/tools/quic/quic_client_session.h"
27 #include "net/tools/quic/quic_spdy_client_stream.h" 27 #include "net/tools/quic/quic_spdy_client_stream.h"
28 28
29 namespace net { 29 namespace net {
30 30
31 class ProofVerifier; 31 class ProofVerifier;
32 class QuicServerId; 32 class QuicServerId;
33 33
34 class QuicClientBase { 34 class QuicClientBase : public QuicClientPushPromiseIndex::Delegate,
35 public QuicSpdyStream::Visitor {
35 public: 36 public:
36 // The client uses these objects to keep track of any data to resend upon 37 // The client uses these objects to keep track of any data to resend upon
37 // receipt of a stateless reject. Recall that the client API allows callers 38 // receipt of a stateless reject. Recall that the client API allows callers
38 // to optimistically send data to the server prior to handshake-confirmation. 39 // to optimistically send data to the server prior to handshake-confirmation.
39 // If the client subsequently receives a stateless reject, it must tear down 40 // If the client subsequently receives a stateless reject, it must tear down
40 // its existing session, create a new session, and resend all previously sent 41 // its existing session, create a new session, and resend all previously sent
41 // data. It uses these objects to keep track of all the sent data, and to 42 // data. It uses these objects to keep track of all the sent data, and to
42 // resend the data upon a subsequent connection. 43 // resend the data upon a subsequent connection.
43 class QuicDataToResend { 44 class QuicDataToResend {
44 public: 45 public:
(...skipping 17 matching lines...) Expand all
62 DISALLOW_COPY_AND_ASSIGN(QuicDataToResend); 63 DISALLOW_COPY_AND_ASSIGN(QuicDataToResend);
63 }; 64 };
64 65
65 QuicClientBase(const QuicServerId& server_id, 66 QuicClientBase(const QuicServerId& server_id,
66 const QuicVersionVector& supported_versions, 67 const QuicVersionVector& supported_versions,
67 const QuicConfig& config, 68 const QuicConfig& config,
68 QuicConnectionHelperInterface* helper, 69 QuicConnectionHelperInterface* helper,
69 QuicAlarmFactory* alarm_factory, 70 QuicAlarmFactory* alarm_factory,
70 std::unique_ptr<ProofVerifier> proof_verifier); 71 std::unique_ptr<ProofVerifier> proof_verifier);
71 72
72 ~QuicClientBase(); 73 ~QuicClientBase() override;
73 74
74 // Initializes the client to create a connection. Should be called exactly 75 // Initializes the client to create a connection. Should be called exactly
75 // once before calling StartConnect or Connect. Returns true if the 76 // once before calling StartConnect or Connect. Returns true if the
76 // initialization succeeds, false otherwise. 77 // initialization succeeds, false otherwise.
77 virtual bool Initialize(); 78 virtual bool Initialize();
78 79
79 // Returns true if the crypto handshake has yet to establish encryption. 80 // Returns true if the crypto handshake has yet to establish encryption.
80 // Returns false if encryption is active (even if the server hasn't confirmed 81 // Returns false if encryption is active (even if the server hasn't confirmed
81 // the handshake) or if the connection has been closed. 82 // the handshake) or if the connection has been closed.
82 bool EncryptionBeingEstablished(); 83 bool EncryptionBeingEstablished();
83 84
84 // Returns a newly created QuicSpdyClientStream, owned by the 85 // Returns a newly created QuicSpdyClientStream, owned by the
85 // QuicSimpleClient. 86 // QuicSimpleClient.
86 virtual QuicSpdyClientStream* CreateReliableClientStream(); 87 virtual QuicSpdyClientStream* CreateReliableClientStream();
87 88
88 // Wait for events until the stream with the given ID is closed. 89 // Wait for events until the stream with the given ID is closed.
89 void WaitForStreamToClose(QuicStreamId id); 90 void WaitForStreamToClose(QuicStreamId id);
90 91
91 // Wait for events until the handshake is confirmed. 92 // Wait for events until the handshake is confirmed.
92 void WaitForCryptoHandshakeConfirmed(); 93 void WaitForCryptoHandshakeConfirmed();
93 94
95 // Sends an HTTP request and does not wait for response before returning.
96 virtual void SendRequest(const SpdyHeaderBlock& headers,
97 base::StringPiece body,
98 bool fin) = 0;
99
94 // Wait up to 50ms, and handle any events which occur. 100 // Wait up to 50ms, and handle any events which occur.
95 // Returns true if there are any outstanding requests. 101 // Returns true if there are any outstanding requests.
96 virtual bool WaitForEvents() = 0; 102 virtual bool WaitForEvents() = 0;
97 103
98 QuicClientSession* session() { return session_.get(); } 104 QuicClientSession* session() { return session_.get(); }
99 105
100 bool connected() const; 106 bool connected() const;
101 bool goaway_received() const; 107 bool goaway_received() const;
102 108
103 const QuicServerId& server_id() const { return server_id_; } 109 const QuicServerId& server_id() const { return server_id_; }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 203 }
198 204
199 ProofVerifier* proof_verifier() const; 205 ProofVerifier* proof_verifier() const;
200 206
201 void set_session(QuicClientSession* session) { session_.reset(session); } 207 void set_session(QuicClientSession* session) { session_.reset(session); }
202 208
203 QuicClientPushPromiseIndex* push_promise_index() { 209 QuicClientPushPromiseIndex* push_promise_index() {
204 return &push_promise_index_; 210 return &push_promise_index_;
205 } 211 }
206 212
213 bool CheckVary(const SpdyHeaderBlock& client_request,
214 const SpdyHeaderBlock& promise_request,
215 const SpdyHeaderBlock& promise_response) override;
216 void OnRendezvousResult(QuicSpdyStream*) override;
217
218 // If the crypto handshake has not yet been confirmed, adds the data to the
219 // queue of data to resend if the client receives a stateless reject.
220 // Otherwise, deletes the data.
221 void MaybeAddQuicDataToResend(
222 std::unique_ptr<QuicDataToResend> data_to_resend);
223
207 protected: 224 protected:
208 // Takes ownership of |connection|. 225 // Takes ownership of |connection|.
209 virtual QuicClientSession* CreateQuicClientSession( 226 virtual QuicClientSession* CreateQuicClientSession(
210 QuicConnection* connection); 227 QuicConnection* connection);
211 228
212 // Generates the next ConnectionId for |server_id_|. By default, if the 229 // Generates the next ConnectionId for |server_id_|. By default, if the
213 // cached server config contains a server-designated ID, that ID will be 230 // cached server config contains a server-designated ID, that ID will be
214 // returned. Otherwise, the next random ID will be returned. 231 // returned. Otherwise, the next random ID will be returned.
215 QuicConnectionId GetNextConnectionId(); 232 QuicConnectionId GetNextConnectionId();
216 233
217 // Returns the next server-designated ConnectionId from the cached config for 234 // Returns the next server-designated ConnectionId from the cached config for
218 // |server_id_|, if it exists. Otherwise, returns 0. 235 // |server_id_|, if it exists. Otherwise, returns 0.
219 QuicConnectionId GetNextServerDesignatedConnectionId(); 236 QuicConnectionId GetNextServerDesignatedConnectionId();
220 237
221 // Generates a new, random connection ID (as opposed to a server-designated 238 // Generates a new, random connection ID (as opposed to a server-designated
222 // connection ID). 239 // connection ID).
223 virtual QuicConnectionId GenerateNewConnectionId(); 240 virtual QuicConnectionId GenerateNewConnectionId();
224 241
242 // If the crypto handshake has not yet been confirmed, adds the data to the
243 // queue of data to resend if the client receives a stateless reject.
244 // Otherwise, deletes the data.
245 void MaybeAddDataToResend(const SpdyHeaderBlock& headers,
246 base::StringPiece body,
247 bool fin);
248
249 void ClearDataToResend();
250
251 void ResendSavedData();
252
253 void AddPromiseDataToResend(const SpdyHeaderBlock& headers,
254 base::StringPiece body,
255 bool fin);
256
225 QuicConnectionHelperInterface* helper() { return helper_.get(); } 257 QuicConnectionHelperInterface* helper() { return helper_.get(); }
226 258
227 QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); } 259 QuicAlarmFactory* alarm_factory() { return alarm_factory_.get(); }
228 260
229 void set_num_sent_client_hellos(int num_sent_client_hellos) { 261 void set_num_sent_client_hellos(int num_sent_client_hellos) {
230 num_sent_client_hellos_ = num_sent_client_hellos; 262 num_sent_client_hellos_ = num_sent_client_hellos;
231 } 263 }
232 264
233 void set_num_stateless_rejects_received(int num_stateless_rejects_received) { 265 void set_num_stateless_rejects_received(int num_stateless_rejects_received) {
234 num_stateless_rejects_received_ = num_stateless_rejects_received; 266 num_stateless_rejects_received_ = num_stateless_rejects_received;
235 } 267 }
236 268
237 private: 269 private:
270 // Specific QuicClient class for storing data to resend.
271 class ClientQuicDataToResend : public QuicDataToResend {
272 public:
273 ClientQuicDataToResend(std::unique_ptr<SpdyHeaderBlock> headers,
274 base::StringPiece body,
275 bool fin,
276 QuicClientBase* client)
277 : QuicDataToResend(std::move(headers), body, fin), client_(client) {
278 DCHECK(headers_);
279 DCHECK(client);
280 }
281
282 ~ClientQuicDataToResend() override {}
283
284 void Resend() override;
285
286 private:
287 QuicClientBase* client_;
288
289 DISALLOW_COPY_AND_ASSIGN(ClientQuicDataToResend);
290 };
291
238 // |server_id_| is a tuple (hostname, port, is_https) of the server. 292 // |server_id_| is a tuple (hostname, port, is_https) of the server.
239 QuicServerId server_id_; 293 QuicServerId server_id_;
240 294
241 // config_ and crypto_config_ contain configuration and cached state about 295 // config_ and crypto_config_ contain configuration and cached state about
242 // servers. 296 // servers.
243 QuicConfig config_; 297 QuicConfig config_;
244 QuicCryptoClientConfig crypto_config_; 298 QuicCryptoClientConfig crypto_config_;
245 299
246 // Helper to be used by created connections. Needs to outlive |session_|. 300 // Helper to be used by created connections. Needs to outlive |session_|.
247 std::unique_ptr<QuicConnectionHelperInterface> helper_; 301 std::unique_ptr<QuicConnectionHelperInterface> helper_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 337
284 // True when the client is attempting to connect or re-connect the session (in 338 // True when the client is attempting to connect or re-connect the session (in
285 // the case of a stateless reject). Set to false between a call to 339 // the case of a stateless reject). Set to false between a call to
286 // Disconnect() and the subsequent call to StartConnect(). When 340 // Disconnect() and the subsequent call to StartConnect(). When
287 // connected_or_attempting_connect_ is false, the session object corresponds 341 // connected_or_attempting_connect_ is false, the session object corresponds
288 // to the previous client-level connection. 342 // to the previous client-level connection.
289 bool connected_or_attempting_connect_; 343 bool connected_or_attempting_connect_;
290 344
291 QuicClientPushPromiseIndex push_promise_index_; 345 QuicClientPushPromiseIndex push_promise_index_;
292 346
347 // Keeps track of any data that must be resent upon a subsequent successful
348 // connection, in case the client receives a stateless reject.
349 std::vector<std::unique_ptr<QuicDataToResend>> data_to_resend_on_connect_;
350
351 std::unique_ptr<ClientQuicDataToResend> push_promise_data_to_resend_;
352
293 DISALLOW_COPY_AND_ASSIGN(QuicClientBase); 353 DISALLOW_COPY_AND_ASSIGN(QuicClientBase);
294 }; 354 };
295 355
296 } // namespace net 356 } // namespace net
297 357
298 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_ 358 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_BASE_H_
OLDNEW
« no previous file with comments | « net/tools/quic/quic_client.cc ('k') | net/tools/quic/quic_client_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698