| 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, and sends requests to the provided URLS. | 6 // Connects to a host using QUIC, and sends requests to the provided URLS. |
| 7 // | 7 // |
| 8 // Example usage: | 8 // Example usage: |
| 9 // 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 |
| 10 // 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 std::string FLAGS_address = "127.0.0.1"; | 25 std::string FLAGS_address = "127.0.0.1"; |
| 26 // The IP or hostname the quic client will connect to. | 26 // The IP or hostname the quic client will connect to. |
| 27 std::string FLAGS_hostname = "localhost"; | 27 std::string FLAGS_hostname = "localhost"; |
| 28 // The port the quic client will connect to. | 28 // The port the quic client will connect to. |
| 29 int32 FLAGS_port = 6121; | 29 int32 FLAGS_port = 6121; |
| 30 // Check the certificates using proof verifier. | 30 // Check the certificates using proof verifier. |
| 31 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 | 32 // QUIC version to speak, e.g. 21. Default value of 0 means 'use the latest |
| 33 // version'. | 33 // version'. |
| 34 int32 FLAGS_quic_version = 0; | 34 int32 FLAGS_quic_version = 0; |
| 35 // Size of flow control receive window to advertize to the peer. |
| 36 int32 FLAGS_flow_control_window_bytes = 10 * 1024 * 1024; // 10 Mb |
| 35 | 37 |
| 36 int main(int argc, char *argv[]) { | 38 int main(int argc, char *argv[]) { |
| 37 base::CommandLine::Init(argc, argv); | 39 base::CommandLine::Init(argc, argv); |
| 38 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); | 40 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); |
| 39 const base::CommandLine::StringVector& urls = line->GetArgs(); | 41 const base::CommandLine::StringVector& urls = line->GetArgs(); |
| 40 | 42 |
| 41 logging::LoggingSettings settings; | 43 logging::LoggingSettings settings; |
| 42 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 44 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 43 CHECK(logging::InitLogging(settings)); | 45 CHECK(logging::InitLogging(settings)); |
| 44 | 46 |
| 45 if (line->HasSwitch("h") || line->HasSwitch("help") || urls.empty()) { | 47 if (line->HasSwitch("h") || line->HasSwitch("help") || urls.empty()) { |
| 46 const char* help_str = | 48 const char* help_str = |
| 47 "Usage: quic_client [options] <url> ...\n" | 49 "Usage: quic_client [options] <url> ...\n" |
| 48 "\n" | 50 "\n" |
| 49 "At least one <url> with scheme must be provided " | 51 "At least one <url> with scheme must be provided " |
| 50 "(e.g. http://www.google.com/)\n\n" | 52 "(e.g. http://www.google.com/)\n\n" |
| 51 "Options:\n" | 53 "Options:\n" |
| 52 "-h, --help show this help message and exit\n" | 54 "-h, --help show this help message and exit\n" |
| 53 "--port=<port> specify the port to connect to\n" | 55 "--port=<port> specify the port to connect to\n" |
| 54 "--address=<address> specify the IP address to connect to\n" | 56 "--address=<address> specify the IP address to connect to\n" |
| 55 "--host=<host> specify the SNI hostname to use\n" | 57 "--host=<host> specify the SNI hostname to use\n" |
| 56 "--secure check certificates\n" | 58 "--secure check certificates\n" |
| 57 "--quic-version=<quic version> specify QUIC version to speak\n"; | 59 "--quic-version=<quic version> specify QUIC version to speak\n" |
| 60 "--flow-control-window-bytes=<bytes> specify size of flow control " |
| 61 "receive window to advertize to the peer\n"; |
| 58 std::cout << help_str; | 62 std::cout << help_str; |
| 59 exit(0); | 63 exit(0); |
| 60 } | 64 } |
| 61 if (line->HasSwitch("port")) { | 65 if (line->HasSwitch("port")) { |
| 62 int port; | 66 int port; |
| 63 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { | 67 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { |
| 64 FLAGS_port = port; | 68 FLAGS_port = port; |
| 65 } | 69 } |
| 66 } | 70 } |
| 67 if (line->HasSwitch("address")) { | 71 if (line->HasSwitch("address")) { |
| 68 FLAGS_address = line->GetSwitchValueASCII("address"); | 72 FLAGS_address = line->GetSwitchValueASCII("address"); |
| 69 } | 73 } |
| 70 if (line->HasSwitch("hostname")) { | 74 if (line->HasSwitch("hostname")) { |
| 71 FLAGS_hostname = line->GetSwitchValueASCII("hostname"); | 75 FLAGS_hostname = line->GetSwitchValueASCII("hostname"); |
| 72 } | 76 } |
| 73 if (line->HasSwitch("secure")) { | 77 if (line->HasSwitch("secure")) { |
| 74 FLAGS_secure = true; | 78 FLAGS_secure = true; |
| 75 } | 79 } |
| 76 if (line->HasSwitch("quic-version")) { | 80 if (line->HasSwitch("quic-version")) { |
| 77 int quic_version; | 81 int quic_version; |
| 78 if (base::StringToInt(line->GetSwitchValueASCII("quic-version"), | 82 if (base::StringToInt(line->GetSwitchValueASCII("quic-version"), |
| 79 &quic_version)) { | 83 &quic_version)) { |
| 80 FLAGS_quic_version = quic_version; | 84 FLAGS_quic_version = quic_version; |
| 81 } | 85 } |
| 82 } | 86 } |
| 87 if (line->HasSwitch("flow-control-window-bytes")) { |
| 88 int flow_control_window_bytes; |
| 89 if (base::StringToInt( |
| 90 line->GetSwitchValueASCII("flow-control-window-bytes"), |
| 91 &flow_control_window_bytes)) { |
| 92 FLAGS_flow_control_window_bytes = flow_control_window_bytes; |
| 93 } |
| 94 } |
| 83 VLOG(1) << "server port: " << FLAGS_port | 95 VLOG(1) << "server port: " << FLAGS_port |
| 84 << " address: " << FLAGS_address | 96 << " address: " << FLAGS_address |
| 85 << " hostname: " << FLAGS_hostname | 97 << " hostname: " << FLAGS_hostname |
| 86 << " secure: " << FLAGS_secure | 98 << " secure: " << FLAGS_secure |
| 87 << " quic-version: " << FLAGS_quic_version; | 99 << " quic-version: " << FLAGS_quic_version; |
| 88 | 100 |
| 89 base::AtExitManager exit_manager; | 101 base::AtExitManager exit_manager; |
| 90 | 102 |
| 91 // Determine IP address to connect to from supplied hostname. | 103 // Determine IP address to connect to from supplied hostname. |
| 92 net::IPAddressNumber addr; | 104 net::IPAddressNumber addr; |
| 93 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr)); | 105 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr)); |
| 94 | 106 |
| 95 // Populate version vector with all versions if none specified. | 107 // Populate version vector with all versions if none specified. |
| 96 net::QuicVersionVector versions; | 108 net::QuicVersionVector versions; |
| 97 if (FLAGS_quic_version == 0) { | 109 if (FLAGS_quic_version == 0) { |
| 98 versions = net::QuicSupportedVersions(); | 110 versions = net::QuicSupportedVersions(); |
| 99 } else { | 111 } else { |
| 100 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); | 112 versions.push_back(static_cast<net::QuicVersion>(FLAGS_quic_version)); |
| 101 } | 113 } |
| 102 | 114 |
| 103 // Build the client, and try to connect. | 115 // Build the client, and try to connect. |
| 104 VLOG(1) << "Conecting to " << FLAGS_hostname << ":" << FLAGS_port | 116 VLOG(1) << "Conecting to " << FLAGS_hostname << ":" << FLAGS_port |
| 105 << " with supported versions " | 117 << " with supported versions " |
| 106 << QuicVersionVectorToString(versions); | 118 << QuicVersionVectorToString(versions); |
| 107 net::EpollServer epoll_server; | 119 net::EpollServer epoll_server; |
| 108 net::QuicConfig config; | 120 net::QuicConfig config; |
| 109 config.SetDefaults(); | 121 config.SetDefaults(); |
| 110 | 122 |
| 123 // The default flow control window of 16 Kb is too small for practical |
| 124 // purposes. Set it to the specified value, which has a large default. |
| 125 config.SetInitialFlowControlWindowToSend( |
| 126 FLAGS_flow_control_window_bytes); |
| 127 config.SetInitialStreamFlowControlWindowToSend( |
| 128 FLAGS_flow_control_window_bytes); |
| 129 config.SetInitialSessionFlowControlWindowToSend( |
| 130 FLAGS_flow_control_window_bytes); |
| 131 |
| 111 net::tools::QuicClient client( | 132 net::tools::QuicClient client( |
| 112 net::IPEndPoint(addr, FLAGS_port), | 133 net::IPEndPoint(addr, FLAGS_port), |
| 113 net::QuicServerId(FLAGS_hostname, FLAGS_port, FLAGS_secure, | 134 net::QuicServerId(FLAGS_hostname, FLAGS_port, FLAGS_secure, |
| 114 net::PRIVACY_MODE_DISABLED), | 135 net::PRIVACY_MODE_DISABLED), |
| 115 versions, true, config, &epoll_server); | 136 versions, true, config, &epoll_server); |
| 116 | 137 |
| 117 client.Initialize(); | 138 client.Initialize(); |
| 118 | 139 |
| 119 if (!client.Connect()) { | 140 if (!client.Connect()) { |
| 120 LOG(ERROR) << "Client failed to connect to host: " | 141 LOG(ERROR) << "Client failed to connect to host: " |
| 121 << FLAGS_hostname << ":" << FLAGS_port; | 142 << FLAGS_hostname << ":" << FLAGS_port; |
| 122 return 1; | 143 return 1; |
| 123 } | 144 } |
| 124 | 145 |
| 125 // Send a GET request for each supplied url. | 146 // Send a GET request for each supplied url. |
| 126 client.SendRequestsAndWaitForResponse(urls); | 147 client.SendRequestsAndWaitForResponse(urls); |
| 127 return 0; | 148 return 0; |
| 128 } | 149 } |
| OLD | NEW |