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

Side by Side Diff: net/tools/quic/quic_client_bin.cc

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
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 // 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 30 matching lines...) Expand all
41 #include <iostream> 41 #include <iostream>
42 42
43 #include "base/at_exit.h" 43 #include "base/at_exit.h"
44 #include "base/command_line.h" 44 #include "base/command_line.h"
45 #include "base/logging.h" 45 #include "base/logging.h"
46 #include "base/strings/string_number_conversions.h" 46 #include "base/strings/string_number_conversions.h"
47 #include "base/strings/string_split.h" 47 #include "base/strings/string_split.h"
48 #include "base/strings/string_util.h" 48 #include "base/strings/string_util.h"
49 #include "net/base/ip_endpoint.h" 49 #include "net/base/ip_endpoint.h"
50 #include "net/base/privacy_mode.h" 50 #include "net/base/privacy_mode.h"
51 #include "net/cert/cert_verifier.h"
52 #include "net/http/transport_security_state.h"
53 #include "net/quic/crypto/proof_verifier_chromium.h"
51 #include "net/quic/quic_protocol.h" 54 #include "net/quic/quic_protocol.h"
52 #include "net/quic/quic_server_id.h" 55 #include "net/quic/quic_server_id.h"
53 #include "net/quic/quic_utils.h" 56 #include "net/quic/quic_utils.h"
54 #include "net/tools/epoll_server/epoll_server.h" 57 #include "net/tools/epoll_server/epoll_server.h"
55 #include "net/tools/quic/quic_client.h" 58 #include "net/tools/quic/quic_client.h"
56 #include "net/tools/quic/spdy_utils.h" 59 #include "net/tools/quic/spdy_utils.h"
57 #include "url/gurl.h" 60 #include "url/gurl.h"
58 61
59 using base::StringPiece; 62 using base::StringPiece;
63 using net::CertVerifier;
64 using net::ProofVerifierChromium;
65 using net::TransportSecurityState;
60 using std::cout; 66 using std::cout;
61 using std::cerr; 67 using std::cerr;
62 using std::map; 68 using std::map;
63 using std::string; 69 using std::string;
64 using std::vector; 70 using std::vector;
65 using std::endl; 71 using std::endl;
66 72
67 // The IP or hostname the quic client will connect to. 73 // The IP or hostname the quic client will connect to.
68 string FLAGS_host = ""; 74 string FLAGS_host = "";
69 // The port to connect to. 75 // The port to connect to.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 GURL url(urls[0]); 170 GURL url(urls[0]);
165 string host = FLAGS_host; 171 string host = FLAGS_host;
166 // TODO(rtenneti): get ip_addr from hostname by doing host resolution. 172 // TODO(rtenneti): get ip_addr from hostname by doing host resolution.
167 CHECK(!host.empty()); 173 CHECK(!host.empty());
168 net::ParseIPLiteralToNumber(host, &ip_addr); 174 net::ParseIPLiteralToNumber(host, &ip_addr);
169 175
170 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port); 176 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port);
171 VLOG(1) << "Resolved " << host << " to " << host_port << endl; 177 VLOG(1) << "Resolved " << host << " to " << host_port << endl;
172 178
173 // Build the client, and try to connect. 179 // Build the client, and try to connect.
180 bool is_https = (FLAGS_port == 443);
174 net::EpollServer epoll_server; 181 net::EpollServer epoll_server;
175 net::QuicServerId server_id(host, FLAGS_port, /*is_https=*/false, 182 net::QuicServerId server_id(host, FLAGS_port, is_https,
176 net::PRIVACY_MODE_DISABLED); 183 net::PRIVACY_MODE_DISABLED);
177 net::QuicVersionVector versions = net::QuicSupportedVersions(); 184 net::QuicVersionVector versions = net::QuicSupportedVersions();
178 if (FLAGS_quic_version != -1) { 185 if (FLAGS_quic_version != -1) {
179 versions.clear(); 186 versions.clear();
180 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); 187 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version));
181 } 188 }
182 net::tools::QuicClient client(net::IPEndPoint(ip_addr, FLAGS_port), server_id, 189 net::tools::QuicClient client(net::IPEndPoint(ip_addr, FLAGS_port), server_id,
183 versions, &epoll_server); 190 versions, &epoll_server);
191 scoped_ptr<CertVerifier> cert_verifier;
192 scoped_ptr<TransportSecurityState> transport_security_state;
193 if (is_https) {
194 // For secure QUIC we need to verify the cert chain.a
195 cert_verifier.reset(CertVerifier::CreateDefault());
196 transport_security_state.reset(new TransportSecurityState);
197 // TODO(rtenneti): Fix "Proof invalid: Missing context" error.
198 client.SetProofVerifier(new ProofVerifierChromium(
199 cert_verifier.get(), transport_security_state.get()));
200 }
184 if (!client.Initialize()) { 201 if (!client.Initialize()) {
185 cerr << "Failed to initialize client." << endl; 202 cerr << "Failed to initialize client." << endl;
186 return 1; 203 return 1;
187 } 204 }
188 if (!client.Connect()) { 205 if (!client.Connect()) {
189 net::QuicErrorCode error = client.session()->error(); 206 net::QuicErrorCode error = client.session()->error();
190 if (FLAGS_version_mismatch_ok && error == net::QUIC_INVALID_VERSION) { 207 if (FLAGS_version_mismatch_ok && error == net::QUIC_INVALID_VERSION) {
191 cout << "Server talks QUIC, but none of the versions supoorted by " 208 cout << "Server talks QUIC, but none of the versions supoorted by "
192 << "this client: " << QuicVersionVectorToString(versions) << endl; 209 << "this client: " << QuicVersionVectorToString(versions) << endl;
193 // Version mismatch is not deemed a failure. 210 // Version mismatch is not deemed a failure.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return 0; 271 return 0;
255 } else { 272 } else {
256 cout << "Request failed (redirect " << response_code << ")." << endl; 273 cout << "Request failed (redirect " << response_code << ")." << endl;
257 return 1; 274 return 1;
258 } 275 }
259 } else { 276 } else {
260 cerr << "Request failed (" << response_code << ")." << endl; 277 cerr << "Request failed (" << response_code << ")." << endl;
261 return 1; 278 return 1;
262 } 279 }
263 } 280 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698