blob: f5f5a6c7faa8f863643082b02c157acb921cc242 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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 "net/third_party/quiche/src/quic/tools/quic_simple_dispatcher.h"
6
7#include "net/third_party/quiche/src/quic/tools/quic_simple_server_session.h"
QUICHE team5015e2e2019-12-11 09:38:06 -08008#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -05009
10namespace quic {
11
12QuicSimpleDispatcher::QuicSimpleDispatcher(
13 const QuicConfig* config,
14 const QuicCryptoServerConfig* crypto_config,
15 QuicVersionManager* version_manager,
16 std::unique_ptr<QuicConnectionHelperInterface> helper,
17 std::unique_ptr<QuicCryptoServerStream::Helper> session_helper,
18 std::unique_ptr<QuicAlarmFactory> alarm_factory,
19 QuicSimpleServerBackend* quic_simple_server_backend,
dschinazi8ff74822019-05-28 16:37:20 -070020 uint8_t expected_server_connection_id_length)
QUICHE teama6ef0a62019-03-07 20:34:33 -050021 : QuicDispatcher(config,
22 crypto_config,
23 version_manager,
24 std::move(helper),
25 std::move(session_helper),
26 std::move(alarm_factory),
dschinazi8ff74822019-05-28 16:37:20 -070027 expected_server_connection_id_length),
QUICHE teama6ef0a62019-03-07 20:34:33 -050028 quic_simple_server_backend_(quic_simple_server_backend) {}
29
30QuicSimpleDispatcher::~QuicSimpleDispatcher() = default;
31
32int QuicSimpleDispatcher::GetRstErrorCount(
33 QuicRstStreamErrorCode error_code) const {
34 auto it = rst_error_map_.find(error_code);
35 if (it == rst_error_map_.end()) {
36 return 0;
37 }
38 return it->second;
39}
40
41void QuicSimpleDispatcher::OnRstStreamReceived(
42 const QuicRstStreamFrame& frame) {
43 auto it = rst_error_map_.find(frame.error_code);
44 if (it == rst_error_map_.end()) {
45 rst_error_map_.insert(std::make_pair(frame.error_code, 1));
46 } else {
47 it->second++;
48 }
49}
50
51QuicServerSessionBase* QuicSimpleDispatcher::CreateQuicSession(
52 QuicConnectionId connection_id,
53 const QuicSocketAddress& client_address,
QUICHE team5015e2e2019-12-11 09:38:06 -080054 quiche::QuicheStringPiece /*alpn*/,
QUICHE teama6ef0a62019-03-07 20:34:33 -050055 const ParsedQuicVersion& version) {
56 // The QuicServerSessionBase takes ownership of |connection| below.
57 QuicConnection* connection = new QuicConnection(
58 connection_id, client_address, helper(), alarm_factory(), writer(),
59 /* owns_writer= */ false, Perspective::IS_SERVER,
60 ParsedQuicVersionVector{version});
61
62 QuicServerSessionBase* session = new 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