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
3 // found in the LICENSE file.
5 // A binary wrapper for QuicClient. Connects to --hostname via --address
6 // on --port and requests URLs specified on the command line.
7 // Pass --secure to check the certificates using proof verifier.
8 // Pass --initial_flow_control_window to specify the size of the initial flow
9 // control receive window to advertise to server.
12 // quic_client --address=127.0.0.1 --port=6122 --hostname=www.google.com
13 // http://www.google.com/index.html http://www.google.com/favicon.ico
17 #include "base/at_exit.h"
18 #include "base/command_line.h"
19 #include "base/logging.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "net/base/ip_endpoint.h"
22 #include "net/base/privacy_mode.h"
23 #include "net/quic/quic_protocol.h"
24 #include "net/quic/quic_server_id.h"
25 #include "net/tools/quic/quic_client.h"
27 // The port the quic client will connect to.
28 int32 FLAGS_port = 6121;
29 std::string FLAGS_address = "127.0.0.1";
30 // The hostname the quic client will connect to.
31 std::string FLAGS_hostname = "localhost";
32 // Size of the initial flow control receive window to advertise to server.
33 int32 FLAGS_initial_flow_control_window = 100 * net::kMaxPacketSize;
34 // Check the certificates using proof verifier.
35 bool FLAGS_secure = false;
37 int main(int argc, char *argv[]) {
38 CommandLine::Init(argc, argv);
39 CommandLine* line = CommandLine::ForCurrentProcess();
41 logging::LoggingSettings settings;
42 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
43 CHECK(logging::InitLogging(settings));
45 if (line->HasSwitch("h") || line->HasSwitch("help")) {
46 const char* help_str =
47 "Usage: quic_client [options]\n"
50 "-h, --help show this help message and exit\n"
51 "--port=<port> specify the port to connect to\n"
52 "--address=<address> specify the IP address to connect to\n"
53 "--host=<host> specify the SNI hostname to use\n"
54 "--secure check certificates\n";
55 std::cout << help_str;
58 if (line->HasSwitch("port")) {
60 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) {
64 if (line->HasSwitch("address")) {
65 FLAGS_address = line->GetSwitchValueASCII("address");
67 if (line->HasSwitch("hostname")) {
68 FLAGS_hostname = line->GetSwitchValueASCII("hostname");
70 if (line->HasSwitch("secure")) {
73 VLOG(1) << "server port: " << FLAGS_port
74 << " address: " << FLAGS_address
75 << " hostname: " << FLAGS_hostname
76 << " secure: " << FLAGS_secure;
78 base::AtExitManager exit_manager;
80 net::IPAddressNumber addr;
81 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr));
82 // TODO(rjshade): Set version on command line.
83 net::tools::QuicClient client(
84 net::IPEndPoint(addr, FLAGS_port),
85 net::QuicServerId(FLAGS_hostname, FLAGS_port, FLAGS_secure,
86 net::PRIVACY_MODE_DISABLED),
87 net::QuicSupportedVersions(), true, FLAGS_initial_flow_control_window);
91 if (!client.Connect()) return 1;
93 client.SendRequestsAndWaitForResponse(line->GetArgs());