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 29 matching lines...) Expand all Loading... |
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/transport_security_state.h" | 54 #include "net/http/transport_security_state.h" |
53 #include "net/quic/crypto/proof_verifier_chromium.h" | 55 #include "net/quic/crypto/proof_verifier_chromium.h" |
54 #include "net/quic/quic_protocol.h" | 56 #include "net/quic/quic_protocol.h" |
55 #include "net/quic/quic_server_id.h" | 57 #include "net/quic/quic_server_id.h" |
56 #include "net/quic/quic_utils.h" | 58 #include "net/quic/quic_utils.h" |
57 #include "net/tools/epoll_server/epoll_server.h" | 59 #include "net/tools/epoll_server/epoll_server.h" |
58 #include "net/tools/quic/quic_client.h" | 60 #include "net/tools/quic/quic_client.h" |
59 #include "net/tools/quic/spdy_utils.h" | 61 #include "net/tools/quic/spdy_utils.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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 165 |
163 base::AtExitManager exit_manager; | 166 base::AtExitManager exit_manager; |
164 | 167 |
165 // Determine IP address to connect to from supplied hostname. | 168 // Determine IP address to connect to from supplied hostname. |
166 net::IPAddressNumber ip_addr; | 169 net::IPAddressNumber ip_addr; |
167 | 170 |
168 // TODO(rtenneti): GURL's doesn't support default_protocol argument, thus | 171 // TODO(rtenneti): GURL's doesn't support default_protocol argument, thus |
169 // protocol is required in the URL. | 172 // protocol is required in the URL. |
170 GURL url(urls[0]); | 173 GURL url(urls[0]); |
171 string host = FLAGS_host; | 174 string host = FLAGS_host; |
172 // TODO(rtenneti): get ip_addr from hostname by doing host resolution. | |
173 if (host.empty()) { | 175 if (host.empty()) { |
174 LOG(ERROR) << "--host must be specified\n"; | 176 host = url.host(); |
175 return 1; | |
176 } | 177 } |
177 if (!net::ParseIPLiteralToNumber(host, &ip_addr)) { | 178 if (!net::ParseIPLiteralToNumber(host, &ip_addr)) { |
178 LOG(ERROR) << "--host could not be parsed as an IP address\n"; | 179 net::AddressList addresses; |
179 return 1; | 180 int rv = net::tools::SynchronousHostResolver::Resolve(host, &addresses); |
| 181 if (rv != net::OK) { |
| 182 LOG(ERROR) << "Unable to resolve '" << host << "' : " |
| 183 << net::ErrorToString(rv); |
| 184 return 1; |
| 185 } |
| 186 ip_addr = addresses[0].address(); |
180 } | 187 } |
181 | 188 |
182 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port); | 189 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port); |
183 VLOG(1) << "Resolved " << host << " to " << host_port << endl; | 190 VLOG(1) << "Resolved " << host << " to " << host_port << endl; |
184 | 191 |
185 // Build the client, and try to connect. | 192 // Build the client, and try to connect. |
186 bool is_https = (FLAGS_port == 443); | 193 bool is_https = (FLAGS_port == 443); |
187 net::EpollServer epoll_server; | 194 net::EpollServer epoll_server; |
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); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 return 0; | 284 return 0; |
278 } else { | 285 } else { |
279 cout << "Request failed (redirect " << response_code << ")." << endl; | 286 cout << "Request failed (redirect " << response_code << ")." << endl; |
280 return 1; | 287 return 1; |
281 } | 288 } |
282 } else { | 289 } else { |
283 cerr << "Request failed (" << response_code << ")." << endl; | 290 cerr << "Request failed (" << response_code << ")." << endl; |
284 return 1; | 291 return 1; |
285 } | 292 } |
286 } | 293 } |
OLD | NEW |