Remove force padding option

This commit is contained in:
klzgrad 2020-06-16 20:44:35 +08:00
parent 855846fcee
commit e8e4f772a3
5 changed files with 11 additions and 40 deletions

View File

@ -29,14 +29,12 @@ namespace net {
NaiveProxy::NaiveProxy(std::unique_ptr<ServerSocket> listen_socket,
ClientProtocol protocol,
bool force_padding,
int concurrency,
RedirectResolver* resolver,
HttpNetworkSession* session,
const NetworkTrafficAnnotationTag& traffic_annotation)
: listen_socket_(std::move(listen_socket)),
protocol_(protocol),
force_padding_(force_padding),
concurrency_(std::min(4, std::max(1, concurrency))),
resolver_(resolver),
session_(session),
@ -106,7 +104,7 @@ void NaiveProxy::DoConnect() {
DCHECK(!proxy_info_.is_empty());
const auto& proxy_server = proxy_info_.proxy_server();
auto padding_detector_delegate = std::make_unique<PaddingDetectorDelegate>(
proxy_delegate, proxy_server, protocol_, force_padding_);
proxy_delegate, proxy_server, protocol_);
if (protocol_ == ClientProtocol::kSocks5) {
socket = std::make_unique<Socks5ServerSocket>(std::move(accepted_socket_),

View File

@ -34,7 +34,6 @@ class NaiveProxy {
public:
NaiveProxy(std::unique_ptr<ServerSocket> server_socket,
ClientProtocol protocol,
bool force_padding,
int concurrency,
RedirectResolver* resolver,
HttpNetworkSession* session,
@ -60,7 +59,6 @@ class NaiveProxy {
std::unique_ptr<ServerSocket> listen_socket_;
ClientProtocol protocol_;
bool force_padding_;
int concurrency_;
ProxyInfo proxy_info_;
SSLConfig server_ssl_config_;

View File

@ -81,7 +81,6 @@ constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
struct CommandLine {
std::string listen;
std::string proxy;
bool padding;
std::string concurrency;
std::string extra_headers;
std::string host_resolver_rules;
@ -96,7 +95,6 @@ struct Params {
net::ClientProtocol protocol;
std::string listen_addr;
int listen_port;
bool force_padding;
int concurrency;
net::HttpRequestHeaders extra_headers;
std::string proxy_url;
@ -144,7 +142,6 @@ void GetCommandLine(const base::CommandLine& proc, CommandLine* cmdline) {
" redir (Linux only)\n"
"--proxy=<proto>://[<user>:<pass>@]<hostname>[:<port>]\n"
" proto: https, quic\n"
"--padding Force use of padding\n"
"--concurrency=<N> Use N connections, less secure\n"
"--extra-headers=... Extra headers split by CRLF\n"
"--host-resolver-rules=... Resolver rules\n"
@ -163,7 +160,6 @@ void GetCommandLine(const base::CommandLine& proc, CommandLine* cmdline) {
cmdline->listen = proc.GetSwitchValueASCII("listen");
cmdline->proxy = proc.GetSwitchValueASCII("proxy");
cmdline->padding = proc.HasSwitch("padding");
cmdline->concurrency = proc.GetSwitchValueASCII("concurrency");
cmdline->extra_headers = proc.GetSwitchValueASCII("extra-headers");
cmdline->host_resolver_rules =
@ -198,7 +194,6 @@ void GetCommandLineFromConfig(const base::FilePath& config_path,
if (proxy) {
cmdline->proxy = *proxy;
}
cmdline->padding = value->FindBoolKey("padding").value_or(false);
const auto* concurrency = value->FindStringKey("concurrency");
if (concurrency) {
cmdline->concurrency = *concurrency;
@ -298,8 +293,6 @@ bool ParseCommandLine(const CommandLine& cmdline, Params* params) {
params->proxy_pass = url.password();
}
params->force_padding = cmdline.padding;
if (!cmdline.concurrency.empty()) {
if (!base::StringToInt(cmdline.concurrency, &params->concurrency) ||
params->concurrency < 1 || params->concurrency > 4) {
@ -438,8 +431,8 @@ std::unique_ptr<URLRequestContext> BuildURLRequestContext(
builder.SetCertVerifier(
CertVerifier::CreateDefault(std::move(cert_net_fetcher)));
builder.set_proxy_delegate(std::make_unique<NaiveProxyDelegate>(
params.extra_headers, params.force_padding));
builder.set_proxy_delegate(
std::make_unique<NaiveProxyDelegate>(params.extra_headers));
auto context = builder.Build();
@ -583,8 +576,8 @@ int main(int argc, char* argv[]) {
}
net::NaiveProxy naive_proxy(std::move(listen_socket), params.protocol,
params.force_padding, params.concurrency,
resolver.get(), session, kTrafficAnnotation);
params.concurrency, resolver.get(), session,
kTrafficAnnotation);
base::RunLoop().Run();

View File

@ -41,9 +41,8 @@ void FillNonindexHeaderValue(uint64_t unique_bits, char* buf, int len) {
}
}
NaiveProxyDelegate::NaiveProxyDelegate(const HttpRequestHeaders& extra_headers,
bool force_padding)
: extra_headers_(extra_headers), force_padding_(force_padding) {
NaiveProxyDelegate::NaiveProxyDelegate(const HttpRequestHeaders& extra_headers)
: extra_headers_(extra_headers) {
InitializeNonindexCodes();
}
@ -62,8 +61,7 @@ void NaiveProxyDelegate::OnBeforeTunnelRequest(
// Enables Fast Open in H2/H3 proxy client socket once the state of server
// padding support is known.
if (force_padding_ ||
padding_state_by_server_[proxy_server] != PaddingSupport::kUnknown) {
if (padding_state_by_server_[proxy_server] != PaddingSupport::kUnknown) {
extra_headers->SetHeader("fastopen", "1");
}
extra_headers->MergeFrom(extra_headers_);
@ -74,8 +72,6 @@ Error NaiveProxyDelegate::OnTunnelHeadersReceived(
const HttpResponseHeaders& response_headers) {
if (proxy_server.is_direct() || proxy_server.is_socks())
return OK;
if (force_padding_)
return OK;
// Detects server padding support, even if it changes dynamically.
bool padding = response_headers.HasHeader("padding");
@ -96,22 +92,16 @@ PaddingSupport NaiveProxyDelegate::GetProxyServerPaddingSupport(
if (proxy_server.is_direct() || proxy_server.is_socks())
return PaddingSupport::kIncapable;
// If detecting padding is possible, forces it.
if (force_padding_)
return PaddingSupport::kCapable;
return padding_state_by_server_[proxy_server];
}
PaddingDetectorDelegate::PaddingDetectorDelegate(
NaiveProxyDelegate* naive_proxy_delegate,
const ProxyServer& proxy_server,
ClientProtocol client_protocol,
bool force_padding)
ClientProtocol client_protocol)
: naive_proxy_delegate_(naive_proxy_delegate),
proxy_server_(proxy_server),
client_protocol_(client_protocol),
force_padding_(force_padding),
detected_client_padding_support_(PaddingSupport::kUnknown),
cached_server_padding_support_(PaddingSupport::kUnknown) {}
@ -151,10 +141,6 @@ PaddingSupport PaddingDetectorDelegate::GetClientPaddingSupport() {
return PaddingSupport::kIncapable;
}
// If detecting padding is possible, forces it.
if (force_padding_)
return PaddingSupport::kCapable;
return detected_client_padding_support_;
}

View File

@ -31,8 +31,7 @@ enum class PaddingSupport {
class NaiveProxyDelegate : public ProxyDelegate {
public:
NaiveProxyDelegate(const HttpRequestHeaders& extra_headers,
bool force_padding);
NaiveProxyDelegate(const HttpRequestHeaders& extra_headers);
~NaiveProxyDelegate() override;
void OnResolveProxy(const GURL& url,
@ -53,7 +52,6 @@ class NaiveProxyDelegate : public ProxyDelegate {
private:
const HttpRequestHeaders& extra_headers_;
bool force_padding_;
std::map<ProxyServer, PaddingSupport> padding_state_by_server_;
};
@ -68,8 +66,7 @@ class PaddingDetectorDelegate : public ClientPaddingDetectorDelegate {
public:
PaddingDetectorDelegate(NaiveProxyDelegate* naive_proxy_delegate,
const ProxyServer& proxy_server,
ClientProtocol client_protocol,
bool force_padding);
ClientProtocol client_protocol);
~PaddingDetectorDelegate() override;
bool IsPaddingSupportKnown();
@ -83,7 +80,6 @@ class PaddingDetectorDelegate : public ClientPaddingDetectorDelegate {
NaiveProxyDelegate* naive_proxy_delegate_;
const ProxyServer& proxy_server_;
ClientProtocol client_protocol_;
bool force_padding_;
PaddingSupport detected_client_padding_support_;
// The result is only cached during one connection, so it's still dynamically