OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 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 NET_QUIC_QUARTC_QUARTC_SESSION_H_ |
| 6 #define NET_QUIC_QUARTC_QUARTC_SESSION_H_ |
| 7 |
| 8 #include "net/quic/core/quic_crypto_client_stream.h" |
| 9 #include "net/quic/core/quic_crypto_server_stream.h" |
| 10 #include "net/quic/core/quic_crypto_stream.h" |
| 11 #include "net/quic/core/quic_session.h" |
| 12 #include "net/quic/quartc/quartc_connection_helper.h" |
| 13 #include "net/quic/quartc/quartc_reliable_stream.h" |
| 14 #include "net/quic/quartc/quartc_session_interface.h" |
| 15 |
| 16 namespace net { |
| 17 class NET_EXPORT_PRIVATE QuartcCryptoServerStreamHelper |
| 18 : public QuicCryptoServerStream::Helper { |
| 19 public: |
| 20 QuicConnectionId GenerateConnectionIdForReject( |
| 21 QuicConnectionId connection_id) const override; |
| 22 |
| 23 bool CanAcceptClientHello(const CryptoHandshakeMessage& message, |
| 24 const IPEndPoint& self_address, |
| 25 std::string* error_details) const override; |
| 26 }; |
| 27 |
| 28 // This class is used to solve the issue that the interface and the base class |
| 29 // have the same function signature. |
| 30 class NET_EXPORT_PRIVATE QuartcSessionTransportObserver |
| 31 : public QuartcSessionInterface::Transport::Observer { |
| 32 public: |
| 33 void OnCanWrite() override; |
| 34 |
| 35 protected: |
| 36 virtual void OnQuartcCanWrite() = 0; |
| 37 }; |
| 38 |
| 39 // This class provides a QUIC session over peer-to-peer transport that |
| 40 // negotiates the crypto handshake (using QuicCryptoHandshake) and provides |
| 41 // reading/writing of data using QUIC packets. |
| 42 class NET_EXPORT_PRIVATE QuartcSession |
| 43 : public QuicSession, |
| 44 public QuartcSessionInterface, |
| 45 public QuartcSessionTransportObserver, |
| 46 public QuicCryptoClientStream::ProofHandler { |
| 47 public: |
| 48 QuartcSession(std::unique_ptr<QuicConnection> connection, |
| 49 const QuicConfig& config, |
| 50 const std::string& remote_finger_print_value, |
| 51 Perspective perspective); |
| 52 ~QuartcSession() override; |
| 53 |
| 54 // QuicSession overrides. |
| 55 QuicCryptoStream* GetCryptoStream() override; |
| 56 QuartcReliableStream* CreateOutgoingDynamicStream( |
| 57 SpdyPriority priority) override; |
| 58 void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) override; |
| 59 void CloseStream(QuicStreamId stream_id) override; |
| 60 // QuicConnectionVisitorInterface overrides. |
| 61 void OnConnectionClosed(QuicErrorCode error, |
| 62 const std::string& error_details, |
| 63 ConnectionCloseSource source) override; |
| 64 |
| 65 // QuartcSessionInterface overrides |
| 66 void StartCryptoHandshake() override; |
| 67 bool ExportKeyingMaterial(const std::string& label, |
| 68 const uint8_t* context, |
| 69 size_t context_len, |
| 70 uint8_t* result, |
| 71 size_t result_len) override; |
| 72 QuartcReliableStreamInterface* CreateOutgoingStream( |
| 73 const OutgoingStreamParameters& param) override; |
| 74 void SetTransport( |
| 75 QuartcSessionInterface::Transport* session_transport) override; |
| 76 void SetObserver(QuartcSessionInterface::Observer* session_observer) override; |
| 77 |
| 78 // QuartcSessionTransportObserver overrides. |
| 79 void OnQuartcCanWrite() override; |
| 80 // QuartcSessionInterface::Transport::Observer overrides. |
| 81 // Decrypts an incoming QUIC packet to a data stream. |
| 82 bool OnReceived(const char* data, size_t data_len) override; |
| 83 |
| 84 // ProofHandler overrides. |
| 85 void OnProofValid(const QuicCryptoClientConfig::CachedState& cached) override; |
| 86 // Called by the client crypto handshake when proof verification details |
| 87 // become available, either because proof verification is complete, or when |
| 88 // cached details are used. |
| 89 void OnProofVerifyDetailsAvailable( |
| 90 const ProofVerifyDetails& verify_details) override; |
| 91 |
| 92 // Override the default crypto configuration. |
| 93 // The session will take the ownership of the configurations. |
| 94 void SetClientCryptoConfig(QuicCryptoClientConfig* client_config); |
| 95 void SetServerCryptoConfig(QuicCryptoServerConfig* server_config); |
| 96 |
| 97 protected: |
| 98 // QuicSession override. |
| 99 ReliableQuicStream* CreateIncomingDynamicStream(QuicStreamId id) override; |
| 100 |
| 101 virtual QuartcReliableStream* CreateDataStream(QuicStreamId id, |
| 102 SpdyPriority priority); |
| 103 |
| 104 private: |
| 105 // For crypto handshake. |
| 106 std::unique_ptr<QuicCryptoStream> crypto_stream_; |
| 107 // For recording packet receipt time |
| 108 QuicClock clock_; |
| 109 // Take ownership of the QuicConnection. |
| 110 std::unique_ptr<QuicConnection> connection_; |
| 111 // QuartcSession will not take the ownership. |
| 112 QuartcSessionInterface::Transport* session_transport_ = nullptr; |
| 113 QuartcSessionInterface::Observer* session_observer_ = nullptr; |
| 114 const std::string remote_finger_print_value_; |
| 115 Perspective perspective_; |
| 116 QuartcConnectionHelper helper_; |
| 117 // Used by QUIC crypto server stream to track most recently compressed certs. |
| 118 std::unique_ptr<QuicCompressedCertsCache> quic_compressed_certs_cache_; |
| 119 // This helper is needed when create QuicCryptoServerStream. |
| 120 QuartcCryptoServerStreamHelper stream_helper_; |
| 121 // Config for QUIC crypto client stream, used by the client. |
| 122 std::unique_ptr<QuicCryptoClientConfig> quic_crypto_client_config_; |
| 123 // Config for QUIC crypto server stream, used by the server. |
| 124 std::unique_ptr<QuicCryptoServerConfig> quic_crypto_server_config_; |
| 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(QuartcSession); |
| 127 }; |
| 128 |
| 129 } // namespace net |
| 130 |
| 131 #endif // NET_QUIC_QUARTC_QUARTC_SESSION_H_ |
OLD | NEW |