henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame^] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame^] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #include "webrtc/api/datachannel.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
| 13 | #include <string> |
| 14 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 15 | #include "webrtc/api/mediastreamprovider.h" |
| 16 | #include "webrtc/api/sctputils.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 17 | #include "webrtc/base/logging.h" |
| 18 | #include "webrtc/base/refcount.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 19 | #include "webrtc/media/sctp/sctpdataengine.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 23 | static size_t kMaxQueuedReceivedDataBytes = 16 * 1024 * 1024; |
| 24 | static size_t kMaxQueuedSendDataBytes = 16 * 1024 * 1024; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 26 | enum { |
| 27 | MSG_CHANNELREADY, |
| 28 | }; |
| 29 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 30 | bool SctpSidAllocator::AllocateSid(rtc::SSLRole role, int* sid) { |
| 31 | int potential_sid = (role == rtc::SSL_CLIENT) ? 0 : 1; |
| 32 | while (!IsSidAvailable(potential_sid)) { |
| 33 | potential_sid += 2; |
| 34 | if (potential_sid > static_cast<int>(cricket::kMaxSctpSid)) { |
| 35 | return false; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | *sid = potential_sid; |
| 40 | used_sids_.insert(potential_sid); |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | bool SctpSidAllocator::ReserveSid(int sid) { |
| 45 | if (!IsSidAvailable(sid)) { |
| 46 | return false; |
| 47 | } |
| 48 | used_sids_.insert(sid); |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | void SctpSidAllocator::ReleaseSid(int sid) { |
| 53 | auto it = used_sids_.find(sid); |
| 54 | if (it != used_sids_.end()) { |
| 55 | used_sids_.erase(it); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | bool SctpSidAllocator::IsSidAvailable(int sid) const { |
| 60 | if (sid < 0 || sid > static_cast<int>(cricket::kMaxSctpSid)) { |
| 61 | return false; |
| 62 | } |
| 63 | return used_sids_.find(sid) == used_sids_.end(); |
| 64 | } |
| 65 | |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 66 | DataChannel::PacketQueue::PacketQueue() : byte_count_(0) {} |
| 67 | |
| 68 | DataChannel::PacketQueue::~PacketQueue() { |
| 69 | Clear(); |
| 70 | } |
| 71 | |
| 72 | bool DataChannel::PacketQueue::Empty() const { |
| 73 | return packets_.empty(); |
| 74 | } |
| 75 | |
| 76 | DataBuffer* DataChannel::PacketQueue::Front() { |
| 77 | return packets_.front(); |
| 78 | } |
| 79 | |
| 80 | void DataChannel::PacketQueue::Pop() { |
| 81 | if (packets_.empty()) { |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | byte_count_ -= packets_.front()->size(); |
| 86 | packets_.pop_front(); |
| 87 | } |
| 88 | |
| 89 | void DataChannel::PacketQueue::Push(DataBuffer* packet) { |
| 90 | byte_count_ += packet->size(); |
| 91 | packets_.push_back(packet); |
| 92 | } |
| 93 | |
| 94 | void DataChannel::PacketQueue::Clear() { |
| 95 | while (!packets_.empty()) { |
| 96 | delete packets_.front(); |
| 97 | packets_.pop_front(); |
| 98 | } |
| 99 | byte_count_ = 0; |
| 100 | } |
| 101 | |
| 102 | void DataChannel::PacketQueue::Swap(PacketQueue* other) { |
| 103 | size_t other_byte_count = other->byte_count_; |
| 104 | other->byte_count_ = byte_count_; |
| 105 | byte_count_ = other_byte_count; |
| 106 | |
| 107 | other->packets_.swap(packets_); |
| 108 | } |
| 109 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 110 | rtc::scoped_refptr<DataChannel> DataChannel::Create( |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 111 | DataChannelProviderInterface* provider, |
| 112 | cricket::DataChannelType dct, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | const std::string& label, |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 114 | const InternalDataChannelInit& config) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 115 | rtc::scoped_refptr<DataChannel> channel( |
| 116 | new rtc::RefCountedObject<DataChannel>(provider, dct, label)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | if (!channel->Init(config)) { |
| 118 | return NULL; |
| 119 | } |
| 120 | return channel; |
| 121 | } |
| 122 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 123 | DataChannel::DataChannel( |
| 124 | DataChannelProviderInterface* provider, |
| 125 | cricket::DataChannelType dct, |
| 126 | const std::string& label) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 127 | : label_(label), |
| 128 | observer_(NULL), |
| 129 | state_(kConnecting), |
henrika@webrtc.org | 44461fa | 2014-01-13 09:35:02 +0000 | [diff] [blame] | 130 | data_channel_type_(dct), |
| 131 | provider_(provider), |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 132 | handshake_state_(kHandshakeInit), |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 133 | connected_to_provider_(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 134 | send_ssrc_set_(false), |
henrika@webrtc.org | 44461fa | 2014-01-13 09:35:02 +0000 | [diff] [blame] | 135 | receive_ssrc_set_(false), |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 136 | writable_(false), |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 137 | send_ssrc_(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | receive_ssrc_(0) { |
| 139 | } |
| 140 | |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 141 | bool DataChannel::Init(const InternalDataChannelInit& config) { |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 142 | if (data_channel_type_ == cricket::DCT_RTP) { |
| 143 | if (config.reliable || |
| 144 | config.id != -1 || |
| 145 | config.maxRetransmits != -1 || |
| 146 | config.maxRetransmitTime != -1) { |
| 147 | LOG(LS_ERROR) << "Failed to initialize the RTP data channel due to " |
| 148 | << "invalid DataChannelInit."; |
| 149 | return false; |
| 150 | } |
| 151 | handshake_state_ = kHandshakeReady; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 152 | } else if (data_channel_type_ == cricket::DCT_SCTP) { |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 153 | if (config.id < -1 || |
| 154 | config.maxRetransmits < -1 || |
| 155 | config.maxRetransmitTime < -1) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 156 | LOG(LS_ERROR) << "Failed to initialize the SCTP data channel due to " |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 157 | << "invalid DataChannelInit."; |
| 158 | return false; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 159 | } |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 160 | if (config.maxRetransmits != -1 && config.maxRetransmitTime != -1) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 161 | LOG(LS_ERROR) << |
| 162 | "maxRetransmits and maxRetransmitTime should not be both set."; |
| 163 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | } |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 165 | config_ = config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 166 | |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 167 | switch (config_.open_handshake_role) { |
| 168 | case webrtc::InternalDataChannelInit::kNone: // pre-negotiated |
| 169 | handshake_state_ = kHandshakeReady; |
| 170 | break; |
| 171 | case webrtc::InternalDataChannelInit::kOpener: |
| 172 | handshake_state_ = kHandshakeShouldSendOpen; |
| 173 | break; |
| 174 | case webrtc::InternalDataChannelInit::kAcker: |
| 175 | handshake_state_ = kHandshakeShouldSendAck; |
| 176 | break; |
| 177 | }; |
| 178 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 179 | // Try to connect to the transport in case the transport channel already |
| 180 | // exists. |
| 181 | OnTransportChannelCreated(); |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 182 | |
| 183 | // Checks if the transport is ready to send because the initial channel |
| 184 | // ready signal may have been sent before the DataChannel creation. |
| 185 | // This has to be done async because the upper layer objects (e.g. |
| 186 | // Chrome glue and WebKit) are not wired up properly until after this |
| 187 | // function returns. |
| 188 | if (provider_->ReadyToSendData()) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 189 | rtc::Thread::Current()->Post(this, MSG_CHANNELREADY, NULL); |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 190 | } |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 194 | } |
| 195 | |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 196 | DataChannel::~DataChannel() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 197 | |
| 198 | void DataChannel::RegisterObserver(DataChannelObserver* observer) { |
| 199 | observer_ = observer; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 200 | DeliverQueuedReceivedData(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | void DataChannel::UnregisterObserver() { |
| 204 | observer_ = NULL; |
| 205 | } |
| 206 | |
| 207 | bool DataChannel::reliable() const { |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 208 | if (data_channel_type_ == cricket::DCT_RTP) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 209 | return false; |
| 210 | } else { |
| 211 | return config_.maxRetransmits == -1 && |
| 212 | config_.maxRetransmitTime == -1; |
| 213 | } |
| 214 | } |
| 215 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 216 | uint64_t DataChannel::buffered_amount() const { |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 217 | return queued_send_data_.byte_count(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | void DataChannel::Close() { |
| 221 | if (state_ == kClosed) |
| 222 | return; |
| 223 | send_ssrc_ = 0; |
| 224 | send_ssrc_set_ = false; |
| 225 | SetState(kClosing); |
| 226 | UpdateState(); |
| 227 | } |
| 228 | |
| 229 | bool DataChannel::Send(const DataBuffer& buffer) { |
| 230 | if (state_ != kOpen) { |
| 231 | return false; |
| 232 | } |
jiayl@webrtc.org | 3edbaaf | 2014-07-18 23:57:50 +0000 | [diff] [blame] | 233 | |
| 234 | // TODO(jiayl): the spec is unclear about if the remote side should get the |
| 235 | // onmessage event. We need to figure out the expected behavior and change the |
| 236 | // code accordingly. |
| 237 | if (buffer.size() == 0) { |
| 238 | return true; |
| 239 | } |
| 240 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 241 | // If the queue is non-empty, we're waiting for SignalReadyToSend, |
| 242 | // so just add to the end of the queue and keep waiting. |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 243 | if (!queued_send_data_.Empty()) { |
| 244 | // Only SCTP DataChannel queues the outgoing data when the transport is |
| 245 | // blocked. |
| 246 | ASSERT(data_channel_type_ == cricket::DCT_SCTP); |
| 247 | if (!QueueSendDataMessage(buffer)) { |
jiayl@webrtc.org | 5dc51fb | 2014-05-29 15:33:54 +0000 | [diff] [blame] | 248 | Close(); |
| 249 | } |
| 250 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 251 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 252 | |
jiayl@webrtc.org | 6ca6190 | 2014-11-12 17:28:40 +0000 | [diff] [blame] | 253 | bool success = SendDataMessage(buffer, true); |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 254 | if (data_channel_type_ == cricket::DCT_RTP) { |
| 255 | return success; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 256 | } |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 257 | |
| 258 | // Always return true for SCTP DataChannel per the spec. |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 259 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 262 | void DataChannel::SetReceiveSsrc(uint32_t receive_ssrc) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 263 | ASSERT(data_channel_type_ == cricket::DCT_RTP); |
| 264 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 265 | if (receive_ssrc_set_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 266 | return; |
| 267 | } |
| 268 | receive_ssrc_ = receive_ssrc; |
| 269 | receive_ssrc_set_ = true; |
| 270 | UpdateState(); |
| 271 | } |
| 272 | |
| 273 | // The remote peer request that this channel shall be closed. |
| 274 | void DataChannel::RemotePeerRequestClose() { |
| 275 | DoClose(); |
| 276 | } |
| 277 | |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 278 | void DataChannel::SetSctpSid(int sid) { |
| 279 | ASSERT(config_.id < 0 && sid >= 0 && data_channel_type_ == cricket::DCT_SCTP); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 280 | if (config_.id == sid) { |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 281 | return; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 282 | } |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 283 | |
| 284 | config_.id = sid; |
| 285 | provider_->AddSctpDataStream(sid); |
| 286 | } |
| 287 | |
| 288 | void DataChannel::OnTransportChannelCreated() { |
| 289 | ASSERT(data_channel_type_ == cricket::DCT_SCTP); |
| 290 | if (!connected_to_provider_) { |
| 291 | connected_to_provider_ = provider_->ConnectDataChannel(this); |
| 292 | } |
| 293 | // The sid may have been unassigned when provider_->ConnectDataChannel was |
| 294 | // done. So always add the streams even if connected_to_provider_ is true. |
| 295 | if (config_.id >= 0) { |
| 296 | provider_->AddSctpDataStream(config_.id); |
| 297 | } |
| 298 | } |
| 299 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 300 | // The underlying transport channel was destroyed. |
| 301 | // This function makes sure the DataChannel is disconnected and changes state to |
| 302 | // kClosed. |
| 303 | void DataChannel::OnTransportChannelDestroyed() { |
| 304 | DoClose(); |
| 305 | } |
| 306 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 307 | void DataChannel::SetSendSsrc(uint32_t send_ssrc) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 308 | ASSERT(data_channel_type_ == cricket::DCT_RTP); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 309 | if (send_ssrc_set_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 310 | return; |
| 311 | } |
| 312 | send_ssrc_ = send_ssrc; |
| 313 | send_ssrc_set_ = true; |
| 314 | UpdateState(); |
| 315 | } |
| 316 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 317 | void DataChannel::OnMessage(rtc::Message* msg) { |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 318 | switch (msg->message_id) { |
| 319 | case MSG_CHANNELREADY: |
| 320 | OnChannelReady(true); |
| 321 | break; |
| 322 | } |
| 323 | } |
| 324 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 325 | void DataChannel::OnDataReceived(cricket::DataChannel* channel, |
| 326 | const cricket::ReceiveDataParams& params, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 327 | const rtc::Buffer& payload) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 328 | uint32_t expected_ssrc = |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 329 | (data_channel_type_ == cricket::DCT_RTP) ? receive_ssrc_ : config_.id; |
| 330 | if (params.ssrc != expected_ssrc) { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 331 | return; |
| 332 | } |
| 333 | |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 334 | if (params.type == cricket::DMT_CONTROL) { |
| 335 | ASSERT(data_channel_type_ == cricket::DCT_SCTP); |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 336 | if (handshake_state_ != kHandshakeWaitingForAck) { |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 337 | // Ignore it if we are not expecting an ACK message. |
| 338 | LOG(LS_WARNING) << "DataChannel received unexpected CONTROL message, " |
| 339 | << "sid = " << params.ssrc; |
| 340 | return; |
| 341 | } |
| 342 | if (ParseDataChannelOpenAckMessage(payload)) { |
| 343 | // We can send unordered as soon as we receive the ACK message. |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 344 | handshake_state_ = kHandshakeReady; |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 345 | LOG(LS_INFO) << "DataChannel received OPEN_ACK message, sid = " |
| 346 | << params.ssrc; |
| 347 | } else { |
| 348 | LOG(LS_WARNING) << "DataChannel failed to parse OPEN_ACK message, sid = " |
| 349 | << params.ssrc; |
| 350 | } |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | ASSERT(params.type == cricket::DMT_BINARY || |
| 355 | params.type == cricket::DMT_TEXT); |
| 356 | |
| 357 | LOG(LS_VERBOSE) << "DataChannel received DATA message, sid = " << params.ssrc; |
| 358 | // We can send unordered as soon as we receive any DATA message since the |
| 359 | // remote side must have received the OPEN (and old clients do not send |
| 360 | // OPEN_ACK). |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 361 | if (handshake_state_ == kHandshakeWaitingForAck) { |
| 362 | handshake_state_ = kHandshakeReady; |
| 363 | } |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 364 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 365 | bool binary = (params.type == cricket::DMT_BINARY); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 366 | rtc::scoped_ptr<DataBuffer> buffer(new DataBuffer(payload, binary)); |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 367 | if (state_ == kOpen && observer_) { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 368 | observer_->OnMessage(*buffer.get()); |
| 369 | } else { |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 370 | if (queued_received_data_.byte_count() + payload.size() > |
| 371 | kMaxQueuedReceivedDataBytes) { |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 372 | LOG(LS_ERROR) << "Queued received data exceeds the max buffer size."; |
| 373 | |
| 374 | queued_received_data_.Clear(); |
| 375 | if (data_channel_type_ != cricket::DCT_RTP) { |
| 376 | Close(); |
| 377 | } |
| 378 | |
| 379 | return; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 380 | } |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 381 | queued_received_data_.Push(buffer.release()); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 385 | void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 386 | if (data_channel_type_ == cricket::DCT_SCTP && sid == config_.id) { |
| 387 | Close(); |
| 388 | } |
| 389 | } |
| 390 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 391 | void DataChannel::OnChannelReady(bool writable) { |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 392 | writable_ = writable; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 393 | if (!writable) { |
| 394 | return; |
| 395 | } |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 396 | |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 397 | SendQueuedControlMessages(); |
| 398 | SendQueuedDataMessages(); |
| 399 | UpdateState(); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 400 | } |
| 401 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 402 | void DataChannel::DoClose() { |
jiayl@webrtc.org | 9f8164c | 2014-05-30 21:53:17 +0000 | [diff] [blame] | 403 | if (state_ == kClosed) |
| 404 | return; |
| 405 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 406 | receive_ssrc_set_ = false; |
| 407 | send_ssrc_set_ = false; |
| 408 | SetState(kClosing); |
| 409 | UpdateState(); |
| 410 | } |
| 411 | |
| 412 | void DataChannel::UpdateState() { |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 413 | // UpdateState determines what to do from a few state variables. Include |
| 414 | // all conditions required for each state transition here for |
| 415 | // clarity. OnChannelReady(true) will send any queued data and then invoke |
| 416 | // UpdateState(). |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 417 | switch (state_) { |
| 418 | case kConnecting: { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 419 | if (send_ssrc_set_ == receive_ssrc_set_) { |
| 420 | if (data_channel_type_ == cricket::DCT_RTP && !connected_to_provider_) { |
| 421 | connected_to_provider_ = provider_->ConnectDataChannel(this); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 422 | } |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 423 | if (connected_to_provider_) { |
| 424 | if (handshake_state_ == kHandshakeShouldSendOpen) { |
| 425 | rtc::Buffer payload; |
| 426 | WriteDataChannelOpenMessage(label_, config_, &payload); |
| 427 | SendControlMessage(payload); |
| 428 | } else if (handshake_state_ == kHandshakeShouldSendAck) { |
| 429 | rtc::Buffer payload; |
| 430 | WriteDataChannelOpenAckMessage(&payload); |
| 431 | SendControlMessage(payload); |
| 432 | } |
| 433 | if (writable_ && |
| 434 | (handshake_state_ == kHandshakeReady || |
| 435 | handshake_state_ == kHandshakeWaitingForAck)) { |
| 436 | SetState(kOpen); |
| 437 | // If we have received buffers before the channel got writable. |
| 438 | // Deliver them now. |
| 439 | DeliverQueuedReceivedData(); |
| 440 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | break; |
| 444 | } |
| 445 | case kOpen: { |
| 446 | break; |
| 447 | } |
| 448 | case kClosing: { |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 449 | if (queued_send_data_.Empty() && queued_control_data_.Empty()) { |
| 450 | if (connected_to_provider_) { |
| 451 | DisconnectFromProvider(); |
| 452 | } |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 453 | |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 454 | if (!connected_to_provider_ && !send_ssrc_set_ && !receive_ssrc_set_) { |
| 455 | SetState(kClosed); |
| 456 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 457 | } |
| 458 | break; |
| 459 | } |
| 460 | case kClosed: |
| 461 | break; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | void DataChannel::SetState(DataState state) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 466 | if (state_ == state) { |
jiayl@webrtc.org | 9f8164c | 2014-05-30 21:53:17 +0000 | [diff] [blame] | 467 | return; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 468 | } |
jiayl@webrtc.org | 9f8164c | 2014-05-30 21:53:17 +0000 | [diff] [blame] | 469 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 470 | state_ = state; |
| 471 | if (observer_) { |
| 472 | observer_->OnStateChange(); |
| 473 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 474 | if (state_ == kClosed) { |
| 475 | SignalClosed(this); |
| 476 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 479 | void DataChannel::DisconnectFromProvider() { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 480 | if (!connected_to_provider_) |
| 481 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 482 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 483 | provider_->DisconnectDataChannel(this); |
| 484 | connected_to_provider_ = false; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 485 | |
bemasc@webrtc.org | 9b5467e | 2014-12-04 23:16:52 +0000 | [diff] [blame] | 486 | if (data_channel_type_ == cricket::DCT_SCTP && config_.id >= 0) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 487 | provider_->RemoveSctpDataStream(config_.id); |
| 488 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 489 | } |
| 490 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 491 | void DataChannel::DeliverQueuedReceivedData() { |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 492 | if (!observer_) { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 493 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 494 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 495 | |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 496 | while (!queued_received_data_.Empty()) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 497 | rtc::scoped_ptr<DataBuffer> buffer(queued_received_data_.Front()); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 498 | observer_->OnMessage(*buffer); |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 499 | queued_received_data_.Pop(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 503 | void DataChannel::SendQueuedDataMessages() { |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 504 | if (queued_send_data_.Empty()) { |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | ASSERT(state_ == kOpen || state_ == kClosing); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 509 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 510 | uint64_t start_buffered_amount = buffered_amount(); |
jiayl@webrtc.org | 6ca6190 | 2014-11-12 17:28:40 +0000 | [diff] [blame] | 511 | while (!queued_send_data_.Empty()) { |
jiayl@webrtc.org | cceb166 | 2015-01-22 00:55:10 +0000 | [diff] [blame] | 512 | DataBuffer* buffer = queued_send_data_.Front(); |
jiayl@webrtc.org | 6ca6190 | 2014-11-12 17:28:40 +0000 | [diff] [blame] | 513 | if (!SendDataMessage(*buffer, false)) { |
jiayl@webrtc.org | cceb166 | 2015-01-22 00:55:10 +0000 | [diff] [blame] | 514 | // Leave the message in the queue if sending is aborted. |
jiayl@webrtc.org | 6ca6190 | 2014-11-12 17:28:40 +0000 | [diff] [blame] | 515 | break; |
| 516 | } |
| 517 | queued_send_data_.Pop(); |
jiayl@webrtc.org | cceb166 | 2015-01-22 00:55:10 +0000 | [diff] [blame] | 518 | delete buffer; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 519 | } |
bemasc | 0edd50c | 2015-07-01 13:34:33 -0700 | [diff] [blame] | 520 | |
| 521 | if (observer_ && buffered_amount() < start_buffered_amount) { |
| 522 | observer_->OnBufferedAmountChange(start_buffered_amount); |
| 523 | } |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 524 | } |
| 525 | |
jiayl@webrtc.org | 6ca6190 | 2014-11-12 17:28:40 +0000 | [diff] [blame] | 526 | bool DataChannel::SendDataMessage(const DataBuffer& buffer, |
| 527 | bool queue_if_blocked) { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 528 | cricket::SendDataParams send_params; |
| 529 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 530 | if (data_channel_type_ == cricket::DCT_SCTP) { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 531 | send_params.ordered = config_.ordered; |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 532 | // Send as ordered if it is still going through OPEN/ACK signaling. |
| 533 | if (handshake_state_ != kHandshakeReady && !config_.ordered) { |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 534 | send_params.ordered = true; |
| 535 | LOG(LS_VERBOSE) << "Sending data as ordered for unordered DataChannel " |
| 536 | << "because the OPEN_ACK message has not been received."; |
| 537 | } |
| 538 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 539 | send_params.max_rtx_count = config_.maxRetransmits; |
| 540 | send_params.max_rtx_ms = config_.maxRetransmitTime; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 541 | send_params.ssrc = config_.id; |
| 542 | } else { |
| 543 | send_params.ssrc = send_ssrc_; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 544 | } |
| 545 | send_params.type = buffer.binary ? cricket::DMT_BINARY : cricket::DMT_TEXT; |
| 546 | |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 547 | cricket::SendDataResult send_result = cricket::SDR_SUCCESS; |
| 548 | bool success = provider_->SendData(send_params, buffer.data, &send_result); |
| 549 | |
jiayl@webrtc.org | 6ca6190 | 2014-11-12 17:28:40 +0000 | [diff] [blame] | 550 | if (success) { |
| 551 | return true; |
| 552 | } |
| 553 | |
| 554 | if (data_channel_type_ != cricket::DCT_SCTP) { |
| 555 | return false; |
| 556 | } |
| 557 | |
| 558 | if (send_result == cricket::SDR_BLOCK) { |
| 559 | if (!queue_if_blocked || QueueSendDataMessage(buffer)) { |
| 560 | return false; |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 561 | } |
| 562 | } |
jiayl@webrtc.org | 6ca6190 | 2014-11-12 17:28:40 +0000 | [diff] [blame] | 563 | // Close the channel if the error is not SDR_BLOCK, or if queuing the |
| 564 | // message failed. |
| 565 | LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send data, " |
| 566 | << "send_result = " << send_result; |
| 567 | Close(); |
| 568 | |
| 569 | return false; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 570 | } |
| 571 | |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 572 | bool DataChannel::QueueSendDataMessage(const DataBuffer& buffer) { |
bemasc | 0edd50c | 2015-07-01 13:34:33 -0700 | [diff] [blame] | 573 | size_t start_buffered_amount = buffered_amount(); |
| 574 | if (start_buffered_amount >= kMaxQueuedSendDataBytes) { |
jiayl@webrtc.org | 5dc51fb | 2014-05-29 15:33:54 +0000 | [diff] [blame] | 575 | LOG(LS_ERROR) << "Can't buffer any more data for the data channel."; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 576 | return false; |
| 577 | } |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 578 | queued_send_data_.Push(new DataBuffer(buffer)); |
bemasc | 0edd50c | 2015-07-01 13:34:33 -0700 | [diff] [blame] | 579 | |
| 580 | // The buffer can have length zero, in which case there is no change. |
| 581 | if (observer_ && buffered_amount() > start_buffered_amount) { |
| 582 | observer_->OnBufferedAmountChange(start_buffered_amount); |
| 583 | } |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 584 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 585 | } |
| 586 | |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 587 | void DataChannel::SendQueuedControlMessages() { |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 588 | PacketQueue control_packets; |
| 589 | control_packets.Swap(&queued_control_data_); |
| 590 | |
| 591 | while (!control_packets.Empty()) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 592 | rtc::scoped_ptr<DataBuffer> buf(control_packets.Front()); |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 593 | SendControlMessage(buf->data); |
| 594 | control_packets.Pop(); |
| 595 | } |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 596 | } |
| 597 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 598 | void DataChannel::QueueControlMessage(const rtc::Buffer& buffer) { |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 599 | queued_control_data_.Push(new DataBuffer(buffer, true)); |
| 600 | } |
| 601 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 602 | bool DataChannel::SendControlMessage(const rtc::Buffer& buffer) { |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 603 | bool is_open_message = handshake_state_ == kHandshakeShouldSendOpen; |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 604 | |
| 605 | ASSERT(data_channel_type_ == cricket::DCT_SCTP && |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 606 | writable_ && |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 607 | config_.id >= 0 && |
| 608 | (!is_open_message || !config_.negotiated)); |
| 609 | |
| 610 | cricket::SendDataParams send_params; |
| 611 | send_params.ssrc = config_.id; |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 612 | // Send data as ordered before we receive any message from the remote peer to |
| 613 | // make sure the remote peer will not receive any data before it receives the |
| 614 | // OPEN message. |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 615 | send_params.ordered = config_.ordered || is_open_message; |
| 616 | send_params.type = cricket::DMT_CONTROL; |
| 617 | |
| 618 | cricket::SendDataResult send_result = cricket::SDR_SUCCESS; |
| 619 | bool retval = provider_->SendData(send_params, buffer, &send_result); |
| 620 | if (retval) { |
| 621 | LOG(LS_INFO) << "Sent CONTROL message on channel " << config_.id; |
| 622 | |
Lally Singh | 5c6c6e0 | 2015-05-29 11:52:39 -0400 | [diff] [blame] | 623 | if (handshake_state_ == kHandshakeShouldSendAck) { |
| 624 | handshake_state_ = kHandshakeReady; |
| 625 | } else if (handshake_state_ == kHandshakeShouldSendOpen) { |
| 626 | handshake_state_ = kHandshakeWaitingForAck; |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 627 | } |
| 628 | } else if (send_result == cricket::SDR_BLOCK) { |
| 629 | QueueControlMessage(buffer); |
| 630 | } else { |
| 631 | LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send" |
| 632 | << " the CONTROL message, send_result = " << send_result; |
| 633 | Close(); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 634 | } |
jiayl@webrtc.org | b43c99d | 2014-06-20 17:11:14 +0000 | [diff] [blame] | 635 | return retval; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 636 | } |
| 637 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 638 | } // namespace webrtc |