blob: 37b17d3a51e3cc73bb39f57ee99801f73013ae63 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle SCTP
3 * Copyright 2012 Google Inc, and Robin Seggelmann
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/media/sctp/sctpdataengine.h"
29
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include <stdarg.h>
31#include <stdio.h>
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +000032#include <sstream>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033#include <vector>
34
35#include "talk/base/buffer.h"
36#include "talk/base/helpers.h"
37#include "talk/base/logging.h"
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +000038#include "talk/base/safe_conversions.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/media/base/codec.h"
40#include "talk/media/base/constants.h"
41#include "talk/media/base/streamparams.h"
42#include "usrsctplib/usrsctp.h"
43
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +000044namespace {
45typedef cricket::SctpDataMediaChannel::StreamSet StreamSet;
46// Returns a comma-separated, human-readable list of the stream IDs in 's'
47std::string ListStreams(const StreamSet& s) {
48 std::stringstream result;
49 bool first = true;
wu@webrtc.orge00265e2014-01-07 19:32:40 +000050 for (StreamSet::const_iterator it = s.begin(); it != s.end(); ++it) {
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +000051 if (!first) {
52 result << ", " << *it;
53 } else {
54 result << *it;
55 first = false;
56 }
57 }
58 return result.str();
59}
60
61// Returns a pipe-separated, human-readable list of the SCTP_STREAM_RESET
62// flags in 'flags'
63std::string ListFlags(int flags) {
64 std::stringstream result;
65 bool first = true;
66 // Skip past the first 12 chars (strlen("SCTP_STREAM_"))
67#define MAKEFLAG(X) { X, #X + 12}
68 struct flaginfo_t {
69 int value;
70 const char* name;
71 } flaginfo[] = {
72 MAKEFLAG(SCTP_STREAM_RESET_INCOMING_SSN),
73 MAKEFLAG(SCTP_STREAM_RESET_OUTGOING_SSN),
74 MAKEFLAG(SCTP_STREAM_RESET_DENIED),
75 MAKEFLAG(SCTP_STREAM_RESET_FAILED),
76 MAKEFLAG(SCTP_STREAM_CHANGE_DENIED)
77 };
78#undef MAKEFLAG
79 for (int i = 0; i < ARRAY_SIZE(flaginfo); ++i) {
80 if (flags & flaginfo[i].value) {
81 if (!first) result << " | ";
82 result << flaginfo[i].name;
83 first = false;
84 }
85 }
86 return result.str();
87}
88
89// Returns a comma-separated, human-readable list of the integers in 'array'.
90// All 'num_elems' of them.
91std::string ListArray(const uint16* array, int num_elems) {
92 std::stringstream result;
93 for (int i = 0; i < num_elems; ++i) {
94 if (i) {
95 result << ", " << array[i];
96 } else {
97 result << array[i];
98 }
99 }
100 return result.str();
101}
102} // namespace
103
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104namespace cricket {
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000105typedef talk_base::ScopedMessageData<SctpInboundPacket> InboundPacketMessage;
106typedef talk_base::ScopedMessageData<talk_base::Buffer> OutboundPacketMessage;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
108// This is the SCTP port to use. It is passed along the wire and the listener
109// and connector must be using the same port. It is not related to the ports at
110// the IP level. (Corresponds to: sockaddr_conn.sconn_port in usrsctp.h)
111//
112// TODO(ldixon): Allow port to be set from higher level code.
113static const int kSctpDefaultPort = 5001;
114// TODO(ldixon): Find where this is defined, and also check is Sctp really
115// respects this.
116static const size_t kSctpMtu = 1280;
117
118enum {
119 MSG_SCTPINBOUNDPACKET = 1, // MessageData is SctpInboundPacket
120 MSG_SCTPOUTBOUNDPACKET = 2, // MessageData is talk_base:Buffer
121};
122
123struct SctpInboundPacket {
124 talk_base::Buffer buffer;
125 ReceiveDataParams params;
126 // The |flags| parameter is used by SCTP to distinguish notification packets
127 // from other types of packets.
128 int flags;
129};
130
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000131// Helper for logging SCTP messages.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132static void debug_sctp_printf(const char *format, ...) {
133 char s[255];
134 va_list ap;
135 va_start(ap, format);
136 vsnprintf(s, sizeof(s), format, ap);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000137 LOG(LS_INFO) << "SCTP: " << s;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138 va_end(ap);
139}
140
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000141// Get the PPID to use for the terminating fragment of this type.
142static SctpDataMediaChannel::PayloadProtocolIdentifier GetPpid(
143 cricket::DataMessageType type) {
144 switch (type) {
145 default:
146 case cricket::DMT_NONE:
147 return SctpDataMediaChannel::PPID_NONE;
148 case cricket::DMT_CONTROL:
149 return SctpDataMediaChannel::PPID_CONTROL;
150 case cricket::DMT_BINARY:
151 return SctpDataMediaChannel::PPID_BINARY_LAST;
152 case cricket::DMT_TEXT:
153 return SctpDataMediaChannel::PPID_TEXT_LAST;
154 };
155}
156
157static bool GetDataMediaType(
158 SctpDataMediaChannel::PayloadProtocolIdentifier ppid,
159 cricket::DataMessageType *dest) {
160 ASSERT(dest != NULL);
161 switch (ppid) {
162 case SctpDataMediaChannel::PPID_BINARY_PARTIAL:
163 case SctpDataMediaChannel::PPID_BINARY_LAST:
164 *dest = cricket::DMT_BINARY;
165 return true;
166
167 case SctpDataMediaChannel::PPID_TEXT_PARTIAL:
168 case SctpDataMediaChannel::PPID_TEXT_LAST:
169 *dest = cricket::DMT_TEXT;
170 return true;
171
172 case SctpDataMediaChannel::PPID_CONTROL:
173 *dest = cricket::DMT_CONTROL;
174 return true;
175
176 case SctpDataMediaChannel::PPID_NONE:
177 *dest = cricket::DMT_NONE;
178 return true;
179
180 default:
181 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183}
184
185// This is the callback usrsctp uses when there's data to send on the network
186// that has been wrapped appropriatly for the SCTP protocol.
187static int OnSctpOutboundPacket(void* addr, void* data, size_t length,
188 uint8_t tos, uint8_t set_df) {
189 SctpDataMediaChannel* channel = static_cast<SctpDataMediaChannel*>(addr);
190 LOG(LS_VERBOSE) << "global OnSctpOutboundPacket():"
191 << "addr: " << addr << "; length: " << length
192 << "; tos: " << std::hex << static_cast<int>(tos)
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000193 << "; set_df: " << std::hex << static_cast<int>(set_df);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 // Note: We have to copy the data; the caller will delete it.
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000195 OutboundPacketMessage* msg =
196 new OutboundPacketMessage(new talk_base::Buffer(data, length));
197 channel->worker_thread()->Post(channel, MSG_SCTPOUTBOUNDPACKET, msg);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 return 0;
199}
200
201// This is the callback called from usrsctp when data has been received, after
202// a packet has been interpreted and parsed by usrsctp and found to contain
203// payload data. It is called by a usrsctp thread. It is assumed this function
204// will free the memory used by 'data'.
205static int OnSctpInboundPacket(struct socket* sock, union sctp_sockstore addr,
206 void* data, size_t length,
207 struct sctp_rcvinfo rcv, int flags,
208 void* ulp_info) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 SctpDataMediaChannel* channel = static_cast<SctpDataMediaChannel*>(ulp_info);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 // Post data to the channel's receiver thread (copying it).
211 // TODO(ldixon): Unclear if copy is needed as this method is responsible for
212 // memory cleanup. But this does simplify code.
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000213 const SctpDataMediaChannel::PayloadProtocolIdentifier ppid =
214 static_cast<SctpDataMediaChannel::PayloadProtocolIdentifier>(
215 talk_base::HostToNetwork32(rcv.rcv_ppid));
216 cricket::DataMessageType type = cricket::DMT_NONE;
217 if (!GetDataMediaType(ppid, &type) && !(flags & MSG_NOTIFICATION)) {
218 // It's neither a notification nor a recognized data packet. Drop it.
219 LOG(LS_ERROR) << "Received an unknown PPID " << ppid
220 << " on an SCTP packet. Dropping.";
221 } else {
222 SctpInboundPacket* packet = new SctpInboundPacket;
223 packet->buffer.SetData(data, length);
224 packet->params.ssrc = rcv.rcv_sid;
225 packet->params.seq_num = rcv.rcv_ssn;
226 packet->params.timestamp = rcv.rcv_tsn;
227 packet->params.type = type;
228 packet->flags = flags;
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000229 // The ownership of |packet| transfers to |msg|.
230 InboundPacketMessage* msg = new InboundPacketMessage(packet);
231 channel->worker_thread()->Post(channel, MSG_SCTPINBOUNDPACKET, msg);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000232 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 free(data);
234 return 1;
235}
236
237// Set the initial value of the static SCTP Data Engines reference count.
238int SctpDataEngine::usrsctp_engines_count = 0;
239
240SctpDataEngine::SctpDataEngine() {
241 if (usrsctp_engines_count == 0) {
242 // First argument is udp_encapsulation_port, which is not releveant for our
243 // AF_CONN use of sctp.
244 usrsctp_init(0, cricket::OnSctpOutboundPacket, debug_sctp_printf);
245
246 // To turn on/off detailed SCTP debugging. You will also need to have the
247 // SCTP_DEBUG cpp defines flag.
248 // usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_ALL);
249
250 // TODO(ldixon): Consider turning this on/off.
251 usrsctp_sysctl_set_sctp_ecn_enable(0);
252
253 // TODO(ldixon): Consider turning this on/off.
254 // This is not needed right now (we don't do dynamic address changes):
255 // If SCTP Auto-ASCONF is enabled, the peer is informed automatically
256 // when a new address is added or removed. This feature is enabled by
257 // default.
258 // usrsctp_sysctl_set_sctp_auto_asconf(0);
259
260 // TODO(ldixon): Consider turning this on/off.
261 // Add a blackhole sysctl. Setting it to 1 results in no ABORTs
262 // being sent in response to INITs, setting it to 2 results
263 // in no ABORTs being sent for received OOTB packets.
264 // This is similar to the TCP sysctl.
265 //
266 // See: http://lakerest.net/pipermail/sctp-coders/2012-January/009438.html
267 // See: http://svnweb.freebsd.org/base?view=revision&revision=229805
268 // usrsctp_sysctl_set_sctp_blackhole(2);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000269
270 // Set the number of default outgoing streams. This is the number we'll
271 // send in the SCTP INIT message. The 'appropriate default' in the
272 // second paragraph of
273 // http://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-05#section-6.2
274 // is cricket::kMaxSctpSid.
275 usrsctp_sysctl_set_sctp_nr_outgoing_streams_default(
276 cricket::kMaxSctpSid);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 }
278 usrsctp_engines_count++;
279
280 // We don't put in a codec because we don't want one offered when we
281 // use the hybrid data engine.
282 // codecs_.push_back(cricket::DataCodec( kGoogleSctpDataCodecId,
283 // kGoogleSctpDataCodecName, 0));
284}
285
286SctpDataEngine::~SctpDataEngine() {
287 // TODO(ldixon): There is currently a bug in teardown of usrsctp that blocks
288 // indefintely if a finish call made too soon after close calls. So teardown
289 // has been skipped. Once the bug is fixed, retest and enable teardown.
290 //
291 // usrsctp_engines_count--;
292 // LOG(LS_VERBOSE) << "usrsctp_engines_count:" << usrsctp_engines_count;
293 // if (usrsctp_engines_count == 0) {
294 // if (usrsctp_finish() != 0) {
295 // LOG(LS_WARNING) << "usrsctp_finish.";
296 // }
297 // }
298}
299
300DataMediaChannel* SctpDataEngine::CreateChannel(
301 DataChannelType data_channel_type) {
302 if (data_channel_type != DCT_SCTP) {
303 return NULL;
304 }
305 return new SctpDataMediaChannel(talk_base::Thread::Current());
306}
307
308SctpDataMediaChannel::SctpDataMediaChannel(talk_base::Thread* thread)
309 : worker_thread_(thread),
wu@webrtc.org78187522013-10-07 23:32:02 +0000310 local_port_(-1),
311 remote_port_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 sock_(NULL),
313 sending_(false),
314 receiving_(false),
315 debug_name_("SctpDataMediaChannel") {
316}
317
318SctpDataMediaChannel::~SctpDataMediaChannel() {
319 CloseSctpSocket();
320}
321
322sockaddr_conn SctpDataMediaChannel::GetSctpSockAddr(int port) {
323 sockaddr_conn sconn = {0};
324 sconn.sconn_family = AF_CONN;
325#ifdef HAVE_SCONN_LEN
326 sconn.sconn_len = sizeof(sockaddr_conn);
327#endif
328 // Note: conversion from int to uint16_t happens here.
329 sconn.sconn_port = talk_base::HostToNetwork16(port);
330 sconn.sconn_addr = this;
331 return sconn;
332}
333
334bool SctpDataMediaChannel::OpenSctpSocket() {
335 if (sock_) {
336 LOG(LS_VERBOSE) << debug_name_
337 << "->Ignoring attempt to re-create existing socket.";
338 return false;
339 }
340 sock_ = usrsctp_socket(AF_CONN, SOCK_STREAM, IPPROTO_SCTP,
341 cricket::OnSctpInboundPacket, NULL, 0, this);
342 if (!sock_) {
343 LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed to create SCTP socket.";
344 return false;
345 }
346
347 // Make the socket non-blocking. Connect, close, shutdown etc will not block
348 // the thread waiting for the socket operation to complete.
349 if (usrsctp_set_non_blocking(sock_, 1) < 0) {
350 LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed to set SCTP to non blocking.";
351 return false;
352 }
353
354 // This ensures that the usrsctp close call deletes the association. This
355 // prevents usrsctp from calling OnSctpOutboundPacket with references to
356 // this class as the address.
357 linger linger_opt;
358 linger_opt.l_onoff = 1;
359 linger_opt.l_linger = 0;
360 if (usrsctp_setsockopt(sock_, SOL_SOCKET, SO_LINGER, &linger_opt,
361 sizeof(linger_opt))) {
362 LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed to set SO_LINGER.";
363 return false;
364 }
365
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000366 // Enable stream ID resets.
367 struct sctp_assoc_value stream_rst;
368 stream_rst.assoc_id = SCTP_ALL_ASSOC;
369 stream_rst.assoc_value = 1;
370 if (usrsctp_setsockopt(sock_, IPPROTO_SCTP, SCTP_ENABLE_STREAM_RESET,
371 &stream_rst, sizeof(stream_rst))) {
372 LOG_ERRNO(LS_ERROR) << debug_name_
373 << "Failed to set SCTP_ENABLE_STREAM_RESET.";
374 return false;
375 }
376
377 // Nagle.
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000378 uint32_t nodelay = 1;
379 if (usrsctp_setsockopt(sock_, IPPROTO_SCTP, SCTP_NODELAY, &nodelay,
380 sizeof(nodelay))) {
381 LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed to set SCTP_NODELAY.";
382 return false;
383 }
384
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 // Subscribe to SCTP event notifications.
386 int event_types[] = {SCTP_ASSOC_CHANGE,
387 SCTP_PEER_ADDR_CHANGE,
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000388 SCTP_SEND_FAILED_EVENT,
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000389 SCTP_SENDER_DRY_EVENT,
390 SCTP_STREAM_RESET_EVENT};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 struct sctp_event event = {0};
392 event.se_assoc_id = SCTP_ALL_ASSOC;
393 event.se_on = 1;
394 for (size_t i = 0; i < ARRAY_SIZE(event_types); i++) {
395 event.se_type = event_types[i];
396 if (usrsctp_setsockopt(sock_, IPPROTO_SCTP, SCTP_EVENT, &event,
397 sizeof(event)) < 0) {
398 LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed to set SCTP_EVENT type: "
399 << event.se_type;
400 return false;
401 }
402 }
403
404 // Register this class as an address for usrsctp. This is used by SCTP to
405 // direct the packets received (by the created socket) to this class.
406 usrsctp_register_address(this);
407 sending_ = true;
408 return true;
409}
410
411void SctpDataMediaChannel::CloseSctpSocket() {
412 sending_ = false;
413 if (sock_) {
414 // We assume that SO_LINGER option is set to close the association when
415 // close is called. This means that any pending packets in usrsctp will be
416 // discarded instead of being sent.
417 usrsctp_close(sock_);
418 sock_ = NULL;
419 usrsctp_deregister_address(this);
420 }
421}
422
423bool SctpDataMediaChannel::Connect() {
424 LOG(LS_VERBOSE) << debug_name_ << "->Connect().";
wu@webrtc.org78187522013-10-07 23:32:02 +0000425 if (remote_port_ < 0) {
426 remote_port_ = kSctpDefaultPort;
427 }
428 if (local_port_ < 0) {
429 local_port_ = kSctpDefaultPort;
430 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431
432 // If we already have a socket connection, just return.
433 if (sock_) {
434 LOG(LS_WARNING) << debug_name_ << "->Connect(): Ignored as socket "
435 "is already established.";
436 return true;
437 }
438
439 // If no socket (it was closed) try to start it again. This can happen when
440 // the socket we are connecting to closes, does an sctp shutdown handshake,
441 // or behaves unexpectedly causing us to perform a CloseSctpSocket.
442 if (!sock_ && !OpenSctpSocket()) {
443 return false;
444 }
445
446 // Note: conversion from int to uint16_t happens on assignment.
447 sockaddr_conn local_sconn = GetSctpSockAddr(local_port_);
448 if (usrsctp_bind(sock_, reinterpret_cast<sockaddr *>(&local_sconn),
449 sizeof(local_sconn)) < 0) {
450 LOG_ERRNO(LS_ERROR) << debug_name_ << "->Connect(): "
451 << ("Failed usrsctp_bind");
452 CloseSctpSocket();
453 return false;
454 }
455
456 // Note: conversion from int to uint16_t happens on assignment.
457 sockaddr_conn remote_sconn = GetSctpSockAddr(remote_port_);
458 int connect_result = usrsctp_connect(
459 sock_, reinterpret_cast<sockaddr *>(&remote_sconn), sizeof(remote_sconn));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000460 if (connect_result < 0 && errno != SCTP_EINPROGRESS) {
461 LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed usrsctp_connect. got errno="
462 << errno << ", but wanted " << SCTP_EINPROGRESS;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 CloseSctpSocket();
464 return false;
465 }
466 return true;
467}
468
469void SctpDataMediaChannel::Disconnect() {
470 // TODO(ldixon): Consider calling |usrsctp_shutdown(sock_, ...)| to do a
471 // shutdown handshake and remove the association.
472 CloseSctpSocket();
473}
474
475bool SctpDataMediaChannel::SetSend(bool send) {
476 if (!sending_ && send) {
477 return Connect();
478 }
479 if (sending_ && !send) {
480 Disconnect();
481 }
482 return true;
483}
484
485bool SctpDataMediaChannel::SetReceive(bool receive) {
486 receiving_ = receive;
487 return true;
488}
489
490bool SctpDataMediaChannel::AddSendStream(const StreamParams& stream) {
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000491 return AddStream(stream);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492}
493
494bool SctpDataMediaChannel::RemoveSendStream(uint32 ssrc) {
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000495 return ResetStream(ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496}
497
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498bool SctpDataMediaChannel::AddRecvStream(const StreamParams& stream) {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000499 // SCTP DataChannels are always bi-directional and calling AddSendStream will
500 // enable both sending and receiving on the stream. So AddRecvStream is a
501 // no-op.
502 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000503}
504
505bool SctpDataMediaChannel::RemoveRecvStream(uint32 ssrc) {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000506 // SCTP DataChannels are always bi-directional and calling RemoveSendStream
507 // will disable both sending and receiving on the stream. So RemoveRecvStream
508 // is a no-op.
509 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510}
511
512bool SctpDataMediaChannel::SendData(
513 const SendDataParams& params,
514 const talk_base::Buffer& payload,
515 SendDataResult* result) {
516 if (result) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000517 // Preset |result| to assume an error. If SendData succeeds, we'll
518 // overwrite |*result| once more at the end.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 *result = SDR_ERROR;
520 }
521
522 if (!sending_) {
523 LOG(LS_WARNING) << debug_name_ << "->SendData(...): "
524 << "Not sending packet with ssrc=" << params.ssrc
525 << " len=" << payload.length() << " before SetSend(true).";
526 return false;
527 }
528
wu@webrtc.org91053e72013-08-10 07:18:04 +0000529 if (params.type != cricket::DMT_CONTROL &&
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000530 open_streams_.find(params.ssrc) == open_streams_.end()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531 LOG(LS_WARNING) << debug_name_ << "->SendData(...): "
532 << "Not sending data because ssrc is unknown: "
533 << params.ssrc;
534 return false;
535 }
536
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 //
538 // Send data using SCTP.
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000539 ssize_t send_res = 0; // result from usrsctp_sendv.
540 struct sctp_sendv_spa spa = {0};
541 spa.sendv_flags |= SCTP_SEND_SNDINFO_VALID;
542 spa.sendv_sndinfo.snd_sid = params.ssrc;
543 spa.sendv_sndinfo.snd_ppid = talk_base::HostToNetwork32(
544 GetPpid(params.type));
545
546 // Ordered implies reliable.
547 if (!params.ordered) {
548 spa.sendv_sndinfo.snd_flags |= SCTP_UNORDERED;
549 if (params.max_rtx_count >= 0 || params.max_rtx_ms == 0) {
550 spa.sendv_flags |= SCTP_SEND_PRINFO_VALID;
551 spa.sendv_prinfo.pr_policy = SCTP_PR_SCTP_RTX;
552 spa.sendv_prinfo.pr_value = params.max_rtx_count;
553 } else {
554 spa.sendv_flags |= SCTP_SEND_PRINFO_VALID;
555 spa.sendv_prinfo.pr_policy = SCTP_PR_SCTP_TTL;
556 spa.sendv_prinfo.pr_value = params.max_rtx_ms;
557 }
558 }
559
560 // We don't fragment.
561 send_res = usrsctp_sendv(sock_, payload.data(),
562 static_cast<size_t>(payload.length()),
563 NULL, 0, &spa,
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000564 talk_base::checked_cast<socklen_t>(sizeof(spa)),
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000565 SCTP_SENDV_SPA, 0);
566 if (send_res < 0) {
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000567 if (errno == EWOULDBLOCK) {
568 *result = SDR_BLOCK;
569 LOG(LS_INFO) << debug_name_ << "->SendData(...): EWOULDBLOCK returned";
570 } else {
571 LOG_ERRNO(LS_ERROR) << "ERROR:" << debug_name_
572 << "->SendData(...): "
573 << " usrsctp_sendv: ";
574 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 return false;
576 }
577 if (result) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000578 // Only way out now is success.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579 *result = SDR_SUCCESS;
580 }
581 return true;
582}
583
584// Called by network interface when a packet has been received.
wu@webrtc.orga9890802013-12-13 00:21:03 +0000585void SctpDataMediaChannel::OnPacketReceived(
586 talk_base::Buffer* packet, const talk_base::PacketTime& packet_time) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000587 LOG(LS_VERBOSE) << debug_name_ << "->OnPacketReceived(...): " << " length="
588 << packet->length() << ", sending: " << sending_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 // Only give receiving packets to usrsctp after if connected. This enables two
590 // peers to each make a connect call, but for them not to receive an INIT
591 // packet before they have called connect; least the last receiver of the INIT
592 // packet will have called connect, and a connection will be established.
593 if (sending_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 // Pass received packet to SCTP stack. Once processed by usrsctp, the data
595 // will be will be given to the global OnSctpInboundData, and then,
596 // marshalled by a Post and handled with OnMessage.
597 usrsctp_conninput(this, packet->data(), packet->length(), 0);
598 } else {
599 // TODO(ldixon): Consider caching the packet for very slightly better
600 // reliability.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000601 }
602}
603
604void SctpDataMediaChannel::OnInboundPacketFromSctpToChannel(
605 SctpInboundPacket* packet) {
606 LOG(LS_VERBOSE) << debug_name_ << "->OnInboundPacketFromSctpToChannel(...): "
607 << "Received SCTP data:"
608 << " ssrc=" << packet->params.ssrc
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 << " notification: " << (packet->flags & MSG_NOTIFICATION)
mallinath@webrtc.org1112c302013-09-23 20:34:45 +0000610 << " length=" << packet->buffer.length();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611 // Sending a packet with data == NULL (no data) is SCTPs "close the
612 // connection" message. This sets sock_ = NULL;
613 if (!packet->buffer.length() || !packet->buffer.data()) {
614 LOG(LS_INFO) << debug_name_ << "->OnInboundPacketFromSctpToChannel(...): "
615 "No data, closing.";
616 return;
617 }
618 if (packet->flags & MSG_NOTIFICATION) {
619 OnNotificationFromSctp(&packet->buffer);
620 } else {
621 OnDataFromSctpToChannel(packet->params, &packet->buffer);
622 }
623}
624
625void SctpDataMediaChannel::OnDataFromSctpToChannel(
626 const ReceiveDataParams& params, talk_base::Buffer* buffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 if (receiving_) {
628 LOG(LS_VERBOSE) << debug_name_ << "->OnDataFromSctpToChannel(...): "
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000629 << "Posting with length: " << buffer->length()
630 << " on stream " << params.ssrc;
631 // Reports all received messages to upper layers, no matter whether the sid
632 // is known.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633 SignalDataReceived(params, buffer->data(), buffer->length());
634 } else {
635 LOG(LS_WARNING) << debug_name_ << "->OnDataFromSctpToChannel(...): "
636 << "Not receiving packet with sid=" << params.ssrc
637 << " len=" << buffer->length()
638 << " before SetReceive(true).";
639 }
640}
641
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000642bool SctpDataMediaChannel::AddStream(const StreamParams& stream) {
643 if (!stream.has_ssrcs()) {
644 return false;
645 }
646
647 const uint32 ssrc = stream.first_ssrc();
648 if (open_streams_.find(ssrc) != open_streams_.end()) {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000649 LOG(LS_WARNING) << debug_name_ << "->Add(Send|Recv)Stream(...): "
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000650 << "Not adding data stream '" << stream.id
651 << "' with ssrc=" << ssrc
652 << " because stream is already open.";
653 return false;
654 } else if (queued_reset_streams_.find(ssrc) != queued_reset_streams_.end()
655 || sent_reset_streams_.find(ssrc) != sent_reset_streams_.end()) {
656 LOG(LS_WARNING) << debug_name_ << "->Add(Send|Recv)Stream(...): "
657 << "Not adding data stream '" << stream.id
658 << "' with ssrc=" << ssrc
659 << " because stream is still closing.";
660 return false;
661 }
662
663 open_streams_.insert(ssrc);
664 return true;
665}
666
667bool SctpDataMediaChannel::ResetStream(uint32 ssrc) {
668 // We typically get this called twice for the same stream, once each for
669 // Send and Recv.
670 StreamSet::iterator found = open_streams_.find(ssrc);
671
672 if (found == open_streams_.end()) {
673 LOG(LS_VERBOSE) << debug_name_ << "->ResetStream(" << ssrc << "): "
674 << "stream not found.";
675 return false;
676 } else {
677 LOG(LS_VERBOSE) << debug_name_ << "->ResetStream(" << ssrc << "): "
678 << "Removing and queuing RE-CONFIG chunk.";
679 open_streams_.erase(found);
680 }
681
682 // SCTP won't let you have more than one stream reset pending at a time, but
683 // you can close multiple streams in a single reset. So, we keep an internal
684 // queue of streams-to-reset, and send them as one reset message in
685 // SendQueuedStreamResets().
686 queued_reset_streams_.insert(ssrc);
687
688 // Signal our stream-reset logic that it should try to send now, if it can.
689 SendQueuedStreamResets();
690
691 // The stream will actually get removed when we get the acknowledgment.
692 return true;
693}
694
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000695void SctpDataMediaChannel::OnNotificationFromSctp(talk_base::Buffer* buffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 const sctp_notification& notification =
697 reinterpret_cast<const sctp_notification&>(*buffer->data());
698 ASSERT(notification.sn_header.sn_length == buffer->length());
699
700 // TODO(ldixon): handle notifications appropriately.
701 switch (notification.sn_header.sn_type) {
702 case SCTP_ASSOC_CHANGE:
703 LOG(LS_VERBOSE) << "SCTP_ASSOC_CHANGE";
704 OnNotificationAssocChange(notification.sn_assoc_change);
705 break;
706 case SCTP_REMOTE_ERROR:
707 LOG(LS_INFO) << "SCTP_REMOTE_ERROR";
708 break;
709 case SCTP_SHUTDOWN_EVENT:
710 LOG(LS_INFO) << "SCTP_SHUTDOWN_EVENT";
711 break;
712 case SCTP_ADAPTATION_INDICATION:
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000713 LOG(LS_INFO) << "SCTP_ADAPTATION_INDICATION";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 break;
715 case SCTP_PARTIAL_DELIVERY_EVENT:
716 LOG(LS_INFO) << "SCTP_PARTIAL_DELIVERY_EVENT";
717 break;
718 case SCTP_AUTHENTICATION_EVENT:
719 LOG(LS_INFO) << "SCTP_AUTHENTICATION_EVENT";
720 break;
721 case SCTP_SENDER_DRY_EVENT:
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000722 LOG(LS_VERBOSE) << "SCTP_SENDER_DRY_EVENT";
wu@webrtc.orgd64719d2013-08-01 00:00:07 +0000723 SignalReadyToSend(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 break;
725 // TODO(ldixon): Unblock after congestion.
726 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
727 LOG(LS_INFO) << "SCTP_NOTIFICATIONS_STOPPED_EVENT";
728 break;
729 case SCTP_SEND_FAILED_EVENT:
730 LOG(LS_INFO) << "SCTP_SEND_FAILED_EVENT";
731 break;
732 case SCTP_STREAM_RESET_EVENT:
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000733 OnStreamResetEvent(&notification.sn_strreset_event);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 break;
735 case SCTP_ASSOC_RESET_EVENT:
736 LOG(LS_INFO) << "SCTP_ASSOC_RESET_EVENT";
737 break;
738 case SCTP_STREAM_CHANGE_EVENT:
739 LOG(LS_INFO) << "SCTP_STREAM_CHANGE_EVENT";
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000740 // An acknowledgment we get after our stream resets have gone through,
741 // if they've failed. We log the message, but don't react -- we don't
742 // keep around the last-transmitted set of SSIDs we wanted to close for
743 // error recovery. It doesn't seem likely to occur, and if so, likely
744 // harmless within the lifetime of a single SCTP association.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 break;
746 default:
747 LOG(LS_WARNING) << "Unknown SCTP event: "
748 << notification.sn_header.sn_type;
749 break;
750 }
751}
752
753void SctpDataMediaChannel::OnNotificationAssocChange(
754 const sctp_assoc_change& change) {
755 switch (change.sac_state) {
756 case SCTP_COMM_UP:
757 LOG(LS_VERBOSE) << "Association change SCTP_COMM_UP";
758 break;
759 case SCTP_COMM_LOST:
760 LOG(LS_INFO) << "Association change SCTP_COMM_LOST";
761 break;
762 case SCTP_RESTART:
763 LOG(LS_INFO) << "Association change SCTP_RESTART";
764 break;
765 case SCTP_SHUTDOWN_COMP:
766 LOG(LS_INFO) << "Association change SCTP_SHUTDOWN_COMP";
767 break;
768 case SCTP_CANT_STR_ASSOC:
769 LOG(LS_INFO) << "Association change SCTP_CANT_STR_ASSOC";
770 break;
771 default:
772 LOG(LS_INFO) << "Association change UNKNOWN";
773 break;
774 }
775}
776
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000777void SctpDataMediaChannel::OnStreamResetEvent(
778 const struct sctp_stream_reset_event* evt) {
779 // A stream reset always involves two RE-CONFIG chunks for us -- we always
780 // simultaneously reset a sid's sequence number in both directions. The
781 // requesting side transmits a RE-CONFIG chunk and waits for the peer to send
782 // one back. Both sides get this SCTP_STREAM_RESET_EVENT when they receive
783 // RE-CONFIGs.
784 const int num_ssrcs = (evt->strreset_length - sizeof(*evt)) /
785 sizeof(evt->strreset_stream_list[0]);
786 LOG(LS_VERBOSE) << "SCTP_STREAM_RESET_EVENT(" << debug_name_
787 << "): Flags = 0x"
788 << std::hex << evt->strreset_flags << " ("
789 << ListFlags(evt->strreset_flags) << ")";
790 LOG(LS_VERBOSE) << "Assoc = " << evt->strreset_assoc_id << ", Streams = ["
791 << ListArray(evt->strreset_stream_list, num_ssrcs)
792 << "], Open: ["
793 << ListStreams(open_streams_) << "], Q'd: ["
794 << ListStreams(queued_reset_streams_) << "], Sent: ["
795 << ListStreams(sent_reset_streams_) << "]";
796 bool local_stream_reset_acknowledged = false;
797
798 // If both sides try to reset some streams at the same time (even if they're
799 // disjoint sets), we can get reset failures.
800 if (evt->strreset_flags & SCTP_STREAM_RESET_FAILED) {
801 // OK, just try again. The stream IDs sent over when the RESET_FAILED flag
802 // is set seem to be garbage values. Ignore them.
803 queued_reset_streams_.insert(
804 sent_reset_streams_.begin(),
805 sent_reset_streams_.end());
806 sent_reset_streams_.clear();
807 local_stream_reset_acknowledged = true;
808
809 } else if (evt->strreset_flags & SCTP_STREAM_RESET_INCOMING_SSN) {
810 // Each side gets an event for each direction of a stream. That is,
811 // closing sid k will make each side receive INCOMING and OUTGOING reset
812 // events for k. As per RFC6525, Section 5, paragraph 2, each side will
813 // get an INCOMING event first.
814 for (int i = 0; i < num_ssrcs; i++) {
815 const int stream_id = evt->strreset_stream_list[i];
816
817 // See if this stream ID was closed by our peer or ourselves.
818 StreamSet::iterator it = sent_reset_streams_.find(stream_id);
819
820 // The reset was requested locally.
821 if (it != sent_reset_streams_.end()) {
822 LOG(LS_VERBOSE) << "SCTP_STREAM_RESET_EVENT(" << debug_name_
823 << "): local sid " << stream_id << " acknowledged.";
824 local_stream_reset_acknowledged = true;
825 sent_reset_streams_.erase(it);
826
827 } else if ((it = open_streams_.find(stream_id))
828 != open_streams_.end()) {
829 // The peer requested the reset.
830 LOG(LS_VERBOSE) << "SCTP_STREAM_RESET_EVENT(" << debug_name_
831 << "): closing sid " << stream_id;
832 open_streams_.erase(it);
833 SignalStreamClosed(stream_id);
834
835 } else if ((it = queued_reset_streams_.find(stream_id))
836 != queued_reset_streams_.end()) {
837 // The peer requested the reset, but there was a local reset
838 // queued.
839 LOG(LS_VERBOSE) << "SCTP_STREAM_RESET_EVENT(" << debug_name_
840 << "): double-sided close for sid " << stream_id;
841 // Both sides want the stream closed, and the peer got to send the
842 // RE-CONFIG first. Treat it like the local Remove(Send|Recv)Stream
843 // finished quickly.
844 queued_reset_streams_.erase(it);
845
846 } else {
847 // This stream is unknown. Sometimes this can be from an
848 // RESET_FAILED-related retransmit.
849 LOG(LS_VERBOSE) << "SCTP_STREAM_RESET_EVENT(" << debug_name_
850 << "): Unknown sid " << stream_id;
851 }
852 }
853 }
854
855 if (local_stream_reset_acknowledged) {
856 // This message acknowledges the last stream-reset request we sent out
857 // (only one can be outstanding at a time). Send out the next one.
858 SendQueuedStreamResets();
859 }
860}
861
wu@webrtc.org78187522013-10-07 23:32:02 +0000862// Puts the specified |param| from the codec identified by |id| into |dest|
863// and returns true. Or returns false if it wasn't there, leaving |dest|
864// untouched.
865static bool GetCodecIntParameter(const std::vector<DataCodec>& codecs,
866 int id, const std::string& name,
867 const std::string& param, int* dest) {
868 std::string value;
869 Codec match_pattern;
870 match_pattern.id = id;
871 match_pattern.name = name;
872 for (size_t i = 0; i < codecs.size(); ++i) {
873 if (codecs[i].Matches(match_pattern)) {
874 if (codecs[i].GetParam(param, &value)) {
875 *dest = talk_base::FromString<int>(value);
876 return true;
877 }
878 }
879 }
880 return false;
881}
882
883bool SctpDataMediaChannel::SetSendCodecs(const std::vector<DataCodec>& codecs) {
884 return GetCodecIntParameter(
885 codecs, kGoogleSctpDataCodecId, kGoogleSctpDataCodecName, kCodecParamPort,
886 &remote_port_);
887}
888
889bool SctpDataMediaChannel::SetRecvCodecs(const std::vector<DataCodec>& codecs) {
890 return GetCodecIntParameter(
891 codecs, kGoogleSctpDataCodecId, kGoogleSctpDataCodecName, kCodecParamPort,
892 &local_port_);
893}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894
895void SctpDataMediaChannel::OnPacketFromSctpToNetwork(
896 talk_base::Buffer* buffer) {
897 if (buffer->length() > kSctpMtu) {
898 LOG(LS_ERROR) << debug_name_ << "->OnPacketFromSctpToNetwork(...): "
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000899 << "SCTP seems to have made a packet that is bigger "
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 "than its official MTU.";
901 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000902 MediaChannel::SendPacket(buffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903}
904
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000905bool SctpDataMediaChannel::SendQueuedStreamResets() {
906 if (!sent_reset_streams_.empty() || queued_reset_streams_.empty())
907 return true;
908
909 LOG(LS_VERBOSE) << "SendQueuedStreamResets[" << debug_name_ << "]: Sending ["
910 << ListStreams(queued_reset_streams_) << "], Open: ["
911 << ListStreams(open_streams_) << "], Sent: ["
912 << ListStreams(sent_reset_streams_) << "]";
913
914 const size_t num_streams = queued_reset_streams_.size();
915 const size_t num_bytes = sizeof(struct sctp_reset_streams)
916 + (num_streams * sizeof(uint16));
917
918 std::vector<uint8> reset_stream_buf(num_bytes, 0);
919 struct sctp_reset_streams* resetp = reinterpret_cast<sctp_reset_streams*>(
920 &reset_stream_buf[0]);
921 resetp->srs_assoc_id = SCTP_ALL_ASSOC;
922 resetp->srs_flags = SCTP_STREAM_RESET_INCOMING | SCTP_STREAM_RESET_OUTGOING;
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000923 resetp->srs_number_streams = talk_base::checked_cast<uint16_t>(num_streams);
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000924 int result_idx = 0;
925 for (StreamSet::iterator it = queued_reset_streams_.begin();
926 it != queued_reset_streams_.end(); ++it) {
927 resetp->srs_stream_list[result_idx++] = *it;
928 }
929
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000930 int ret = usrsctp_setsockopt(
931 sock_, IPPROTO_SCTP, SCTP_RESET_STREAMS, resetp,
932 talk_base::checked_cast<socklen_t>(reset_stream_buf.size()));
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000933 if (ret < 0) {
934 LOG_ERRNO(LS_ERROR) << debug_name_ << "Failed to send a stream reset for "
935 << num_streams << " streams";
936 return false;
937 }
938
939 // sent_reset_streams_ is empty, and all the queued_reset_streams_ go into
940 // it now.
941 queued_reset_streams_.swap(sent_reset_streams_);
942 return true;
943}
944
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945void SctpDataMediaChannel::OnMessage(talk_base::Message* msg) {
946 switch (msg->message_id) {
947 case MSG_SCTPINBOUNDPACKET: {
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000948 talk_base::scoped_ptr<InboundPacketMessage> pdata(
949 static_cast<InboundPacketMessage*>(msg->pdata));
950 OnInboundPacketFromSctpToChannel(pdata->data().get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 break;
952 }
953 case MSG_SCTPOUTBOUNDPACKET: {
wu@webrtc.orgf6d6ed02014-01-03 22:08:47 +0000954 talk_base::scoped_ptr<OutboundPacketMessage> pdata(
955 static_cast<OutboundPacketMessage*>(msg->pdata));
956 OnPacketFromSctpToNetwork(pdata->data().get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 break;
958 }
959 }
960}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961} // namespace cricket