xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/tools/quic_simple_dispatcher.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2012 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 
5 #include "quiche/quic/tools/quic_simple_dispatcher.h"
6 
7 #include "absl/strings/string_view.h"
8 #include "quiche/quic/core/connection_id_generator.h"
9 #include "quiche/quic/core/quic_types.h"
10 #include "quiche/quic/core/quic_versions.h"
11 #include "quiche/quic/tools/quic_simple_server_session.h"
12 
13 namespace quic {
14 
QuicSimpleDispatcher(const QuicConfig * config,const QuicCryptoServerConfig * crypto_config,QuicVersionManager * version_manager,std::unique_ptr<QuicConnectionHelperInterface> helper,std::unique_ptr<QuicCryptoServerStreamBase::Helper> session_helper,std::unique_ptr<QuicAlarmFactory> alarm_factory,QuicSimpleServerBackend * quic_simple_server_backend,uint8_t expected_server_connection_id_length,ConnectionIdGeneratorInterface & generator)15 QuicSimpleDispatcher::QuicSimpleDispatcher(
16     const QuicConfig* config, const QuicCryptoServerConfig* crypto_config,
17     QuicVersionManager* version_manager,
18     std::unique_ptr<QuicConnectionHelperInterface> helper,
19     std::unique_ptr<QuicCryptoServerStreamBase::Helper> session_helper,
20     std::unique_ptr<QuicAlarmFactory> alarm_factory,
21     QuicSimpleServerBackend* quic_simple_server_backend,
22     uint8_t expected_server_connection_id_length,
23     ConnectionIdGeneratorInterface& generator)
24     : QuicDispatcher(config, crypto_config, version_manager, std::move(helper),
25                      std::move(session_helper), std::move(alarm_factory),
26                      expected_server_connection_id_length, generator),
27       quic_simple_server_backend_(quic_simple_server_backend) {}
28 
29 QuicSimpleDispatcher::~QuicSimpleDispatcher() = default;
30 
GetRstErrorCount(QuicRstStreamErrorCode error_code) const31 int QuicSimpleDispatcher::GetRstErrorCount(
32     QuicRstStreamErrorCode error_code) const {
33   auto it = rst_error_map_.find(error_code);
34   if (it == rst_error_map_.end()) {
35     return 0;
36   }
37   return it->second;
38 }
39 
OnRstStreamReceived(const QuicRstStreamFrame & frame)40 void QuicSimpleDispatcher::OnRstStreamReceived(
41     const QuicRstStreamFrame& frame) {
42   auto it = rst_error_map_.find(frame.error_code);
43   if (it == rst_error_map_.end()) {
44     rst_error_map_.insert(std::make_pair(frame.error_code, 1));
45   } else {
46     it->second++;
47   }
48 }
49 
CreateQuicSession(QuicConnectionId connection_id,const QuicSocketAddress & self_address,const QuicSocketAddress & peer_address,absl::string_view,const ParsedQuicVersion & version,const ParsedClientHello &,ConnectionIdGeneratorInterface & connection_id_generator)50 std::unique_ptr<QuicSession> QuicSimpleDispatcher::CreateQuicSession(
51     QuicConnectionId connection_id, const QuicSocketAddress& self_address,
52     const QuicSocketAddress& peer_address, absl::string_view /*alpn*/,
53     const ParsedQuicVersion& version, const ParsedClientHello& /*parsed_chlo*/,
54     ConnectionIdGeneratorInterface& connection_id_generator) {
55   // The QuicServerSessionBase takes ownership of |connection| below.
56   QuicConnection* connection = new QuicConnection(
57       connection_id, self_address, peer_address, helper(), alarm_factory(),
58       writer(),
59       /* owns_writer= */ false, Perspective::IS_SERVER,
60       ParsedQuicVersionVector{version}, connection_id_generator);
61 
62   auto session = std::make_unique<QuicSimpleServerSession>(
63       config(), GetSupportedVersions(), connection, this, session_helper(),
64       crypto_config(), compressed_certs_cache(), quic_simple_server_backend_);
65   session->Initialize();
66   return session;
67 }
68 
69 }  // namespace quic
70