Allow setting QUIC version manually

This commit is contained in:
klzgrad 2019-10-05 21:33:27 +08:00
parent 9f3cf4b00d
commit dfe0285de4

View File

@ -47,6 +47,7 @@
#include "net/socket/ssl_client_socket.h" #include "net/socket/ssl_client_socket.h"
#include "net/socket/tcp_server_socket.h" #include "net/socket/tcp_server_socket.h"
#include "net/ssl/ssl_key_logger_impl.h" #include "net/ssl/ssl_key_logger_impl.h"
#include "net/third_party/quiche/src/quic/core/quic_versions.h"
#include "net/tools/naive/naive_proxy.h" #include "net/tools/naive/naive_proxy.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
@ -74,6 +75,7 @@ struct CommandLine {
std::string proxy; std::string proxy;
bool padding; bool padding;
std::string host_resolver_rules; std::string host_resolver_rules;
std::string quic_version;
bool no_log; bool no_log;
base::FilePath log; base::FilePath log;
base::FilePath log_net_log; base::FilePath log_net_log;
@ -89,6 +91,7 @@ struct Params {
std::string proxy_user; std::string proxy_user;
std::string proxy_pass; std::string proxy_pass;
std::string host_resolver_rules; std::string host_resolver_rules;
quic::ParsedQuicVersion quic_version = quic::UnsupportedQuicVersion();
logging::LoggingSettings log_settings; logging::LoggingSettings log_settings;
base::FilePath log_path; base::FilePath log_path;
base::FilePath net_log_path; base::FilePath net_log_path;
@ -140,6 +143,12 @@ std::unique_ptr<net::URLRequestContext> BuildURLRequestContext(
builder.set_host_mapping_rules(params.host_resolver_rules); builder.set_host_mapping_rules(params.host_resolver_rules);
} }
if (params.quic_version != quic::UnsupportedQuicVersion()) {
net::HttpNetworkSession::Params session_params;
session_params.quic_params.supported_versions = {params.quic_version};
builder.set_http_network_session_params(session_params);
}
auto context = builder.Build(); auto context = builder.Build();
if (!params.proxy_url.empty() && !params.proxy_user.empty() && if (!params.proxy_url.empty() && !params.proxy_user.empty() &&
@ -175,6 +184,7 @@ void GetCommandLine(const base::CommandLine& proc, CommandLine* cmdline) {
" proto: https, quic\n" " proto: https, quic\n"
"--padding Use padding\n" "--padding Use padding\n"
"--host-resolver-rules=... Resolver rules\n" "--host-resolver-rules=... Resolver rules\n"
"--quic-version=... Force QUIC version\n"
"--log[=<path>] Log to stderr, or file\n" "--log[=<path>] Log to stderr, or file\n"
"--log-net-log=<path> Save NetLog\n" "--log-net-log=<path> Save NetLog\n"
"--ssl-key-log-file=<path> Save SSL keys for Wireshark\n" "--ssl-key-log-file=<path> Save SSL keys for Wireshark\n"
@ -192,6 +202,7 @@ void GetCommandLine(const base::CommandLine& proc, CommandLine* cmdline) {
cmdline->padding = proc.HasSwitch("padding"); cmdline->padding = proc.HasSwitch("padding");
cmdline->host_resolver_rules = cmdline->host_resolver_rules =
proc.GetSwitchValueASCII("host-resolver-rules"); proc.GetSwitchValueASCII("host-resolver-rules");
cmdline->quic_version = proc.GetSwitchValueASCII("quic-version");
cmdline->no_log = !proc.HasSwitch("log"); cmdline->no_log = !proc.HasSwitch("log");
cmdline->log = proc.GetSwitchValuePath("log"); cmdline->log = proc.GetSwitchValuePath("log");
cmdline->log_net_log = proc.GetSwitchValuePath("log-net-log"); cmdline->log_net_log = proc.GetSwitchValuePath("log-net-log");
@ -227,6 +238,9 @@ void GetCommandLineFromConfig(const base::FilePath& config_path,
cmdline->host_resolver_rules = cmdline->host_resolver_rules =
value->FindKey("host-resolver-rules")->GetString(); value->FindKey("host-resolver-rules")->GetString();
} }
if (value->FindKeyOfType("quic-version", base::Value::Type::STRING)) {
cmdline->quic_version = value->FindKey("quic-version")->GetString();
}
cmdline->no_log = true; cmdline->no_log = true;
if (value->FindKeyOfType("log", base::Value::Type::STRING)) { if (value->FindKeyOfType("log", base::Value::Type::STRING)) {
cmdline->no_log = false; cmdline->no_log = false;
@ -324,6 +338,14 @@ bool ParseCommandLine(const CommandLine& cmdline, Params* params) {
} }
} }
if (!cmdline.quic_version.empty()) {
params->quic_version = quic::ParseQuicVersionString(cmdline.quic_version);
if (params->quic_version == quic::UnsupportedQuicVersion()) {
std::cerr << "Invalid QUIC version" << std::endl;
return false;
}
}
if (!cmdline.no_log) { if (!cmdline.no_log) {
if (!params->log_path.empty()) { if (!params->log_path.empty()) {
params->log_settings.logging_dest = logging::LOG_TO_FILE; params->log_settings.logging_dest = logging::LOG_TO_FILE;