blob: 942eb0a5f394caac4032fce3dcf7fce8946a324e [file] [log] [blame]
QUICHE teamc9b2cec2019-01-07 17:54:15 -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(
QUICHE team2bfc7542019-02-26 14:36:06 -050012 const QuicConfig* config,
QUICHE teamc9b2cec2019-01-07 17:54:15 -050013 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)
19 : QuicDispatcher(config,
20 crypto_config,
21 version_manager,
22 std::move(helper),
23 std::move(session_helper),
24 std::move(alarm_factory)),
25 quic_simple_server_backend_(quic_simple_server_backend) {}
26
27QuicSimpleDispatcher::~QuicSimpleDispatcher() = default;
28
29int QuicSimpleDispatcher::GetRstErrorCount(
30 QuicRstStreamErrorCode error_code) const {
31 auto it = rst_error_map_.find(error_code);
32 if (it == rst_error_map_.end()) {
33 return 0;
34 }
35 return it->second;
36}
37
38void QuicSimpleDispatcher::OnRstStreamReceived(
39 const QuicRstStreamFrame& frame) {
40 auto it = rst_error_map_.find(frame.error_code);
41 if (it == rst_error_map_.end()) {
42 rst_error_map_.insert(std::make_pair(frame.error_code, 1));
43 } else {
44 it->second++;
45 }
46}
47
48QuicServerSessionBase* QuicSimpleDispatcher::CreateQuicSession(
49 QuicConnectionId connection_id,
50 const QuicSocketAddress& client_address,
51 QuicStringPiece /*alpn*/,
52 const ParsedQuicVersion& version) {
53 // The QuicServerSessionBase takes ownership of |connection| below.
54 QuicConnection* connection = new QuicConnection(
55 connection_id, client_address, helper(), alarm_factory(), writer(),
56 /* owns_writer= */ false, Perspective::IS_SERVER,
57 ParsedQuicVersionVector{version});
58
59 QuicServerSessionBase* session = new 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