Chromium Code Reviews| 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 a locally-initiated QUIC stream with an |
| 65 // QUIC data streams. | 66 // internally assigned ID. SignalIncomingStream is emitted when the remote |
| 67 // peer initiates a QUIC stream with a new ID. | |
| 68 // | |
| 69 // TODO(mikescarlett): Implement secure QUIC handshake and 0-RTT handshakes. | |
| 70 // Eliminate inheritance of Transport when TransportController no longer | |
| 71 // requires it internally. | |
| 66 class QuicTransportChannel : public TransportChannelImpl, | 72 class QuicTransportChannel : public TransportChannelImpl, |
| 73 public Transport, | |
|
Taylor Brandstetter
2016/04/01 23:23:42
As discussed, I think it will be confusing for a Q
mikescarlett
2016/04/05 19:58:53
Done and split into a new CL.
| |
| 67 public net::QuicPacketWriter, | 74 public net::QuicPacketWriter, |
| 68 public net::QuicCryptoClientStream::ProofHandler { | 75 public net::QuicCryptoClientStream::ProofHandler { |
| 69 public: | 76 public: |
| 70 // |channel| - the TransportChannelImpl we are wrapping. | 77 // |channel| - the TransportChannelImpl we are wrapping. |
| 71 explicit QuicTransportChannel(TransportChannelImpl* channel); | 78 explicit QuicTransportChannel(TransportChannelImpl* channel); |
| 72 ~QuicTransportChannel() override; | 79 ~QuicTransportChannel() override; |
| 73 | 80 |
| 74 // TransportChannel overrides. | 81 // TransportChannel overrides. |
| 75 // TODO(mikescarlett): Implement certificate authentication. | 82 // TODO(mikescarlett): Implement certificate authentication. |
| 76 bool SetLocalCertificate( | 83 bool SetLocalCertificate( |
| 77 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; | 84 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; |
| 78 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override; | 85 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const; |
| 79 // TODO(mikescarlett): Implement fingerprint authentication. | 86 // TODO(mikescarlett): Implement fingerprint authentication. |
| 80 bool SetRemoteFingerprint(const std::string& digest_alg, | 87 bool SetRemoteFingerprint(const std::string& digest_alg, |
| 81 const uint8_t* digest, | 88 const uint8_t* digest, |
| 82 size_t digest_len) override; | 89 size_t digest_len) override; |
| 83 // TODO(mikescarlett): Remove this DTLS-specific method when TransportChannel | 90 // TODO(mikescarlett): Remove this DTLS-specific method when TransportChannel |
| 84 // does not require defining it. | 91 // does not require defining it. |
| 85 bool IsDtlsActive() const override { return true; } | 92 bool IsDtlsActive() const override { return true; } |
| 86 // Sends a RTP packet if the PF_SRTP_BYPASS flag is set. | 93 // Sends a RTP packet if the PF_SRTP_BYPASS flag is set. |
| 87 int SendPacket(const char* data, | 94 int SendPacket(const char* data, |
| 88 size_t size, | 95 size_t size, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 // QuicCryptoClientStream::ProofHandler overrides. | 199 // QuicCryptoClientStream::ProofHandler overrides. |
| 193 // Called by client crypto handshake when cached proof is marked valid. | 200 // Called by client crypto handshake when cached proof is marked valid. |
| 194 void OnProofValid( | 201 void OnProofValid( |
| 195 const net::QuicCryptoClientConfig::CachedState& cached) override; | 202 const net::QuicCryptoClientConfig::CachedState& cached) override; |
| 196 // Called by the client crypto handshake when proof verification details | 203 // Called by the client crypto handshake when proof verification details |
| 197 // become available, either because proof verification is complete, or when | 204 // become available, either because proof verification is complete, or when |
| 198 // cached details are used. | 205 // cached details are used. |
| 199 void OnProofVerifyDetailsAvailable( | 206 void OnProofVerifyDetailsAvailable( |
| 200 const net::ProofVerifyDetails& verify_details) override; | 207 const net::ProofVerifyDetails& verify_details) override; |
| 201 | 208 |
| 209 // Transport override. | |
| 210 bool GetLocalCertificate( | |
| 211 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override { | |
| 212 return false; | |
| 213 } | |
| 214 | |
| 202 // Returns true if |quic_| has queued data which wasn't written due | 215 // Returns true if |quic_| has queued data which wasn't written due |
| 203 // to |channel_| being write blocked. | 216 // to |channel_| being write blocked. |
| 204 bool HasDataToWrite() const; | 217 bool HasDataToWrite() const; |
| 205 // Writes queued data for |quic_| when |channel_| is no longer write blocked. | 218 // Writes queued data for |quic_| when |channel_| is no longer write blocked. |
| 206 void OnCanWrite(); | 219 void OnCanWrite(); |
| 207 // Connectivity state of QuicTransportChannel. | 220 // Connectivity state of QuicTransportChannel. |
| 208 QuicTransportState quic_state() const { return quic_state_; } | 221 QuicTransportState quic_state() const { return quic_state_; } |
| 222 // Creates a new QUIC stream that can send or receive data. | |
|
pthatcher1
2016/03/30 20:34:50
Isn't this just for sending data (because each mes
mikescarlett
2016/04/05 19:58:53
Changed comment.
| |
| 223 ReliableQuicStream* CreateQuicStream(); | |
| 224 | |
| 225 // Emitted when |quic_| creates a QUIC stream to receive incoming data from | |
| 226 // the remote peer, when the stream did not exist previously. | |
| 227 sigslot::signal1<ReliableQuicStream*> SignalIncomingStream; | |
| 228 // Emitted when the QuicTransportChannel state becomes QUIC_TRANSPORT_CLOSED. | |
| 229 // It might occur before this channel is writable if the handshake fails, or | |
| 230 // after a successful handshake when a peer explicitly closes the connection. | |
| 231 sigslot::signal0<> SignalClosed; | |
| 232 | |
| 233 // Testing methods. | |
| 234 const TransportDescription* local_description_for_test() const { | |
|
Taylor Brandstetter
2016/04/01 23:23:42
I don't like having "for test" methods that expose
mikescarlett
2016/04/05 19:58:53
This class doesn't need these anyway since it no l
| |
| 235 return local_description(); | |
| 236 } | |
| 237 const TransportDescription* remote_description_for_test() const { | |
| 238 return remote_description(); | |
| 239 } | |
| 240 | |
| 241 protected: | |
| 242 // Transport overrides. | |
| 243 bool NegotiateTransportDescription(ContentAction local_role, | |
| 244 std::string* error_desc) override; | |
| 245 // TODO(mikescarlett): Remove these methods once Transport does not require | |
| 246 // them. The QuicTransportChannel should be created/deleted directly. | |
| 247 TransportChannelImpl* CreateTransportChannel(int component) override { | |
| 248 return this; | |
| 249 } | |
| 250 void DestroyTransportChannel(TransportChannelImpl* channel) override {} | |
| 209 | 251 |
| 210 private: | 252 private: |
| 211 // Fingerprint of remote peer. | 253 // Fingerprint of remote peer. |
| 212 struct RemoteFingerprint { | 254 struct RemoteFingerprint { |
| 213 std::string value; | 255 std::string value; |
| 214 std::string algorithm; | 256 std::string algorithm; |
| 215 }; | 257 }; |
| 216 | 258 |
| 217 // Callbacks for |channel_|. | 259 // Callbacks for |channel_|. |
| 218 void OnReadableState(TransportChannel* channel); | 260 void OnReadableState(TransportChannel* channel); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 233 void OnSelectedCandidatePairChanged( | 275 void OnSelectedCandidatePairChanged( |
| 234 TransportChannel* channel, | 276 TransportChannel* channel, |
| 235 CandidatePairInterface* selected_candidate_pair); | 277 CandidatePairInterface* selected_candidate_pair); |
| 236 void OnConnectionRemoved(TransportChannelImpl* channel); | 278 void OnConnectionRemoved(TransportChannelImpl* channel); |
| 237 | 279 |
| 238 // Callbacks for |quic_|. | 280 // Callbacks for |quic_|. |
| 239 // Called when |quic_| has established the crypto handshake. | 281 // Called when |quic_| has established the crypto handshake. |
| 240 void OnHandshakeComplete(); | 282 void OnHandshakeComplete(); |
| 241 // Called when |quic_| has closed the connection. | 283 // Called when |quic_| has closed the connection. |
| 242 void OnConnectionClosed(net::QuicErrorCode error, bool from_peer); | 284 void OnConnectionClosed(net::QuicErrorCode error, bool from_peer); |
| 285 // Called when |quic_| has created a new QUIC stream for incoming data. | |
| 286 void OnIncomingStream(ReliableQuicStream* stream); | |
| 243 | 287 |
| 244 // Called by OnReadPacket() when a QUIC packet is received. | 288 // Called by OnReadPacket() when a QUIC packet is received. |
| 245 bool HandleQuicPacket(const char* data, size_t size); | 289 bool HandleQuicPacket(const char* data, size_t size); |
| 246 // Sets up the QUIC handshake. | 290 // Sets up the QUIC handshake. |
| 247 bool MaybeStartQuic(); | 291 bool MaybeStartQuic(); |
| 248 // Creates the QUIC connection and |quic_|. | 292 // Creates the QUIC connection and |quic_|. |
| 249 bool CreateQuicSession(); | 293 bool CreateQuicSession(); |
| 250 // Creates the crypto stream and initializes the handshake. | 294 // Creates the crypto stream and initializes the handshake. |
| 251 bool StartQuicHandshake(); | 295 bool StartQuicHandshake(); |
| 252 // Sets the QuicTransportChannel connectivity state. | 296 // Sets the QuicTransportChannel connectivity state. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 279 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; | 323 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate_; |
| 280 // Fingerprint of the remote peer. This must be set before we start QUIC. | 324 // Fingerprint of the remote peer. This must be set before we start QUIC. |
| 281 rtc::Optional<RemoteFingerprint> remote_fingerprint_; | 325 rtc::Optional<RemoteFingerprint> remote_fingerprint_; |
| 282 | 326 |
| 283 RTC_DISALLOW_COPY_AND_ASSIGN(QuicTransportChannel); | 327 RTC_DISALLOW_COPY_AND_ASSIGN(QuicTransportChannel); |
| 284 }; | 328 }; |
| 285 | 329 |
| 286 } // namespace cricket | 330 } // namespace cricket |
| 287 | 331 |
| 288 #endif // WEBRTC_P2P_QUIC_QUICTRANSPORTCHANNEL_H_ | 332 #endif // WEBRTC_P2P_QUIC_QUICTRANSPORTCHANNEL_H_ |
| OLD | NEW |