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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 bool FLAGS_quiet = false; | 85 bool FLAGS_quiet = false; |
86 // QUIC version to speak, e.g. 21. If not set, then all available versions are | 86 // QUIC version to speak, e.g. 21. If not set, then all available versions are |
87 // offered in the handshake. | 87 // offered in the handshake. |
88 int32 FLAGS_quic_version = -1; | 88 int32 FLAGS_quic_version = -1; |
89 // If true, a version mismatch in the handshake is not considered a failure. | 89 // If true, a version mismatch in the handshake is not considered a failure. |
90 // Useful for probing a server to determine if it speaks any version of QUIC. | 90 // Useful for probing a server to determine if it speaks any version of QUIC. |
91 bool FLAGS_version_mismatch_ok = false; | 91 bool FLAGS_version_mismatch_ok = false; |
92 // If true, an HTTP response code of 3xx is considered to be a successful | 92 // If true, an HTTP response code of 3xx is considered to be a successful |
93 // response, otherwise a failure. | 93 // response, otherwise a failure. |
94 bool FLAGS_redirect_is_success = true; | 94 bool FLAGS_redirect_is_success = true; |
| 95 // Initial MTU of the connection. |
| 96 int32 FLAGS_initial_mtu = 0; |
95 | 97 |
96 int main(int argc, char *argv[]) { | 98 int main(int argc, char *argv[]) { |
97 base::CommandLine::Init(argc, argv); | 99 base::CommandLine::Init(argc, argv); |
98 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); | 100 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); |
99 const base::CommandLine::StringVector& urls = line->GetArgs(); | 101 const base::CommandLine::StringVector& urls = line->GetArgs(); |
100 | 102 |
101 logging::LoggingSettings settings; | 103 logging::LoggingSettings settings; |
102 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 104 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
103 CHECK(logging::InitLogging(settings)); | 105 CHECK(logging::InitLogging(settings)); |
104 | 106 |
105 if (line->HasSwitch("h") || line->HasSwitch("help") || urls.empty()) { | 107 if (line->HasSwitch("h") || line->HasSwitch("help") || urls.empty()) { |
106 const char* help_str = | 108 const char* help_str = |
107 "Usage: quic_client [options] <url>\n" | 109 "Usage: quic_client [options] <url>\n" |
108 "\n" | 110 "\n" |
109 "<url> with scheme must be provided (e.g. http://www.google.com)\n\n" | 111 "<url> with scheme must be provided (e.g. http://www.google.com)\n\n" |
110 "Options:\n" | 112 "Options:\n" |
111 "-h, --help show this help message and exit\n" | 113 "-h, --help show this help message and exit\n" |
112 "--host=<host> specify the IP address of the hostname to " | 114 "--host=<host> specify the IP address of the hostname to " |
113 "connect to\n" | 115 "connect to\n" |
114 "--port=<port> specify the port to connect to\n" | 116 "--port=<port> specify the port to connect to\n" |
115 "--body=<body> specify the body to post\n" | 117 "--body=<body> specify the body to post\n" |
116 "--headers=<headers> specify a semicolon separated list of " | 118 "--headers=<headers> specify a semicolon separated list of " |
117 "key:value pairs to add to request headers\n" | 119 "key:value pairs to add to request headers\n" |
118 "--quiet specify for a quieter output experience\n" | 120 "--quiet specify for a quieter output experience\n" |
119 "--quic-version=<quic version> specify QUIC version to speak\n" | 121 "--quic-version=<quic version> specify QUIC version to speak\n" |
120 "--version_mismatch_ok if specified a version mismatch in the " | 122 "--version_mismatch_ok if specified a version mismatch in the " |
121 "handshake is not considered a failure\n" | 123 "handshake is not considered a failure\n" |
122 "--redirect_is_success if specified an HTTP response code of 3xx " | 124 "--redirect_is_success if specified an HTTP response code of 3xx " |
123 "is considered to be a successful response, otherwise a failure\n"; | 125 "is considered to be a successful response, otherwise a failure\n" |
| 126 "--initial_mtu=<initial_mtu> specify the initial MTU of the connection" |
| 127 "\n"; |
124 cout << help_str; | 128 cout << help_str; |
125 exit(0); | 129 exit(0); |
126 } | 130 } |
127 if (line->HasSwitch("host")) { | 131 if (line->HasSwitch("host")) { |
128 FLAGS_host = line->GetSwitchValueASCII("host"); | 132 FLAGS_host = line->GetSwitchValueASCII("host"); |
129 } | 133 } |
130 if (line->HasSwitch("port")) { | 134 if (line->HasSwitch("port")) { |
131 if (!base::StringToInt(line->GetSwitchValueASCII("port"), &FLAGS_port)) { | 135 if (!base::StringToInt(line->GetSwitchValueASCII("port"), &FLAGS_port)) { |
132 std::cerr << "--port must be an integer\n"; | 136 std::cerr << "--port must be an integer\n"; |
133 return 1; | 137 return 1; |
(...skipping 14 matching lines...) Expand all Loading... |
148 &quic_version)) { | 152 &quic_version)) { |
149 FLAGS_quic_version = quic_version; | 153 FLAGS_quic_version = quic_version; |
150 } | 154 } |
151 } | 155 } |
152 if (line->HasSwitch("version_mismatch_ok")) { | 156 if (line->HasSwitch("version_mismatch_ok")) { |
153 FLAGS_version_mismatch_ok = true; | 157 FLAGS_version_mismatch_ok = true; |
154 } | 158 } |
155 if (line->HasSwitch("redirect_is_success")) { | 159 if (line->HasSwitch("redirect_is_success")) { |
156 FLAGS_redirect_is_success = true; | 160 FLAGS_redirect_is_success = true; |
157 } | 161 } |
| 162 if (line->HasSwitch("initial_mtu")) { |
| 163 if (!base::StringToInt(line->GetSwitchValueASCII("initial_mtu"), |
| 164 &FLAGS_initial_mtu)) { |
| 165 std::cerr << "--initial_mtu must be an integer\n"; |
| 166 return 1; |
| 167 } |
| 168 } |
158 | 169 |
159 VLOG(1) << "server host: " << FLAGS_host << " port: " << FLAGS_port | 170 VLOG(1) << "server host: " << FLAGS_host << " port: " << FLAGS_port |
160 << " body: " << FLAGS_body << " headers: " << FLAGS_headers | 171 << " body: " << FLAGS_body << " headers: " << FLAGS_headers |
161 << " quiet: " << FLAGS_quiet | 172 << " quiet: " << FLAGS_quiet |
162 << " quic-version: " << FLAGS_quic_version | 173 << " quic-version: " << FLAGS_quic_version |
163 << " version_mismatch_ok: " << FLAGS_version_mismatch_ok | 174 << " version_mismatch_ok: " << FLAGS_version_mismatch_ok |
164 << " redirect_is_success: " << FLAGS_redirect_is_success; | 175 << " redirect_is_success: " << FLAGS_redirect_is_success |
| 176 << " initial_mtu: " << FLAGS_initial_mtu; |
165 | 177 |
166 base::AtExitManager exit_manager; | 178 base::AtExitManager exit_manager; |
167 base::MessageLoopForIO message_loop; | 179 base::MessageLoopForIO message_loop; |
168 | 180 |
169 // Determine IP address to connect to from supplied hostname. | 181 // Determine IP address to connect to from supplied hostname. |
170 net::IPAddressNumber ip_addr; | 182 net::IPAddressNumber ip_addr; |
171 | 183 |
172 // TODO(rtenneti): GURL's doesn't support default_protocol argument, thus | 184 // TODO(rtenneti): GURL's doesn't support default_protocol argument, thus |
173 // protocol is required in the URL. | 185 // protocol is required in the URL. |
174 GURL url(urls[0]); | 186 GURL url(urls[0]); |
(...skipping 21 matching lines...) Expand all Loading... |
196 net::PRIVACY_MODE_DISABLED); | 208 net::PRIVACY_MODE_DISABLED); |
197 net::QuicVersionVector versions = net::QuicSupportedVersions(); | 209 net::QuicVersionVector versions = net::QuicSupportedVersions(); |
198 if (FLAGS_quic_version != -1) { | 210 if (FLAGS_quic_version != -1) { |
199 versions.clear(); | 211 versions.clear(); |
200 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); | 212 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); |
201 } | 213 } |
202 net::tools::QuicSimpleClient client(net::IPEndPoint(ip_addr, FLAGS_port), | 214 net::tools::QuicSimpleClient client(net::IPEndPoint(ip_addr, FLAGS_port), |
203 server_id, versions); | 215 server_id, versions); |
204 scoped_ptr<CertVerifier> cert_verifier; | 216 scoped_ptr<CertVerifier> cert_verifier; |
205 scoped_ptr<TransportSecurityState> transport_security_state; | 217 scoped_ptr<TransportSecurityState> transport_security_state; |
| 218 if (FLAGS_initial_mtu != 0) { |
| 219 client.set_initial_max_packet_length(FLAGS_initial_mtu); |
| 220 } |
206 if (is_https) { | 221 if (is_https) { |
207 // For secure QUIC we need to verify the cert chain.a | 222 // For secure QUIC we need to verify the cert chain.a |
208 cert_verifier.reset(CertVerifier::CreateDefault()); | 223 cert_verifier.reset(CertVerifier::CreateDefault()); |
209 transport_security_state.reset(new TransportSecurityState); | 224 transport_security_state.reset(new TransportSecurityState); |
210 client.SetProofVerifier(new ProofVerifierChromium( | 225 client.SetProofVerifier(new ProofVerifierChromium( |
211 cert_verifier.get(), transport_security_state.get())); | 226 cert_verifier.get(), transport_security_state.get())); |
212 } | 227 } |
213 if (!client.Initialize()) { | 228 if (!client.Initialize()) { |
214 cerr << "Failed to initialize client." << endl; | 229 cerr << "Failed to initialize client." << endl; |
215 return 1; | 230 return 1; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 return 0; | 301 return 0; |
287 } else { | 302 } else { |
288 cout << "Request failed (redirect " << response_code << ")." << endl; | 303 cout << "Request failed (redirect " << response_code << ")." << endl; |
289 return 1; | 304 return 1; |
290 } | 305 } |
291 } else { | 306 } else { |
292 cerr << "Request failed (" << response_code << ")." << endl; | 307 cerr << "Request failed (" << response_code << ")." << endl; |
293 return 1; | 308 return 1; |
294 } | 309 } |
295 } | 310 } |
OLD | NEW |