sctp: Rename SctpTransport to UsrSctpTransport

The rename ensures we don't confuse this implementation with
the new one based on the new dcSCTP library.

Bug: webrtc:12614
No-Presubmit: True
Change-Id: Ida08659bbea9c98aba8247d4368799ff7dd18729
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214482
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33688}
This commit is contained in:
Florent Castelli 2021-04-08 15:06:09 +02:00 committed by Commit Bot
parent 606bd6d163
commit 22379fc8dc
8 changed files with 154 additions and 141 deletions

View file

@ -21,7 +21,7 @@ CPPLINT_EXCEPTIONS = [
'examples/objc',
'media/base/stream_params.h',
'media/base/video_common.h',
'media/sctp/sctp_transport.cc',
'media/sctp/usrsctp_transport.cc',
'modules/audio_coding',
'modules/audio_device',
'modules/audio_processing',

View file

@ -419,11 +419,11 @@ rtc_library("rtc_data") {
if (rtc_enable_sctp) {
sources = [
"sctp/sctp_transport.cc",
"sctp/sctp_transport.h",
"sctp/sctp_transport_factory.cc",
"sctp/sctp_transport_factory.h",
"sctp/sctp_transport_internal.h",
"sctp/usrsctp_transport.cc",
"sctp/usrsctp_transport.h",
]
} else {
# libtool on mac does not like empty targets.
@ -643,8 +643,8 @@ if (rtc_include_tests) {
if (rtc_enable_sctp) {
sources += [
"sctp/sctp_transport_reliability_unittest.cc",
"sctp/sctp_transport_unittest.cc",
"sctp/usrsctp_transport_reliability_unittest.cc",
"sctp/usrsctp_transport_unittest.cc",
]
deps += [
"../rtc_base/task_utils:pending_task_safety_flag",

View file

@ -19,7 +19,7 @@ std::unique_ptr<SctpTransportInternal>
SctpTransportFactory::CreateSctpTransport(
rtc::PacketTransportInternal* transport) {
return std::unique_ptr<SctpTransportInternal>(
new SctpTransport(network_thread_, transport));
new UsrsctpTransport(network_thread_, transport));
}
} // namespace cricket

View file

@ -14,7 +14,7 @@
#include <memory>
#include "api/transport/sctp_transport_factory_interface.h"
#include "media/sctp/sctp_transport.h"
#include "media/sctp/usrsctp_transport.h"
#include "rtc_base/thread.h"
namespace cricket {

View file

@ -30,6 +30,7 @@ constexpr int kSctpErrorReturn = 0;
#include <memory>
#include <unordered_map>
#include <utility>
#include "absl/algorithm/container.h"
#include "absl/base/attributes.h"
@ -39,7 +40,7 @@ constexpr int kSctpErrorReturn = 0;
#include "media/base/media_channel.h"
#include "media/base/media_constants.h"
#include "media/base/stream_params.h"
#include "media/sctp/sctp_transport.h"
#include "media/sctp/usrsctp_transport.h"
#include "p2p/base/dtls_transport_internal.h" // For PF_NORMAL
#include "rtc_base/arraysize.h"
#include "rtc_base/copy_on_write_buffer.h"
@ -94,7 +95,7 @@ enum {
};
// Should only be modified by UsrSctpWrapper.
ABSL_CONST_INIT cricket::SctpTransportMap* g_transport_map_ = nullptr;
ABSL_CONST_INIT cricket::UsrsctpTransportMap* g_transport_map_ = nullptr;
// Helper that will call C's free automatically.
// TODO(b/181900299): Figure out why unique_ptr with a custom deleter is causing
@ -235,15 +236,16 @@ sctp_sendv_spa CreateSctpSendParams(const cricket::SendDataParams& params) {
namespace cricket {
// Maps SCTP transport ID to SctpTransport object, necessary in send threshold
// callback and outgoing packet callback. It also provides a facility to
// safely post a task to an SctpTransport's network thread from another thread.
class SctpTransportMap {
// Maps SCTP transport ID to UsrsctpTransport object, necessary in send
// threshold callback and outgoing packet callback. It also provides a facility
// to safely post a task to an UsrsctpTransport's network thread from another
// thread.
class UsrsctpTransportMap {
public:
SctpTransportMap() = default;
UsrsctpTransportMap() = default;
// Assigns a new unused ID to the following transport.
uintptr_t Register(cricket::SctpTransport* transport) {
uintptr_t Register(cricket::UsrsctpTransport* transport) {
webrtc::MutexLock lock(&lock_);
// usrsctp_connect fails with a value of 0...
if (next_id_ == 0) {
@ -256,7 +258,7 @@ class SctpTransportMap {
if (next_id_ == 0) {
++next_id_;
}
};
}
map_[next_id_] = transport;
return next_id_++;
}
@ -274,7 +276,7 @@ class SctpTransportMap {
template <typename F>
bool PostToTransportThread(uintptr_t id, F action) const {
webrtc::MutexLock lock(&lock_);
SctpTransport* transport = RetrieveWhileHoldingLock(id);
UsrsctpTransport* transport = RetrieveWhileHoldingLock(id);
if (!transport) {
return false;
}
@ -285,7 +287,7 @@ class SctpTransportMap {
}
private:
SctpTransport* RetrieveWhileHoldingLock(uintptr_t id) const
UsrsctpTransport* RetrieveWhileHoldingLock(uintptr_t id) const
RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_) {
auto it = map_.find(id);
if (it == map_.end()) {
@ -297,12 +299,12 @@ class SctpTransportMap {
mutable webrtc::Mutex lock_;
uintptr_t next_id_ RTC_GUARDED_BY(lock_) = 0;
std::unordered_map<uintptr_t, SctpTransport*> map_ RTC_GUARDED_BY(lock_);
std::unordered_map<uintptr_t, UsrsctpTransport*> map_ RTC_GUARDED_BY(lock_);
};
// Handles global init/deinit, and mapping from usrsctp callbacks to
// SctpTransport calls.
class SctpTransport::UsrSctpWrapper {
// UsrsctpTransport calls.
class UsrsctpTransport::UsrSctpWrapper {
public:
static void InitializeUsrSctp() {
RTC_LOG(LS_INFO) << __FUNCTION__;
@ -361,7 +363,7 @@ class SctpTransport::UsrSctpWrapper {
// send in the SCTP INIT message.
usrsctp_sysctl_set_sctp_nr_outgoing_streams_default(kMaxSctpStreams);
g_transport_map_ = new SctpTransportMap();
g_transport_map_ = new UsrsctpTransportMap();
}
static void UninitializeUsrSctp() {
@ -427,7 +429,7 @@ class SctpTransport::UsrSctpWrapper {
// simultaneously deregistered/deleted, since this callback may come from
// the SCTP timer thread and thus race with the network thread.
bool found = g_transport_map_->PostToTransportThread(
reinterpret_cast<uintptr_t>(addr), [buf](SctpTransport* transport) {
reinterpret_cast<uintptr_t>(addr), [buf](UsrsctpTransport* transport) {
transport->OnPacketFromSctpToNetwork(buf);
});
if (!found) {
@ -471,7 +473,7 @@ class SctpTransport::UsrSctpWrapper {
// the SCTP timer thread and thus race with the network thread.
bool found = g_transport_map_->PostToTransportThread(
*id, [owned_data{std::move(owned_data)}, length, rcv,
flags](SctpTransport* transport) {
flags](UsrsctpTransport* transport) {
transport->OnDataOrNotificationFromSctp(owned_data.get(), length, rcv,
flags);
});
@ -493,7 +495,7 @@ class SctpTransport::UsrSctpWrapper {
return ret;
}
// usrsctp_getladdrs() returns the addresses bound to this socket, which
// contains the SctpTransport id as sconn_addr. Read the id,
// contains the UsrsctpTransport id as sconn_addr. Read the id,
// then free the list of addresses once we have the pointer. We only open
// AF_CONN sockets, and they should all have the sconn_addr set to the
// id of the transport that created them, so [0] is as good as any other.
@ -508,7 +510,7 @@ class SctpTransport::UsrSctpWrapper {
// TODO(crbug.com/webrtc/11899): This is a legacy callback signature, remove
// when usrsctp is updated.
static int SendThresholdCallback(struct socket* sock, uint32_t sb_free) {
// Fired on our I/O thread. SctpTransport::OnPacketReceived() gets
// Fired on our I/O thread. UsrsctpTransport::OnPacketReceived() gets
// a packet containing acknowledgments, which goes into usrsctp_conninput,
// and then back here.
absl::optional<uintptr_t> id = GetTransportIdFromSocket(sock);
@ -524,8 +526,9 @@ class SctpTransport::UsrSctpWrapper {
return 0;
}
bool found = g_transport_map_->PostToTransportThread(
*id,
[](SctpTransport* transport) { transport->OnSendThresholdCallback(); });
*id, [](UsrsctpTransport* transport) {
transport->OnSendThresholdCallback();
});
if (!found) {
RTC_LOG(LS_ERROR)
<< "SendThresholdCallback: Failed to get transport for socket ID "
@ -537,7 +540,7 @@ class SctpTransport::UsrSctpWrapper {
static int SendThresholdCallback(struct socket* sock,
uint32_t sb_free,
void* ulp_info) {
// Fired on our I/O thread. SctpTransport::OnPacketReceived() gets
// Fired on our I/O thread. UsrsctpTransport::OnPacketReceived() gets
// a packet containing acknowledgments, which goes into usrsctp_conninput,
// and then back here.
absl::optional<uintptr_t> id = GetTransportIdFromSocket(sock);
@ -553,8 +556,9 @@ class SctpTransport::UsrSctpWrapper {
return 0;
}
bool found = g_transport_map_->PostToTransportThread(
*id,
[](SctpTransport* transport) { transport->OnSendThresholdCallback(); });
*id, [](UsrsctpTransport* transport) {
transport->OnSendThresholdCallback();
});
if (!found) {
RTC_LOG(LS_ERROR)
<< "SendThresholdCallback: Failed to get transport for socket ID "
@ -564,7 +568,7 @@ class SctpTransport::UsrSctpWrapper {
}
};
SctpTransport::SctpTransport(rtc::Thread* network_thread,
UsrsctpTransport::UsrsctpTransport(rtc::Thread* network_thread,
rtc::PacketTransportInternal* transport)
: network_thread_(network_thread),
transport_(transport),
@ -574,17 +578,17 @@ SctpTransport::SctpTransport(rtc::Thread* network_thread,
ConnectTransportSignals();
}
SctpTransport::~SctpTransport() {
UsrsctpTransport::~UsrsctpTransport() {
RTC_DCHECK_RUN_ON(network_thread_);
// Close abruptly; no reset procedure.
CloseSctpSocket();
// It's not strictly necessary to reset these fields to nullptr,
// but having these fields set to nullptr is a clear indication that
// object was destructed. There was a bug in usrsctp when it
// invoked OnSctpOutboundPacket callback for destructed SctpTransport,
// invoked OnSctpOutboundPacket callback for destructed UsrsctpTransport,
// which caused obscure SIGSEGV on access to these fields,
// having this fields set to nullptr will make it easier to understand
// that SctpTransport was destructed and "use-after-free" bug happen.
// that UsrsctpTransport was destructed and "use-after-free" bug happen.
// SIGSEGV error triggered on dereference these pointers will also
// be easier to understand due to 0x0 address. All of this assumes
// that ASAN is not enabled to detect "use-after-free", which is
@ -593,7 +597,8 @@ SctpTransport::~SctpTransport() {
transport_ = nullptr;
}
void SctpTransport::SetDtlsTransport(rtc::PacketTransportInternal* transport) {
void UsrsctpTransport::SetDtlsTransport(
rtc::PacketTransportInternal* transport) {
RTC_DCHECK_RUN_ON(network_thread_);
DisconnectTransportSignals();
transport_ = transport;
@ -609,7 +614,7 @@ void SctpTransport::SetDtlsTransport(rtc::PacketTransportInternal* transport) {
}
}
bool SctpTransport::Start(int local_sctp_port,
bool UsrsctpTransport::Start(int local_sctp_port,
int remote_sctp_port,
int max_message_size) {
RTC_DCHECK_RUN_ON(network_thread_);
@ -653,7 +658,7 @@ bool SctpTransport::Start(int local_sctp_port,
return true;
}
bool SctpTransport::OpenStream(int sid) {
bool UsrsctpTransport::OpenStream(int sid) {
RTC_DCHECK_RUN_ON(network_thread_);
if (sid > kMaxSctpSid) {
RTC_LOG(LS_WARNING) << debug_name_
@ -685,7 +690,7 @@ bool SctpTransport::OpenStream(int sid) {
}
}
bool SctpTransport::ResetStream(int sid) {
bool UsrsctpTransport::ResetStream(int sid) {
RTC_DCHECK_RUN_ON(network_thread_);
auto it = stream_status_by_sid_.find(sid);
@ -707,7 +712,7 @@ bool SctpTransport::ResetStream(int sid) {
return true;
}
bool SctpTransport::SendData(const SendDataParams& params,
bool UsrsctpTransport::SendData(const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload,
SendDataResult* result) {
RTC_DCHECK_RUN_ON(network_thread_);
@ -759,7 +764,7 @@ bool SctpTransport::SendData(const SendDataParams& params,
return true;
}
SendDataResult SctpTransport::SendMessageInternal(OutgoingMessage* message) {
SendDataResult UsrsctpTransport::SendMessageInternal(OutgoingMessage* message) {
RTC_DCHECK_RUN_ON(network_thread_);
if (!sock_) {
RTC_LOG(LS_WARNING) << debug_name_
@ -815,23 +820,23 @@ SendDataResult SctpTransport::SendMessageInternal(OutgoingMessage* message) {
return SDR_SUCCESS;
}
bool SctpTransport::ReadyToSendData() {
bool UsrsctpTransport::ReadyToSendData() {
RTC_DCHECK_RUN_ON(network_thread_);
return ready_to_send_data_;
}
void SctpTransport::ConnectTransportSignals() {
void UsrsctpTransport::ConnectTransportSignals() {
RTC_DCHECK_RUN_ON(network_thread_);
if (!transport_) {
return;
}
transport_->SignalWritableState.connect(this,
&SctpTransport::OnWritableState);
transport_->SignalReadPacket.connect(this, &SctpTransport::OnPacketRead);
transport_->SignalClosed.connect(this, &SctpTransport::OnClosed);
&UsrsctpTransport::OnWritableState);
transport_->SignalReadPacket.connect(this, &UsrsctpTransport::OnPacketRead);
transport_->SignalClosed.connect(this, &UsrsctpTransport::OnClosed);
}
void SctpTransport::DisconnectTransportSignals() {
void UsrsctpTransport::DisconnectTransportSignals() {
RTC_DCHECK_RUN_ON(network_thread_);
if (!transport_) {
return;
@ -841,7 +846,7 @@ void SctpTransport::DisconnectTransportSignals() {
transport_->SignalClosed.disconnect(this);
}
bool SctpTransport::Connect() {
bool UsrsctpTransport::Connect() {
RTC_DCHECK_RUN_ON(network_thread_);
RTC_LOG(LS_VERBOSE) << debug_name_ << "->Connect().";
@ -904,7 +909,7 @@ bool SctpTransport::Connect() {
return true;
}
bool SctpTransport::OpenSctpSocket() {
bool UsrsctpTransport::OpenSctpSocket() {
RTC_DCHECK_RUN_ON(network_thread_);
if (sock_) {
RTC_LOG(LS_WARNING) << debug_name_
@ -947,7 +952,7 @@ bool SctpTransport::OpenSctpSocket() {
return true;
}
bool SctpTransport::ConfigureSctpSocket() {
bool UsrsctpTransport::ConfigureSctpSocket() {
RTC_DCHECK_RUN_ON(network_thread_);
RTC_DCHECK(sock_);
// Make the socket non-blocking. Connect, close, shutdown etc will not block
@ -1028,7 +1033,7 @@ bool SctpTransport::ConfigureSctpSocket() {
return true;
}
void SctpTransport::CloseSctpSocket() {
void UsrsctpTransport::CloseSctpSocket() {
RTC_DCHECK_RUN_ON(network_thread_);
if (sock_) {
// We assume that SO_LINGER option is set to close the association when
@ -1043,7 +1048,7 @@ void SctpTransport::CloseSctpSocket() {
}
}
bool SctpTransport::SendQueuedStreamResets() {
bool UsrsctpTransport::SendQueuedStreamResets() {
RTC_DCHECK_RUN_ON(network_thread_);
auto needs_reset =
@ -1109,7 +1114,7 @@ bool SctpTransport::SendQueuedStreamResets() {
return true;
}
void SctpTransport::SetReadyToSendData() {
void UsrsctpTransport::SetReadyToSendData() {
RTC_DCHECK_RUN_ON(network_thread_);
if (!ready_to_send_data_) {
ready_to_send_data_ = true;
@ -1117,7 +1122,7 @@ void SctpTransport::SetReadyToSendData() {
}
}
bool SctpTransport::SendBufferedMessage() {
bool UsrsctpTransport::SendBufferedMessage() {
RTC_DCHECK_RUN_ON(network_thread_);
RTC_DCHECK(partial_outgoing_message_.has_value());
RTC_DLOG(LS_VERBOSE) << "Sending partially buffered message of size "
@ -1142,7 +1147,8 @@ bool SctpTransport::SendBufferedMessage() {
return true;
}
void SctpTransport::OnWritableState(rtc::PacketTransportInternal* transport) {
void UsrsctpTransport::OnWritableState(
rtc::PacketTransportInternal* transport) {
RTC_DCHECK_RUN_ON(network_thread_);
RTC_DCHECK_EQ(transport_, transport);
if (!was_ever_writable_ && transport->writable()) {
@ -1154,14 +1160,14 @@ void SctpTransport::OnWritableState(rtc::PacketTransportInternal* transport) {
}
// Called by network interface when a packet has been received.
void SctpTransport::OnPacketRead(rtc::PacketTransportInternal* transport,
void UsrsctpTransport::OnPacketRead(rtc::PacketTransportInternal* transport,
const char* data,
size_t len,
const int64_t& /* packet_time_us */,
int flags) {
RTC_DCHECK_RUN_ON(network_thread_);
RTC_DCHECK_EQ(transport_, transport);
TRACE_EVENT0("webrtc", "SctpTransport::OnPacketRead");
TRACE_EVENT0("webrtc", "UsrsctpTransport::OnPacketRead");
if (flags & PF_SRTP_BYPASS) {
// We are only interested in SCTP packets.
@ -1188,11 +1194,11 @@ void SctpTransport::OnPacketRead(rtc::PacketTransportInternal* transport,
}
}
void SctpTransport::OnClosed(rtc::PacketTransportInternal* transport) {
void UsrsctpTransport::OnClosed(rtc::PacketTransportInternal* transport) {
SignalClosedAbruptly();
}
void SctpTransport::OnSendThresholdCallback() {
void UsrsctpTransport::OnSendThresholdCallback() {
RTC_DCHECK_RUN_ON(network_thread_);
if (partial_outgoing_message_.has_value()) {
if (!SendBufferedMessage()) {
@ -1203,7 +1209,7 @@ void SctpTransport::OnSendThresholdCallback() {
SetReadyToSendData();
}
sockaddr_conn SctpTransport::GetSctpSockAddr(int port) {
sockaddr_conn UsrsctpTransport::GetSctpSockAddr(int port) {
sockaddr_conn sconn = {0};
sconn.sconn_family = AF_CONN;
#ifdef HAVE_SCONN_LEN
@ -1215,7 +1221,7 @@ sockaddr_conn SctpTransport::GetSctpSockAddr(int port) {
return sconn;
}
void SctpTransport::OnPacketFromSctpToNetwork(
void UsrsctpTransport::OnPacketFromSctpToNetwork(
const rtc::CopyOnWriteBuffer& buffer) {
RTC_DCHECK_RUN_ON(network_thread_);
if (buffer.size() > (kSctpMtu)) {
@ -1225,7 +1231,7 @@ void SctpTransport::OnPacketFromSctpToNetwork(
"than its official MTU: "
<< buffer.size() << " vs max of " << kSctpMtu;
}
TRACE_EVENT0("webrtc", "SctpTransport::OnPacketFromSctpToNetwork");
TRACE_EVENT0("webrtc", "UsrsctpTransport::OnPacketFromSctpToNetwork");
// Don't create noise by trying to send a packet when the DTLS transport isn't
// even writable.
@ -1238,7 +1244,7 @@ void SctpTransport::OnPacketFromSctpToNetwork(
rtc::PacketOptions(), PF_NORMAL);
}
void SctpTransport::InjectDataOrNotificationFromSctpForTesting(
void UsrsctpTransport::InjectDataOrNotificationFromSctpForTesting(
const void* data,
size_t length,
struct sctp_rcvinfo rcv,
@ -1246,7 +1252,7 @@ void SctpTransport::InjectDataOrNotificationFromSctpForTesting(
OnDataOrNotificationFromSctp(data, length, rcv, flags);
}
void SctpTransport::OnDataOrNotificationFromSctp(const void* data,
void UsrsctpTransport::OnDataOrNotificationFromSctp(const void* data,
size_t length,
struct sctp_rcvinfo rcv,
int flags) {
@ -1345,7 +1351,7 @@ void SctpTransport::OnDataOrNotificationFromSctp(const void* data,
partial_incoming_message_.Clear();
}
void SctpTransport::OnDataFromSctpToTransport(
void UsrsctpTransport::OnDataFromSctpToTransport(
const ReceiveDataParams& params,
const rtc::CopyOnWriteBuffer& buffer) {
RTC_DCHECK_RUN_ON(network_thread_);
@ -1358,7 +1364,7 @@ void SctpTransport::OnDataFromSctpToTransport(
SignalDataReceived(params, buffer);
}
void SctpTransport::OnNotificationFromSctp(
void UsrsctpTransport::OnNotificationFromSctp(
const rtc::CopyOnWriteBuffer& buffer) {
RTC_DCHECK_RUN_ON(network_thread_);
if (buffer.size() < sizeof(sctp_notification::sn_header)) {
@ -1459,7 +1465,8 @@ void SctpTransport::OnNotificationFromSctp(
}
}
void SctpTransport::OnNotificationAssocChange(const sctp_assoc_change& change) {
void UsrsctpTransport::OnNotificationAssocChange(
const sctp_assoc_change& change) {
RTC_DCHECK_RUN_ON(network_thread_);
switch (change.sac_state) {
case SCTP_COMM_UP:
@ -1491,7 +1498,7 @@ void SctpTransport::OnNotificationAssocChange(const sctp_assoc_change& change) {
}
}
void SctpTransport::OnStreamResetEvent(
void UsrsctpTransport::OnStreamResetEvent(
const struct sctp_stream_reset_event* evt) {
RTC_DCHECK_RUN_ON(network_thread_);

View file

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MEDIA_SCTP_SCTP_TRANSPORT_H_
#define MEDIA_SCTP_SCTP_TRANSPORT_H_
#ifndef MEDIA_SCTP_USRSCTP_TRANSPORT_H_
#define MEDIA_SCTP_USRSCTP_TRANSPORT_H_
#include <errno.h>
@ -66,16 +66,16 @@ struct SctpInboundPacket;
// 12. SctpTransport::SignalDataReceived(data)
// [from the same thread, methods registered/connected to
// SctpTransport are called with the recieved data]
class SctpTransport : public SctpTransportInternal,
class UsrsctpTransport : public SctpTransportInternal,
public sigslot::has_slots<> {
public:
// |network_thread| is where packets will be processed and callbacks from
// this transport will be posted, and is the only thread on which public
// methods can be called.
// |transport| is not required (can be null).
SctpTransport(rtc::Thread* network_thread,
UsrsctpTransport(rtc::Thread* network_thread,
rtc::PacketTransportInternal* transport);
~SctpTransport() override;
~UsrsctpTransport() override;
// SctpTransportInternal overrides (see sctptransportinternal.h for comments).
void SetDtlsTransport(rtc::PacketTransportInternal* transport) override;
@ -270,7 +270,7 @@ class SctpTransport : public SctpTransportInternal,
std::map<uint32_t, StreamStatus> stream_status_by_sid_;
// A static human-readable name for debugging messages.
const char* debug_name_ = "SctpTransport";
const char* debug_name_ = "UsrsctpTransport";
// Hides usrsctp interactions from this header file.
class UsrSctpWrapper;
// Number of channels negotiated. Not set before negotiation completes.
@ -281,13 +281,13 @@ class SctpTransport : public SctpTransportInternal,
// various callbacks.
uintptr_t id_ = 0;
friend class SctpTransportMap;
friend class UsrsctpTransportMap;
RTC_DISALLOW_COPY_AND_ASSIGN(SctpTransport);
RTC_DISALLOW_COPY_AND_ASSIGN(UsrsctpTransport);
};
class SctpTransportMap;
class UsrsctpTransportMap;
} // namespace cricket
#endif // MEDIA_SCTP_SCTP_TRANSPORT_H_
#endif // MEDIA_SCTP_USRSCTP_TRANSPORT_H_

View file

@ -11,8 +11,8 @@
#include <queue>
#include <string>
#include "media/sctp/sctp_transport.h"
#include "media/sctp/sctp_transport_internal.h"
#include "media/sctp/usrsctp_transport.h"
#include "rtc_base/async_invoker.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/gunit.h"
@ -143,7 +143,7 @@ class SimulatedPacketTransport final : public rtc::PacketTransportInternal {
/**
* A helper class to send specified number of messages
* over SctpTransport with SCTP reliability settings
* over UsrsctpTransport with SCTP reliability settings
* provided by user. The reliability settings are specified
* by passing a template instance of SendDataParams.
* When .sid field inside SendDataParams is specified to
@ -156,7 +156,7 @@ class SimulatedPacketTransport final : public rtc::PacketTransportInternal {
class SctpDataSender final {
public:
SctpDataSender(rtc::Thread* thread,
cricket::SctpTransport* transport,
cricket::UsrsctpTransport* transport,
uint64_t target_messages_count,
cricket::SendDataParams send_params,
uint32_t sender_id)
@ -233,14 +233,14 @@ class SctpDataSender final {
break;
case cricket::SDR_ERROR:
// give up
last_error_ = "SctpTransport::SendData error returned";
last_error_ = "UsrsctpTransport::SendData error returned";
sent_target_messages_count_.Set();
break;
}
}
rtc::Thread* const thread_;
cricket::SctpTransport* const transport_;
cricket::UsrsctpTransport* const transport_;
const uint64_t target_messages_count_;
const cricket::SendDataParams send_params_;
const uint32_t sender_id_;
@ -256,7 +256,7 @@ class SctpDataSender final {
/**
* A helper class which counts number of received messages
* and bytes over SctpTransport. Also allow waiting until
* and bytes over UsrsctpTransport. Also allow waiting until
* specified number of messages received.
*/
class SctpDataReceiver final : public sigslot::has_slots<> {
@ -323,7 +323,7 @@ class ThreadPool final {
};
/**
* Represents single ping-pong test over SctpTransport.
* Represents single ping-pong test over UsrsctpTransport.
* User can specify target number of message for bidirectional
* send, underlying transport packets loss and average packet delay
* and SCTP delivery settings.
@ -505,7 +505,7 @@ class SctpPingPong final {
"SctpPingPong id = " + rtc::ToString(id_) + ", packet transport 1",
transport_thread1_, packet_loss_percents_, avg_send_delay_millis_));
data_receiver1_.reset(new SctpDataReceiver(id_, messages_count_));
sctp_transport1_.reset(new cricket::SctpTransport(
sctp_transport1_.reset(new cricket::UsrsctpTransport(
transport_thread1_, packet_transport1_.get()));
sctp_transport1_->set_debug_name_for_testing("sctp transport 1");
@ -527,7 +527,7 @@ class SctpPingPong final {
"SctpPingPong id = " + rtc::ToString(id_) + "packet transport 2",
transport_thread2_, packet_loss_percents_, avg_send_delay_millis_));
data_receiver2_.reset(new SctpDataReceiver(id_, messages_count_));
sctp_transport2_.reset(new cricket::SctpTransport(
sctp_transport2_.reset(new cricket::UsrsctpTransport(
transport_thread2_, packet_transport2_.get()));
sctp_transport2_->set_debug_name_for_testing("sctp transport 2");
sctp_transport2_->SignalDataReceived.connect(
@ -576,8 +576,8 @@ class SctpPingPong final {
std::unique_ptr<SimulatedPacketTransport> packet_transport2_;
std::unique_ptr<SctpDataReceiver> data_receiver1_;
std::unique_ptr<SctpDataReceiver> data_receiver2_;
std::unique_ptr<cricket::SctpTransport> sctp_transport1_;
std::unique_ptr<cricket::SctpTransport> sctp_transport2_;
std::unique_ptr<cricket::UsrsctpTransport> sctp_transport1_;
std::unique_ptr<cricket::UsrsctpTransport> sctp_transport2_;
std::unique_ptr<SctpDataSender> data_sender1_;
std::unique_ptr<SctpDataSender> data_sender2_;
mutable webrtc::Mutex lock_;

View file

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "media/sctp/sctp_transport.h"
#include "media/sctp/usrsctp_transport.h"
#include <stdio.h>
#include <string.h>
@ -74,7 +74,7 @@ class SctpFakeDataReceiver : public sigslot::has_slots<> {
class SctpTransportObserver : public sigslot::has_slots<> {
public:
explicit SctpTransportObserver(SctpTransport* transport) {
explicit SctpTransportObserver(UsrsctpTransport* transport) {
transport->SignalClosingProcedureComplete.connect(
this, &SctpTransportObserver::OnClosingProcedureComplete);
transport->SignalReadyToSendData.connect(
@ -105,7 +105,8 @@ class SctpTransportObserver : public sigslot::has_slots<> {
// been closed.
class SignalTransportClosedReopener : public sigslot::has_slots<> {
public:
SignalTransportClosedReopener(SctpTransport* transport, SctpTransport* peer)
SignalTransportClosedReopener(UsrsctpTransport* transport,
UsrsctpTransport* peer)
: transport_(transport), peer_(peer) {}
int StreamCloseCount(int stream) { return absl::c_count(streams_, stream); }
@ -117,8 +118,8 @@ class SignalTransportClosedReopener : public sigslot::has_slots<> {
streams_.push_back(stream);
}
SctpTransport* transport_;
SctpTransport* peer_;
UsrsctpTransport* transport_;
UsrsctpTransport* peer_;
std::vector<int> streams_;
};
@ -169,17 +170,17 @@ class SctpTransportTest : public ::testing::Test, public sigslot::has_slots<> {
return ret;
}
SctpTransport* CreateTransport(FakeDtlsTransport* fake_dtls,
UsrsctpTransport* CreateTransport(FakeDtlsTransport* fake_dtls,
SctpFakeDataReceiver* recv) {
SctpTransport* transport =
new SctpTransport(rtc::Thread::Current(), fake_dtls);
UsrsctpTransport* transport =
new UsrsctpTransport(rtc::Thread::Current(), fake_dtls);
// When data is received, pass it to the SctpFakeDataReceiver.
transport->SignalDataReceived.connect(
recv, &SctpFakeDataReceiver::OnDataReceived);
return transport;
}
bool SendData(SctpTransport* chan,
bool SendData(UsrsctpTransport* chan,
int sid,
const std::string& msg,
SendDataResult* result,
@ -210,8 +211,8 @@ class SctpTransportTest : public ::testing::Test, public sigslot::has_slots<> {
return !thread->IsQuitting();
}
SctpTransport* transport1() { return transport1_.get(); }
SctpTransport* transport2() { return transport2_.get(); }
UsrsctpTransport* transport1() { return transport1_.get(); }
UsrsctpTransport* transport2() { return transport2_.get(); }
SctpFakeDataReceiver* receiver1() { return recv1_.get(); }
SctpFakeDataReceiver* receiver2() { return recv2_.get(); }
FakeDtlsTransport* fake_dtls1() { return fake_dtls1_.get(); }
@ -229,8 +230,8 @@ class SctpTransportTest : public ::testing::Test, public sigslot::has_slots<> {
std::unique_ptr<FakeDtlsTransport> fake_dtls2_;
std::unique_ptr<SctpFakeDataReceiver> recv1_;
std::unique_ptr<SctpFakeDataReceiver> recv2_;
std::unique_ptr<SctpTransport> transport1_;
std::unique_ptr<SctpTransport> transport2_;
std::unique_ptr<UsrsctpTransport> transport1_;
std::unique_ptr<UsrsctpTransport> transport2_;
int transport1_ready_to_send_count_ = 0;
int transport2_ready_to_send_count_ = 0;
@ -244,9 +245,9 @@ TEST_F(SctpTransportTest, MessageInterleavedWithNotification) {
FakeDtlsTransport fake_dtls2("fake dtls 2", 0);
SctpFakeDataReceiver recv1;
SctpFakeDataReceiver recv2;
std::unique_ptr<SctpTransport> transport1(
std::unique_ptr<UsrsctpTransport> transport1(
CreateTransport(&fake_dtls1, &recv1));
std::unique_ptr<SctpTransport> transport2(
std::unique_ptr<UsrsctpTransport> transport2(
CreateTransport(&fake_dtls2, &recv2));
// Add a stream.
@ -317,9 +318,9 @@ TEST_F(SctpTransportTest, SwitchDtlsTransport) {
SctpFakeDataReceiver recv2;
// Construct transport1 with the "black hole" transport.
std::unique_ptr<SctpTransport> transport1(
std::unique_ptr<UsrsctpTransport> transport1(
CreateTransport(&black_hole, &recv1));
std::unique_ptr<SctpTransport> transport2(
std::unique_ptr<UsrsctpTransport> transport2(
CreateTransport(&fake_dtls2, &recv2));
// Add a stream.
@ -377,9 +378,9 @@ TEST_F(SctpTransportTest, NegativeOnePortTreatedAsDefault) {
FakeDtlsTransport fake_dtls2("fake dtls 2", 0);
SctpFakeDataReceiver recv1;
SctpFakeDataReceiver recv2;
std::unique_ptr<SctpTransport> transport1(
std::unique_ptr<UsrsctpTransport> transport1(
CreateTransport(&fake_dtls1, &recv1));
std::unique_ptr<SctpTransport> transport2(
std::unique_ptr<UsrsctpTransport> transport2(
CreateTransport(&fake_dtls2, &recv2));
// Add a stream.
@ -406,7 +407,8 @@ TEST_F(SctpTransportTest, NegativeOnePortTreatedAsDefault) {
TEST_F(SctpTransportTest, OpenStreamWithAlreadyOpenedStreamFails) {
FakeDtlsTransport fake_dtls("fake dtls", 0);
SctpFakeDataReceiver recv;
std::unique_ptr<SctpTransport> transport(CreateTransport(&fake_dtls, &recv));
std::unique_ptr<UsrsctpTransport> transport(
CreateTransport(&fake_dtls, &recv));
EXPECT_TRUE(transport->OpenStream(1));
EXPECT_FALSE(transport->OpenStream(1));
}
@ -414,7 +416,8 @@ TEST_F(SctpTransportTest, OpenStreamWithAlreadyOpenedStreamFails) {
TEST_F(SctpTransportTest, ResetStreamWithAlreadyResetStreamFails) {
FakeDtlsTransport fake_dtls("fake dtls", 0);
SctpFakeDataReceiver recv;
std::unique_ptr<SctpTransport> transport(CreateTransport(&fake_dtls, &recv));
std::unique_ptr<UsrsctpTransport> transport(
CreateTransport(&fake_dtls, &recv));
EXPECT_TRUE(transport->OpenStream(1));
EXPECT_TRUE(transport->ResetStream(1));
EXPECT_FALSE(transport->ResetStream(1));
@ -425,7 +428,8 @@ TEST_F(SctpTransportTest, ResetStreamWithAlreadyResetStreamFails) {
TEST_F(SctpTransportTest, SignalReadyToSendDataAfterDtlsWritable) {
FakeDtlsTransport fake_dtls("fake dtls", 0);
SctpFakeDataReceiver recv;
std::unique_ptr<SctpTransport> transport(CreateTransport(&fake_dtls, &recv));
std::unique_ptr<UsrsctpTransport> transport(
CreateTransport(&fake_dtls, &recv));
SctpTransportObserver observer(transport.get());
transport->Start(kSctpDefaultPort, kSctpDefaultPort, kSctpSendBufferSize);
@ -438,8 +442,8 @@ class SctpTransportTestWithOrdered
: public SctpTransportTest,
public ::testing::WithParamInterface<bool> {};
// Tests that a small message gets buffered and later sent by the SctpTransport
// when the sctp library only accepts the message partially.
// Tests that a small message gets buffered and later sent by the
// UsrsctpTransport when the sctp library only accepts the message partially.
TEST_P(SctpTransportTestWithOrdered, SendSmallBufferedOutgoingMessage) {
bool ordered = GetParam();
SetupConnectedTransportsWithTwoStreams();
@ -456,7 +460,7 @@ TEST_P(SctpTransportTestWithOrdered, SendSmallBufferedOutgoingMessage) {
ordered));
std::string buffered_message("hello hello");
// SctpTransport accepts this message by buffering part of it.
// UsrsctpTransport accepts this message by buffering part of it.
ASSERT_TRUE(
SendData(transport1(), /*sid=*/1, buffered_message, &result, ordered));
ASSERT_TRUE(transport1()->ReadyToSendData());
@ -478,8 +482,8 @@ TEST_P(SctpTransportTestWithOrdered, SendSmallBufferedOutgoingMessage) {
EXPECT_EQ(2u, receiver2()->num_messages_received());
}
// Tests that a large message gets buffered and later sent by the SctpTransport
// when the sctp library only accepts the message partially.
// Tests that a large message gets buffered and later sent by the
// UsrsctpTransport when the sctp library only accepts the message partially.
TEST_P(SctpTransportTestWithOrdered, SendLargeBufferedOutgoingMessage) {
bool ordered = GetParam();
SetupConnectedTransportsWithTwoStreams();
@ -496,7 +500,7 @@ TEST_P(SctpTransportTestWithOrdered, SendLargeBufferedOutgoingMessage) {
ordered));
std::string buffered_message(kSctpSendBufferSize, 'b');
// SctpTransport accepts this message by buffering the second half.
// UsrsctpTransport accepts this message by buffering the second half.
ASSERT_TRUE(
SendData(transport1(), /*sid=*/1, buffered_message, &result, ordered));
ASSERT_TRUE(transport1()->ReadyToSendData());
@ -518,9 +522,9 @@ TEST_P(SctpTransportTestWithOrdered, SendLargeBufferedOutgoingMessage) {
EXPECT_EQ(2u, receiver2()->num_messages_received());
}
// Tests that a large message gets buffered and later sent by the SctpTransport
// when the sctp library only accepts the message partially during a stream
// reset.
// Tests that a large message gets buffered and later sent by the
// UsrsctpTransport when the sctp library only accepts the message partially
// during a stream reset.
TEST_P(SctpTransportTestWithOrdered,
SendLargeBufferedOutgoingMessageDuringReset) {
bool ordered = GetParam();
@ -540,7 +544,7 @@ TEST_P(SctpTransportTestWithOrdered,
ordered));
std::string buffered_message(kSctpSendBufferSize, 'b');
// SctpTransport accepts this message by buffering the second half.
// UsrsctpTransport accepts this message by buffering the second half.
ASSERT_TRUE(
SendData(transport1(), /*sid=*/1, buffered_message, &result, ordered));
// Queue a stream reset
@ -808,7 +812,8 @@ TEST_F(SctpTransportTest, ReusesAStream) {
TEST_F(SctpTransportTest, RejectsTooLargeMessageSize) {
FakeDtlsTransport fake_dtls("fake dtls", 0);
SctpFakeDataReceiver recv;
std::unique_ptr<SctpTransport> transport(CreateTransport(&fake_dtls, &recv));
std::unique_ptr<UsrsctpTransport> transport(
CreateTransport(&fake_dtls, &recv));
EXPECT_FALSE(transport->Start(kSctpDefaultPort, kSctpDefaultPort,
kSctpSendBufferSize + 1));
@ -817,7 +822,8 @@ TEST_F(SctpTransportTest, RejectsTooLargeMessageSize) {
TEST_F(SctpTransportTest, RejectsTooSmallMessageSize) {
FakeDtlsTransport fake_dtls("fake dtls", 0);
SctpFakeDataReceiver recv;
std::unique_ptr<SctpTransport> transport(CreateTransport(&fake_dtls, &recv));
std::unique_ptr<UsrsctpTransport> transport(
CreateTransport(&fake_dtls, &recv));
EXPECT_FALSE(transport->Start(kSctpDefaultPort, kSctpDefaultPort, 0));
}
@ -844,11 +850,11 @@ TEST_F(SctpTransportTest, SctpRestartWithPendingDataDoesNotDeadlock) {
SctpFakeDataReceiver recv2;
SctpFakeDataReceiver recv3;
std::unique_ptr<SctpTransport> transport1(
std::unique_ptr<UsrsctpTransport> transport1(
CreateTransport(&fake_dtls1, &recv1));
std::unique_ptr<SctpTransport> transport2(
std::unique_ptr<UsrsctpTransport> transport2(
CreateTransport(&fake_dtls2, &recv2));
std::unique_ptr<SctpTransport> transport3(
std::unique_ptr<UsrsctpTransport> transport3(
CreateTransport(&fake_dtls3, &recv3));
SctpTransportObserver observer(transport1.get());