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

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: Merge with TOT 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& server_key,
103 const QuicVersionVector& supported_versions) 104 const QuicVersionVector& supported_versions)
104 : QuicClient(server_address, server_hostname, supported_versions, false), 105 : QuicClient(server_address, server_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& server_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, server_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& server_key,
149 const QuicVersionVector& supported_versions) 151 const QuicVersionVector& supported_versions)
150 : client_(new MockableQuicClient(address, hostname, supported_versions)) { 152 : client_(new MockableQuicClient(address, server_key, supported_versions)) {
151 Initialize(address, hostname, true); 153 Initialize(address, server_key, true);
152 } 154 }
153 155
154 QuicTestClient::QuicTestClient(IPEndPoint address, 156 QuicTestClient::QuicTestClient(IPEndPoint address,
155 const string& hostname, 157 const QuicSessionKey& server_key,
156 bool secure, 158 bool secure,
157 const QuicVersionVector& supported_versions) 159 const QuicVersionVector& supported_versions)
158 : client_(new MockableQuicClient(address, hostname, supported_versions)) { 160 : client_(new MockableQuicClient(address, server_key, supported_versions)) {
159 Initialize(address, hostname, secure); 161 Initialize(address, server_key, secure);
160 } 162 }
161 163
162 QuicTestClient::QuicTestClient(IPEndPoint address, 164 QuicTestClient::QuicTestClient(IPEndPoint address,
163 const string& hostname, 165 const QuicSessionKey& server_key,
164 bool secure, 166 bool secure,
165 const QuicConfig& config, 167 const QuicConfig& config,
166 const QuicVersionVector& supported_versions) 168 const QuicVersionVector& supported_versions)
167 : client_(new MockableQuicClient( 169 : client_(new MockableQuicClient(address, server_key, config,
168 address, hostname, config, supported_versions)) { 170 supported_versions)) {
169 Initialize(address, hostname, secure); 171 Initialize(address, server_key, secure);
170 } 172 }
171 173
172 void QuicTestClient::Initialize(IPEndPoint address, 174 void QuicTestClient::Initialize(IPEndPoint address,
173 const string& hostname, 175 const QuicSessionKey& server_key,
174 bool secure) { 176 bool secure) {
175 server_address_ = address; 177 server_address_ = address;
178 server_key_ = server_key;
176 priority_ = 3; 179 priority_ = 3;
177 connect_attempted_ = false; 180 connect_attempted_ = false;
178 secure_ = secure; 181 secure_ = secure;
179 auto_reconnect_ = false; 182 auto_reconnect_ = false;
180 buffer_body_ = true; 183 buffer_body_ = true;
181 proof_verifier_ = NULL; 184 proof_verifier_ = NULL;
182 ClearPerRequestState(); 185 ClearPerRequestState();
183 ExpectCertificates(secure_); 186 ExpectCertificates(secure_);
184 } 187 }
185 188
(...skipping 18 matching lines...) Expand all
204 return SendMessage(message); 207 return SendMessage(message);
205 } 208 }
206 209
207 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { 210 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) {
208 stream_ = NULL; // Always force creation of a stream for SendMessage. 211 stream_ = NULL; // Always force creation of a stream for SendMessage.
209 212
210 // If we're not connected, try to find an sni hostname. 213 // If we're not connected, try to find an sni hostname.
211 if (!connected()) { 214 if (!connected()) {
212 GURL url(message.headers()->request_uri().as_string()); 215 GURL url(message.headers()->request_uri().as_string());
213 if (!url.host().empty()) { 216 if (!url.host().empty()) {
214 client_->set_server_hostname(url.host()); 217 client_->set_server_key(
218 QuicSessionKey(url.host(), url.EffectiveIntPort(),
219 url.SchemeIs("https") ? true : false));
215 } 220 }
216 } 221 }
217 222
218 QuicSpdyClientStream* stream = GetOrCreateStream(); 223 QuicSpdyClientStream* stream = GetOrCreateStream();
219 if (!stream) { return 0; } 224 if (!stream) { return 0; }
220 225
221 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), 226 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(),
222 secure_)); 227 secure_));
223 ssize_t ret = GetOrCreateStream()->SendRequest( 228 ssize_t ret = GetOrCreateStream()->SendRequest(
224 munged_headers.get() ? *munged_headers.get() : *message.headers(), 229 munged_headers.get() ? *munged_headers.get() : *message.headers(),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 290
286 const string& QuicTestClient::cert_common_name() const { 291 const string& QuicTestClient::cert_common_name() const {
287 return reinterpret_cast<RecordingProofVerifier*>(proof_verifier_) 292 return reinterpret_cast<RecordingProofVerifier*>(proof_verifier_)
288 ->common_name(); 293 ->common_name();
289 } 294 }
290 295
291 QuicTagValueMap QuicTestClient::GetServerConfig() const { 296 QuicTagValueMap QuicTestClient::GetServerConfig() const {
292 net::QuicCryptoClientConfig* config = 297 net::QuicCryptoClientConfig* config =
293 QuicClientPeer::GetCryptoConfig(client_.get()); 298 QuicClientPeer::GetCryptoConfig(client_.get());
294 net::QuicCryptoClientConfig::CachedState* state = 299 net::QuicCryptoClientConfig::CachedState* state =
295 config->LookupOrCreate(client_->server_hostname()); 300 config->LookupOrCreate(client_->server_key());
296 const net::CryptoHandshakeMessage* handshake_msg = state->GetServerConfig(); 301 const net::CryptoHandshakeMessage* handshake_msg = state->GetServerConfig();
297 if (handshake_msg != NULL) { 302 if (handshake_msg != NULL) {
298 return handshake_msg->tag_value_map(); 303 return handshake_msg->tag_value_map();
299 } else { 304 } else {
300 return QuicTagValueMap(); 305 return QuicTagValueMap();
301 } 306 }
302 } 307 }
303 308
304 bool QuicTestClient::connected() const { 309 bool QuicTestClient::connected() const {
305 return client_->connected(); 310 return client_->connected();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 460
456 void QuicTestClient::WaitForWriteToFlush() { 461 void QuicTestClient::WaitForWriteToFlush() {
457 while (connected() && client()->session()->HasDataToWrite()) { 462 while (connected() && client()->session()->HasDataToWrite()) {
458 client_->WaitForEvents(); 463 client_->WaitForEvents();
459 } 464 }
460 } 465 }
461 466
462 } // namespace test 467 } // namespace test
463 } // namespace tools 468 } // namespace tools
464 } // namespace net 469 } // namespace net
OLDNEW
« net/quic/quic_session_key.h ('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