Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / net / tools / quic / quic_client_bin.cc
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.
4
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.
10 //
11 // For example:
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
14
15 #include <iostream>
16
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"
26
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;
36
37 int main(int argc, char *argv[]) {
38   CommandLine::Init(argc, argv);
39   CommandLine* line = CommandLine::ForCurrentProcess();
40
41   logging::LoggingSettings settings;
42   settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
43   CHECK(logging::InitLogging(settings));
44
45   if (line->HasSwitch("h") || line->HasSwitch("help")) {
46     const char* help_str =
47         "Usage: quic_client [options]\n"
48         "\n"
49         "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;
56     exit(0);
57   }
58   if (line->HasSwitch("port")) {
59     int port;
60     if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) {
61       FLAGS_port = port;
62     }
63   }
64   if (line->HasSwitch("address")) {
65     FLAGS_address = line->GetSwitchValueASCII("address");
66   }
67   if (line->HasSwitch("hostname")) {
68     FLAGS_hostname = line->GetSwitchValueASCII("hostname");
69   }
70   if (line->HasSwitch("secure")) {
71     FLAGS_secure = true;
72   }
73   VLOG(1) << "server port: " << FLAGS_port
74           << " address: " << FLAGS_address
75           << " hostname: " << FLAGS_hostname
76           << " secure: " << FLAGS_secure;
77
78   base::AtExitManager exit_manager;
79
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);
88
89   client.Initialize();
90
91   if (!client.Connect()) return 1;
92
93   client.SendRequestsAndWaitForResponse(line->GetArgs());
94   return 0;
95 }