QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 "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 | |
| 9 | namespace quic { |
| 10 | |
| 11 | QuicSimpleDispatcher::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, |
dschinazi | 8ff7482 | 2019-05-28 16:37:20 -0700 | [diff] [blame] | 19 | uint8_t expected_server_connection_id_length) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 20 | : QuicDispatcher(config, |
| 21 | crypto_config, |
| 22 | version_manager, |
| 23 | std::move(helper), |
| 24 | std::move(session_helper), |
| 25 | std::move(alarm_factory), |
dschinazi | 8ff7482 | 2019-05-28 16:37:20 -0700 | [diff] [blame] | 26 | expected_server_connection_id_length), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 27 | quic_simple_server_backend_(quic_simple_server_backend) {} |
| 28 | |
| 29 | QuicSimpleDispatcher::~QuicSimpleDispatcher() = default; |
| 30 | |
| 31 | 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 | |
| 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 | |
| 50 | QuicServerSessionBase* 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 |