OLD | NEW |
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/quic_server_id.h" |
14 #include "net/quic/test_tools/quic_connection_peer.h" | 14 #include "net/quic/test_tools/quic_connection_peer.h" |
15 #include "net/quic/test_tools/quic_test_utils.h" | 15 #include "net/quic/test_tools/quic_test_utils.h" |
16 #include "net/tools/balsa/balsa_headers.h" | 16 #include "net/tools/balsa/balsa_headers.h" |
17 #include "net/tools/quic/quic_epoll_connection_helper.h" | 17 #include "net/tools/quic/quic_epoll_connection_helper.h" |
18 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 18 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
19 #include "net/tools/quic/quic_spdy_client_stream.h" | 19 #include "net/tools/quic/quic_spdy_client_stream.h" |
20 #include "net/tools/quic/test_tools/http_message.h" | 20 #include "net/tools/quic/test_tools/http_message.h" |
21 #include "net/tools/quic/test_tools/quic_client_peer.h" | 21 #include "net/tools/quic/test_tools/quic_client_peer.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 | 23 |
24 using base::StringPiece; | 24 using base::StringPiece; |
| 25 using net::QuicServerId; |
25 using net::test::kInitialFlowControlWindowForTest; | 26 using net::test::kInitialFlowControlWindowForTest; |
26 using net::test::QuicConnectionPeer; | 27 using net::test::QuicConnectionPeer; |
27 using std::string; | 28 using std::string; |
28 using std::vector; | 29 using std::vector; |
29 | 30 |
30 namespace net { | 31 namespace net { |
31 namespace tools { | 32 namespace tools { |
32 namespace test { | 33 namespace test { |
33 namespace { | 34 namespace { |
34 | 35 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 full_uri.append(uri.as_string()); | 95 full_uri.append(uri.as_string()); |
95 headers->SetRequestUri(full_uri); | 96 headers->SetRequestUri(full_uri); |
96 } | 97 } |
97 return headers; | 98 return headers; |
98 } | 99 } |
99 | 100 |
100 // A quic client which allows mocking out writes. | 101 // A quic client which allows mocking out writes. |
101 class MockableQuicClient : public QuicClient { | 102 class MockableQuicClient : public QuicClient { |
102 public: | 103 public: |
103 MockableQuicClient(IPEndPoint server_address, | 104 MockableQuicClient(IPEndPoint server_address, |
104 const QuicSessionKey& server_key, | 105 const QuicServerId& server_id, |
105 const QuicVersionVector& supported_versions, | 106 const QuicVersionVector& supported_versions, |
106 uint32 initial_flow_control_window) | 107 uint32 initial_flow_control_window) |
107 : QuicClient(server_address, | 108 : QuicClient(server_address, |
108 server_key, | 109 server_id, |
109 supported_versions, | 110 supported_versions, |
110 false, | 111 false, |
111 initial_flow_control_window), | 112 initial_flow_control_window), |
112 override_connection_id_(0), | 113 override_connection_id_(0), |
113 test_writer_(NULL) {} | 114 test_writer_(NULL) {} |
114 | 115 |
115 MockableQuicClient(IPEndPoint server_address, | 116 MockableQuicClient(IPEndPoint server_address, |
116 const QuicSessionKey& server_key, | 117 const QuicServerId& server_id, |
117 const QuicConfig& config, | 118 const QuicConfig& config, |
118 const QuicVersionVector& supported_versions, | 119 const QuicVersionVector& supported_versions, |
119 uint32 initial_flow_control_window) | 120 uint32 initial_flow_control_window) |
120 : QuicClient(server_address, | 121 : QuicClient(server_address, |
121 server_key, | 122 server_id, |
122 config, | 123 config, |
123 supported_versions, | 124 supported_versions, |
124 initial_flow_control_window), | 125 initial_flow_control_window), |
125 override_connection_id_(0), | 126 override_connection_id_(0), |
126 test_writer_(NULL) {} | 127 test_writer_(NULL) {} |
127 | 128 |
128 virtual ~MockableQuicClient() { | 129 virtual ~MockableQuicClient() { |
129 if (connected()) { | 130 if (connected()) { |
130 Disconnect(); | 131 Disconnect(); |
131 } | 132 } |
(...skipping 21 matching lines...) Expand all Loading... |
153 | 154 |
154 void UseConnectionId(QuicConnectionId connection_id) { | 155 void UseConnectionId(QuicConnectionId connection_id) { |
155 override_connection_id_ = connection_id; | 156 override_connection_id_ = connection_id; |
156 } | 157 } |
157 | 158 |
158 private: | 159 private: |
159 QuicConnectionId override_connection_id_; // ConnectionId to use, if nonzero | 160 QuicConnectionId override_connection_id_; // ConnectionId to use, if nonzero |
160 QuicPacketWriterWrapper* test_writer_; | 161 QuicPacketWriterWrapper* test_writer_; |
161 }; | 162 }; |
162 | 163 |
163 QuicTestClient::QuicTestClient(IPEndPoint address, | 164 QuicTestClient::QuicTestClient(IPEndPoint server_address, |
164 const QuicSessionKey& server_key, | 165 const string& server_hostname, |
165 const QuicVersionVector& supported_versions) | 166 const QuicVersionVector& supported_versions) |
166 : client_(new MockableQuicClient(address, | 167 : client_(new MockableQuicClient(server_address, |
167 server_key, | 168 QuicServerId(server_hostname, |
| 169 server_address.port(), |
| 170 false, |
| 171 kPrivacyModeDisabled), |
168 supported_versions, | 172 supported_versions, |
169 kInitialFlowControlWindowForTest)) { | 173 kInitialFlowControlWindowForTest)) { |
170 Initialize(address, server_key, true); | 174 Initialize(server_address, server_hostname, true); |
171 } | 175 } |
172 | 176 |
173 QuicTestClient::QuicTestClient(IPEndPoint address, | 177 QuicTestClient::QuicTestClient(IPEndPoint server_address, |
174 const QuicSessionKey& server_key, | 178 const string& server_hostname, |
175 bool secure, | 179 bool secure, |
176 const QuicVersionVector& supported_versions) | 180 const QuicVersionVector& supported_versions) |
177 : client_(new MockableQuicClient(address, | 181 : client_(new MockableQuicClient(server_address, |
178 server_key, | 182 QuicServerId(server_hostname, |
| 183 server_address.port(), |
| 184 secure, |
| 185 kPrivacyModeDisabled), |
179 supported_versions, | 186 supported_versions, |
180 kInitialFlowControlWindowForTest)) { | 187 kInitialFlowControlWindowForTest)) { |
181 Initialize(address, server_key, secure); | 188 Initialize(server_address, server_hostname, secure); |
182 } | 189 } |
183 | 190 |
184 QuicTestClient::QuicTestClient( | 191 QuicTestClient::QuicTestClient( |
185 IPEndPoint address, | 192 IPEndPoint server_address, |
186 const QuicSessionKey& server_key, | 193 const string& server_hostname, |
187 bool secure, | 194 bool secure, |
188 const QuicConfig& config, | 195 const QuicConfig& config, |
189 const QuicVersionVector& supported_versions, | 196 const QuicVersionVector& supported_versions, |
190 uint32 client_initial_flow_control_receive_window) | 197 uint32 client_initial_flow_control_receive_window) |
191 : client_( | 198 : client_( |
192 new MockableQuicClient(address, | 199 new MockableQuicClient(server_address, |
193 server_key, | 200 QuicServerId(server_hostname, |
| 201 server_address.port(), |
| 202 secure, |
| 203 kPrivacyModeDisabled), |
194 config, | 204 config, |
195 supported_versions, | 205 supported_versions, |
196 client_initial_flow_control_receive_window)) { | 206 client_initial_flow_control_receive_window)) { |
197 Initialize(address, server_key, secure); | 207 Initialize(server_address, server_hostname, secure); |
198 } | 208 } |
199 | 209 |
200 void QuicTestClient::Initialize(IPEndPoint address, | 210 void QuicTestClient::Initialize(IPEndPoint address, |
201 const QuicSessionKey& server_key, | 211 const string& hostname, |
202 bool secure) { | 212 bool secure) { |
203 server_address_ = address; | 213 server_address_ = address; |
204 server_key_ = server_key; | |
205 priority_ = 3; | 214 priority_ = 3; |
206 connect_attempted_ = false; | 215 connect_attempted_ = false; |
207 secure_ = secure; | 216 secure_ = secure; |
208 auto_reconnect_ = false; | 217 auto_reconnect_ = false; |
209 buffer_body_ = true; | 218 buffer_body_ = true; |
210 proof_verifier_ = NULL; | 219 proof_verifier_ = NULL; |
211 ClearPerRequestState(); | 220 ClearPerRequestState(); |
212 ExpectCertificates(secure_); | 221 ExpectCertificates(secure_); |
213 } | 222 } |
214 | 223 |
(...skipping 18 matching lines...) Expand all Loading... |
233 return SendMessage(message); | 242 return SendMessage(message); |
234 } | 243 } |
235 | 244 |
236 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { | 245 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { |
237 stream_ = NULL; // Always force creation of a stream for SendMessage. | 246 stream_ = NULL; // Always force creation of a stream for SendMessage. |
238 | 247 |
239 // If we're not connected, try to find an sni hostname. | 248 // If we're not connected, try to find an sni hostname. |
240 if (!connected()) { | 249 if (!connected()) { |
241 GURL url(message.headers()->request_uri().as_string()); | 250 GURL url(message.headers()->request_uri().as_string()); |
242 if (!url.host().empty()) { | 251 if (!url.host().empty()) { |
243 client_->set_server_key( | 252 client_->set_server_id( |
244 QuicSessionKey(url.host(), url.EffectiveIntPort(), | 253 QuicServerId(url.host(), url.EffectiveIntPort(), |
245 url.SchemeIs("https"), kPrivacyModeDisabled)); | 254 url.SchemeIs("https"), kPrivacyModeDisabled)); |
246 } | 255 } |
247 } | 256 } |
248 | 257 |
249 QuicSpdyClientStream* stream = GetOrCreateStream(); | 258 QuicSpdyClientStream* stream = GetOrCreateStream(); |
250 if (!stream) { return 0; } | 259 if (!stream) { return 0; } |
251 | 260 |
252 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), | 261 scoped_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers(), |
253 secure_)); | 262 secure_)); |
254 ssize_t ret = GetOrCreateStream()->SendRequest( | 263 ssize_t ret = GetOrCreateStream()->SendRequest( |
255 munged_headers.get() ? *munged_headers.get() : *message.headers(), | 264 munged_headers.get() ? *munged_headers.get() : *message.headers(), |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 | 325 |
317 const string& QuicTestClient::cert_common_name() const { | 326 const string& QuicTestClient::cert_common_name() const { |
318 return reinterpret_cast<RecordingProofVerifier*>(proof_verifier_) | 327 return reinterpret_cast<RecordingProofVerifier*>(proof_verifier_) |
319 ->common_name(); | 328 ->common_name(); |
320 } | 329 } |
321 | 330 |
322 QuicTagValueMap QuicTestClient::GetServerConfig() const { | 331 QuicTagValueMap QuicTestClient::GetServerConfig() const { |
323 net::QuicCryptoClientConfig* config = | 332 net::QuicCryptoClientConfig* config = |
324 QuicClientPeer::GetCryptoConfig(client_.get()); | 333 QuicClientPeer::GetCryptoConfig(client_.get()); |
325 net::QuicCryptoClientConfig::CachedState* state = | 334 net::QuicCryptoClientConfig::CachedState* state = |
326 config->LookupOrCreate(client_->server_key()); | 335 config->LookupOrCreate(client_->server_id()); |
327 const net::CryptoHandshakeMessage* handshake_msg = state->GetServerConfig(); | 336 const net::CryptoHandshakeMessage* handshake_msg = state->GetServerConfig(); |
328 if (handshake_msg != NULL) { | 337 if (handshake_msg != NULL) { |
329 return handshake_msg->tag_value_map(); | 338 return handshake_msg->tag_value_map(); |
330 } else { | 339 } else { |
331 return QuicTagValueMap(); | 340 return QuicTagValueMap(); |
332 } | 341 } |
333 } | 342 } |
334 | 343 |
335 bool QuicTestClient::connected() const { | 344 bool QuicTestClient::connected() const { |
336 return client_->connected(); | 345 return client_->connected(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 495 |
487 void QuicTestClient::WaitForWriteToFlush() { | 496 void QuicTestClient::WaitForWriteToFlush() { |
488 while (connected() && client()->session()->HasDataToWrite()) { | 497 while (connected() && client()->session()->HasDataToWrite()) { |
489 client_->WaitForEvents(); | 498 client_->WaitForEvents(); |
490 } | 499 } |
491 } | 500 } |
492 | 501 |
493 } // namespace test | 502 } // namespace test |
494 } // namespace tools | 503 } // namespace tools |
495 } // namespace net | 504 } // namespace net |
OLD | NEW |