1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/quic/quic_context.h"
7 #include "base/containers/contains.h"
8 #include "net/quic/platform/impl/quic_chromium_clock.h"
9 #include "net/quic/quic_chromium_connection_helper.h"
10 #include "net/ssl/cert_compression.h"
11 #include "net/ssl/ssl_key_logger.h"
12 #include "net/third_party/quiche/src/quiche/quic/core/crypto/crypto_protocol.h"
13 #include "net/third_party/quiche/src/quiche/quic/core/crypto/quic_random.h"
14 #include "net/third_party/quiche/src/quiche/quic/core/quic_constants.h"
20 // The maximum receive window sizes for QUIC sessions and streams.
21 const int32_t kQuicSessionMaxRecvWindowSize = 15 * 1024 * 1024; // 15 MB
22 const int32_t kQuicStreamMaxRecvWindowSize = 6 * 1024 * 1024; // 6 MB
24 // Set the maximum number of undecryptable packets the connection will store.
25 const int32_t kMaxUndecryptablePackets = 100;
29 QuicParams::QuicParams() = default;
31 QuicParams::QuicParams(const QuicParams& other) = default;
33 QuicParams::~QuicParams() = default;
35 QuicContext::QuicContext()
36 : QuicContext(std::make_unique<QuicChromiumConnectionHelper>(
37 quic::QuicChromiumClock::GetInstance(),
38 quic::QuicRandom::GetInstance())) {}
40 QuicContext::QuicContext(
41 std::unique_ptr<quic::QuicConnectionHelperInterface> helper)
42 : helper_(std::move(helper)) {}
44 QuicContext::~QuicContext() = default;
46 quic::QuicConfig InitializeQuicConfig(const QuicParams& params) {
47 DCHECK_GT(params.idle_connection_timeout, base::TimeDelta());
48 quic::QuicConfig config;
49 config.SetIdleNetworkTimeout(
50 quic::QuicTime::Delta::FromMicroseconds(
51 params.idle_connection_timeout.InMicroseconds()));
52 config.set_max_time_before_crypto_handshake(
53 quic::QuicTime::Delta::FromMicroseconds(
54 params.max_time_before_crypto_handshake.InMicroseconds()));
55 config.set_max_idle_time_before_crypto_handshake(
56 quic::QuicTime::Delta::FromMicroseconds(
57 params.max_idle_time_before_crypto_handshake.InMicroseconds()));
58 quic::QuicTagVector copt_to_send = params.connection_options;
59 config.SetConnectionOptionsToSend(copt_to_send);
60 config.SetClientConnectionOptions(params.client_connection_options);
61 config.set_max_undecryptable_packets(kMaxUndecryptablePackets);
62 config.SetInitialSessionFlowControlWindowToSend(
63 kQuicSessionMaxRecvWindowSize);
64 config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize);
65 config.SetBytesForConnectionIdToSend(0);
69 void ConfigureQuicCryptoClientConfig(
70 quic::QuicCryptoClientConfig& crypto_config) {
71 if (SSLKeyLoggerManager::IsActive()) {
72 SSL_CTX_set_keylog_callback(crypto_config.ssl_ctx(),
73 SSLKeyLoggerManager::KeyLogCallback);
75 ConfigureCertificateCompression(crypto_config.ssl_ctx());