QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // 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_FACTORY_H_ |
| 6 | #define QUICHE_QUIC_QUARTC_QUARTC_FACTORY_H_ |
| 7 | |
| 8 | #include "net/third_party/quiche/src/quic/core/quic_alarm_factory.h" |
| 9 | #include "net/third_party/quiche/src/quic/core/quic_connection.h" |
| 10 | #include "net/third_party/quiche/src/quic/core/quic_simple_buffer_allocator.h" |
| 11 | #include "net/third_party/quiche/src/quic/quartc/quartc_packet_writer.h" |
| 12 | #include "net/third_party/quiche/src/quic/quartc/quartc_session.h" |
| 13 | |
| 14 | namespace quic { |
| 15 | |
| 16 | // The configuration for creating a QuartcFactory. |
| 17 | struct QuartcFactoryConfig { |
| 18 | // Factory for |QuicAlarm|s. Implemented by the Quartc user with different |
| 19 | // mechanisms. For example in WebRTC, it is implemented with rtc::Thread. |
| 20 | // Owned by the user, and needs to stay alive for as long as the QuartcFactory |
| 21 | // exists. |
| 22 | QuicAlarmFactory* alarm_factory = nullptr; |
| 23 | // The clock used by |QuicAlarm|s. Implemented by the Quartc user. Owned by |
| 24 | // the user, and needs to stay alive for as long as the QuartcFactory exists. |
| 25 | const QuicClock* clock = nullptr; |
| 26 | }; |
| 27 | |
| 28 | struct QuartcSessionConfig { |
| 29 | // If a pre-shared cryptographic key is available for this session, specify it |
| 30 | // here. This value will only be used if non-empty. |
| 31 | QuicString pre_shared_key; |
| 32 | |
| 33 | // The maximum size of the packet can be written with the packet writer. |
| 34 | // 1200 bytes by default. |
| 35 | QuicPacketLength max_packet_size = 1200; |
| 36 | |
| 37 | // Timeouts for the crypto handshake. Set them to higher values to |
| 38 | // prevent closing the session before it started on a slow network. |
| 39 | // Zero entries are ignored and QUIC defaults are used in that case. |
| 40 | QuicTime::Delta max_idle_time_before_crypto_handshake = |
| 41 | QuicTime::Delta::Zero(); |
| 42 | QuicTime::Delta max_time_before_crypto_handshake = QuicTime::Delta::Zero(); |
| 43 | QuicTime::Delta idle_network_timeout = QuicTime::Delta::Zero(); |
| 44 | |
| 45 | // Tail loss probes (TLP) are enabled by default, but it may be useful to |
| 46 | // disable them in tests. We can also consider disabling them in production |
| 47 | // if we discover that tail loss probes add overhead in low bitrate audio. |
| 48 | bool enable_tail_loss_probe = true; |
| 49 | }; |
| 50 | |
| 51 | // Factory that creates instances of QuartcSession. Implements the |
| 52 | // QuicConnectionHelperInterface used by the QuicConnections. Only one |
| 53 | // QuartcFactory is expected to be created. |
| 54 | class QuartcFactory { |
| 55 | public: |
| 56 | explicit QuartcFactory(const QuartcFactoryConfig& factory_config); |
| 57 | |
| 58 | // Creates a new QuartcSession using the given configuration. |
| 59 | std::unique_ptr<QuartcSession> CreateQuartcClientSession( |
| 60 | const QuartcSessionConfig& quartc_session_config, |
| 61 | const ParsedQuicVersionVector& supported_versions, |
| 62 | QuicStringPiece server_crypto_config, |
| 63 | QuartcPacketTransport* packet_transport); |
| 64 | |
| 65 | private: |
| 66 | std::unique_ptr<QuicConnection> CreateQuicConnection( |
| 67 | Perspective perspective, |
| 68 | const ParsedQuicVersionVector& supported_versions, |
| 69 | QuartcPacketWriter* packet_writer); |
| 70 | |
| 71 | // Used to implement QuicAlarmFactory. Owned by the user and must outlive |
| 72 | // QuartcFactory. |
| 73 | QuicAlarmFactory* alarm_factory_; |
| 74 | // Used to implement the QuicConnectionHelperInterface. Owned by the user and |
| 75 | // must outlive QuartcFactory. |
| 76 | const QuicClock* clock_; |
| 77 | |
| 78 | // Helper used by all QuicConnections. |
| 79 | std::unique_ptr<QuicConnectionHelperInterface> connection_helper_; |
| 80 | |
| 81 | // Used by QuicCryptoServerStream to track most recently compressed certs. |
| 82 | std::unique_ptr<QuicCompressedCertsCache> compressed_certs_cache_; |
| 83 | |
| 84 | // This helper is needed to create QuicCryptoServerStreams. |
| 85 | std::unique_ptr<QuicCryptoServerStream::Helper> stream_helper_; |
| 86 | }; |
| 87 | |
| 88 | // Configures global settings, such as supported quic versions. |
| 89 | // Must execute on QUIC thread. |
| 90 | void ConfigureGlobalQuicSettings(); |
| 91 | |
| 92 | // Must execute on QUIC thread. |
| 93 | QuicConfig CreateQuicConfig(const QuartcSessionConfig& quartc_session_config); |
| 94 | |
| 95 | std::unique_ptr<QuicConnection> CreateQuicConnection( |
| 96 | QuicConnectionId connection_id, |
| 97 | const QuicSocketAddress& peer_address, |
| 98 | QuicConnectionHelperInterface* connection_helper, |
| 99 | QuicAlarmFactory* alarm_factory, |
| 100 | QuicPacketWriter* packet_writer, |
| 101 | Perspective perspective, |
| 102 | ParsedQuicVersionVector supported_versions); |
| 103 | |
| 104 | // Creates a new instance of QuartcFactory. |
| 105 | std::unique_ptr<QuartcFactory> CreateQuartcFactory( |
| 106 | const QuartcFactoryConfig& factory_config); |
| 107 | |
| 108 | } // namespace quic |
| 109 | |
| 110 | #endif // QUICHE_QUIC_QUARTC_QUARTC_FACTORY_H_ |