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