Skip to content

Commit

Permalink
Remove force padding option
Browse files Browse the repository at this point in the history
  • Loading branch information
klzgrad committed Jun 16, 2020
1 parent 855846f commit e8e4f77
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 40 deletions.
4 changes: 1 addition & 3 deletions src/net/tools/naive/naive_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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_),
Expand Down
2 changes: 0 additions & 2 deletions src/net/tools/naive/naive_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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_;
Expand Down
15 changes: 4 additions & 11 deletions src/net/tools/naive/naive_proxy_bin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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"
Expand All @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
22 changes: 4 additions & 18 deletions src/net/tools/naive/naive_proxy_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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_);
Expand All @@ -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");
Expand All @@ -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) {}

Expand Down Expand Up @@ -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_;
}

Expand Down
8 changes: 2 additions & 6 deletions src/net/tools/naive/naive_proxy_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -53,7 +52,6 @@ class NaiveProxyDelegate : public ProxyDelegate {

private:
const HttpRequestHeaders& extra_headers_;
bool force_padding_;
std::map<ProxyServer, PaddingSupport> padding_state_by_server_;
};

Expand All @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit e8e4f77

Please sign in to comment.