Skip to content

Commit

Permalink
Quic options (#4586)
Browse files Browse the repository at this point in the history
This adds support for setting `quic_connection_options` and
`quic_client_connection_options` from both the command-line and `h5vcc`,
and raiseskMaxRetransmittablePacketsBeforeAck to 50.

This allows careful evaluation of setting unlimited ack decimation as
well as exploration of non-unlimited ack decimation limits.

b/205134049
  • Loading branch information
jellefoks authored Dec 19, 2024
1 parent a082466 commit 974ad46
Show file tree
Hide file tree
Showing 21 changed files with 270 additions and 14 deletions.
6 changes: 6 additions & 0 deletions cobalt/black_box_tests/testdata/h5vcc_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
]);
assertTrue(reset());
assertFalse(reset());

assertTrue(window.h5vcc.settings.set('QUICConnectionOptions', 'AKDU'));
assertTrue(window.h5vcc.settings.set('QUICClientConnectionOptions', 'TBBR'));
assertTrue(window.h5vcc.settings.set('QUICConnectionOptions', ''));
assertTrue(window.h5vcc.settings.set('QUICClientConnectionOptions', ''));

onEndTest();
</script>
</body>
Expand Down
17 changes: 16 additions & 1 deletion cobalt/h5vcc/h5vcc_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
const char kMediaPrefix[] = "Media.";
const char kMediaCodecBlockList[] = "MediaCodecBlockList";
const char kNavigatorUAData[] = "NavigatorUAData";
const char kDeprecatedProtocolFilter[] = "protocolfilter";
const char kQUIC[] = "QUIC";
const char kQUICConectionOptions[] = "QUICConnectionOptions";
const char kQUICClientConectionOptions[] = "QUICClientConnectionOptions";
const char kHTTP2[] = "HTTP2";
const char kHTTP3[] = "HTTP3";
const char kSkiaRasterizer[] = "SkiaRasterizer";
Expand Down Expand Up @@ -96,6 +99,18 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
}
}

if (name.compare(kQUICConectionOptions) == 0 && value.IsType<std::string>()) {
network_module_->SetQuicConnectionOptions(value.AsType<std::string>());
return true;
}

if (name.compare(kQUICClientConectionOptions) == 0 &&
value.IsType<std::string>()) {
network_module_->SetQuicClientConnectionOptions(
value.AsType<std::string>());
return true;
}

