| 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 // A binary wrapper for QuicClient. | 5 // A binary wrapper for QuicClient. |
| 6 // Connects to a host using QUIC, sends a request to the provided URL, and | 6 // Connects to a host using QUIC, sends a request to the provided URL, and |
| 7 // displays the response. | 7 // displays the response. |
| 8 // | 8 // |
| 9 // Some usage examples: | 9 // Some usage examples: |
| 10 // | 10 // |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return 1; | 203 return 1; |
| 204 } | 204 } |
| 205 ip_addr = addresses[0].address(); | 205 ip_addr = addresses[0].address(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port); | 208 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port); |
| 209 VLOG(1) << "Resolved " << host << " to " << host_port << endl; | 209 VLOG(1) << "Resolved " << host << " to " << host_port << endl; |
| 210 | 210 |
| 211 // Build the client, and try to connect. | 211 // Build the client, and try to connect. |
| 212 net::QuicServerId server_id(url.host(), url.EffectiveIntPort(), | 212 net::QuicServerId server_id(url.host(), url.EffectiveIntPort(), |
| 213 /*is_https=*/true, net::PRIVACY_MODE_DISABLED); | 213 net::PRIVACY_MODE_DISABLED); |
| 214 net::QuicVersionVector versions = net::QuicSupportedVersions(); | 214 net::QuicVersionVector versions = net::QuicSupportedVersions(); |
| 215 if (FLAGS_quic_version != -1) { | 215 if (FLAGS_quic_version != -1) { |
| 216 versions.clear(); | 216 versions.clear(); |
| 217 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); | 217 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); |
| 218 } | 218 } |
| 219 net::tools::QuicSimpleClient client(net::IPEndPoint(ip_addr, port), server_id, | |
| 220 versions); | |
| 221 scoped_ptr<CertVerifier> cert_verifier; | 219 scoped_ptr<CertVerifier> cert_verifier; |
| 222 scoped_ptr<TransportSecurityState> transport_security_state; | 220 scoped_ptr<TransportSecurityState> transport_security_state; |
| 221 ProofVerifierChromium* proof_verifier = new ProofVerifierChromium( |
| 222 cert_verifier.get(), nullptr, transport_security_state.get()); |
| 223 net::tools::QuicSimpleClient client(net::IPEndPoint(ip_addr, port), server_id, |
| 224 versions, proof_verifier); |
| 223 client.set_initial_max_packet_length( | 225 client.set_initial_max_packet_length( |
| 224 FLAGS_initial_mtu != 0 ? FLAGS_initial_mtu : net::kDefaultMaxPacketSize); | 226 FLAGS_initial_mtu != 0 ? FLAGS_initial_mtu : net::kDefaultMaxPacketSize); |
| 225 // For secure QUIC we need to verify the cert chain. | 227 // For secure QUIC we need to verify the cert chain. |
| 226 cert_verifier = CertVerifier::CreateDefault(); | 228 cert_verifier = CertVerifier::CreateDefault(); |
| 227 transport_security_state.reset(new TransportSecurityState); | 229 transport_security_state.reset(new TransportSecurityState); |
| 228 client.SetProofVerifier(new ProofVerifierChromium( | |
| 229 cert_verifier.get(), nullptr, transport_security_state.get())); | |
| 230 if (!client.Initialize()) { | 230 if (!client.Initialize()) { |
| 231 cerr << "Failed to initialize client." << endl; | 231 cerr << "Failed to initialize client." << endl; |
| 232 return 1; | 232 return 1; |
| 233 } | 233 } |
| 234 if (!client.Connect()) { | 234 if (!client.Connect()) { |
| 235 net::QuicErrorCode error = client.session()->error(); | 235 net::QuicErrorCode error = client.session()->error(); |
| 236 if (FLAGS_version_mismatch_ok && error == net::QUIC_INVALID_VERSION) { | 236 if (FLAGS_version_mismatch_ok && error == net::QUIC_INVALID_VERSION) { |
| 237 cout << "Server talks QUIC, but none of the versions supported by " | 237 cout << "Server talks QUIC, but none of the versions supported by " |
| 238 << "this client: " << QuicVersionVectorToString(versions) << endl; | 238 << "this client: " << QuicVersionVectorToString(versions) << endl; |
| 239 // Version mismatch is not deemed a failure. | 239 // Version mismatch is not deemed a failure. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 return 0; | 303 return 0; |
| 304 } else { | 304 } else { |
| 305 cout << "Request failed (redirect " << response_code << ")." << endl; | 305 cout << "Request failed (redirect " << response_code << ")." << endl; |
| 306 return 1; | 306 return 1; |
| 307 } | 307 } |
| 308 } else { | 308 } else { |
| 309 cerr << "Request failed (" << response_code << ")." << endl; | 309 cerr << "Request failed (" << response_code << ")." << endl; |
| 310 return 1; | 310 return 1; |
| 311 } | 311 } |
| 312 } | 312 } |
| OLD | NEW |