From b6f7a0e1f71aeb06765c799a8fb010ad6c46118d Mon Sep 17 00:00:00 2001 From: klzgrad Date: Sat, 5 Oct 2019 21:33:27 +0800 Subject: [PATCH] Allow setting QUIC version manually --- src/net/tools/naive/naive_proxy_bin.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/net/tools/naive/naive_proxy_bin.cc b/src/net/tools/naive/naive_proxy_bin.cc index c033a8e71c..f87b58465f 100644 --- a/src/net/tools/naive/naive_proxy_bin.cc +++ b/src/net/tools/naive/naive_proxy_bin.cc @@ -47,6 +47,7 @@ #include "net/socket/ssl_client_socket.h" #include "net/socket/tcp_server_socket.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/traffic_annotation/network_traffic_annotation.h" #include "net/url_request/url_request_context.h" @@ -74,6 +75,7 @@ struct CommandLine { std::string proxy; bool padding; std::string host_resolver_rules; + std::string quic_version; bool no_log; base::FilePath log; base::FilePath log_net_log; @@ -89,6 +91,7 @@ struct Params { std::string proxy_user; std::string proxy_pass; std::string host_resolver_rules; + quic::ParsedQuicVersion quic_version = quic::UnsupportedQuicVersion(); logging::LoggingSettings log_settings; base::FilePath log_path; base::FilePath net_log_path; @@ -140,6 +143,12 @@ std::unique_ptr BuildURLRequestContext( 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(); 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" "--padding Use padding\n" "--host-resolver-rules=... Resolver rules\n" + "--quic-version=... Force QUIC version\n" "--log[=] Log to stderr, or file\n" "--log-net-log= Save NetLog\n" "--ssl-key-log-file= Save SSL keys for Wireshark\n" @@ -192,6 +202,7 @@ void GetCommandLine(const base::CommandLine& proc, CommandLine* cmdline) { cmdline->padding = proc.HasSwitch("padding"); cmdline->host_resolver_rules = proc.GetSwitchValueASCII("host-resolver-rules"); + cmdline->quic_version = proc.GetSwitchValueASCII("quic-version"); cmdline->no_log = !proc.HasSwitch("log"); cmdline->log = proc.GetSwitchValuePath("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 = 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; if (value->FindKeyOfType("log", base::Value::Type::STRING)) { 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 (!params->log_path.empty()) { params->log_settings.logging_dest = logging::LOG_TO_FILE;