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

View File

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

View File

@ -81,7 +81,6 @@ constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
struct CommandLine { struct CommandLine {
std::string listen; std::string listen;
std::string proxy; std::string proxy;
bool padding;
std::string concurrency; std::string concurrency;
std::string extra_headers; std::string extra_headers;
std::string host_resolver_rules; std::string host_resolver_rules;
@ -96,7 +95,6 @@ struct Params {
net::ClientProtocol protocol; net::ClientProtocol protocol;
std::string listen_addr; std::string listen_addr;
int listen_port; int listen_port;
bool force_padding;
int concurrency; int concurrency;
net::HttpRequestHeaders extra_headers; net::HttpRequestHeaders extra_headers;
std::string proxy_url; std::string proxy_url;
@ -144,7 +142,6 @@ void GetCommandLine(const base::CommandLine& proc, CommandLine* cmdline) {
" redir (Linux only)\n" " redir (Linux only)\n"
"--proxy=<proto>://[<user>:<pass>@]<hostname>[:<port>]\n" "--proxy=<proto>://[<user>:<pass>@]<hostname>[:<port>]\n"
" proto: https, quic\n" " proto: https, quic\n"
"--padding Force use of padding\n"
"--concurrency=<N> Use N connections, less secure\n" "--concurrency=<N> Use N connections, less secure\n"
"--extra-headers=... Extra headers split by CRLF\n" "--extra-headers=... Extra headers split by CRLF\n"
"--host-resolver-rules=... Resolver rules\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->listen = proc.GetSwitchValueASCII("listen");
cmdline->proxy = proc.GetSwitchValueASCII("proxy"); cmdline->proxy = proc.GetSwitchValueASCII("proxy");
cmdline->padding = proc.HasSwitch("padding");
cmdline->concurrency = proc.GetSwitchValueASCII("concurrency"); cmdline->concurrency = proc.GetSwitchValueASCII("concurrency");
cmdline->extra_headers = proc.GetSwitchValueASCII("extra-headers"); cmdline->extra_headers = proc.GetSwitchValueASCII("extra-headers");
cmdline->host_resolver_rules = cmdline->host_resolver_rules =
@ -198,7 +194,6 @@ void GetCommandLineFromConfig(const base::FilePath& config_path,
if (proxy) { if (proxy) {
cmdline->proxy = *proxy; cmdline->proxy = *proxy;
} }
cmdline->padding = value->FindBoolKey("padding").value_or(false);
const auto* concurrency = value->FindStringKey("concurrency"); const auto* concurrency = value->FindStringKey("concurrency");
if (concurrency) { if (concurrency) {
cmdline->concurrency = *concurrency; cmdline->concurrency = *concurrency;
@ -298,8 +293,6 @@ bool ParseCommandLine(const CommandLine& cmdline, Params* params) {
params->proxy_pass = url.password(); params->proxy_pass = url.password();
} }
params->force_padding = cmdline.padding;
if (!cmdline.concurrency.empty()) { if (!cmdline.concurrency.empty()) {
if (!base::StringToInt(cmdline.concurrency, &params->concurrency) || if (!base::StringToInt(cmdline.concurrency, &params->concurrency) ||
params->concurrency < 1 || params->concurrency > 4) { params->concurrency < 1 || params->concurrency > 4) {
@ -438,8 +431,8 @@ std::unique_ptr<URLRequestContext> BuildURLRequestContext(
builder.SetCertVerifier( builder.SetCertVerifier(
CertVerifier::CreateDefault(std::move(cert_net_fetcher))); CertVerifier::CreateDefault(std::move(cert_net_fetcher)));
builder.set_proxy_delegate(std::make_unique<NaiveProxyDelegate>( builder.set_proxy_delegate(
params.extra_headers, params.force_padding)); std::make_unique<NaiveProxyDelegate>(params.extra_headers));
auto context = builder.Build(); auto context = builder.Build();
@ -583,8 +576,8 @@ int main(int argc, char* argv[]) {
} }
net::NaiveProxy naive_proxy(std::move(listen_socket), params.protocol, net::NaiveProxy naive_proxy(std::move(listen_socket), params.protocol,
params.force_padding, params.concurrency, params.concurrency, resolver.get(), session,
resolver.get(), session, kTrafficAnnotation); kTrafficAnnotation);
base::RunLoop().Run(); 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, NaiveProxyDelegate::NaiveProxyDelegate(const HttpRequestHeaders& extra_headers)
bool force_padding) : extra_headers_(extra_headers) {
: extra_headers_(extra_headers), force_padding_(force_padding) {
InitializeNonindexCodes(); InitializeNonindexCodes();
} }
@ -62,8 +61,7 @@ void NaiveProxyDelegate::OnBeforeTunnelRequest(
// Enables Fast Open in H2/H3 proxy client socket once the state of server // Enables Fast Open in H2/H3 proxy client socket once the state of server
// padding support is known. // padding support is known.
if (force_padding_ || if (padding_state_by_server_[proxy_server] != PaddingSupport::kUnknown) {
padding_state_by_server_[proxy_server] != PaddingSupport::kUnknown) {
extra_headers->SetHeader("fastopen", "1"); extra_headers->SetHeader("fastopen", "1");
} }
extra_headers->MergeFrom(extra_headers_); extra_headers->MergeFrom(extra_headers_);
@ -74,8 +72,6 @@ Error NaiveProxyDelegate::OnTunnelHeadersReceived(
const HttpResponseHeaders& response_headers) { const HttpResponseHeaders& response_headers) {
if (proxy_server.is_direct() || proxy_server.is_socks()) if (proxy_server.is_direct() || proxy_server.is_socks())
return OK; return OK;
if (force_padding_)
return OK;
// Detects server padding support, even if it changes dynamically. // Detects server padding support, even if it changes dynamically.
bool padding = response_headers.HasHeader("padding"); bool padding = response_headers.HasHeader("padding");
@ -96,22 +92,16 @@ PaddingSupport NaiveProxyDelegate::GetProxyServerPaddingSupport(
if (proxy_server.is_direct() || proxy_server.is_socks()) if (proxy_server.is_direct() || proxy_server.is_socks())
return PaddingSupport::kIncapable; return PaddingSupport::kIncapable;
// If detecting padding is possible, forces it.
if (force_padding_)
return PaddingSupport::kCapable;
return padding_state_by_server_[proxy_server]; return padding_state_by_server_[proxy_server];
} }
PaddingDetectorDelegate::PaddingDetectorDelegate( PaddingDetectorDelegate::PaddingDetectorDelegate(
NaiveProxyDelegate* naive_proxy_delegate, NaiveProxyDelegate* naive_proxy_delegate,
const ProxyServer& proxy_server, const ProxyServer& proxy_server,
ClientProtocol client_protocol, ClientProtocol client_protocol)
bool force_padding)
: naive_proxy_delegate_(naive_proxy_delegate), : naive_proxy_delegate_(naive_proxy_delegate),
proxy_server_(proxy_server), proxy_server_(proxy_server),
client_protocol_(client_protocol), client_protocol_(client_protocol),
force_padding_(force_padding),
detected_client_padding_support_(PaddingSupport::kUnknown), detected_client_padding_support_(PaddingSupport::kUnknown),
cached_server_padding_support_(PaddingSupport::kUnknown) {} cached_server_padding_support_(PaddingSupport::kUnknown) {}
@ -151,10 +141,6 @@ PaddingSupport PaddingDetectorDelegate::GetClientPaddingSupport() {
return PaddingSupport::kIncapable; return PaddingSupport::kIncapable;
} }
// If detecting padding is possible, forces it.
if (force_padding_)
return PaddingSupport::kCapable;
return detected_client_padding_support_; return detected_client_padding_support_;
} }

View File

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