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

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

Issue 1004173004: Make the simple QUIC client able to resolve hosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove EXPORT to fix Win Created 5 years, 9 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
« no previous file with comments | « net/tools/quic/quic_client_bin.cc ('k') | net/tools/quic/synchronous_host_resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 29 matching lines...) Expand all
40 40
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/net_errors.h"
51 #include "net/base/net_log.h"
50 #include "net/base/privacy_mode.h" 52 #include "net/base/privacy_mode.h"
51 #include "net/cert/cert_verifier.h" 53 #include "net/cert/cert_verifier.h"
52 #include "net/http/http_request_info.h" 54 #include "net/http/http_request_info.h"
53 #include "net/http/transport_security_state.h" 55 #include "net/http/transport_security_state.h"
54 #include "net/quic/crypto/proof_verifier_chromium.h" 56 #include "net/quic/crypto/proof_verifier_chromium.h"
55 #include "net/quic/quic_protocol.h" 57 #include "net/quic/quic_protocol.h"
56 #include "net/quic/quic_server_id.h" 58 #include "net/quic/quic_server_id.h"
57 #include "net/quic/quic_utils.h" 59 #include "net/quic/quic_utils.h"
58 #include "net/spdy/spdy_http_utils.h" 60 #include "net/spdy/spdy_http_utils.h"
59 #include "net/tools/quic/quic_simple_client.h" 61 #include "net/tools/quic/quic_simple_client.h"
62 #include "net/tools/quic/synchronous_host_resolver.h"
60 #include "url/gurl.h" 63 #include "url/gurl.h"
61 64
62 using base::StringPiece; 65 using base::StringPiece;
63 using net::CertVerifier; 66 using net::CertVerifier;
64 using net::ProofVerifierChromium; 67 using net::ProofVerifierChromium;
65 using net::TransportSecurityState; 68 using net::TransportSecurityState;
66 using std::cout; 69 using std::cout;
67 using std::cerr; 70 using std::cerr;
68 using std::map; 71 using std::map;
69 using std::string; 72 using std::string;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 base::AtExitManager exit_manager; 166 base::AtExitManager exit_manager;
164 base::MessageLoopForIO message_loop; 167 base::MessageLoopForIO message_loop;
165 168
166 // Determine IP address to connect to from supplied hostname. 169 // Determine IP address to connect to from supplied hostname.
167 net::IPAddressNumber ip_addr; 170 net::IPAddressNumber ip_addr;
168 171
169 // TODO(rtenneti): GURL's doesn't support default_protocol argument, thus 172 // TODO(rtenneti): GURL's doesn't support default_protocol argument, thus
170 // protocol is required in the URL. 173 // protocol is required in the URL.
171 GURL url(urls[0]); 174 GURL url(urls[0]);
172 string host = FLAGS_host; 175 string host = FLAGS_host;
173 // TODO(rtenneti): get ip_addr from hostname by doing host resolution.
174 if (host.empty()) { 176 if (host.empty()) {
175 LOG(ERROR) << "--host must be specified\n"; 177 host = url.host();
176 return 1;
177 } 178 }
178 if (!net::ParseIPLiteralToNumber(host, &ip_addr)) { 179 if (!net::ParseIPLiteralToNumber(host, &ip_addr)) {
179 LOG(ERROR) << "--host could not be parsed as an IP address\n"; 180 net::AddressList addresses;
180 return 1; 181 int rv = net::tools::SynchronousHostResolver::Resolve(host, &addresses);
182 if (rv != net::OK) {
183 LOG(ERROR) << "Unable to resolve '" << host << "' : "
184 << net::ErrorToString(rv);
185 return 1;
186 }
187 ip_addr = addresses[0].address();
181 } 188 }
182 189
183 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port); 190 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port);
184 VLOG(1) << "Resolved " << host << " to " << host_port << endl; 191 VLOG(1) << "Resolved " << host << " to " << host_port << endl;
185 192
186 // Build the client, and try to connect. 193 // Build the client, and try to connect.
187 bool is_https = (FLAGS_port == 443); 194 bool is_https = (FLAGS_port == 443);
188 net::QuicServerId server_id(host, FLAGS_port, is_https, 195 net::QuicServerId server_id(host, FLAGS_port, is_https,
189 net::PRIVACY_MODE_DISABLED); 196 net::PRIVACY_MODE_DISABLED);
190 net::QuicVersionVector versions = net::QuicSupportedVersions(); 197 net::QuicVersionVector versions = net::QuicSupportedVersions();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return 0; 287 return 0;
281 } else { 288 } else {
282 cout << "Request failed (redirect " << response_code << ")." << endl; 289 cout << "Request failed (redirect " << response_code << ")." << endl;
283 return 1; 290 return 1;
284 } 291 }
285 } else { 292 } else {
286 cerr << "Request failed (" << response_code << ")." << endl; 293 cerr << "Request failed (" << response_code << ")." << endl;
287 return 1; 294 return 1;
288 } 295 }
289 } 296 }
OLDNEW
« no previous file with comments | « net/tools/quic/quic_client_bin.cc ('k') | net/tools/quic/synchronous_host_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698