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. Connects to --hostname or --address on | 5 // A binary wrapper for QuicClient. Connects to --hostname via --address |
6 // --port and requests URLs specified on the command line. | 6 // on --port and requests URLs specified on the command line. |
7 // | 7 // |
8 // For example: | 8 // For example: |
9 // quic_client --port=6122 /index.html /favicon.ico | 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 |
| 11 |
| 12 #include <iostream> |
10 | 13 |
11 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
12 #include "base/command_line.h" | 15 #include "base/command_line.h" |
13 #include "base/logging.h" | 16 #include "base/logging.h" |
14 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
15 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
16 #include "net/quic/quic_protocol.h" | 19 #include "net/quic/quic_protocol.h" |
17 #include "net/tools/quic/quic_client.h" | 20 #include "net/tools/quic/quic_client.h" |
18 | 21 |
19 int32 FLAGS_port = 6121; | 22 int32 FLAGS_port = 6121; |
20 std::string FLAGS_address = "127.0.0.1"; | 23 std::string FLAGS_address = "127.0.0.1"; |
21 std::string FLAGS_hostname = "localhost"; | 24 std::string FLAGS_hostname = "localhost"; |
22 | 25 |
23 int main(int argc, char *argv[]) { | 26 int main(int argc, char *argv[]) { |
24 CommandLine::Init(argc, argv); | 27 CommandLine::Init(argc, argv); |
25 CommandLine* line = CommandLine::ForCurrentProcess(); | 28 CommandLine* line = CommandLine::ForCurrentProcess(); |
| 29 if (line->HasSwitch("h") || line->HasSwitch("help")) { |
| 30 const char* help_str = |
| 31 "Usage: quic_client [options]\n" |
| 32 "\n" |
| 33 "Options:\n" |
| 34 "-h, --help show this help message and exit\n" |
| 35 "--port=<port> specify the port to connect to\n" |
| 36 "--address=<address> specify the IP address to connect to\n" |
| 37 "--host=<host> specify the SNI hostname to use\n"; |
| 38 std::cout << help_str; |
| 39 exit(0); |
| 40 } |
26 if (line->HasSwitch("port")) { | 41 if (line->HasSwitch("port")) { |
27 int port; | 42 int port; |
28 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { | 43 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { |
29 FLAGS_port = port; | 44 FLAGS_port = port; |
30 } | 45 } |
31 } | 46 } |
32 if (line->HasSwitch("address")) { | 47 if (line->HasSwitch("address")) { |
33 FLAGS_address = line->GetSwitchValueASCII("address"); | 48 FLAGS_address = line->GetSwitchValueASCII("address"); |
34 } | 49 } |
35 if (line->HasSwitch("hostname")) { | 50 if (line->HasSwitch("hostname")) { |
36 FLAGS_hostname = line->GetSwitchValueASCII("hostname"); | 51 FLAGS_hostname = line->GetSwitchValueASCII("hostname"); |
37 } | 52 } |
38 LOG(INFO) << "server port: " << FLAGS_port | 53 LOG(INFO) << "server port: " << FLAGS_port |
39 << " address: " << FLAGS_address | 54 << " address: " << FLAGS_address |
40 << " hostname: " << FLAGS_hostname; | 55 << " hostname: " << FLAGS_hostname; |
41 | 56 |
42 base::AtExitManager exit_manager; | 57 base::AtExitManager exit_manager; |
43 | 58 |
44 net::IPAddressNumber addr; | 59 net::IPAddressNumber addr; |
45 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr)); | 60 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr)); |
46 // TODO(rjshade): Set version on command line. | 61 // TODO(rjshade): Set version on command line. |
47 net::tools::QuicClient client( | 62 net::tools::QuicClient client(net::IPEndPoint(addr, FLAGS_port), |
48 net::IPEndPoint(addr, FLAGS_port), FLAGS_hostname, net::QuicVersionMax()); | 63 FLAGS_hostname, net::QuicVersionMax(), true); |
49 | 64 |
50 client.Initialize(); | 65 client.Initialize(); |
51 | 66 |
52 if (!client.Connect()) return 1; | 67 if (!client.Connect()) return 1; |
53 | 68 |
54 client.SendRequestsAndWaitForResponse(line->GetArgs()); | 69 client.SendRequestsAndWaitForResponse(line->GetArgs()); |
55 return 0; | 70 return 0; |
56 } | 71 } |
OLD | NEW |