Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / tools / quic / quic_client_bin.cc
blobf743a7dc127213e78a79078b2fb0db7e4395c126
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_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.
13 // For example:
14 // 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
17 #include <iostream>
19 #include "base/at_exit.h"
20 #include "base/command_line.h"
21 #include "base/logging.h"
22 #include "base/strings/string_number_conversions.h"
23 #include "net/base/ip_endpoint.h"
24 #include "net/base/privacy_mode.h"
25 #include "net/quic/quic_protocol.h"
26 #include "net/quic/quic_server_id.h"
27 #include "net/tools/epoll_server/epoll_server.h"
28 #include "net/tools/quic/quic_client.h"
30 // The port the quic client will connect to.
31 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.
42 bool FLAGS_secure = false;
44 int main(int argc, char *argv[]) {
45 base::CommandLine::Init(argc, argv);
46 base::CommandLine* line = base::CommandLine::ForCurrentProcess();
48 logging::LoggingSettings settings;
49 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
50 CHECK(logging::InitLogging(settings));
52 if (line->HasSwitch("h") || line->HasSwitch("help")) {
53 const char* help_str =
54 "Usage: quic_client [options]\n"
55 "\n"
56 "Options:\n"
57 "-h, --help show this help message and exit\n"
58 "--port=<port> specify the port to connect to\n"
59 "--address=<address> specify the IP address to connect to\n"
60 "--host=<host> specify the SNI hostname to use\n"
61 "--secure check certificates\n";
62 std::cout << help_str;
63 exit(0);
65 if (line->HasSwitch("port")) {
66 int port;
67 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) {
68 FLAGS_port = port;
71 if (line->HasSwitch("address")) {
72 FLAGS_address = line->GetSwitchValueASCII("address");
74 if (line->HasSwitch("hostname")) {
75 FLAGS_hostname = line->GetSwitchValueASCII("hostname");
77 if (line->HasSwitch("secure")) {
78 FLAGS_secure = true;
80 VLOG(1) << "server port: " << FLAGS_port
81 << " address: " << FLAGS_address
82 << " hostname: " << FLAGS_hostname
83 << " secure: " << FLAGS_secure;
85 base::AtExitManager exit_manager;
87 net::IPAddressNumber addr;
88 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr));
90 net::QuicConfig config;
91 config.SetDefaults();
92 config.SetInitialFlowControlWindowToSend(
93 FLAGS_initial_session_flow_control_window);
94 config.SetInitialStreamFlowControlWindowToSend(
95 FLAGS_initial_stream_flow_control_window);
96 config.SetInitialSessionFlowControlWindowToSend(
97 FLAGS_initial_session_flow_control_window);
99 // TODO(rjshade): Set version on command line.
100 net::EpollServer epoll_server;
101 net::tools::QuicClient client(
102 net::IPEndPoint(addr, FLAGS_port),
103 net::QuicServerId(FLAGS_hostname, FLAGS_port, FLAGS_secure,
104 net::PRIVACY_MODE_DISABLED),
105 net::QuicSupportedVersions(), true, config, &epoll_server);
107 client.Initialize();
109 if (!client.Connect()) return 1;
111 client.SendRequestsAndWaitForResponse(line->GetArgs());
112 return 0;