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