• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "net/quic/quic_context.h"
6 
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/third_party/quiche/src/quiche/quic/core/crypto/crypto_protocol.h"
11 #include "net/third_party/quiche/src/quiche/quic/core/crypto/quic_random.h"
12 #include "net/third_party/quiche/src/quiche/quic/core/quic_constants.h"
13 
14 namespace net {
15 
16 namespace {
17 
18 // The maximum receive window sizes for QUIC sessions and streams.
19 const int32_t kQuicSessionMaxRecvWindowSize = 15 * 1024 * 1024;  // 15 MB
20 const int32_t kQuicStreamMaxRecvWindowSize = 6 * 1024 * 1024;    // 6 MB
21 
22 // Set the maximum number of undecryptable packets the connection will store.
23 const int32_t kMaxUndecryptablePackets = 100;
24 
25 }  // namespace
26 
27 QuicParams::QuicParams() = default;
28 
29 QuicParams::QuicParams(const QuicParams& other) = default;
30 
31 QuicParams::~QuicParams() = default;
32 
QuicContext()33 QuicContext::QuicContext()
34     : QuicContext(std::make_unique<QuicChromiumConnectionHelper>(
35           quic::QuicChromiumClock::GetInstance(),
36           quic::QuicRandom::GetInstance())) {}
37 
QuicContext(std::unique_ptr<quic::QuicConnectionHelperInterface> helper)38 QuicContext::QuicContext(
39     std::unique_ptr<quic::QuicConnectionHelperInterface> helper)
40     : helper_(std::move(helper)) {}
41 
42 QuicContext::~QuicContext() = default;
43 
InitializeQuicConfig(const QuicParams & params)44 quic::QuicConfig InitializeQuicConfig(const QuicParams& params) {
45   DCHECK_GT(params.idle_connection_timeout, base::TimeDelta());
46   quic::QuicConfig config;
47   config.SetIdleNetworkTimeout(
48       quic::QuicTime::Delta::FromMicroseconds(
49           params.idle_connection_timeout.InMicroseconds()));
50   config.set_max_time_before_crypto_handshake(
51       quic::QuicTime::Delta::FromMicroseconds(
52           params.max_time_before_crypto_handshake.InMicroseconds()));
53   config.set_max_idle_time_before_crypto_handshake(
54       quic::QuicTime::Delta::FromMicroseconds(
55           params.max_idle_time_before_crypto_handshake.InMicroseconds()));
56   quic::QuicTagVector copt_to_send = params.connection_options;
57   if (!base::Contains(copt_to_send, quic::kRVCM)) {
58     copt_to_send.push_back(quic::kRVCM);
59   }
60   config.SetConnectionOptionsToSend(copt_to_send);
61   config.SetClientConnectionOptions(params.client_connection_options);
62   config.set_max_undecryptable_packets(kMaxUndecryptablePackets);
63   config.SetInitialSessionFlowControlWindowToSend(
64       kQuicSessionMaxRecvWindowSize);
65   config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize);
66   config.SetBytesForConnectionIdToSend(0);
67   return config;
68 }
69 
70 }  // namespace net
71