blob: 4f871b4d504c0935c612adbfd88c723c314a69d4 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +000010
Steve Anton10542f22019-01-11 09:11:00 -080011#include "pc/data_channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
kwibergd1fe2812016-04-27 06:47:29 -070013#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014#include <string>
Steve Anton944c7552018-12-13 14:19:10 -080015#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
Steve Anton10542f22019-01-11 09:11:00 -080017#include "media/sctp/sctp_transport_internal.h"
18#include "pc/sctp_utils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/checks.h"
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "rtc_base/location.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "rtc_base/ref_counted_object.h"
Yves Gerey3e707812018-11-28 16:47:49 +010023#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024
25namespace webrtc {
26
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +000027static size_t kMaxQueuedReceivedDataBytes = 16 * 1024 * 1024;
28static size_t kMaxQueuedSendDataBytes = 16 * 1024 * 1024;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
Harald Alvestrand928e7a32019-07-31 07:16:45 -040030namespace {
31
32static std::atomic<int> g_unique_id{0};
33
34int GenerateUniqueId() {
35 return ++g_unique_id;
36}
37
38} // namespace
39
Harald Alvestrandf3736ed2019-04-08 13:09:30 +020040InternalDataChannelInit::InternalDataChannelInit(const DataChannelInit& base)
41 : DataChannelInit(base), open_handshake_role(kOpener) {
42 // If the channel is externally negotiated, do not send the OPEN message.
43 if (base.negotiated) {
44 open_handshake_role = kNone;
45 } else {
46 // Datachannel is externally negotiated. Ignore the id value.
47 // Specified in createDataChannel, WebRTC spec section 6.1 bullet 13.
48 id = -1;
49 }
50 // Backwards compatibility: If base.maxRetransmits or base.maxRetransmitTime
51 // have been set to -1, unset them.
52 if (maxRetransmits && *maxRetransmits == -1) {
53 RTC_LOG(LS_ERROR)
54 << "Accepting maxRetransmits = -1 for backwards compatibility";
55 maxRetransmits = absl::nullopt;
56 }
57 if (maxRetransmitTime && *maxRetransmitTime == -1) {
58 RTC_LOG(LS_ERROR)
59 << "Accepting maxRetransmitTime = -1 for backwards compatibility";
60 maxRetransmitTime = absl::nullopt;
61 }
62}
63
deadbeefab9b2d12015-10-14 11:33:11 -070064bool SctpSidAllocator::AllocateSid(rtc::SSLRole role, int* sid) {
65 int potential_sid = (role == rtc::SSL_CLIENT) ? 0 : 1;
66 while (!IsSidAvailable(potential_sid)) {
67 potential_sid += 2;
68 if (potential_sid > static_cast<int>(cricket::kMaxSctpSid)) {
69 return false;
70 }
71 }
72
73 *sid = potential_sid;
74 used_sids_.insert(potential_sid);
75 return true;
76}
77
78bool SctpSidAllocator::ReserveSid(int sid) {
79 if (!IsSidAvailable(sid)) {
80 return false;
81 }
82 used_sids_.insert(sid);
83 return true;
84}
85
86void SctpSidAllocator::ReleaseSid(int sid) {
87 auto it = used_sids_.find(sid);
88 if (it != used_sids_.end()) {
89 used_sids_.erase(it);
90 }
91}
92
93bool SctpSidAllocator::IsSidAvailable(int sid) const {
Taylor Brandstetter1d7a6372016-08-24 13:15:27 -070094 if (sid < static_cast<int>(cricket::kMinSctpSid) ||
95 sid > static_cast<int>(cricket::kMaxSctpSid)) {
deadbeefab9b2d12015-10-14 11:33:11 -070096 return false;
97 }
98 return used_sids_.find(sid) == used_sids_.end();
99}
100
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000101bool DataChannel::PacketQueue::Empty() const {
102 return packets_.empty();
103}
104
Steve Anton944c7552018-12-13 14:19:10 -0800105std::unique_ptr<DataBuffer> DataChannel::PacketQueue::PopFront() {
106 RTC_DCHECK(!packets_.empty());
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000107 byte_count_ -= packets_.front()->size();
Steve Anton944c7552018-12-13 14:19:10 -0800108 std::unique_ptr<DataBuffer> packet = std::move(packets_.front());
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000109 packets_.pop_front();
Steve Anton944c7552018-12-13 14:19:10 -0800110 return packet;
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000111}
112
Steve Anton944c7552018-12-13 14:19:10 -0800113void DataChannel::PacketQueue::PushFront(std::unique_ptr<DataBuffer> packet) {
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000114 byte_count_ += packet->size();
Steve Anton944c7552018-12-13 14:19:10 -0800115 packets_.push_front(std::move(packet));
116}
117
118void DataChannel::PacketQueue::PushBack(std::unique_ptr<DataBuffer> packet) {
119 byte_count_ += packet->size();
120 packets_.push_back(std::move(packet));
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000121}
122
123void DataChannel::PacketQueue::Clear() {
Steve Anton944c7552018-12-13 14:19:10 -0800124 packets_.clear();
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000125 byte_count_ = 0;
126}
127
128void DataChannel::PacketQueue::Swap(PacketQueue* other) {
129 size_t other_byte_count = other->byte_count_;
130 other->byte_count_ = byte_count_;
131 byte_count_ = other_byte_count;
132
133 other->packets_.swap(packets_);
134}
135
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000136rtc::scoped_refptr<DataChannel> DataChannel::Create(
wu@webrtc.org78187522013-10-07 23:32:02 +0000137 DataChannelProviderInterface* provider,
138 cricket::DataChannelType dct,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 const std::string& label,
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000140 const InternalDataChannelInit& config) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141 rtc::scoped_refptr<DataChannel> channel(
142 new rtc::RefCountedObject<DataChannel>(provider, dct, label));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 if (!channel->Init(config)) {
144 return NULL;
145 }
146 return channel;
147}
148
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800149bool DataChannel::IsSctpLike(cricket::DataChannelType type) {
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700150 return type == cricket::DCT_SCTP || type == cricket::DCT_MEDIA_TRANSPORT ||
151 type == cricket::DCT_DATA_CHANNEL_TRANSPORT ||
152 type == cricket::DCT_DATA_CHANNEL_TRANSPORT_SCTP;
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800153}
154
Yves Gerey665174f2018-06-19 15:03:05 +0200155DataChannel::DataChannel(DataChannelProviderInterface* provider,
156 cricket::DataChannelType dct,
157 const std::string& label)
Harald Alvestrand928e7a32019-07-31 07:16:45 -0400158 : internal_id_(GenerateUniqueId()),
159 label_(label),
hbos84ffdee2016-10-12 14:14:39 -0700160 observer_(nullptr),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 state_(kConnecting),
hbos84ffdee2016-10-12 14:14:39 -0700162 messages_sent_(0),
163 bytes_sent_(0),
164 messages_received_(0),
165 bytes_received_(0),
Marina Cioceae448a3f2019-03-04 15:52:21 +0100166 buffered_amount_(0),
henrika@webrtc.org44461fa2014-01-13 09:35:02 +0000167 data_channel_type_(dct),
168 provider_(provider),
Lally Singh5c6c6e02015-05-29 11:52:39 -0400169 handshake_state_(kHandshakeInit),
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000170 connected_to_provider_(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 send_ssrc_set_(false),
henrika@webrtc.org44461fa2014-01-13 09:35:02 +0000172 receive_ssrc_set_(false),
Lally Singh5c6c6e02015-05-29 11:52:39 -0400173 writable_(false),
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000174 send_ssrc_(0),
Yves Gerey665174f2018-06-19 15:03:05 +0200175 receive_ssrc_(0) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000177bool DataChannel::Init(const InternalDataChannelInit& config) {
Lally Singh5c6c6e02015-05-29 11:52:39 -0400178 if (data_channel_type_ == cricket::DCT_RTP) {
Harald Alvestrandf3736ed2019-04-08 13:09:30 +0200179 if (config.reliable || config.id != -1 || config.maxRetransmits ||
180 config.maxRetransmitTime) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100181 RTC_LOG(LS_ERROR) << "Failed to initialize the RTP data channel due to "
Jonas Olsson45cc8902018-02-13 10:37:07 +0100182 "invalid DataChannelInit.";
Lally Singh5c6c6e02015-05-29 11:52:39 -0400183 return false;
184 }
185 handshake_state_ = kHandshakeReady;
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800186 } else if (IsSctpLike(data_channel_type_)) {
Harald Alvestrandf3736ed2019-04-08 13:09:30 +0200187 if (config.id < -1 ||
188 (config.maxRetransmits && *config.maxRetransmits < 0) ||
189 (config.maxRetransmitTime && *config.maxRetransmitTime < 0)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100190 RTC_LOG(LS_ERROR) << "Failed to initialize the SCTP data channel due to "
Jonas Olsson45cc8902018-02-13 10:37:07 +0100191 "invalid DataChannelInit.";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 return false;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000193 }
Harald Alvestrandf3736ed2019-04-08 13:09:30 +0200194 if (config.maxRetransmits && config.maxRetransmitTime) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100195 RTC_LOG(LS_ERROR)
196 << "maxRetransmits and maxRetransmitTime should not be both set.";
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000197 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 }
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000199 config_ = config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200
Lally Singh5c6c6e02015-05-29 11:52:39 -0400201 switch (config_.open_handshake_role) {
Yves Gerey665174f2018-06-19 15:03:05 +0200202 case webrtc::InternalDataChannelInit::kNone: // pre-negotiated
203 handshake_state_ = kHandshakeReady;
204 break;
205 case webrtc::InternalDataChannelInit::kOpener:
206 handshake_state_ = kHandshakeShouldSendOpen;
207 break;
208 case webrtc::InternalDataChannelInit::kAcker:
209 handshake_state_ = kHandshakeShouldSendAck;
210 break;
Steve Anton36b29d12017-10-30 09:57:42 -0700211 }
Lally Singh5c6c6e02015-05-29 11:52:39 -0400212
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000213 // Try to connect to the transport in case the transport channel already
214 // exists.
215 OnTransportChannelCreated();
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000216
217 // Checks if the transport is ready to send because the initial channel
218 // ready signal may have been sent before the DataChannel creation.
219 // This has to be done async because the upper layer objects (e.g.
220 // Chrome glue and WebKit) are not wired up properly until after this
221 // function returns.
222 if (provider_->ReadyToSendData()) {
Steve Anton044a04d2018-08-31 13:51:19 -0700223 invoker_.AsyncInvoke<void>(RTC_FROM_HERE, rtc::Thread::Current(),
224 [this] { OnChannelReady(true); });
wu@webrtc.org07a6fbe2013-11-04 18:41:34 +0000225 }
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000226 }
227
228 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229}
230
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000231DataChannel::~DataChannel() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232
233void DataChannel::RegisterObserver(DataChannelObserver* observer) {
234 observer_ = observer;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000235 DeliverQueuedReceivedData();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236}
237
238void DataChannel::UnregisterObserver() {
239 observer_ = NULL;
240}
241
242bool DataChannel::reliable() const {
wu@webrtc.org78187522013-10-07 23:32:02 +0000243 if (data_channel_type_ == cricket::DCT_RTP) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 return false;
245 } else {
Harald Alvestrandf3736ed2019-04-08 13:09:30 +0200246 return !config_.maxRetransmits && !config_.maxRetransmitTime;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 }
248}
249
Peter Boström0c4e06b2015-10-07 12:23:21 +0200250uint64_t DataChannel::buffered_amount() const {
Marina Cioceae448a3f2019-03-04 15:52:21 +0100251 return buffered_amount_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252}
253
254void DataChannel::Close() {
255 if (state_ == kClosed)
256 return;
257 send_ssrc_ = 0;
258 send_ssrc_set_ = false;
259 SetState(kClosing);
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700260 // Will send queued data before beginning the underlying closing procedure.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 UpdateState();
262}
263
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100264RTCError DataChannel::error() const {
265 return error_;
266}
267
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268bool DataChannel::Send(const DataBuffer& buffer) {
Marina Cioceae448a3f2019-03-04 15:52:21 +0100269 buffered_amount_ += buffer.size();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 if (state_ != kOpen) {
271 return false;
272 }
jiayl@webrtc.org3edbaaf2014-07-18 23:57:50 +0000273
274 // TODO(jiayl): the spec is unclear about if the remote side should get the
275 // onmessage event. We need to figure out the expected behavior and change the
276 // code accordingly.
277 if (buffer.size() == 0) {
278 return true;
279 }
280
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000281 // If the queue is non-empty, we're waiting for SignalReadyToSend,
282 // so just add to the end of the queue and keep waiting.
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000283 if (!queued_send_data_.Empty()) {
284 // Only SCTP DataChannel queues the outgoing data when the transport is
285 // blocked.
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800286 RTC_DCHECK(IsSctpLike(data_channel_type_));
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000287 if (!QueueSendDataMessage(buffer)) {
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700288 RTC_LOG(LS_ERROR) << "Closing the DataChannel due to a failure to queue "
289 "additional data.";
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100290 // https://w3c.github.io/webrtc-pc/#dom-rtcdatachannel-send step 5
291 // Note that the spec doesn't explicitly say to close in this situation.
292 CloseAbruptlyWithError(RTCError(RTCErrorType::RESOURCE_EXHAUSTED,
293 "Unable to queue data for sending"));
jiayl@webrtc.org5dc51fb2014-05-29 15:33:54 +0000294 }
295 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000298 bool success = SendDataMessage(buffer, true);
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000299 if (data_channel_type_ == cricket::DCT_RTP) {
300 return success;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000301 }
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000302
303 // Always return true for SCTP DataChannel per the spec.
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000304 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305}
306
Peter Boström0c4e06b2015-10-07 12:23:21 +0200307void DataChannel::SetReceiveSsrc(uint32_t receive_ssrc) {
nisseede5da42017-01-12 05:15:36 -0800308 RTC_DCHECK(data_channel_type_ == cricket::DCT_RTP);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000309
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 if (receive_ssrc_set_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 return;
312 }
313 receive_ssrc_ = receive_ssrc;
314 receive_ssrc_set_ = true;
315 UpdateState();
316}
317
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000318void DataChannel::SetSctpSid(int sid) {
kwibergee89e782017-08-09 17:22:01 -0700319 RTC_DCHECK_LT(config_.id, 0);
320 RTC_DCHECK_GE(sid, 0);
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800321 RTC_DCHECK(IsSctpLike(data_channel_type_));
deadbeefab9b2d12015-10-14 11:33:11 -0700322 if (config_.id == sid) {
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000323 return;
deadbeefab9b2d12015-10-14 11:33:11 -0700324 }
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000325
326 config_.id = sid;
327 provider_->AddSctpDataStream(sid);
328}
329
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700330void DataChannel::OnClosingProcedureStartedRemotely(int sid) {
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800331 if (IsSctpLike(data_channel_type_) && sid == config_.id &&
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700332 state_ != kClosing && state_ != kClosed) {
333 // Don't bother sending queued data since the side that initiated the
334 // closure wouldn't receive it anyway. See crbug.com/559394 for a lengthy
335 // discussion about this.
336 queued_send_data_.Clear();
337 queued_control_data_.Clear();
338 // Just need to change state to kClosing, SctpTransport will handle the
339 // rest of the closing procedure and OnClosingProcedureComplete will be
340 // called later.
341 started_closing_procedure_ = true;
342 SetState(kClosing);
343 }
344}
345
346void DataChannel::OnClosingProcedureComplete(int sid) {
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800347 if (IsSctpLike(data_channel_type_) && sid == config_.id) {
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700348 // If the closing procedure is complete, we should have finished sending
349 // all pending data and transitioned to kClosing already.
350 RTC_DCHECK_EQ(state_, kClosing);
351 RTC_DCHECK(queued_send_data_.Empty());
352 DisconnectFromProvider();
353 SetState(kClosed);
354 }
355}
356
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000357void DataChannel::OnTransportChannelCreated() {
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800358 RTC_DCHECK(IsSctpLike(data_channel_type_));
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000359 if (!connected_to_provider_) {
360 connected_to_provider_ = provider_->ConnectDataChannel(this);
361 }
362 // The sid may have been unassigned when provider_->ConnectDataChannel was
363 // done. So always add the streams even if connected_to_provider_ is true.
364 if (config_.id >= 0) {
365 provider_->AddSctpDataStream(config_.id);
366 }
367}
368
Harald Alvestrand408cb4b2019-11-16 12:09:08 +0100369void DataChannel::OnTransportChannelClosed() {
370 // The SctpTransport is unusable (for example, because the SCTP m= section
371 // was rejected, or because the DTLS transport closed), so we need to close
372 // abruptly.
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100373 // Note: this needs to differentiate between normal close and error close.
374 // https://w3c.github.io/webrtc-pc/#announcing-a-data-channel-as-closed
375 CloseAbruptlyWithError(
376 RTCError(RTCErrorType::NETWORK_ERROR, "Transport channel closed"));
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700377}
378
379// The remote peer request that this channel shall be closed.
380void DataChannel::RemotePeerRequestClose() {
381 RTC_DCHECK(data_channel_type_ == cricket::DCT_RTP);
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100382 // Close with error code explicitly set to OK.
383 CloseAbruptlyWithError(RTCError());
deadbeefab9b2d12015-10-14 11:33:11 -0700384}
385
Peter Boström0c4e06b2015-10-07 12:23:21 +0200386void DataChannel::SetSendSsrc(uint32_t send_ssrc) {
nisseede5da42017-01-12 05:15:36 -0800387 RTC_DCHECK(data_channel_type_ == cricket::DCT_RTP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 if (send_ssrc_set_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 return;
390 }
391 send_ssrc_ = send_ssrc;
392 send_ssrc_set_ = true;
393 UpdateState();
394}
395
deadbeef953c2ce2017-01-09 14:53:41 -0800396void DataChannel::OnDataReceived(const cricket::ReceiveDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -0700397 const rtc::CopyOnWriteBuffer& payload) {
deadbeef953c2ce2017-01-09 14:53:41 -0800398 if (data_channel_type_ == cricket::DCT_RTP && params.ssrc != receive_ssrc_) {
399 return;
400 }
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800401 if (IsSctpLike(data_channel_type_) && params.sid != config_.id) {
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000402 return;
403 }
404
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000405 if (params.type == cricket::DMT_CONTROL) {
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800406 RTC_DCHECK(IsSctpLike(data_channel_type_));
Lally Singh5c6c6e02015-05-29 11:52:39 -0400407 if (handshake_state_ != kHandshakeWaitingForAck) {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000408 // Ignore it if we are not expecting an ACK message.
Jonas Olsson45cc8902018-02-13 10:37:07 +0100409 RTC_LOG(LS_WARNING)
410 << "DataChannel received unexpected CONTROL message, sid = "
411 << params.sid;
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000412 return;
413 }
414 if (ParseDataChannelOpenAckMessage(payload)) {
415 // We can send unordered as soon as we receive the ACK message.
Lally Singh5c6c6e02015-05-29 11:52:39 -0400416 handshake_state_ = kHandshakeReady;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100417 RTC_LOG(LS_INFO) << "DataChannel received OPEN_ACK message, sid = "
418 << params.sid;
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000419 } else {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100420 RTC_LOG(LS_WARNING)
421 << "DataChannel failed to parse OPEN_ACK message, sid = "
422 << params.sid;
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000423 }
424 return;
425 }
426
nisseede5da42017-01-12 05:15:36 -0800427 RTC_DCHECK(params.type == cricket::DMT_BINARY ||
428 params.type == cricket::DMT_TEXT);
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000429
Mirko Bonadei675513b2017-11-09 11:09:25 +0100430 RTC_LOG(LS_VERBOSE) << "DataChannel received DATA message, sid = "
431 << params.sid;
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000432 // We can send unordered as soon as we receive any DATA message since the
433 // remote side must have received the OPEN (and old clients do not send
434 // OPEN_ACK).
Lally Singh5c6c6e02015-05-29 11:52:39 -0400435 if (handshake_state_ == kHandshakeWaitingForAck) {
436 handshake_state_ = kHandshakeReady;
437 }
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000438
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000439 bool binary = (params.type == cricket::DMT_BINARY);
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200440 auto buffer = std::make_unique<DataBuffer>(payload, binary);
Lally Singh5c6c6e02015-05-29 11:52:39 -0400441 if (state_ == kOpen && observer_) {
hbos84ffdee2016-10-12 14:14:39 -0700442 ++messages_received_;
443 bytes_received_ += buffer->size();
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000444 observer_->OnMessage(*buffer.get());
445 } else {
kwiberg@webrtc.orgeebcab52015-03-24 09:19:06 +0000446 if (queued_received_data_.byte_count() + payload.size() >
447 kMaxQueuedReceivedDataBytes) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100448 RTC_LOG(LS_ERROR) << "Queued received data exceeds the max buffer size.";
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000449
450 queued_received_data_.Clear();
451 if (data_channel_type_ != cricket::DCT_RTP) {
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100452 CloseAbruptlyWithError(
453 RTCError(RTCErrorType::RESOURCE_EXHAUSTED,
454 "Queued received data exceeds the max buffer size."));
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000455 }
456
457 return;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000458 }
Steve Anton944c7552018-12-13 14:19:10 -0800459 queued_received_data_.PushBack(std::move(buffer));
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000460 }
461}
462
463void DataChannel::OnChannelReady(bool writable) {
Lally Singh5c6c6e02015-05-29 11:52:39 -0400464 writable_ = writable;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000465 if (!writable) {
466 return;
467 }
Harald Alvestrandb9bb3712019-03-27 07:23:31 +0000468
Lally Singh5c6c6e02015-05-29 11:52:39 -0400469 SendQueuedControlMessages();
470 SendQueuedDataMessages();
471 UpdateState();
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000472}
473
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100474void DataChannel::CloseAbruptlyWithError(RTCError error) {
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700475 if (state_ == kClosed) {
jiayl@webrtc.org9f8164c2014-05-30 21:53:17 +0000476 return;
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700477 }
jiayl@webrtc.org9f8164c2014-05-30 21:53:17 +0000478
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700479 if (connected_to_provider_) {
480 DisconnectFromProvider();
481 }
482
483 // Closing abruptly means any queued data gets thrown away.
484 queued_send_data_.Clear();
Marina Cioceae448a3f2019-03-04 15:52:21 +0100485 buffered_amount_ = 0;
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700486 queued_control_data_.Clear();
487
488 // Still go to "kClosing" before "kClosed", since observers may be expecting
489 // that.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490 SetState(kClosing);
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100491 error_ = std::move(error);
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700492 SetState(kClosed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493}
494
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100495void DataChannel::CloseAbruptlyWithDataChannelFailure(
496 const std::string& message) {
497 RTCError error(RTCErrorType::OPERATION_ERROR_WITH_DATA, message);
498 error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE);
499 CloseAbruptlyWithError(std::move(error));
500}
501
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502void DataChannel::UpdateState() {
Lally Singh5c6c6e02015-05-29 11:52:39 -0400503 // UpdateState determines what to do from a few state variables. Include
504 // all conditions required for each state transition here for
505 // clarity. OnChannelReady(true) will send any queued data and then invoke
506 // UpdateState().
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000507 switch (state_) {
508 case kConnecting: {
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000509 if (send_ssrc_set_ == receive_ssrc_set_) {
510 if (data_channel_type_ == cricket::DCT_RTP && !connected_to_provider_) {
511 connected_to_provider_ = provider_->ConnectDataChannel(this);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 }
Lally Singh5c6c6e02015-05-29 11:52:39 -0400513 if (connected_to_provider_) {
514 if (handshake_state_ == kHandshakeShouldSendOpen) {
jbaucheec21bd2016-03-20 06:15:43 -0700515 rtc::CopyOnWriteBuffer payload;
Lally Singh5c6c6e02015-05-29 11:52:39 -0400516 WriteDataChannelOpenMessage(label_, config_, &payload);
517 SendControlMessage(payload);
518 } else if (handshake_state_ == kHandshakeShouldSendAck) {
jbaucheec21bd2016-03-20 06:15:43 -0700519 rtc::CopyOnWriteBuffer payload;
Lally Singh5c6c6e02015-05-29 11:52:39 -0400520 WriteDataChannelOpenAckMessage(&payload);
521 SendControlMessage(payload);
522 }
Yves Gerey665174f2018-06-19 15:03:05 +0200523 if (writable_ && (handshake_state_ == kHandshakeReady ||
524 handshake_state_ == kHandshakeWaitingForAck)) {
Lally Singh5c6c6e02015-05-29 11:52:39 -0400525 SetState(kOpen);
526 // If we have received buffers before the channel got writable.
527 // Deliver them now.
528 DeliverQueuedReceivedData();
529 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 }
531 }
532 break;
533 }
534 case kOpen: {
535 break;
536 }
537 case kClosing: {
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700538 // Wait for all queued data to be sent before beginning the closing
539 // procedure.
Lally Singh5c6c6e02015-05-29 11:52:39 -0400540 if (queued_send_data_.Empty() && queued_control_data_.Empty()) {
Taylor Brandstettercdd05f02018-05-31 13:23:32 -0700541 if (data_channel_type_ == cricket::DCT_RTP) {
542 // For RTP data channels, we can go to "closed" after we finish
543 // sending data and the send/recv SSRCs are unset.
544 if (connected_to_provider_) {
545 DisconnectFromProvider();
546 }
547 if (!send_ssrc_set_ && !receive_ssrc_set_) {
548 SetState(kClosed);
549 }
550 } else {
551 // For SCTP data channels, we need to wait for the closing procedure
552 // to complete; after calling RemoveSctpDataStream,
553 // OnClosingProcedureComplete will end up called asynchronously
554 // afterwards.
555 if (connected_to_provider_ && !started_closing_procedure_ &&
556 config_.id >= 0) {
557 started_closing_procedure_ = true;
558 provider_->RemoveSctpDataStream(config_.id);
559 }
Lally Singh5c6c6e02015-05-29 11:52:39 -0400560 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 }
562 break;
563 }
564 case kClosed:
565 break;
566 }
567}
568
569void DataChannel::SetState(DataState state) {
deadbeefab9b2d12015-10-14 11:33:11 -0700570 if (state_ == state) {
jiayl@webrtc.org9f8164c2014-05-30 21:53:17 +0000571 return;
deadbeefab9b2d12015-10-14 11:33:11 -0700572 }
jiayl@webrtc.org9f8164c2014-05-30 21:53:17 +0000573
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 state_ = state;
575 if (observer_) {
576 observer_->OnStateChange();
577 }
hbos82ebe022016-11-14 01:41:09 -0800578 if (state_ == kOpen) {
579 SignalOpened(this);
580 } else if (state_ == kClosed) {
deadbeefab9b2d12015-10-14 11:33:11 -0700581 SignalClosed(this);
582 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583}
584
Lally Singh5c6c6e02015-05-29 11:52:39 -0400585void DataChannel::DisconnectFromProvider() {
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000586 if (!connected_to_provider_)
587 return;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588
wu@webrtc.org78187522013-10-07 23:32:02 +0000589 provider_->DisconnectDataChannel(this);
590 connected_to_provider_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591}
592
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000593void DataChannel::DeliverQueuedReceivedData() {
Lally Singh5c6c6e02015-05-29 11:52:39 -0400594 if (!observer_) {
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000595 return;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000598 while (!queued_received_data_.Empty()) {
Steve Anton944c7552018-12-13 14:19:10 -0800599 std::unique_ptr<DataBuffer> buffer = queued_received_data_.PopFront();
hbos84ffdee2016-10-12 14:14:39 -0700600 ++messages_received_;
601 bytes_received_ += buffer->size();
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000602 observer_->OnMessage(*buffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 }
604}
605
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000606void DataChannel::SendQueuedDataMessages() {
Lally Singh5c6c6e02015-05-29 11:52:39 -0400607 if (queued_send_data_.Empty()) {
608 return;
609 }
610
nisseede5da42017-01-12 05:15:36 -0800611 RTC_DCHECK(state_ == kOpen || state_ == kClosing);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000612
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000613 while (!queued_send_data_.Empty()) {
Steve Anton944c7552018-12-13 14:19:10 -0800614 std::unique_ptr<DataBuffer> buffer = queued_send_data_.PopFront();
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000615 if (!SendDataMessage(*buffer, false)) {
Steve Anton944c7552018-12-13 14:19:10 -0800616 // Return the message to the front of the queue if sending is aborted.
617 queued_send_data_.PushFront(std::move(buffer));
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000618 break;
619 }
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000620 }
621}
622
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000623bool DataChannel::SendDataMessage(const DataBuffer& buffer,
624 bool queue_if_blocked) {
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000625 cricket::SendDataParams send_params;
626
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800627 if (IsSctpLike(data_channel_type_)) {
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000628 send_params.ordered = config_.ordered;
Lally Singh5c6c6e02015-05-29 11:52:39 -0400629 // Send as ordered if it is still going through OPEN/ACK signaling.
630 if (handshake_state_ != kHandshakeReady && !config_.ordered) {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000631 send_params.ordered = true;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100632 RTC_LOG(LS_VERBOSE)
633 << "Sending data as ordered for unordered DataChannel "
Jonas Olsson45cc8902018-02-13 10:37:07 +0100634 "because the OPEN_ACK message has not been received.";
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000635 }
636
Harald Alvestrandf3736ed2019-04-08 13:09:30 +0200637 send_params.max_rtx_count =
638 config_.maxRetransmits ? *config_.maxRetransmits : -1;
639 send_params.max_rtx_ms =
640 config_.maxRetransmitTime ? *config_.maxRetransmitTime : -1;
deadbeef953c2ce2017-01-09 14:53:41 -0800641 send_params.sid = config_.id;
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +0000642 } else {
643 send_params.ssrc = send_ssrc_;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000644 }
645 send_params.type = buffer.binary ? cricket::DMT_BINARY : cricket::DMT_TEXT;
646
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000647 cricket::SendDataResult send_result = cricket::SDR_SUCCESS;
648 bool success = provider_->SendData(send_params, buffer.data, &send_result);
649
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000650 if (success) {
hbos84ffdee2016-10-12 14:14:39 -0700651 ++messages_sent_;
652 bytes_sent_ += buffer.size();
Marina Cioceae448a3f2019-03-04 15:52:21 +0100653
654 RTC_DCHECK(buffered_amount_ >= buffer.size());
655 buffered_amount_ -= buffer.size();
656 if (observer_ && buffer.size() > 0) {
657 observer_->OnBufferedAmountChange(buffer.size());
658 }
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000659 return true;
660 }
661
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800662 if (!IsSctpLike(data_channel_type_)) {
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000663 return false;
664 }
665
666 if (send_result == cricket::SDR_BLOCK) {
667 if (!queue_if_blocked || QueueSendDataMessage(buffer)) {
668 return false;
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000669 }
670 }
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000671 // Close the channel if the error is not SDR_BLOCK, or if queuing the
672 // message failed.
Mirko Bonadei675513b2017-11-09 11:09:25 +0100673 RTC_LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send data, "
Jonas Olsson45cc8902018-02-13 10:37:07 +0100674 "send_result = "
675 << send_result;
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100676 CloseAbruptlyWithError(
677 RTCError(RTCErrorType::NETWORK_ERROR, "Failure to send data"));
jiayl@webrtc.org6ca61902014-11-12 17:28:40 +0000678
679 return false;
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000680}
681
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000682bool DataChannel::QueueSendDataMessage(const DataBuffer& buffer) {
Marina Cioceae448a3f2019-03-04 15:52:21 +0100683 size_t start_buffered_amount = queued_send_data_.byte_count();
684 if (start_buffered_amount + buffer.size() > kMaxQueuedSendDataBytes) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100685 RTC_LOG(LS_ERROR) << "Can't buffer any more data for the data channel.";
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000686 return false;
687 }
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200688 queued_send_data_.PushBack(std::make_unique<DataBuffer>(buffer));
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000689 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690}
691
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000692void DataChannel::SendQueuedControlMessages() {
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000693 PacketQueue control_packets;
694 control_packets.Swap(&queued_control_data_);
695
696 while (!control_packets.Empty()) {
Steve Anton944c7552018-12-13 14:19:10 -0800697 std::unique_ptr<DataBuffer> buf = control_packets.PopFront();
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000698 SendControlMessage(buf->data);
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000699 }
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000700}
701
jbaucheec21bd2016-03-20 06:15:43 -0700702void DataChannel::QueueControlMessage(const rtc::CopyOnWriteBuffer& buffer) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200703 queued_control_data_.PushBack(std::make_unique<DataBuffer>(buffer, true));
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000704}
705
jbaucheec21bd2016-03-20 06:15:43 -0700706bool DataChannel::SendControlMessage(const rtc::CopyOnWriteBuffer& buffer) {
Lally Singh5c6c6e02015-05-29 11:52:39 -0400707 bool is_open_message = handshake_state_ == kHandshakeShouldSendOpen;
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000708
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800709 RTC_DCHECK(IsSctpLike(data_channel_type_));
kwibergee89e782017-08-09 17:22:01 -0700710 RTC_DCHECK(writable_);
711 RTC_DCHECK_GE(config_.id, 0);
712 RTC_DCHECK(!is_open_message || !config_.negotiated);
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000713
714 cricket::SendDataParams send_params;
deadbeef953c2ce2017-01-09 14:53:41 -0800715 send_params.sid = config_.id;
Lally Singh5c6c6e02015-05-29 11:52:39 -0400716 // Send data as ordered before we receive any message from the remote peer to
717 // make sure the remote peer will not receive any data before it receives the
718 // OPEN message.
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000719 send_params.ordered = config_.ordered || is_open_message;
720 send_params.type = cricket::DMT_CONTROL;
721
722 cricket::SendDataResult send_result = cricket::SDR_SUCCESS;
723 bool retval = provider_->SendData(send_params, buffer, &send_result);
724 if (retval) {
Harald Alvestrand977b2652019-12-12 13:40:50 +0100725 RTC_LOG(LS_VERBOSE) << "Sent CONTROL message on channel " << config_.id;
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000726
Lally Singh5c6c6e02015-05-29 11:52:39 -0400727 if (handshake_state_ == kHandshakeShouldSendAck) {
728 handshake_state_ = kHandshakeReady;
729 } else if (handshake_state_ == kHandshakeShouldSendOpen) {
730 handshake_state_ = kHandshakeWaitingForAck;
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000731 }
732 } else if (send_result == cricket::SDR_BLOCK) {
733 QueueControlMessage(buffer);
734 } else {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100735 RTC_LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send"
Jonas Olsson45cc8902018-02-13 10:37:07 +0100736 " the CONTROL message, send_result = "
737 << send_result;
Harald Alvestranddfbfb462019-12-08 05:55:43 +0100738 CloseAbruptlyWithError(RTCError(RTCErrorType::NETWORK_ERROR,
739 "Failed to send a CONTROL message"));
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000740 }
jiayl@webrtc.orgb43c99d2014-06-20 17:11:14 +0000741 return retval;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000742}
743
Harald Alvestrand928e7a32019-07-31 07:16:45 -0400744// static
745void DataChannel::ResetInternalIdAllocatorForTesting(int new_value) {
746 g_unique_id = new_value;
747}
748
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749} // namespace webrtc