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.
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
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
37 int32 FLAGS_initial_stream_flow_control_window
= 100 * net::kMaxPacketSize
;
38 // Size of the initial session flow control receive window to advertise to
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"
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
;
65 if (line
->HasSwitch("port")) {
67 if (base::StringToInt(line
->GetSwitchValueASCII("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")) {
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
;
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
);
109 if (!client
.Connect()) return 1;
111 client
.SendRequestsAndWaitForResponse(line
->GetArgs());