dschinazi | 22e23c7 | 2019-12-17 17:16:15 -0800 | [diff] [blame] | 1 | // Copyright 2019 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 | #ifndef QUICHE_QUIC_MASQUE_MASQUE_DISPATCHER_H_ |
| 6 | #define QUICHE_QUIC_MASQUE_MASQUE_DISPATCHER_H_ |
| 7 | |
| 8 | #include "net/third_party/quiche/src/quic/masque/masque_server_backend.h" |
| 9 | #include "net/third_party/quiche/src/quic/masque/masque_server_session.h" |
| 10 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
| 11 | #include "net/third_party/quiche/src/quic/tools/quic_simple_dispatcher.h" |
| 12 | |
| 13 | namespace quic { |
| 14 | |
| 15 | // QUIC dispatcher that handles new MASQUE connections and can proxy traffic |
| 16 | // between MASQUE clients and QUIC servers. |
| 17 | class QUIC_NO_EXPORT MasqueDispatcher : public QuicSimpleDispatcher, |
| 18 | public MasqueServerSession::Visitor { |
| 19 | public: |
| 20 | explicit MasqueDispatcher( |
| 21 | const QuicConfig* config, |
| 22 | const QuicCryptoServerConfig* crypto_config, |
| 23 | QuicVersionManager* version_manager, |
| 24 | std::unique_ptr<QuicConnectionHelperInterface> helper, |
| 25 | std::unique_ptr<QuicCryptoServerStream::Helper> session_helper, |
| 26 | std::unique_ptr<QuicAlarmFactory> alarm_factory, |
| 27 | MasqueServerBackend* masque_server_backend, |
| 28 | uint8_t expected_server_connection_id_length); |
| 29 | |
| 30 | // Disallow copy and assign. |
| 31 | MasqueDispatcher(const MasqueDispatcher&) = delete; |
| 32 | MasqueDispatcher& operator=(const MasqueDispatcher&) = delete; |
| 33 | |
| 34 | // From QuicSimpleDispatcher. |
| 35 | std::unique_ptr<QuicSession> CreateQuicSession( |
| 36 | QuicConnectionId connection_id, |
| 37 | const QuicSocketAddress& client_address, |
| 38 | quiche::QuicheStringPiece alpn, |
| 39 | const ParsedQuicVersion& version) override; |
| 40 | |
| 41 | bool OnFailedToDispatchPacket(const ReceivedPacketInfo& packet_info) override; |
| 42 | |
| 43 | // From MasqueServerSession::Visitor. |
| 44 | void RegisterClientConnectionId( |
| 45 | QuicConnectionId client_connection_id, |
| 46 | MasqueServerSession* masque_server_session) override; |
| 47 | |
| 48 | void UnregisterClientConnectionId( |
| 49 | QuicConnectionId client_connection_id) override; |
| 50 | |
| 51 | private: |
| 52 | MasqueServerBackend* masque_server_backend_; // Unowned. |
| 53 | // Mapping from client connection IDs to server sessions, allows routing |
| 54 | // incoming packets to the right MASQUE connection. |
| 55 | QuicUnorderedMap<QuicConnectionId, MasqueServerSession*, QuicConnectionIdHash> |
| 56 | client_connection_id_registrations_; |
| 57 | }; |
| 58 | |
| 59 | } // namespace quic |
| 60 | |
| 61 | #endif // QUICHE_QUIC_MASQUE_MASQUE_DISPATCHER_H_ |