quic_context.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "net/quic/quic_context.h"
  5. #include "net/quic/platform/impl/quic_chromium_clock.h"
  6. #include "net/quic/quic_chromium_connection_helper.h"
  7. #include "net/third_party/quiche/src/quiche/quic/core/crypto/crypto_protocol.h"
  8. #include "net/third_party/quiche/src/quiche/quic/core/crypto/quic_random.h"
  9. #include "net/third_party/quiche/src/quiche/quic/core/quic_constants.h"
  10. namespace net {
  11. namespace {
  12. // The maximum receive window sizes for QUIC sessions and streams.
  13. const int32_t kQuicSessionMaxRecvWindowSize = 15 * 1024 * 1024; // 15 MB
  14. const int32_t kQuicStreamMaxRecvWindowSize = 6 * 1024 * 1024; // 6 MB
  15. // Set the maximum number of undecryptable packets the connection will store.
  16. const int32_t kMaxUndecryptablePackets = 100;
  17. } // namespace
  18. QuicParams::QuicParams() = default;
  19. QuicParams::QuicParams(const QuicParams& other) = default;
  20. QuicParams::~QuicParams() = default;
  21. QuicContext::QuicContext()
  22. : QuicContext(std::make_unique<QuicChromiumConnectionHelper>(
  23. quic::QuicChromiumClock::GetInstance(),
  24. quic::QuicRandom::GetInstance())) {}
  25. QuicContext::QuicContext(
  26. std::unique_ptr<quic::QuicConnectionHelperInterface> helper)
  27. : helper_(std::move(helper)) {}
  28. QuicContext::~QuicContext() = default;
  29. quic::QuicConfig InitializeQuicConfig(const QuicParams& params) {
  30. DCHECK_GT(params.idle_connection_timeout, base::TimeDelta());
  31. quic::QuicConfig config;
  32. config.SetIdleNetworkTimeout(
  33. quic::QuicTime::Delta::FromMicroseconds(
  34. params.idle_connection_timeout.InMicroseconds()));
  35. config.set_max_time_before_crypto_handshake(
  36. quic::QuicTime::Delta::FromMicroseconds(
  37. params.max_time_before_crypto_handshake.InMicroseconds()));
  38. config.set_max_idle_time_before_crypto_handshake(
  39. quic::QuicTime::Delta::FromMicroseconds(
  40. params.max_idle_time_before_crypto_handshake.InMicroseconds()));
  41. quic::QuicTagVector copt_to_send = params.connection_options;
  42. if (std::find(copt_to_send.begin(), copt_to_send.end(), quic::kRVCM) ==
  43. copt_to_send.end()) {
  44. copt_to_send.push_back(quic::kRVCM);
  45. }
  46. config.SetConnectionOptionsToSend(copt_to_send);
  47. config.SetClientConnectionOptions(params.client_connection_options);
  48. config.set_max_undecryptable_packets(kMaxUndecryptablePackets);
  49. config.SetInitialSessionFlowControlWindowToSend(
  50. kQuicSessionMaxRecvWindowSize);
  51. config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize);
  52. config.SetBytesForConnectionIdToSend(0);
  53. return config;
  54. }
  55. } // namespace net