Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: webrtc/api/quicdatachannel.h

Issue 1844803002: Modify PeerConnection for end-to-end QuicDataChannel usage (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_QUICDATACHANNEL_H_
12 #define WEBRTC_API_QUICDATACHANNEL_H_
13
14 #include <string>
15 #include <unordered_map>
16 #include <unordered_set>
17
18 #include "webrtc/api/datachannelinterface.h"
19 #include "webrtc/api/proxy.h"
20 #include "webrtc/base/copyonwritebuffer.h"
21 #include "webrtc/base/bytebuffer.h"
22 #include "webrtc/base/scoped_ref_ptr.h"
pthatcher1 2016/03/30 20:34:48 If these aren't used in the .h, please move them t
mikescarlett 2016/04/05 19:58:50 Done.
23 #include "webrtc/base/sigslot.h"
24 #include "webrtc/base/thread.h"
25
26 namespace net {
27 typedef uint32_t QuicStreamId;
28 } // namespace net
29
30 namespace cricket {
31 class QuicTransportChannel;
32 class ReliableQuicStream;
33 class TransportChannel;
34 } // namepsace cricket
35
36 namespace webrtc {
37
38 // QuicDataChannel is an implementation of DataChannelInterface based on the
39 // QUIC protocol. It uses a QuicTransportChannel to establish encryption and
40 // transfer data. Currently this class implements unordered, reliable delivery.
41 //
42 // Each time a message is sent:
43 //
44 // - The local peer uses QuicTransportChannel to create a ReliableQuicStream.
45 // The message is prepended with the data channel id and message id, then the
46 // ReliableQuicStream sends it to the remote peer with a FIN.
47 //
48 // - The remote peer's QuicSession creates a ReliableQuicStream to receive the
49 // data. The
pthatcher1 2016/03/30 20:34:48 Funny formatting here.
mikescarlett 2016/04/05 19:58:50 I'll fix the formatting
50 // ReliableQuicStream is assigned to a QuicDataChannel with the same id as the
51 // local
52 // peer's data channel.
53 //
54 // - The remote QuicDataChannel queues data from the ReliableQuicStream until
55 // the QUIC stream receives a frame with a FIN.
56 //
57 // TODO(mikescarlett): Write blocked? closed? thread safety?
58 // TODO(mikescarlett): Allow peers to negotiate QUIC flow control window size,
59 // so that peers can set the maximum size of a message. Currently QUIC
60 // defaults to 16KB per stream and session.
61 // TODO(mikescarlett): Jitter buffer
62 class QuicDataChannel : public rtc::RefCountedObject<DataChannelInterface>,
63 public sigslot::has_slots<> {
64 public:
65 QuicDataChannel(cricket::QuicTransportChannel* quic_transport_channel,
66 rtc::Thread* signaling_thread,
67 rtc::Thread* worker_thread,
68 const std::string& label,
69 const DataChannelInit* config);
70 ~QuicDataChannel() override;
71
72 // DataChannelInterface overrides.
73 std::string label() const override { return label_; }
74 bool reliable() const override { return true; }
75 bool ordered() const override { return false; }
76 uint16_t maxRetransmitTime() const override { return -1; }
77 uint16_t maxRetransmits() const override { return -1; }
78 bool negotiated() const override { return false; }
79 int id() const override { return id_; }
80 DataState state() const override { return state_; }
81 uint64_t buffered_amount() const override { return buffered_amount_; }
82 std::string protocol() const override { return protocol_; }
83 void RegisterObserver(DataChannelObserver* observer) override;
84 void UnregisterObserver() override;
85 void Close() override;
86
87 bool Send(const DataBuffer& buffer) override;
88 // Registers a new QUIC stream to this data channel.
89 virtual void OnIncomingStream(cricket::ReliableQuicStream* stream,
90 rtc::ByteBuffer* remaining_bytes);
Taylor Brandstetter 2016/04/01 23:23:41 Maybe make this private and declare "friend QuicTr
mikescarlett 2016/04/05 19:58:50 Is this to prevent the method from being exposed d
Taylor Brandstetter 2016/04/05 22:31:17 Peter's suggestion sounds good. But even then, mak
mikescarlett 2016/04/13 16:53:36 I made this method private. For testing I have a f
91 rtc::Thread* worker_thread() const { return worker_thread_; }
92
93 bool has_incoming_quic_stream(net::QuicStreamId id) const {
94 return incoming_quic_streams_.find(id) != incoming_quic_streams_.end();
95 }
Taylor Brandstetter 2016/04/01 23:23:41 What is this used for, and does it need to be publ
mikescarlett 2016/04/05 19:58:50 This isn't needed. I removed it.
96
97 // Emitted when the state transitions to kClosed.
98 sigslot::signal1<QuicDataChannel*> SignalClosed;
99
100 protected:
101 virtual bool Send_w(const DataBuffer& buffer);
102 virtual bool WriteData_w(const char* data, size_t len);
103 virtual void OnMessage_s(const DataBuffer& received_data);
104 // Sends the data channel OPEN message.
105 // TODO(mikescarlett): Implement this method.
106 virtual void SendOpenMessage_w();
107 virtual void SetState(DataState state);
108
109 rtc::Thread* signaling_thread() { return signaling_thread_; }
110 rtc::Thread* worker_thread() { return worker_thread_; }
111
112 private:
113 // Callbacks for ReliableQuicStream.
114 void OnDataReceived(net::QuicStreamId stream_id,
115 const char* data,
116 size_t len);
117 void OnStreamClosed(net::QuicStreamId stream_id, int error);
118
119 // Callbacks for |quic_transport_channel_|.
120 // Called when the transport chennel becomes writable or unwritable.
121 void OnWritableState(cricket::TransportChannel* channel);
122 // Called when the QUIC session closes the connection due to handshake failure
123 // or explicit
124 // termination.
125 void OnConnectionClosed();
126
127 // QUIC transport channel which owns the QUIC session.
128 cricket::QuicTransportChannel* const quic_transport_channel_;
129 // Signaling thread for DataChannelInterface methods.
130 rtc::Thread* const signaling_thread_;
131 // Worker thread for sending/receiving data.
132 rtc::Thread* const worker_thread_;
133 // QUIC streams which have queued incoming data from the remote peer.
134 std::unordered_map<net::QuicStreamId, cricket::ReliableQuicStream*>
135 incoming_quic_streams_;
136 // Queued data for each incoming QUIC stream.
137 std::unordered_map<net::QuicStreamId, rtc::CopyOnWriteBuffer> queued_data_;
138 // Handles received data from the remote peer.
139 DataChannelObserver* observer_;
140 // Data channel id.
141 int id_;
142 // Connectivity state of the data channel.
143 DataState state_;
144 // Total bytes that are buffered among the QUIC streams.
145 uint64_t buffered_amount_;
146 // Counter for number of sent messages that is used for message ids.
147 uint64_t num_sent_messages_;
148
149 // Variables for application use.
150 const std::string& label_;
151 const std::string& protocol_;
152
153 // True if the data channel sends an OPEN message to the remote peer once
154 // this data channel is open.
155 bool send_open_message_;
156 };
157
158 } // namespace webrtc
159
160 #endif // WEBRTC_API_QUICDATACHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698