OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #ifndef WEBRTC_API_QUICDATATRANSPORT_H_ |
| 12 #define WEBRTC_API_QUICDATATRANSPORT_H_ |
| 13 |
| 14 #include <string> |
| 15 #include <unordered_map> |
| 16 |
| 17 #include "webrtc/api/datachannelinterface.h" |
| 18 #include "webrtc/api/quicdatachannel.h" |
| 19 #include "webrtc/base/scoped_ref_ptr.h" |
| 20 #include "webrtc/base/sigslot.h" |
| 21 #include "webrtc/base/thread.h" |
| 22 |
| 23 namespace cricket { |
| 24 class QuicTransportChannel; |
| 25 class ReliableQuicStream; |
| 26 } // namepsace cricket |
| 27 |
| 28 namespace webrtc { |
| 29 |
| 30 // QuicDataTransport creates QuicDataChannels. It handles QUIC stream demuxing |
| 31 // by prepending the data channel ID and message ID to outgoing messages, and |
| 32 // distributes incoming QUIC streams from the QuicTransportChannel. |
| 33 // |
| 34 // QuicDataTransport reads the data channel ID from the incoming QUIC stream, |
| 35 // then looks it up in a map of ID => QuicDataChannel. If the data channel |
| 36 // exists, it sends the stream to the QuicDataChannel. |
| 37 class QuicDataTransport : public QuicMessageDispatcher, |
| 38 public sigslot::has_slots<> { |
| 39 public: |
| 40 QuicDataTransport(); |
| 41 ~QuicDataTransport() override; |
| 42 |
| 43 // Sets the QUIC transport channel for the QuicDataChannels and the |
| 44 // QuicDataTransport. The QUIC transport channel must not already be set. |
| 45 void SetTransportChannel( |
| 46 cricket::QuicTransportChannel* quic_transport_channel); |
| 47 // Creates a QuicDataChannel that uses this QuicDataTransport. |
| 48 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
| 49 rtc::Thread* signaling_thread, |
| 50 rtc::Thread* worker_thread, |
| 51 const std::string& label, |
| 52 const DataChannelInit* config); |
| 53 // Removes a QuicDataChannel from the QuicDataTransport's data channel map. |
| 54 void DestroyDataChannel(int id); |
| 55 // True if the QuicDataTransport has a data channel with the given ID. |
| 56 bool HasDataChannel(int id) const; |
| 57 // True if the QuicDataTransport has data channels. |
| 58 bool HasDataChannels() const; |
| 59 |
| 60 // QuicMessageDispatcher override. |
| 61 void EncodeHeader(int data_channel_id, |
| 62 uint64_t message_id, |
| 63 rtc::CopyOnWriteBuffer* payload) const override; |
| 64 |
| 65 private: |
| 66 // Called by the QuicTransportChannel when a ReliableQuicStream is created to |
| 67 // receive incoming data. |
| 68 void OnIncomingStream(cricket::ReliableQuicStream* stream); |
| 69 // Called by the ReliableQuicStream when the first QUIC stream frame is |
| 70 // received for incoming data. |
| 71 void OnDataReceived(net::QuicStreamId stream_id, |
| 72 const char* data, |
| 73 size_t len); |
| 74 |
| 75 // Map of data channel ID => QUIC data channel values. |
| 76 std::unordered_map<int, rtc::scoped_refptr<QuicDataChannel>> |
| 77 data_channel_by_id_; |
| 78 // Map of QUIC stream ID => ReliableQuicStream* values. |
| 79 std::unordered_map<net::QuicStreamId, cricket::ReliableQuicStream*> |
| 80 quic_stream_by_id_; |
| 81 // QuicTransportChannel for sending/receiving data. |
| 82 cricket::QuicTransportChannel* quic_transport_channel_ = nullptr; |
| 83 }; |
| 84 |
| 85 } // namespace webrtc |
| 86 |
| 87 #endif // WEBRTC_API_QUICDATATRANSPORT_H_ |
OLD | NEW |