blob: 0f4d4476848966ea80111c7a20dca63f18745f7d [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"
8
9namespace quic {
10
11QuicSimpleDispatcher::QuicSimpleDispatcher(
12 const QuicConfig* config,
13 const QuicCryptoServerConfig* crypto_config,
14 QuicVersionManager* version_manager,
15 std::unique_ptr<QuicConnectionHelperInterface> helper,
16 std::unique_ptr<QuicCryptoServerStream::Helper> session_helper,
17 std::unique_ptr<QuicAlarmFactory> alarm_factory,
18 QuicSimpleServerBackend* quic_simple_server_backend,
dschinazi8ff74822019-05-28 16:37:20 -070019 uint8_t expected_server_connection_id_length)
QUICHE teama6ef0a62019-03-07 20:34:33 -050020 : QuicDispatcher(config,
21 crypto_config,
22 version_manager,
23 std::move(helper),
24 std::move(session_helper),
25 std::move(alarm_factory),
dschinazi8ff74822019-05-28 16:37:20 -070026 expected_server_connection_id_length),
QUICHE teama6ef0a62019-03-07 20:34:33 -050027 quic_simple_server_backend_(quic_simple_server_backend) {}
28
29QuicSimpleDispatcher::~QuicSimpleDispatcher() = default;
30
31int 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
40void 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
50QuicServerSessionBase* QuicSimpleDispatcher::CreateQuicSession(
51 QuicConnectionId connection_id,
52 const QuicSocketAddress& client_address,
53 QuicStringPiece /*alpn*/,
54 const ParsedQuicVersion& version) {
55 // The QuicServerSessionBase takes ownership of |connection| below.
56 QuicConnection* connection = new QuicConnection(
57 connection_id, client_address, helper(), alarm_factory(), writer(),
58 /* owns_writer= */ false, Perspective::IS_SERVER,
59 ParsedQuicVersionVector{version});
60
61 QuicServerSessionBase* session = new QuicSimpleServerSession(
62 config(), GetSupportedVersions(), connection, this, session_helper(),
63 crypto_config(), compressed_certs_cache(), quic_simple_server_backend_);
64 session->Initialize();
65 return session;
66}
67
68} // namespace quic