Index: webrtc/api/quicdatatransport.h |
diff --git a/webrtc/api/quicdatatransport.h b/webrtc/api/quicdatatransport.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cda9f8da402c70d2c24e533e128297b66eb8686f |
--- /dev/null |
+++ b/webrtc/api/quicdatatransport.h |
@@ -0,0 +1,87 @@ |
+/* |
+ * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#ifndef WEBRTC_API_QUICDATATRANSPORT_H_ |
+#define WEBRTC_API_QUICDATATRANSPORT_H_ |
+ |
+#include <string> |
+#include <unordered_map> |
+ |
+#include "webrtc/api/datachannelinterface.h" |
+#include "webrtc/api/quicdatachannel.h" |
+#include "webrtc/base/scoped_ref_ptr.h" |
+#include "webrtc/base/sigslot.h" |
+#include "webrtc/base/thread.h" |
+ |
+namespace cricket { |
+class QuicTransportChannel; |
+class ReliableQuicStream; |
+} // namepsace cricket |
+ |
+namespace webrtc { |
+ |
+// QuicDataTransport creates QuicDataChannels. It handles QUIC stream demuxing |
+// by prepending the data channel ID and message ID to outgoing messages, and |
+// distributes incoming QUIC streams from the QuicTransportChannel. |
+// |
+// QuicDataTransport reads the data channel ID from the incoming QUIC stream, |
+// then looks it up in a map of ID => QuicDataChannel. If the data channel |
+// exists, it sends the stream to the QuicDataChannel. |
+class QuicDataTransport : public QuicMessageDispatcher, |
+ public sigslot::has_slots<> { |
+ public: |
+ QuicDataTransport(); |
+ ~QuicDataTransport() override; |
+ |
+ // Sets the QUIC transport channel for the QuicDataChannels and the |
+ // QuicDataTransport. The QUIC transport channel must not already be set. |
+ void SetTransportChannel( |
+ cricket::QuicTransportChannel* quic_transport_channel); |
+ // Creates a QuicDataChannel that uses this QuicDataTransport. |
+ rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
+ rtc::Thread* signaling_thread, |
+ rtc::Thread* worker_thread, |
+ const std::string& label, |
+ const DataChannelInit* config); |
+ // Removes a QuicDataChannel from the QuicDataTransport's data channel map. |
+ void DestroyDataChannel(int id); |
+ // True if the QuicDataTransport has a data channel with the given ID. |
+ bool HasDataChannel(int id) const; |
+ // True if the QuicDataTransport has data channels. |
+ bool HasDataChannels() const; |
+ |
+ // QuicMessageDispatcher override. |
+ void EncodeHeader(int data_channel_id, |
+ uint64_t message_id, |
+ rtc::CopyOnWriteBuffer* payload) const override; |
+ |
+ private: |
+ // Called by the QuicTransportChannel when a ReliableQuicStream is created to |
+ // receive incoming data. |
+ void OnIncomingStream(cricket::ReliableQuicStream* stream); |
+ // Called by the ReliableQuicStream when the first QUIC stream frame is |
+ // received for incoming data. |
+ void OnDataReceived(net::QuicStreamId stream_id, |
+ const char* data, |
+ size_t len); |
+ |
+ // Map of data channel ID => QUIC data channel values. |
+ std::unordered_map<int, rtc::scoped_refptr<QuicDataChannel>> |
+ data_channel_by_id_; |
+ // Map of QUIC stream ID => ReliableQuicStream* values. |
+ std::unordered_map<net::QuicStreamId, cricket::ReliableQuicStream*> |
+ quic_stream_by_id_; |
+ // QuicTransportChannel for sending/receiving data. |
+ cricket::QuicTransportChannel* quic_transport_channel_ = nullptr; |
+}; |
+ |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_API_QUICDATATRANSPORT_H_ |