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

Side by Side Diff: net/tools/quic/test_tools/quic_test_client.cc

Issue 192583004: QUIC - use QuicSessionKey tuple (host, port, is_https) instead of server_hostname (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use QuicSessionKey as arg and delete server_hostname as arg Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
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 #include "net/tools/quic/test_tools/quic_test_client.h" 5 #include "net/tools/quic/test_tools/quic_test_client.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "net/base/completion_callback.h" 8 #include "net/base/completion_callback.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/cert/cert_verify_result.h" 10 #include "net/cert/cert_verify_result.h"
11 #include "net/cert/x509_certificate.h" 11 #include "net/cert/x509_certificate.h"
12 #include "net/quic/crypto/proof_verifier.h" 12 #include "net/quic/crypto/proof_verifier.h"
13 #include "net/quic/quic_session_key.h"
13 #include "net/quic/test_tools/quic_connection_peer.h" 14 #include "net/quic/test_tools/quic_connection_peer.h"
14 #include "net/tools/balsa/balsa_headers.h" 15 #include "net/tools/balsa/balsa_headers.h"
15 #include "net/tools/quic/quic_epoll_connection_helper.h" 16 #include "net/tools/quic/quic_epoll_connection_helper.h"
16 #include "net/tools/quic/quic_packet_writer_wrapper.h" 17 #include "net/tools/quic/quic_packet_writer_wrapper.h"
17 #include "net/tools/quic/quic_spdy_client_stream.h" 18 #include "net/tools/quic/quic_spdy_client_stream.h"
18 #include "net/tools/quic/test_tools/http_message.h" 19 #include "net/tools/quic/test_tools/http_message.h"
19 #include "net/tools/quic/test_tools/quic_client_peer.h" 20 #include "net/tools/quic/test_tools/quic_client_peer.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 using base::StringPiece; 23 using base::StringPiece;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 full_uri.append(uri.as_string()); 93 full_uri.append(uri.as_string());
93 headers->SetRequestUri(full_uri); 94 headers->SetRequestUri(full_uri);
94 } 95 }
95 return headers; 96 return headers;
96 } 97 }
97 98
98 // A quic client which allows mocking out writes. 99 // A quic client which allows mocking out writes.
99 class MockableQuicClient : public QuicClient { 100 class MockableQuicClient : public QuicClient {
100 public: 101 public:
101 MockableQuicClient(IPEndPoint server_address, 102 MockableQuicClient(IPEndPoint server_address,
102 const string& server_hostname, 103 const QuicSessionKey& session_key,
103 const QuicVersionVector& supported_versions) 104 const QuicVersionVector& supported_versions)
104 : QuicClient(server_address, server_hostname, supported_versions, false), 105 : QuicClient(server_address, session_key, supported_versions, false),
105 override_connection_id_(0), 106 override_connection_id_(0),
106 test_writer_(NULL) {} 107 test_writer_(NULL) {}
107 108
108 MockableQuicClient(IPEndPoint server_address, 109 MockableQuicClient(IPEndPoint server_address,
109 const string& server_hostname, 110 const QuicSessionKey& session_key,
110 const QuicConfig& config, 111 const QuicConfig& config,
111 const QuicVersionVector& supported_versions) 112 const QuicVersionVector& supported_versions)
112 : QuicClient(server_address, server_hostname, config, supported_versions), 113 : QuicClient(server_address, session_key, config, supported_versions),
113 override_connection_id_(0), 114 override_connection_id_(0),
114 test_writer_(NULL) {} 115 test_writer_(NULL) {}
115 116
116 virtual ~MockableQuicClient() { 117 virtual ~MockableQuicClient() {
117 if (connected()) { 118 if (connected()) {
118 Disconnect(); 119 Disconnect();
119 } 120 }
120 } 121 }
121 122
122 virtual QuicPacketWriter* CreateQuicPacketWriter() OVERRIDE { 123 virtual QuicPacketWriter* CreateQuicPacketWriter() OVERRIDE {
(...skipping 15 matching lines...) Expand all
138 139
139 void UseConnectionId(QuicConnectionId connection_id) { 140 void UseConnectionId(QuicConnectionId connection_id) {
140 override_connection_id_ = connection_id; 141 override_connection_id_ = connection_id;
141 } 142 }
142 143
143 private: 144 private:
144 QuicConnectionId override_connection_id_; // ConnectionId to use, if nonzero 145 QuicConnectionId override_connection_id_; // ConnectionId to use, if nonzero
145 QuicPacketWriterWrapper* test_writer_; 146 QuicPacketWriterWrapper* test_writer_;
146 }; 147 };
147 148
148 QuicTestClient::QuicTestClient(IPEndPoint address, const string& hostname, 149 QuicTestClient::QuicTestClient(IPEndPoint address,
150 const QuicSessionKey& session_key,
149 const QuicVersionVector& supported_versions) 151 const QuicVersionVector& supported_versions)
150 : client_(new MockableQuicClient(address, hostname, supported_versions)) { 152 : client_(new MockableQuicClient(address, session_key,
151 Initialize(address, hostname, true); 153 supported_versions)) {
154 Initialize(address, session_key, true);
152 } 155 }
153 156
154 QuicTestClient::QuicTestClient(IPEndPoint address, 157 QuicTestClient::QuicTestClient(IPEndPoint address,
155 const string& hostname, 158 const QuicSessionKey& session_key,
156 bool secure, 159 bool secure,
157 const QuicVersionVector& supported_versions) 160 const QuicVersionVector& supported_versions)
158 : client_(new MockableQuicClient(address, hostname, supported_versions)) { 161 : client_(new MockableQuicClient(address, session_key,
159 Initialize(address, hostname, secure); 162 supported_versions)) {
163 Initialize(address, session_key, secure);
160 } 164 }
161 165
162 QuicTestClient::QuicTestClient(IPEndPoint address, 166 QuicTestClient::QuicTestClient(IPEndPoint address,
163 const string& hostname, 167 const QuicSessionKey& session_key,
164 bool secure, 168 bool secure,
165 const QuicConfig& config, 169 const QuicConfig& config,
166 const QuicVersionVector& supported_versions) 170 const QuicVersionVector& supported_versions)
167 : client_(new MockableQuicClient( 171 : client_(new MockableQuicClient(address, session_key, config,
168 address, hostname, config, supported_versions)) { 172 supported_versions)) {
169 Initialize(address, hostname, secure); 173 Initialize(address, session_key, secure);
170 } 174 }
171 175
172 void QuicTestClient::Initialize(IPEndPoint address, 176 void QuicTestClient::Initialize(IPEndPoint address,
173 const string& hostname, 177 const QuicSessionKey& session_key,
174 bool secure) { 178 bool secure) {
175 server_address_ = address; 179 server_address_ = address;
180 session_key_ = session_key;
176 priority_ = 3; 181 priority_ = 3;
177 connect_attempted_ = false; 182 connect_attempted_ = false;
178 secure_ = secure; 183 secure_ = secure;
179 auto_reconnect_ = false; 184 auto_reconnect_ = false;
180 buffer_body_ = true; 185 buffer_body_ = true;
181 proof_verifier_ = NULL; 186 proof_verifier_ = NULL;
182 ClearPerRequestState(); 187 ClearPerRequestState();
183 ExpectCertificates(secure_); 188 ExpectCertificates(secure_);
184 } 189 }
185 190
(...skipping 18 matching lines...) Expand all
204 return SendMessage(message); 209 return SendMessage(message);
205 } 210 }
206 211
207 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { 212 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) {
208 stream_ = NULL; // Always force creation of a stream for SendMessage. 213 stream_ = NULL; // Always force creation of a stream for SendMessage.
209 214
210 // If we're not connected, try to find an sni hostname. 215 // If we're not connected, try to find an sni hostname.
211 if (!connected()) { 216 if (!connected()) {
212 GURL url(message.headers()->request_uri().as_string()); 217 GURL url(message.headers()->request_uri().as_string());
213 if (!url.host().empty()) { 218 if (!url.host().empty()) {
214 client_->set_server_hostname(url.host()); 219 client_->set_session_key(
220 QuicSessionKey(url.host(), url.EffectiveIntPort(),
221 url.SchemeIs("https") ? true : false));
215 } 222 }
216 } 223 }
217 224
218 QuicSpdyClientStream* stream = GetOrCreateStream(); 225 QuicSpdyClientStream* stream = GetOrCreateStream();
219 if (!stream) { return 0; } 226 if (!stream) { return 0; }
220 227
221 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), 228 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(),
222 secure_)); 229 secure_));
223 ssize_t ret = GetOrCreateStream()->SendRequest( 230 ssize_t ret = GetOrCreateStream()->SendRequest(
224 munged_headers.get() ? *munged_headers.get() : *message.headers(), 231 munged_headers.get() ? *munged_headers.get() : *message.headers(),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 292
286 const string& QuicTestClient::cert_common_name() const { 293 const string& QuicTestClient::cert_common_name() const {
287 return reinterpret_cast<RecordingProofVerifier*>(proof_verifier_) 294 return reinterpret_cast<RecordingProofVerifier*>(proof_verifier_)
288 ->common_name(); 295 ->common_name();
289 } 296 }
290 297
291 QuicTagValueMap QuicTestClient::GetServerConfig() const { 298 QuicTagValueMap QuicTestClient::GetServerConfig() const {
292 net::QuicCryptoClientConfig* config = 299 net::QuicCryptoClientConfig* config =
293 QuicClientPeer::GetCryptoConfig(client_.get()); 300 QuicClientPeer::GetCryptoConfig(client_.get());
294 net::QuicCryptoClientConfig::CachedState* state = 301 net::QuicCryptoClientConfig::CachedState* state =
295 config->LookupOrCreate(client_->server_hostname()); 302 config->LookupOrCreate(client_->session_key());
296 const net::CryptoHandshakeMessage* handshake_msg = state->GetServerConfig(); 303 const net::CryptoHandshakeMessage* handshake_msg = state->GetServerConfig();
297 if (handshake_msg != NULL) { 304 if (handshake_msg != NULL) {
298 return handshake_msg->tag_value_map(); 305 return handshake_msg->tag_value_map();
299 } else { 306 } else {
300 return QuicTagValueMap(); 307 return QuicTagValueMap();
301 } 308 }
302 } 309 }
303 310
304 bool QuicTestClient::connected() const { 311 bool QuicTestClient::connected() const {
305 return client_->connected(); 312 return client_->connected();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 462
456 void QuicTestClient::WaitForWriteToFlush() { 463 void QuicTestClient::WaitForWriteToFlush() {
457 while (connected() && client()->session()->HasDataToWrite()) { 464 while (connected() && client()->session()->HasDataToWrite()) {
458 client_->WaitForEvents(); 465 client_->WaitForEvents();
459 } 466 }
460 } 467 }
461 468
462 } // namespace test 469 } // namespace test
463 } // namespace tools 470 } // namespace tools
464 } // namespace net 471 } // namespace net
OLDNEW
« net/tools/quic/quic_client_bin.cc ('K') | « net/tools/quic/test_tools/quic_test_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698