Clear webapp storage when site data is cleared
[chromium-blink-merge.git] / net / tools / quic / quic_simple_server_bin.cc
blobb1f6a6ab1bb797b6c06d02cca59d02c3d3c9d884
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/crypto/proof_source_chromium.h"
18 #include "net/quic/quic_protocol.h"
19 #include "net/tools/quic/quic_in_memory_cache.h"
20 #include "net/tools/quic/quic_simple_server.h"
22 // The port the quic server will listen on.
23 int32 FLAGS_port = 6121;
25 net::ProofSource* CreateProofSource(const base::FilePath& cert_path,
26 const base::FilePath& key_path) {
27 net::ProofSourceChromium* proof_source = new net::ProofSourceChromium();
28 CHECK(proof_source->Initialize(cert_path, key_path));
29 return proof_source;
32 int main(int argc, char *argv[]) {
33 base::AtExitManager exit_manager;
34 base::MessageLoopForIO message_loop;
36 base::CommandLine::Init(argc, argv);
37 base::CommandLine* line = base::CommandLine::ForCurrentProcess();
39 logging::LoggingSettings settings;
40 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
41 CHECK(logging::InitLogging(settings));
43 if (line->HasSwitch("h") || line->HasSwitch("help")) {
44 const char* help_str =
45 "Usage: quic_server [options]\n"
46 "\n"
47 "Options:\n"
48 "-h, --help show this help message and exit\n"
49 "--port=<port> specify the port to listen on\n"
50 "--quic_in_memory_cache_dir directory containing response data\n"
51 " to load\n"
52 "--certificate_file=<file> path to the certificate chain\n"
53 "--key_file=<file> path to the pkcs8 private key\n";
54 std::cout << help_str;
55 exit(0);
58 if (line->HasSwitch("quic_in_memory_cache_dir")) {
59 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory(
60 line->GetSwitchValueASCII("quic_in_memory_cache_dir"));
63 if (line->HasSwitch("port")) {
64 if (!base::StringToInt(line->GetSwitchValueASCII("port"), &FLAGS_port)) {
65 LOG(ERROR) << "--port must be an integer\n";
66 return 1;
70 net::IPAddressNumber ip;
71 CHECK(net::ParseIPLiteralToNumber("::", &ip));
73 net::QuicConfig config;
74 net::tools::QuicSimpleServer server(config, net::QuicSupportedVersions());
75 server.SetStrikeRegisterNoStartupPeriod();
76 if (!line->HasSwitch("certificate_file")) {
77 LOG(ERROR) << "missing --certificate_file";
78 return 1;
80 if (!line->HasSwitch("key_file")) {
81 LOG(ERROR) << "missing --key_file";
82 return 1;
84 server.SetProofSource(
85 CreateProofSource(line->GetSwitchValuePath("certificate_file"),
86 line->GetSwitchValuePath("key_file")));
88 int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port));
89 if (rc < 0) {
90 return 1;
93 base::RunLoop().Run();
95 return 0;