| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_P2P_QUIC_QUICTRANSPORTCHANNEL_H_ | 11 #ifndef WEBRTC_P2P_QUIC_QUICTRANSPORTCHANNEL_H_ |
| 12 #define WEBRTC_P2P_QUIC_QUICTRANSPORTCHANNEL_H_ | 12 #define WEBRTC_P2P_QUIC_QUICTRANSPORTCHANNEL_H_ |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "net/quic/quic_crypto_client_stream.h" | 17 #include "net/quic/quic_crypto_client_stream.h" |
| 18 #include "net/quic/quic_packet_writer.h" | 18 #include "net/quic/quic_packet_writer.h" |
| 19 #include "webrtc/base/optional.h" | 19 #include "webrtc/base/optional.h" |
| 20 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
| 21 #include "webrtc/p2p/base/transport.h" |
| 21 #include "webrtc/p2p/base/transportchannelimpl.h" | 22 #include "webrtc/p2p/base/transportchannelimpl.h" |
| 22 #include "webrtc/p2p/quic/quicconnectionhelper.h" | 23 #include "webrtc/p2p/quic/quicconnectionhelper.h" |
| 23 #include "webrtc/p2p/quic/quicsession.h" | 24 #include "webrtc/p2p/quic/quicsession.h" |
| 24 | 25 |
| 25 namespace cricket { | 26 namespace cricket { |
| 26 | 27 |
| 27 enum QuicTransportState { | 28 enum QuicTransportState { |
| 28 // Haven't started QUIC handshake. | 29 // Haven't started QUIC handshake. |
| 29 QUIC_TRANSPORT_NEW = 0, | 30 QUIC_TRANSPORT_NEW = 0, |
| 30 // Started QUIC handshake. | 31 // Started QUIC handshake. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 // Once the wrapped transport channel is connected, QuicTransportChannel | 42 // Once the wrapped transport channel is connected, QuicTransportChannel |
| 42 // negotiates the crypto handshake and establishes SRTP keying material. | 43 // negotiates the crypto handshake and establishes SRTP keying material. |
| 43 // | 44 // |
| 44 // How it works: | 45 // How it works: |
| 45 // | 46 // |
| 46 // QuicTransportChannel { | 47 // QuicTransportChannel { |
| 47 // QuicSession* quic_; | 48 // QuicSession* quic_; |
| 48 // TransportChannelImpl* channel_; | 49 // TransportChannelImpl* channel_; |
| 49 // } | 50 // } |
| 50 // | 51 // |
| 51 // - Data written to SendPacket() is passed directly to |channel_| if it is | 52 // - Data written to SendPacket() is passed directly to |channel_| if it is |
| 52 // an SRTP packet with the PF_SRTP_BYPASS flag. | 53 // an SRTP packet with the PF_SRTP_BYPASS flag. |
| 53 // | 54 // |
| 54 // - |quic_| passes outgoing packets to WritePacket(), which transfers them | 55 // - |quic_| passes outgoing packets to WritePacket(), which transfers them |
| 55 // to |channel_| to be sent across the network. | 56 // to |channel_| to be sent across the network. |
| 56 // | 57 // |
| 57 // - Data which comes into QuicTransportChannel::OnReadPacket is checked to | 58 // - Data which comes into QuicTransportChannel::OnReadPacket is checked to |
| 58 // see if it is QUIC, and if it is, passed to |quic_|. SRTP packets are | 59 // see if it is QUIC, and if it is, passed to |quic_|. SRTP packets are |
| 59 // signaled upwards as bypass packets. | 60 // signaled upwards as bypass packets. |
| 60 // | 61 // |
| 61 // - When the QUIC handshake is completed, quic_state() returns | 62 // - When the QUIC handshake is completed, quic_state() returns |
| 62 // QUIC_TRANSPORT_CONNECTED and SRTP keying material can be exported. | 63 // QUIC_TRANSPORT_CONNECTED and SRTP keying material can be exported. |
| 63 // | 64 // |
| 64 // TODO(mikescarlett): Implement secure QUIC handshake, 0-RTT handshakes, and | 65 // - CreateQuicStream() creates an outgoing QUIC stream. Once the local peer |
| 65 // QUIC data streams. | 66 // sends data from this stream, the remote peer emits SignalIncomingStream |
| 67 // with a QUIC stream of the same id to handle received data. |
| 68 // |
| 69 // TODO(mikescarlett): Implement secure QUIC handshake and 0-RTT handshakes. |
| 66 class QuicTransportChannel : public TransportChannelImpl, | 70 class QuicTransportChannel : public TransportChannelImpl, |
| 67 public net::QuicPacketWriter, | 71 public net::QuicPacketWriter, |
| 68 public net::QuicCryptoClientStream::ProofHandler { | 72 public net::QuicCryptoClientStream::ProofHandler { |
| 69 public: | 73 public: |
| 70 // |channel| - the TransportChannelImpl we are wrapping. | 74 // |channel| - the TransportChannelImpl we are wrapping. |
| 71 explicit QuicTransportChannel(TransportChannelImpl* channel); | 75 explicit QuicTransportChannel(TransportChannelImpl* channel); |
| 72 ~QuicTransportChannel() override; | 76 ~QuicTransportChannel() override; |
| 73 | 77 |
| 74 // TransportChannel overrides. | 78 // TransportChannel overrides. |
| 75 // TODO(mikescarlett): Implement certificate authentication. | 79 // TODO(mikescarlett): Implement certificate authentication. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 // this extracts the keys negotiated during the QUIC handshake, for use | 110 // this extracts the keys negotiated during the QUIC handshake, for use |
| 107 // in external encryption such as for extracting SRTP keys. | 111 // in external encryption such as for extracting SRTP keys. |
| 108 bool ExportKeyingMaterial(const std::string& label, | 112 bool ExportKeyingMaterial(const std::string& label, |
| 109 const uint8_t* context, | 113 const uint8_t* context, |
| 110 size_t context_len, | 114 size_t context_len, |
| 111 bool use_context, | 115 bool use_context, |
| 112 uint8_t* result, | 116 uint8_t* result, |
| 113 size_t result_len) override; | 117 size_t result_len) override; |
| 114 // TODO(mikescarlett): Remove this method once TransportChannel does not | 118 // TODO(mikescarlett): Remove this method once TransportChannel does not |
| 115 // require defining it. | 119 // require defining it. |
| 116 bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const override { | 120 rtc::scoped_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate() |
| 117 return false; | 121 const override { |
| 122 return nullptr; |
| 118 } | 123 } |
| 119 | 124 |
| 120 // TransportChannelImpl overrides that we forward to the wrapped transport. | 125 // TransportChannelImpl overrides that we forward to the wrapped transport. |
| 121 void SetIceRole(IceRole role) override { channel_->SetIceRole(role); } | 126 void SetIceRole(IceRole role) override { channel_->SetIceRole(role); } |
| 122 IceRole GetIceRole() const override { return channel_->GetIceRole(); } | 127 IceRole GetIceRole() const override { return channel_->GetIceRole(); } |
| 123 int SetOption(rtc::Socket::Option opt, int value) override { | 128 int SetOption(rtc::Socket::Option opt, int value) override { |
| 124 return channel_->SetOption(opt, value); | 129 return channel_->SetOption(opt, value); |
| 125 } | 130 } |
| 126 bool GetOption(rtc::Socket::Option opt, int* value) override { | 131 bool GetOption(rtc::Socket::Option opt, int* value) override { |
| 127 return channel_->GetOption(opt, value); | 132 return channel_->GetOption(opt, value); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 void OnProofVerifyDetailsAvailable( | 204 void OnProofVerifyDetailsAvailable( |
| 200 const net::ProofVerifyDetails& verify_details) override; | 205 const net::ProofVerifyDetails& verify_details) override; |
| 201 | 206 |
| 202 // Returns true if |quic_| has queued data which wasn't written due | 207 // Returns true if |quic_| has queued data which wasn't written due |
| 203 // to |channel_| being write blocked. | 208 // to |channel_| being write blocked. |
| 204 bool HasDataToWrite() const; | 209 bool HasDataToWrite() const; |
| 205 // Writes queued data for |quic_| when |channel_| is no longer write blocked. | 210 // Writes queued data for |quic_| when |channel_| is no longer write blocked. |
| 206 void OnCanWrite(); | 211 void OnCanWrite(); |
| 207 // Connectivity state of QuicTransportChannel. | 212 // Connectivity state of QuicTransportChannel. |
| 208 QuicTransportState quic_state() const { return quic_state_; } | 213 QuicTransportState quic_state() const { return quic_state_; } |
| 214 // Creates a new QUIC stream that can send data. |
| 215 ReliableQuicStream* CreateQuicStream(); |
| 216 |
| 217 // Emitted when |quic_| creates a QUIC stream to receive data from the remote |
| 218 // peer, when the stream did not exist previously. |
| 219 sigslot::signal1<ReliableQuicStream*> SignalIncomingStream; |
| 220 // Emitted when the QuicTransportChannel state becomes QUIC_TRANSPORT_CLOSED. |
| 221 sigslot::signal0<> SignalClosed; |
| 209 | 222 |
| 210 private: | 223 private: |
| 211 // Fingerprint of remote peer. | 224 // Fingerprint of remote peer. |
| 212 struct RemoteFingerprint { | 225 struct RemoteFingerprint { |
| 213 std::string value; | 226 std::string value; |
| 214 std::string algorithm; | 227 std::string algorithm; |
| 215 }; | 228 }; |
| 216 | 229 |
| 217 // Callbacks for |channel_|. | 230 // Callbacks for |channel_|. |
| 218 void OnReadableState(TransportChannel* channel); | 231 void OnReadableState(TransportChannel* channel); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 234 TransportChannel* channel, | 247 TransportChannel* channel, |
| 235 CandidatePairInterface* selected_candidate_pair, | 248 CandidatePairInterface* selected_candidate_pair, |
| 236 int last_sent_packet_id); | 249 int last_sent_packet_id); |
| 237 void OnConnectionRemoved(TransportChannelImpl* channel); | 250 void OnConnectionRemoved(TransportChannelImpl* channel); |
| 238 | 251 |
| 239 // Callbacks for |quic_|. | 252 // Callbacks for |quic_|. |
| 240 // Called when |quic_| has established the crypto handshake. | 253 // Called when |quic_| has established the crypto handshake. |
| 241 void OnHandshakeComplete(); | 254 void OnHandshakeComplete(); |
| 242 // Called when |quic_| has closed the connection. | 255 // Called when |quic_| has closed the connection. |
| 243 void OnConnectionClosed(net::QuicErrorCode error, bool from_peer); | 256 void OnConnectionClosed(net::QuicErrorCode error, bool from_peer); |
| 257 // Called when |quic_| has created a new QUIC stream for incoming data. |
| 258 void OnIncomingStream(ReliableQuicStream* stream); |
| 244 | 259 |
| 245 // Called by OnReadPacket() when a QUIC packet is received. | 260 // Called by OnReadPacket() when a QUIC packet is received. |
| 246 bool HandleQuicPacket(const char* data, size_t size); | 261 bool HandleQuicPacket(const char* data, size_t size); |
| 247 // Sets up the QUIC handshake. | 262 // Sets up the QUIC handshake. |
| 248 bool MaybeStartQuic(); | 263 bool MaybeStartQuic(); |
| 249 // Creates the QUIC connection and |quic_|. | 264 // Creates the QUIC connection and |quic_|. |
| 250 bool CreateQuicSession(); | 265 bool CreateQuicSession(); |
| 251 // Creates the crypto stream and initializes the handshake. | 266 // Creates the crypto stream and initializes the handshake. |
| 252 bool StartQuicHandshake(); | 267 bool StartQuicHandshake(); |
| 253 // Sets the QuicTransportChannel connectivity state. | 268 // Sets the QuicTransportChannel connectivity state. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 280 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; | 295 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; |
| 281 // Fingerprint of the remote peer. This must be set before we start QUIC. | 296 // Fingerprint of the remote peer. This must be set before we start QUIC. |
| 282 rtc::Optional<RemoteFingerprint> remote_fingerprint_; | 297 rtc::Optional<RemoteFingerprint> remote_fingerprint_; |
| 283 | 298 |
| 284 RTC_DISALLOW_COPY_AND_ASSIGN(QuicTransportChannel); | 299 RTC_DISALLOW_COPY_AND_ASSIGN(QuicTransportChannel); |
| 285 }; | 300 }; |
| 286 | 301 |
| 287 } // namespace cricket | 302 } // namespace cricket |
| 288 | 303 |
| 289 #endif // WEBRTC_P2P_QUIC_QUICTRANSPORTCHANNEL_H_ | 304 #endif // WEBRTC_P2P_QUIC_QUICTRANSPORTCHANNEL_H_ |
| OLD | NEW |