if (name.compare(kHTTP2) == 0 && value.IsType<int32>()) {
if (!persistent_settings_ || !network_module_) {
return false;
Expand All @@ -119,7 +134,7 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
}

// Disabled due to a bug with previous implementation.
if (name.compare("protocolfilter") == 0) {
if (name.compare(kDeprecatedProtocolFilter) == 0) {
return false;
}
if (name.compare(network::kProtocolFilterKey) == 0 &&
Expand Down
16 changes: 16 additions & 0 deletions cobalt/network/network_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ void NetworkModule::SetProtocolFilterFromPersistentSettings() {
std::move(protocol_filter)));
}

void NetworkModule::SetQuicConnectionOptions(
const std::string& connection_options) {
task_runner()->PostTask(
FROM_HERE, base::Bind(&URLRequestContext::SetQuicConnectionOptions,
base::Unretained(url_request_context_.get()),
connection_options));
}

void NetworkModule::SetQuicClientConnectionOptions(
const std::string& client_connection_options) {
task_runner()->PostTask(
FROM_HERE, base::Bind(&URLRequestContext::SetQuicClientConnectionOptions,
base::Unretained(url_request_context_.get()),
client_connection_options));
}

void NetworkModule::EnsureStorageManagerStarted() {
DCHECK(storage_manager_);
storage_manager_->EnsureStarted();
Expand Down
2 changes: 2 additions & 0 deletions cobalt/network/network_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class NetworkModule : public base::CurrentThread::DestructionObserver {
void SetEnableHttp3FromPersistentSettings();
bool SetHttpProtocolFilterPersistentSetting(const std::string&);
void SetProtocolFilterFromPersistentSettings();
void SetQuicConnectionOptions(const std::string&);
void SetQuicClientConnectionOptions(const std::string&);

// Adds the Client Hint Headers to the provided URLFetcher if enabled.
void AddClientHintHeaders(net::URLFetcher& url_fetcher,
Expand Down
14 changes: 14 additions & 0 deletions cobalt/network/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ const char kMaxNetworkDelayHelp[] =
const char kDisableInAppDial[] = "disable_in_app_dial";
const char kDisableInAppDialHelp[] = "Disable the in-app dial server.";

const char kQuicConnectionOptions[] = "quic_connection_options";
const char kQuicConnectionOptionsHelp[] =
"Specify QUIC connection options. "
"Refer to QUICHE header crypto_protocol.h for existing tags. "
"For example: --quic_connection_options=AKDU";

const char kQuicClientConnectionOptions[] = "quic_client_connection_options.";
const char kQuicClientConnectionOptionsHelp[] =
"Specify QUIC client connection options"
"Refer to QUICHE header crypto_protocol.h for existing tags. ";

#endif // ENABLE_DEBUG_COMMAND_LINE_SWITCHES

const char kDisableQuic[] = "disable_quic";
Expand All @@ -71,7 +82,10 @@ std::map<std::string, const char*> HelpMap() {
{kNetLog, kNetLogHelp},
{kNetLogCaptureMode, kNetLogCaptureModeHelp},
{kUserAgent, kUserAgentHelp},
{kMaxNetworkDelay, kMaxNetworkDelayHelp},
{kDisableInAppDial, kDisableInAppDialHelp},
{kQuicConnectionOptions, kQuicConnectionOptionsHelp},
{kQuicClientConnectionOptions, kQuicClientConnectionOptionsHelp},
#endif // !defined(ENABLE_DEBUG_COMMAND_LINE_SWITCHES)
{kDisableQuic, kDisableQuicHelp},
{kDisableHttp2, kDisableHttp2Help},
Expand Down
4 changes: 4 additions & 0 deletions cobalt/network/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ extern const char kUserAgent[];
extern const char kMaxNetworkDelay[];
extern const char kMaxNetworkDelayHelp[];
extern const char kDisableInAppDial[];
extern const char kQuicConnectionOptions[];
extern const char kQuicConnectionOptionsHelp[];
extern const char kQuicClientConnectionOptions[];
extern const char kQuicClientConnectionOptionsHelp[];
#endif // ENABLE_DEBUG_COMMAND_LINE_SWITCHES
extern const char kDisableQuic[];
extern const char kDisableHttp2[];
Expand Down
44 changes: 43 additions & 1 deletion cobalt/network/url_request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "net/quic/quic_context.h"
#include "net/ssl/ssl_config_service.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/third_party/quiche/src/quiche/quic/core/quic_tag.h"
#include "starboard/common/murmurhash2.h"
#include "starboard/configuration_constants.h"

Expand Down Expand Up @@ -207,9 +208,27 @@ URLRequestContext::URLRequestContext(
auto quic_context = std::make_unique<net::QuicContext>();
quic_context->params()->supported_versions =
quic::ParsedQuicVersionVector{quic::ParsedQuicVersion::Q046()};
url_request_context_builder->set_quic_context(std::move(quic_context));

base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();

#if defined(ENABLE_DEBUG_COMMAND_LINE_SWITCHES)
std::string quic_connection_options =
command_line->GetSwitchValueASCII(switches::kQuicConnectionOptions);
if (!quic_connection_options.empty()) {
quic_context->params()->connection_options =
quic::ParseQuicTagVector(quic_connection_options);
}

std::string quic_client_connection_options =
command_line->GetSwitchValueASCII(switches::kQuicClientConnectionOptions);
if (!quic_connection_options.empty()) {
quic_context->params()->client_connection_options =
quic::ParseQuicTagVector(quic_client_connection_options);
}
#endif

url_request_context_builder->set_quic_context(std::move(quic_context));

bool quic_enabled =
configuration::Configuration::GetInstance()->CobaltEnableQuic() &&
!command_line->HasSwitch(switches::kDisableQuic);
Expand Down Expand Up @@ -345,6 +364,29 @@ void URLRequestContext::SetEnableHttp2(bool enable_http2) {
enable_http2 && http2_commandline_enabled);
}

void URLRequestContext::SetQuicConnectionOptions(
const std::string& connection_options) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

quic::QuicTagVector options = quic::ParseQuicTagVector(connection_options);
// Set the new tags in all copies of QuicParams.
url_request_context_->quic_context()->params()->connection_options = options;
url_request_context_->http_network_session()->SetConnectionOptions(options);
}

void URLRequestContext::SetQuicClientConnectionOptions(
const std::string& client_connection_options) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

quic::QuicTagVector options =
quic::ParseQuicTagVector(client_connection_options);
// Set the new tags in all copies of QuicParams.
url_request_context_->quic_context()->params()->client_connection_options =
options;
url_request_context_->http_network_session()->SetClientConnectionOptions(
options);
}

bool URLRequestContext::using_http_cache() { return using_http_cache_; }

#if defined(ENABLE_DEBUGGER)
Expand Down
3 changes: 3 additions & 0 deletions cobalt/network/url_request_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class URLRequestContext {
void SetEnableQuic(bool enable_quic);
void SetEnableHttp2(bool enable_http2);

void SetQuicConnectionOptions(const std::string&);
void SetQuicClientConnectionOptions(const std::string&);

bool using_http_cache();

void UpdateCacheSizeSetting(disk_cache::ResourceType type, uint32_t bytes);
Expand Down
16 changes: 14 additions & 2 deletions net/http/http_network_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void HttpNetworkSession::DisableQuic() {
params_.enable_quic = false;
}

#if defined(STARBOARD)
#if defined(USE_COBALT_CUSTOMIZATIONS)
void HttpNetworkSession::SetEnableQuic(bool enable_quic) {
params_.enable_quic = enable_quic;
}
Expand All @@ -396,7 +396,7 @@ void HttpNetworkSession::SetEnableHttp2(bool enable_http2) {
bool HttpNetworkSession::UseQuicForUnknownOrigin() const {
return params_.use_quic_for_unknown_origins;
}
#endif // defined(STARBOARD)
#endif // defined(USE_COBALT_CUSTOMIZATIONS)

void HttpNetworkSession::ClearSSLSessionCache() {
ssl_client_session_cache_.Flush();
Expand All @@ -418,6 +418,18 @@ CommonConnectJobParams HttpNetworkSession::CreateCommonConnectJobParams(
for_websockets ? &websocket_endpoint_lock_manager_ : nullptr);
}

#if defined(USE_COBALT_CUSTOMIZATIONS)
void HttpNetworkSession::SetConnectionOptions(
const quic::QuicTagVector& options) {
quic_stream_factory_.SetConnectionOptions(options);
}

void HttpNetworkSession::SetClientConnectionOptions(
const quic::QuicTagVector& options) {
quic_stream_factory_.SetClientConnectionOptions(options);
}
#endif // defined(USE_COBALT_CUSTOMIZATIONS)

ClientSocketPoolManager* HttpNetworkSession::GetSocketPoolManager(
SocketPoolType pool_type) {
switch (pool_type) {
Expand Down
17 changes: 11 additions & 6 deletions net/http/http_network_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ struct NET_EXPORT HttpNetworkSessionParams {
// If true, HTTPS URLs can be sent to QUIC proxies.
bool enable_quic_proxies_for_https_urls = false;

#if defined(STARBOARD)
// If true, request to an origin without recorded alt-svc info will
// try to establish both QUIC and TCP connections and use the faster one.
#if defined(USE_COBALT_CUSTOMIZATIONS)
// If true, request to an origin without recorded alt-svc info will
// try to establish both QUIC and TCP connections and use the faster one.
bool use_quic_for_unknown_origins = false;
#endif
#endif // defined(USE_COBALT_CUSTOMIZATIONS)

// If non-empty, QUIC will only be spoken to hosts in this list.
base::flat_set<std::string> quic_host_allowlist;
Expand Down Expand Up @@ -313,13 +313,13 @@ class NET_EXPORT HttpNetworkSession {
// Disable QUIC for new streams.
void DisableQuic();

#if defined(STARBOARD)
#if defined(USE_COBALT_CUSTOMIZATIONS)
void SetEnableQuic(bool enable_quic);
void SetEnableHttp2(bool enable_http2);

// Whether to try QUIC connection for origins without alt-svc on record.
bool UseQuicForUnknownOrigin() const;
#endif // defined(STARBOARD)
#endif // defined(USE_COBALT_CUSTOMIZATIONS)

// Clear the SSL session cache.
void ClearSSLSessionCache();
Expand All @@ -331,6 +331,11 @@ class NET_EXPORT HttpNetworkSession {
CommonConnectJobParams CreateCommonConnectJobParams(
bool for_websockets = false);

#if defined(USE_COBALT_CUSTOMIZATIONS)
void SetConnectionOptions(const quic::QuicTagVector& options);
void SetClientConnectionOptions(const quic::QuicTagVector& options);
#endif // defined(USE_COBALT_CUSTOMIZATIONS)

private:
friend class HttpNetworkSessionPeer;

Expand Down
14 changes: 14 additions & 0 deletions net/quic/quic_stream_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,20 @@ const std::set<std::string>& QuicStreamFactory::GetDnsAliasesForSessionKey(
return it->second;
}

#if defined(USE_COBALT_CUSTOMIZATIONS)
void QuicStreamFactory::SetConnectionOptions(
const quic::QuicTagVector& options) {
params_.connection_options = options;
config_.SetConnectionOptionsToSend(options);
}

void QuicStreamFactory::SetClientConnectionOptions(
const quic::QuicTagVector& options) {
params_.client_connection_options = options;
config_.SetClientConnectionOptions(options);
}
#endif // defined(USE_COBALT_CUSTOMIZATIONS)

bool QuicStreamFactory::HasMatchingIpSession(
const QuicSessionAliasKey& key,
const std::vector<IPEndPoint>& ip_endpoints,
Expand Down
9 changes: 9 additions & 0 deletions net/quic/quic_stream_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ class NET_EXPORT_PRIVATE QuicStreamFactory
const std::set<std::string>& GetDnsAliasesForSessionKey(
const QuicSessionKey& key) const;

#if defined(USE_COBALT_CUSTOMIZATIONS)
void SetConnectionOptions(const quic::QuicTagVector& options);
void SetClientConnectionOptions(const quic::QuicTagVector& options);
#endif // defined(USE_COBALT_CUSTOMIZATIONS)

private:
class Job;
class QuicCryptoClientConfigOwner;
Expand Down Expand Up @@ -685,7 +690,11 @@ class NET_EXPORT_PRIVATE QuicStreamFactory
std::unique_ptr<QuicCryptoClientConfigOwner>>
recent_crypto_config_map_;

#if defined(USE_COBALT_CUSTOMIZATIONS)
quic::QuicConfig config_;
#else
const quic::QuicConfig config_;
#endif // defined(USE_COBALT_CUSTOMIZATIONS)

JobMap active_jobs_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,30 @@ const QuicTag kCertificateTag = TAG('C', 'R', 'T', 255); // Certificate chain
const QuicTag kCertificateSCTTag =
TAG('C', 'S', 'C', 'T'); // Signed cert timestamp (RFC6962) of leaf cert.

#if defined(USE_COBALT_CUSTOMIZATIONS)
// A number of tags for evaluation to find the optimal value.
const QuicTag kCOB0 = TAG('C', 'O', 'B', '0'); // 10 packets received before
// acking
const QuicTag kCOB1 = TAG('C', 'O', 'B', '1'); // 20 packets received before
// acking
const QuicTag kCOB2 = TAG('C', 'O', 'B', '2'); // 40 packets received before
// acking
const QuicTag kCOB3 = TAG('C', 'O', 'B', '3'); // 60 packets received before
// acking
const QuicTag kCOB4 = TAG('C', 'O', 'B', '4'); // 80 packets received before
// acking
const QuicTag kCOB5 = TAG('C', 'O', 'B', '5'); // 100 packets received before
// acking
const QuicTag kCOB6 = TAG('C', 'O', 'B', '6'); // 120 packets received before
// acking
const QuicTag kCOB7 = TAG('C', 'O', 'B', '7'); // 160 packets received before
// acking
const QuicTag kCOB8 = TAG('C', 'O', 'B', '8'); // 200 packets received before
// acking
const QuicTag kCOB9 = TAG('C', 'O', 'B', '9'); // 240 packets received before
// acking
#endif // defined(USE_COBALT_CUSTOMIZATIONS)

#undef TAG

const size_t kMaxEntries = 128; // Max number of entries in a message.
Expand Down
6 changes: 5 additions & 1 deletion net/third_party/quiche/src/quiche/quic/core/quic_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,12 @@ inline constexpr int kDefaultIetfLossDelayShift = 3;

// Maximum number of retransmittable packets received before sending an ack.
inline constexpr QuicPacketCount kDefaultRetransmittablePacketsBeforeAck = 2;
// Wait for up to 10 retransmittable packets before sending an ack.
// Wait for up to 50 retransmittable packets before sending an ack.
#if defined(USE_COBALT_CUSTOMIZATIONS)
inline constexpr QuicPacketCount kMaxRetransmittablePacketsBeforeAck = 50;
#else
inline constexpr QuicPacketCount kMaxRetransmittablePacketsBeforeAck = 10;
#endif // defined(USE_COBALT_CUSTOMIZATIONS)
// Minimum number of packets received before ack decimation is enabled.
// This intends to avoid the beginning of slow start, when CWNDs may be
// rapidly increasing.
Expand Down
Loading

0 comments on commit 974ad46

Please sign in to comment.