blob: 6022720aac28b34798823b4624fe26e18a71ce74 [file] [log] [blame]
QUICHE team2bfc7542019-02-26 14:36:06 -05001// Copyright (c) 2017 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_QUARTC_QUARTC_DISPATCHER_H_
6#define QUICHE_QUIC_QUARTC_QUARTC_DISPATCHER_H_
7
8#include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_server_config.h"
9#include "net/third_party/quiche/src/quic/core/quic_alarm_factory.h"
10#include "net/third_party/quiche/src/quic/core/quic_config.h"
11#include "net/third_party/quiche/src/quic/core/quic_connection.h"
12#include "net/third_party/quiche/src/quic/core/quic_connection_id.h"
13#include "net/third_party/quiche/src/quic/core/quic_crypto_server_stream.h"
14#include "net/third_party/quiche/src/quic/core/quic_dispatcher.h"
15#include "net/third_party/quiche/src/quic/core/quic_version_manager.h"
16#include "net/third_party/quiche/src/quic/core/quic_versions.h"
17#include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h"
18#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
19#include "net/third_party/quiche/src/quic/quartc/quartc_session.h"
20
21namespace quic {
22
23class QuartcDispatcher : public QuicDispatcher,
24 QuartcPacketTransport::Delegate {
25 public:
26 class Delegate {
27 public:
28 virtual ~Delegate() = default;
29 virtual void OnSessionCreated(QuartcSession* session) = 0;
30 };
31
32 QuartcDispatcher(
33 std::unique_ptr<QuicConfig> config,
34 std::unique_ptr<QuicCryptoServerConfig> crypto_config,
35 QuicStringPiece crypto_config_serialized,
36 std::unique_ptr<QuicVersionManager> version_manager,
37 std::unique_ptr<QuicConnectionHelperInterface> helper,
38 std::unique_ptr<QuicCryptoServerStream::Helper> session_helper,
39 std::unique_ptr<QuicAlarmFactory> alarm_factory,
40 std::unique_ptr<QuartcPacketWriter> packet_writer,
41 Delegate* delegate);
42 ~QuartcDispatcher() override;
43
44 QuartcSession* CreateQuicSession(QuicConnectionId connection_id,
45 const QuicSocketAddress& client_address,
46 QuicStringPiece alpn,
47 const ParsedQuicVersion& version) override;
48
49 // QuartcPacketTransport::Delegate overrides.
50 void OnTransportCanWrite() override;
51 void OnTransportReceived(const char* data, size_t data_len) override;
52
53 // A serialized server config in quic wire format.
54 QuicStringPiece server_crypto_config() const { return crypto_config_; }
55
56 private:
57 // Members owned by QuartcDispatcher but not QuicDispatcher.
58 std::unique_ptr<QuicConfig> owned_quic_config_;
59 std::unique_ptr<QuicCryptoServerConfig> owned_crypto_config_;
60 QuicString crypto_config_;
61 std::unique_ptr<QuicVersionManager> owned_version_manager_;
62
63 // Delegate invoked when the dispatcher creates a new session.
64 Delegate* delegate_;
65
66 // The packet writer used by this dispatcher. Owned by the base class, but
67 // the base class upcasts it to QuicPacketWriter (which prevents detaching the
68 // transport delegate without a downcast).
69 QuartcPacketWriter* packet_writer_;
70};
71
72} // namespace quic
73
74#endif // QUICHE_QUIC_QUARTC_QUARTC_DISPATCHER_H_