| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #include "net/quic/quic_utils.h" | 59 #include "net/quic/quic_utils.h" |
| 60 #include "net/spdy/spdy_header_block.h" | 60 #include "net/spdy/spdy_header_block.h" |
| 61 #include "net/tools/epoll_server/epoll_server.h" | 61 #include "net/tools/epoll_server/epoll_server.h" |
| 62 #include "net/tools/quic/quic_client.h" | 62 #include "net/tools/quic/quic_client.h" |
| 63 #include "net/tools/quic/spdy_balsa_utils.h" | 63 #include "net/tools/quic/spdy_balsa_utils.h" |
| 64 #include "net/tools/quic/synchronous_host_resolver.h" | 64 #include "net/tools/quic/synchronous_host_resolver.h" |
| 65 #include "url/gurl.h" | 65 #include "url/gurl.h" |
| 66 | 66 |
| 67 using base::StringPiece; | 67 using base::StringPiece; |
| 68 using net::CertVerifier; | 68 using net::CertVerifier; |
| 69 using net::ProofVerifier; |
| 69 using net::ProofVerifierChromium; | 70 using net::ProofVerifierChromium; |
| 70 using net::TransportSecurityState; | 71 using net::TransportSecurityState; |
| 71 using std::cout; | 72 using std::cout; |
| 72 using std::cerr; | 73 using std::cerr; |
| 73 using std::string; | 74 using std::string; |
| 74 using std::vector; | 75 using std::vector; |
| 75 using std::endl; | 76 using std::endl; |
| 76 | 77 |
| 77 // The IP or hostname the quic client will connect to. | 78 // The IP or hostname the quic client will connect to. |
| 78 string FLAGS_host = ""; | 79 string FLAGS_host = ""; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 202 } |
| 202 ip_addr = addresses[0].address(); | 203 ip_addr = addresses[0].address(); |
| 203 } | 204 } |
| 204 | 205 |
| 205 string host_port = net::IPAddressToStringWithPort(ip_addr, port); | 206 string host_port = net::IPAddressToStringWithPort(ip_addr, port); |
| 206 VLOG(1) << "Resolved " << host << " to " << host_port << endl; | 207 VLOG(1) << "Resolved " << host << " to " << host_port << endl; |
| 207 | 208 |
| 208 // Build the client, and try to connect. | 209 // Build the client, and try to connect. |
| 209 net::EpollServer epoll_server; | 210 net::EpollServer epoll_server; |
| 210 net::QuicServerId server_id(url.host(), url.EffectiveIntPort(), | 211 net::QuicServerId server_id(url.host(), url.EffectiveIntPort(), |
| 211 /*is_https=*/true, net::PRIVACY_MODE_DISABLED); | 212 net::PRIVACY_MODE_DISABLED); |
| 212 net::QuicVersionVector versions = net::QuicSupportedVersions(); | 213 net::QuicVersionVector versions = net::QuicSupportedVersions(); |
| 213 if (FLAGS_quic_version != -1) { | 214 if (FLAGS_quic_version != -1) { |
| 214 versions.clear(); | 215 versions.clear(); |
| 215 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); | 216 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); |
| 216 } | 217 } |
| 218 scoped_ptr<CertVerifier> cert_verifier(CertVerifier::CreateDefault()); |
| 219 scoped_ptr<TransportSecurityState> transport_security_state( |
| 220 new TransportSecurityState); |
| 221 ProofVerifier* proof_verifier = new ProofVerifierChromium( |
| 222 cert_verifier.get(), nullptr, transport_security_state.get()); |
| 217 net::tools::QuicClient client(net::IPEndPoint(ip_addr, port), server_id, | 223 net::tools::QuicClient client(net::IPEndPoint(ip_addr, port), server_id, |
| 218 versions, &epoll_server); | 224 versions, &epoll_server, proof_verifier); |
| 219 scoped_ptr<CertVerifier> cert_verifier; | |
| 220 scoped_ptr<TransportSecurityState> transport_security_state; | |
| 221 client.set_initial_max_packet_length( | 225 client.set_initial_max_packet_length( |
| 222 FLAGS_initial_mtu != 0 ? FLAGS_initial_mtu : net::kDefaultMaxPacketSize); | 226 FLAGS_initial_mtu != 0 ? FLAGS_initial_mtu : net::kDefaultMaxPacketSize); |
| 223 // For secure QUIC we need to verify the cert chain. | |
| 224 cert_verifier = CertVerifier::CreateDefault(); | |
| 225 transport_security_state.reset(new TransportSecurityState); | |
| 226 client.SetProofVerifier(new ProofVerifierChromium( | |
| 227 cert_verifier.get(), nullptr, transport_security_state.get())); | |
| 228 if (!client.Initialize()) { | 227 if (!client.Initialize()) { |
| 229 cerr << "Failed to initialize client." << endl; | 228 cerr << "Failed to initialize client." << endl; |
| 230 return 1; | 229 return 1; |
| 231 } | 230 } |
| 232 if (!client.Connect()) { | 231 if (!client.Connect()) { |
| 233 net::QuicErrorCode error = client.session()->error(); | 232 net::QuicErrorCode error = client.session()->error(); |
| 234 if (FLAGS_version_mismatch_ok && error == net::QUIC_INVALID_VERSION) { | 233 if (FLAGS_version_mismatch_ok && error == net::QUIC_INVALID_VERSION) { |
| 235 cout << "Server talks QUIC, but none of the versions supported by " | 234 cout << "Server talks QUIC, but none of the versions supported by " |
| 236 << "this client: " << QuicVersionVectorToString(versions) << endl; | 235 << "this client: " << QuicVersionVectorToString(versions) << endl; |
| 237 // Version mismatch is not deemed a failure. | 236 // Version mismatch is not deemed a failure. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return 0; | 299 return 0; |
| 301 } else { | 300 } else { |
| 302 cout << "Request failed (redirect " << response_code << ")." << endl; | 301 cout << "Request failed (redirect " << response_code << ")." << endl; |
| 303 return 1; | 302 return 1; |
| 304 } | 303 } |
| 305 } else { | 304 } else { |
| 306 cerr << "Request failed (" << response_code << ")." << endl; | 305 cerr << "Request failed (" << response_code << ")." << endl; |
| 307 return 1; | 306 return 1; |
| 308 } | 307 } |
| 309 } | 308 } |
| OLD | NEW |