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