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. Connects to --hostname via --address | 5 // A binary wrapper for QuicClient. |
6 // on --port and requests URLs specified on the command line. | 6 // Connects to a host using QUIC, and sends requests to the provided URLS. |
7 // Pass --secure to check the certificates using proof verifier. | |
8 // Pass --initial_stream_flow_control_window to specify the size of the initial | |
9 // stream flow control receive window to advertise to server. | |
10 // Pass --initial_session_flow_control_window to specify the size of the initial | |
11 // session flow control receive window to advertise to server. | |
12 // | 7 // |
13 // For example: | 8 // Example usage: |
14 // quic_client --address=127.0.0.1 --port=6122 --hostname=www.google.com | 9 // quic_client --address=127.0.0.1 --port=6122 --hostname=www.google.com \ |
15 // http://www.google.com/index.html http://www.google.com/favicon.ico | 10 // http://www.google.com/index.html http://www.google.com/favicon.ico |
16 | 11 |
17 #include <iostream> | 12 #include <iostream> |
18 | 13 |
19 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
20 #include "base/command_line.h" | 15 #include "base/command_line.h" |
21 #include "base/logging.h" | 16 #include "base/logging.h" |
22 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
23 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
24 #include "net/base/privacy_mode.h" | 19 #include "net/base/privacy_mode.h" |
25 #include "net/quic/quic_protocol.h" | 20 #include "net/quic/quic_protocol.h" |
26 #include "net/quic/quic_server_id.h" | 21 #include "net/quic/quic_server_id.h" |
27 #include "net/tools/epoll_server/epoll_server.h" | 22 #include "net/tools/epoll_server/epoll_server.h" |
28 #include "net/tools/quic/quic_client.h" | 23 #include "net/tools/quic/quic_client.h" |
29 | 24 |
| 25 std::string FLAGS_address = "127.0.0.1"; |
| 26 // The IP or hostname the quic client will connect to. |
| 27 std::string FLAGS_hostname = "localhost"; |
30 // The port the quic client will connect to. | 28 // The port the quic client will connect to. |
31 int32 FLAGS_port = 6121; | 29 int32 FLAGS_port = 6121; |
32 std::string FLAGS_address = "127.0.0.1"; | |
33 // The hostname the quic client will connect to. | |
34 std::string FLAGS_hostname = "localhost"; | |
35 // Size of the initial stream flow control receive window to advertise to | |
36 // server. | |
37 int32 FLAGS_initial_stream_flow_control_window = 100 * net::kMaxPacketSize; | |
38 // Size of the initial session flow control receive window to advertise to | |
39 // server. | |
40 int32 FLAGS_initial_session_flow_control_window = 200 * net::kMaxPacketSize; | |
41 // Check the certificates using proof verifier. | 30 // Check the certificates using proof verifier. |
42 bool FLAGS_secure = false; | 31 bool FLAGS_secure = false; |
| 32 // QUIC version to speak, e.g. 21. Default value of 0 means 'use the latest |
| 33 // version'. |
| 34 int32 FLAGS_quic_version = 0; |
43 | 35 |
44 int main(int argc, char *argv[]) { | 36 int main(int argc, char *argv[]) { |
45 base::CommandLine::Init(argc, argv); | 37 base::CommandLine::Init(argc, argv); |
46 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); | 38 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); |
47 const base::CommandLine::StringVector& urls = line->GetArgs(); | 39 const base::CommandLine::StringVector& urls = line->GetArgs(); |
48 | 40 |
49 logging::LoggingSettings settings; | 41 logging::LoggingSettings settings; |
50 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 42 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
51 CHECK(logging::InitLogging(settings)); | 43 CHECK(logging::InitLogging(settings)); |
52 | 44 |
53 if (line->HasSwitch("h") || line->HasSwitch("help") || urls.empty()) { | 45 if (line->HasSwitch("h") || line->HasSwitch("help") || urls.empty()) { |
54 const char* help_str = | 46 const char* help_str = |
55 "Usage: quic_client [options] <url> ...\n" | 47 "Usage: quic_client [options] <url> ...\n" |
56 "\n" | 48 "\n" |
57 "At least one <url> with scheme must be provided " | 49 "At least one <url> with scheme must be provided " |
58 "(e.g. http://www.google.com/)\n\n" | 50 "(e.g. http://www.google.com/)\n\n" |
59 "Options:\n" | 51 "Options:\n" |
60 "-h, --help show this help message and exit\n" | 52 "-h, --help show this help message and exit\n" |
61 "--port=<port> specify the port to connect to\n" | 53 "--port=<port> specify the port to connect to\n" |
62 "--address=<address> specify the IP address to connect to\n" | 54 "--address=<address> specify the IP address to connect to\n" |
63 "--host=<host> specify the SNI hostname to use\n" | 55 "--host=<host> specify the SNI hostname to use\n" |
64 "--secure check certificates\n"; | 56 "--secure check certificates\n" |
| 57 "--quic-version=<quic version> specify QUIC version to speak\n"; |
65 std::cout << help_str; | 58 std::cout << help_str; |
66 exit(0); | 59 exit(0); |
67 } | 60 } |
68 if (line->HasSwitch("port")) { | 61 if (line->HasSwitch("port")) { |
69 int port; | 62 int port; |
70 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { | 63 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { |
71 FLAGS_port = port; | 64 FLAGS_port = port; |
72 } | 65 } |
73 } | 66 } |
74 if (line->HasSwitch("address")) { | 67 if (line->HasSwitch("address")) { |
75 FLAGS_address = line->GetSwitchValueASCII("address"); | 68 FLAGS_address = line->GetSwitchValueASCII("address"); |
76 } | 69 } |
77 if (line->HasSwitch("hostname")) { | 70 if (line->HasSwitch("hostname")) { |
78 FLAGS_hostname = line->GetSwitchValueASCII("hostname"); | 71 FLAGS_hostname = line->GetSwitchValueASCII("hostname"); |
79 } | 72 } |
80 if (line->HasSwitch("secure")) { | 73 if (line->HasSwitch("secure")) { |
81 FLAGS_secure = true; | 74 FLAGS_secure = true; |
82 } | 75 } |
| 76 if (line->HasSwitch("quic-version")) { |
| 77 int quic_version; |
| 78 if (base::StringToInt(line->GetSwitchValueASCII("quic-version"), |
| 79 &quic_version)) { |
| 80 FLAGS_quic_version = quic_version; |
| 81 } |
| 82 } |
83 VLOG(1) << "server port: " << FLAGS_port | 83 VLOG(1) << "server port: " << FLAGS_port |
84 << " address: " << FLAGS_address | 84 << " address: " << FLAGS_address |
85 << " hostname: " << FLAGS_hostname | 85 << " hostname: " << FLAGS_hostname |
86 << " secure: " << FLAGS_secure; | 86 << " secure: " << FLAGS_secure |
| 87 << " quic-version: " << FLAGS_quic_version; |
87 | 88 |
88 base::AtExitManager exit_manager; | 89 base::AtExitManager exit_manager; |
89 | 90 |
| 91 // Determine IP address to connect to from supplied hostname. |
90 net::IPAddressNumber addr; | 92 net::IPAddressNumber addr; |
91 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr)); | 93 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr)); |
92 | 94 |
| 95 // Populate version vector with all versions if none specified. |
| 96 net::QuicVersionVector versions; |
| 97 if (FLAGS_quic_version == 0) { |
| 98 versions = net::QuicSupportedVersions(); |
| 99 } else { |
| 100 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); |
| 101 } |
| 102 |
| 103 // Build the client, and try to connect. |
| 104 VLOG(1) << "Conecting to " << FLAGS_hostname << ":" << FLAGS_port |
| 105 << " with supported versions " |
| 106 << QuicVersionVectorToString(versions); |
| 107 net::EpollServer epoll_server; |
93 net::QuicConfig config; | 108 net::QuicConfig config; |
94 config.SetDefaults(); | 109 config.SetDefaults(); |
95 config.SetInitialFlowControlWindowToSend( | |
96 FLAGS_initial_session_flow_control_window); | |
97 config.SetInitialStreamFlowControlWindowToSend( | |
98 FLAGS_initial_stream_flow_control_window); | |
99 config.SetInitialSessionFlowControlWindowToSend( | |
100 FLAGS_initial_session_flow_control_window); | |
101 | 110 |
102 // TODO(rjshade): Set version on command line. | |
103 net::EpollServer epoll_server; | |
104 net::tools::QuicClient client( | 111 net::tools::QuicClient client( |
105 net::IPEndPoint(addr, FLAGS_port), | 112 net::IPEndPoint(addr, FLAGS_port), |
106 net::QuicServerId(FLAGS_hostname, FLAGS_port, FLAGS_secure, | 113 net::QuicServerId(FLAGS_hostname, FLAGS_port, FLAGS_secure, |
107 net::PRIVACY_MODE_DISABLED), | 114 net::PRIVACY_MODE_DISABLED), |
108 net::QuicSupportedVersions(), true, config, &epoll_server); | 115 versions, true, config, &epoll_server); |
109 | 116 |
110 client.Initialize(); | 117 client.Initialize(); |
111 | 118 |
112 if (!client.Connect()) return 1; | 119 if (!client.Connect()) { |
| 120 LOG(ERROR) << "Client failed to connect to host: " |
| 121 << FLAGS_hostname << ":" << FLAGS_port; |
| 122 return 1; |
| 123 } |
113 | 124 |
| 125 // Send a GET request for each supplied url. |
114 client.SendRequestsAndWaitForResponse(urls); | 126 client.SendRequestsAndWaitForResponse(urls); |
115 return 0; | 127 return 0; |
116 } | 128 } |
OLD | NEW |