| 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_API_QUICDATATRANSPORT_H_ | 11 #ifndef WEBRTC_API_QUICDATATRANSPORT_H_ |
| 12 #define WEBRTC_API_QUICDATATRANSPORT_H_ | 12 #define WEBRTC_API_QUICDATATRANSPORT_H_ |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 #include <unordered_map> | 15 #include <unordered_map> |
| 16 | 16 |
| 17 #include "webrtc/api/datachannelinterface.h" | 17 #include "webrtc/api/datachannelinterface.h" |
| 18 #include "webrtc/api/quicdatachannel.h" | 18 #include "webrtc/api/quicdatachannel.h" |
| 19 #include "webrtc/base/scoped_ref_ptr.h" | 19 #include "webrtc/base/scoped_ref_ptr.h" |
| 20 #include "webrtc/base/sigslot.h" | 20 #include "webrtc/base/sigslot.h" |
| 21 #include "webrtc/base/thread.h" | 21 #include "webrtc/base/thread.h" |
| 22 #include "webrtc/p2p/base/transportcontroller.h" | |
| 23 | 22 |
| 24 namespace cricket { | 23 namespace cricket { |
| 25 class QuicTransportChannel; | 24 class QuicTransportChannel; |
| 26 class ReliableQuicStream; | 25 class ReliableQuicStream; |
| 27 } // namepsace cricket | 26 } // namepsace cricket |
| 28 | 27 |
| 29 namespace webrtc { | 28 namespace webrtc { |
| 30 | 29 |
| 31 // QuicDataTransport creates QuicDataChannels for the PeerConnection. It also | 30 // QuicDataTransport creates QuicDataChannels for the PeerConnection. It also |
| 32 // handles QUIC stream demuxing by distributing incoming QUIC streams from the | 31 // handles QUIC stream demuxing by distributing incoming QUIC streams from the |
| 33 // QuicTransportChannel among the QuicDataChannels that it has created. | 32 // QuicTransportChannel among the QuicDataChannels that it has created. |
| 34 // | 33 // |
| 35 // QuicDataTransport reads the data channel ID from the incoming QUIC stream, | 34 // QuicDataTransport reads the data channel ID from the incoming QUIC stream, |
| 36 // then looks it up in a map of ID => QuicDataChannel. If the data channel | 35 // then looks it up in a map of ID => QuicDataChannel. If the data channel |
| 37 // exists, it sends the QUIC stream to the QuicDataChannel. | 36 // exists, it sends the QUIC stream to the QuicDataChannel. |
| 38 class QuicDataTransport : public sigslot::has_slots<> { | 37 class QuicDataTransport : public sigslot::has_slots<> { |
| 39 public: | 38 public: |
| 40 QuicDataTransport(rtc::Thread* signaling_thread, | 39 QuicDataTransport(rtc::Thread* signaling_thread, |
| 41 rtc::Thread* worker_thread, | 40 rtc::Thread* worker_thread, |
| 42 rtc::Thread* network_thread, | 41 rtc::Thread* network_thread); |
| 43 cricket::TransportController* transport_controller); | |
| 44 ~QuicDataTransport() override; | 42 ~QuicDataTransport() override; |
| 45 | 43 |
| 46 // The QuicDataTransport acts like a BaseChannel with these functions. | 44 // Sets the QUIC transport channel for the QuicDataChannels and the |
| 47 bool SetTransport(const std::string& transport_name); | 45 // QuicDataTransport. Returns false if a different QUIC transport channel is |
| 48 const std::string& transport_name() const { return transport_name_; } | 46 // already set, the QUIC transport channel cannot be set for any of the |
| 49 const std::string& content_name() const { return content_name_; } | 47 // QuicDataChannels, or |channel| is NULL. |
| 50 void set_content_name(const std::string& content_name) { | 48 bool SetTransportChannel(cricket::QuicTransportChannel* channel); |
| 51 content_name_ = content_name; | |
| 52 } | |
| 53 | 49 |
| 54 // Creates a QuicDataChannel that uses this QuicDataTransport. | 50 // Creates a QuicDataChannel that uses this QuicDataTransport. |
| 55 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( | 51 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
| 56 const std::string& label, | 52 const std::string& label, |
| 57 const DataChannelInit* config); | 53 const DataChannelInit* config); |
| 58 | 54 |
| 59 // Removes a QuicDataChannel with the given ID from the QuicDataTransport's | 55 // Removes a QuicDataChannel with the given ID from the QuicDataTransport's |
| 60 // data channel map. | 56 // data channel map. |
| 61 void DestroyDataChannel(int id); | 57 void DestroyDataChannel(int id); |
| 62 | 58 |
| 63 // True if the QuicDataTransport has a data channel with the given ID. | 59 // True if the QuicDataTransport has a data channel with the given ID. |
| 64 bool HasDataChannel(int id) const; | 60 bool HasDataChannel(int id) const; |
| 65 | 61 |
| 66 // True if the QuicDataTransport has data channels. | 62 // True if the QuicDataTransport has data channels. |
| 67 bool HasDataChannels() const; | 63 bool HasDataChannels() const; |
| 68 | 64 |
| 69 cricket::QuicTransportChannel* quic_transport_channel() { | |
| 70 return quic_transport_channel_; | |
| 71 } | |
| 72 | |
| 73 private: | 65 private: |
| 74 // Sets the QUIC transport channel for the QuicDataChannels and the | |
| 75 // QuicDataTransport. Returns false if a different QUIC transport channel is | |
| 76 // already set, the QUIC transport channel cannot be set for any of the | |
| 77 // QuicDataChannels, or |channel| is NULL. | |
| 78 bool SetTransportChannel(cricket::QuicTransportChannel* channel); | |
| 79 | |
| 80 // Called from the QuicTransportChannel when a ReliableQuicStream is created | 66 // Called from the QuicTransportChannel when a ReliableQuicStream is created |
| 81 // to receive incoming data. | 67 // to receive incoming data. |
| 82 void OnIncomingStream(cricket::ReliableQuicStream* stream); | 68 void OnIncomingStream(cricket::ReliableQuicStream* stream); |
| 83 // Called from the ReliableQuicStream when the first QUIC stream frame is | 69 // Called from the ReliableQuicStream when the first QUIC stream frame is |
| 84 // received for incoming data. The QuicDataTransport reads the data channel ID | 70 // received for incoming data. The QuicDataTransport reads the data channel ID |
| 85 // and message ID from the incoming data, then dispatches the | 71 // and message ID from the incoming data, then dispatches the |
| 86 // ReliableQuicStream to the QuicDataChannel with the same data channel ID. | 72 // ReliableQuicStream to the QuicDataChannel with the same data channel ID. |
| 87 void OnDataReceived(net::QuicStreamId stream_id, | 73 void OnDataReceived(net::QuicStreamId stream_id, |
| 88 const char* data, | 74 const char* data, |
| 89 size_t len); | 75 size_t len); |
| 90 | 76 |
| 91 cricket::QuicTransportChannel* CreateTransportChannel( | |
| 92 const std::string& transport_name); | |
| 93 void DestroyTransportChannel(cricket::TransportChannel* transport_channel); | |
| 94 | |
| 95 // Map of data channel ID => QUIC data channel values. | 77 // Map of data channel ID => QUIC data channel values. |
| 96 std::unordered_map<int, rtc::scoped_refptr<QuicDataChannel>> | 78 std::unordered_map<int, rtc::scoped_refptr<QuicDataChannel>> |
| 97 data_channel_by_id_; | 79 data_channel_by_id_; |
| 98 // Map of QUIC stream ID => ReliableQuicStream* values. | 80 // Map of QUIC stream ID => ReliableQuicStream* values. |
| 99 std::unordered_map<net::QuicStreamId, cricket::ReliableQuicStream*> | 81 std::unordered_map<net::QuicStreamId, cricket::ReliableQuicStream*> |
| 100 quic_stream_by_id_; | 82 quic_stream_by_id_; |
| 101 // QuicTransportChannel for sending/receiving data. | 83 // QuicTransportChannel for sending/receiving data. |
| 102 cricket::QuicTransportChannel* quic_transport_channel_ = nullptr; | 84 cricket::QuicTransportChannel* quic_transport_channel_ = nullptr; |
| 103 // Threads for the QUIC data channel. | 85 // Threads for the QUIC data channel. |
| 104 rtc::Thread* const signaling_thread_; | 86 rtc::Thread* const signaling_thread_; |
| 105 rtc::Thread* const worker_thread_; | 87 rtc::Thread* const worker_thread_; |
| 106 rtc::Thread* const network_thread_; | 88 rtc::Thread* const network_thread_; |
| 107 | |
| 108 cricket::TransportController* transport_controller_; | |
| 109 std::string content_name_; | |
| 110 std::string transport_name_; | |
| 111 }; | 89 }; |
| 112 | 90 |
| 113 } // namespace webrtc | 91 } // namespace webrtc |
| 114 | 92 |
| 115 #endif // WEBRTC_API_QUICDATATRANSPORT_H_ | 93 #endif // WEBRTC_API_QUICDATATRANSPORT_H_ |
| OLD | NEW |