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