OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 QuicServer. It listens forever on --port | 5 // A binary wrapper for QuicServer. It listens forever on --port |
6 // (default 6121) until it's killed or ctrl-cd to death. | 6 // (default 6121) until it's killed or ctrl-cd to death. |
7 | 7 |
8 #include <iostream> | 8 #include <iostream> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "net/base/ip_address.h" | 15 #include "net/base/ip_address.h" |
16 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
17 #include "net/quic/chromium/crypto/proof_source_chromium.h" | 17 #include "net/quic/chromium/crypto/proof_source_chromium.h" |
18 #include "net/quic/core/quic_protocol.h" | 18 #include "net/quic/core/quic_packets.h" |
19 #include "net/tools/quic/quic_in_memory_cache.h" | 19 #include "net/tools/quic/quic_http_response_cache.h" |
20 #include "net/tools/quic/quic_simple_server.h" | 20 #include "net/tools/quic/quic_simple_server.h" |
21 | 21 |
22 // The port the quic server will listen on. | 22 // The port the quic server will listen on. |
23 int32_t FLAGS_port = 6121; | 23 int32_t FLAGS_port = 6121; |
24 | 24 |
25 std::unique_ptr<net::ProofSource> CreateProofSource( | 25 std::unique_ptr<net::ProofSource> CreateProofSource( |
26 const base::FilePath& cert_path, | 26 const base::FilePath& cert_path, |
27 const base::FilePath& key_path) { | 27 const base::FilePath& key_path) { |
28 std::unique_ptr<net::ProofSourceChromium> proof_source( | 28 std::unique_ptr<net::ProofSourceChromium> proof_source( |
29 new net::ProofSourceChromium()); | 29 new net::ProofSourceChromium()); |
(...skipping 12 matching lines...) Expand all Loading... |
42 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 42 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
43 CHECK(logging::InitLogging(settings)); | 43 CHECK(logging::InitLogging(settings)); |
44 | 44 |
45 if (line->HasSwitch("h") || line->HasSwitch("help")) { | 45 if (line->HasSwitch("h") || line->HasSwitch("help")) { |
46 const char* help_str = | 46 const char* help_str = |
47 "Usage: quic_server [options]\n" | 47 "Usage: quic_server [options]\n" |
48 "\n" | 48 "\n" |
49 "Options:\n" | 49 "Options:\n" |
50 "-h, --help show this help message and exit\n" | 50 "-h, --help show this help message and exit\n" |
51 "--port=<port> specify the port to listen on\n" | 51 "--port=<port> specify the port to listen on\n" |
52 "--quic_in_memory_cache_dir directory containing response data\n" | 52 "--quic_response_cache_dir directory containing response data\n" |
53 " to load\n" | 53 " to load\n" |
54 "--certificate_file=<file> path to the certificate chain\n" | 54 "--certificate_file=<file> path to the certificate chain\n" |
55 "--key_file=<file> path to the pkcs8 private key\n"; | 55 "--key_file=<file> path to the pkcs8 private key\n"; |
56 std::cout << help_str; | 56 std::cout << help_str; |
57 exit(0); | 57 exit(0); |
58 } | 58 } |
59 | 59 |
60 net::QuicInMemoryCache in_memory_cache; | 60 net::QuicHttpResponseCache response_cache; |
61 if (line->HasSwitch("quic_in_memory_cache_dir")) { | 61 if (line->HasSwitch("quic_response_cache_dir")) { |
62 in_memory_cache.InitializeFromDirectory( | 62 response_cache.InitializeFromDirectory( |
63 line->GetSwitchValueASCII("quic_in_memory_cache_dir")); | 63 line->GetSwitchValueASCII("quic_response_cache_dir")); |
64 } | 64 } |
65 | 65 |
66 if (line->HasSwitch("port")) { | 66 if (line->HasSwitch("port")) { |
67 if (!base::StringToInt(line->GetSwitchValueASCII("port"), &FLAGS_port)) { | 67 if (!base::StringToInt(line->GetSwitchValueASCII("port"), &FLAGS_port)) { |
68 LOG(ERROR) << "--port must be an integer\n"; | 68 LOG(ERROR) << "--port must be an integer\n"; |
69 return 1; | 69 return 1; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 if (!line->HasSwitch("certificate_file")) { | 73 if (!line->HasSwitch("certificate_file")) { |
74 LOG(ERROR) << "missing --certificate_file"; | 74 LOG(ERROR) << "missing --certificate_file"; |
75 return 1; | 75 return 1; |
76 } | 76 } |
77 | 77 |
78 if (!line->HasSwitch("key_file")) { | 78 if (!line->HasSwitch("key_file")) { |
79 LOG(ERROR) << "missing --key_file"; | 79 LOG(ERROR) << "missing --key_file"; |
80 return 1; | 80 return 1; |
81 } | 81 } |
82 | 82 |
83 net::IPAddress ip = net::IPAddress::IPv6AllZeros(); | 83 net::IPAddress ip = net::IPAddress::IPv6AllZeros(); |
84 | 84 |
85 net::QuicConfig config; | 85 net::QuicConfig config; |
86 net::QuicSimpleServer server( | 86 net::QuicSimpleServer server( |
87 CreateProofSource(line->GetSwitchValuePath("certificate_file"), | 87 CreateProofSource(line->GetSwitchValuePath("certificate_file"), |
88 line->GetSwitchValuePath("key_file")), | 88 line->GetSwitchValuePath("key_file")), |
89 config, net::QuicCryptoServerConfig::ConfigOptions(), | 89 config, net::QuicCryptoServerConfig::ConfigOptions(), |
90 net::AllSupportedVersions(), &in_memory_cache); | 90 net::AllSupportedVersions(), &response_cache); |
91 | 91 |
92 int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port)); | 92 int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port)); |
93 if (rc < 0) { | 93 if (rc < 0) { |
94 return 1; | 94 return 1; |
95 } | 95 } |
96 | 96 |
97 base::RunLoop().Run(); | 97 base::RunLoop().Run(); |
98 | 98 |
99 return 0; | 99 return 0; |
100 } | 100 } |
OLD | NEW |