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" |
QUICHE team | 5015e2e | 2019-12-11 09:38:06 -0800 | [diff] [blame^] | 8 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | |
| 10 | namespace quic { |
| 11 | |
| 12 | QuicSimpleDispatcher::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, |
dschinazi | 8ff7482 | 2019-05-28 16:37:20 -0700 | [diff] [blame] | 20 | uint8_t expected_server_connection_id_length) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 21 | : QuicDispatcher(config, |
| 22 | crypto_config, |
| 23 | version_manager, |
| 24 | std::move(helper), |
| 25 | std::move(session_helper), |
| 26 | std::move(alarm_factory), |
dschinazi | 8ff7482 | 2019-05-28 16:37:20 -0700 | [diff] [blame] | 27 | expected_server_connection_id_length), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 28 | quic_simple_server_backend_(quic_simple_server_backend) {} |
| 29 | |
| 30 | QuicSimpleDispatcher::~QuicSimpleDispatcher() = default; |
| 31 | |
| 32 | int 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 | |
| 41 | void 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 | |
| 51 | QuicServerSessionBase* QuicSimpleDispatcher::CreateQuicSession( |
| 52 | QuicConnectionId connection_id, |
| 53 | const QuicSocketAddress& client_address, |
QUICHE team | 5015e2e | 2019-12-11 09:38:06 -0800 | [diff] [blame^] | 54 | quiche::QuicheStringPiece /*alpn*/, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 55 | 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 |