Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / tools / quic / quic_server_bin.cc
blob235d5c7a1461901f691aba5685108c0cfc90a536
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
3 // found in the LICENSE file.
4 //
5 // A binary wrapper for QuicServer. It listens forever on --port
6 // (default 6121) until it's killed or ctrl-cd to death.
8 #include <iostream>
10 #include "base/at_exit.h"
11 #include "base/basictypes.h"
12 #include "base/command_line.h"
13 #include "base/logging.h"
14 #include "base/run_loop.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "net/base/ip_endpoint.h"
17 #include "net/quic/quic_protocol.h"
18 #include "net/tools/quic/quic_in_memory_cache.h"
19 #include "net/tools/quic/quic_server.h"
21 // The port the quic server will listen on.
22 int32 FLAGS_port = 6121;
24 // TODO(rtenneti): Enable the following code when Chromium has a working
25 // ProofSourceChromium.
26 #if 0
27 // The directory containing certificate files.
28 char* FLAGS_certificate_dir = nullptr;
29 // The name of the file containing the intermediate certificate.
30 char* FLAGS_intermediate_certificate_name = "intermediate.crt";
31 // The name of the file containing the leaf certificate.
32 char* FLAGS_leaf_certificate_name = "test.example.com";
33 bool FLAGS_disable_permission_validation = true;
35 ProofSource* CreateProofSource(const string& base_directory,
36 const string& intermediate_cert_name,
37 const string& leaf_cert_name) {
38 return new net::ProofSourceChromium();
40 #endif
42 int main(int argc, char *argv[]) {
43 base::AtExitManager exit_manager;
44 base::MessageLoopForIO message_loop;
46 base::CommandLine::Init(argc, argv);
47 base::CommandLine* line = base::CommandLine::ForCurrentProcess();
49 logging::LoggingSettings settings;
50 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
51 CHECK(logging::InitLogging(settings));
53 if (line->HasSwitch("h") || line->HasSwitch("help")) {
54 const char* help_str =
55 "Usage: quic_server [options]\n"
56 "\n"
57 "Options:\n"
58 "-h, --help show this help message and exit\n"
59 "--port=<port> specify the port to listen on\n"
60 "--quic_in_memory_cache_dir directory containing response data\n"
61 " to load\n";
62 std::cout << help_str;
63 exit(0);
66 if (line->HasSwitch("quic_in_memory_cache_dir")) {
67 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory(
68 line->GetSwitchValueASCII("quic_in_memory_cache_dir"));
71 if (line->HasSwitch("port")) {
72 if (!base::StringToInt(line->GetSwitchValueASCII("port"), &FLAGS_port)) {
73 LOG(ERROR) << "--port must be an integer\n";
74 return 1;
78 net::IPAddressNumber ip;
79 CHECK(net::ParseIPLiteralToNumber("::", &ip));
81 net::QuicConfig config;
82 net::tools::QuicServer server(config, net::QuicSupportedVersions());
83 server.SetStrikeRegisterNoStartupPeriod();
85 // TODO(rtenneti): Enable the following code when Chromium has a working
86 // ProofSourceChromium.
87 // if (!FLAGS_certificate_dir.empty()) {
88 // server.SetProofSource(CreateProofSource(
89 // FLAGS_certificate_dir,
90 // FLAGS_intermediate_certificate_name,
91 // FLAGS_leaf_certificate_name));
92 // }
94 int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port));
95 if (rc < 0) {
96 return 1;
99 while (1) {
100 server.WaitForEvents();