#include "media/sctp/dcsctp_transport.h"
#include <atomic>
#include <cstdint>
#include <limits>
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/data_channel_interface.h"
#include "api/environment/environment.h"
#include "api/priority.h"
#include "media/base/media_channel.h"
#include "net/dcsctp/public/dcsctp_socket_factory.h"
#include "net/dcsctp/public/packet_observer.h"
#include "net/dcsctp/public/text_pcap_packet_observer.h"
#include "net/dcsctp/public/types.h"
#include "p2p/base/packet_transport_internal.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/socket.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/thread.h"
#include "rtc_base/trace_event.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
namespace {
SendPacketStatus;
constexpr dcsctp::DurationMs kMaxTimerBackoffDuration = …;
enum class WebrtcPPID : dcsctp::PPID::UnderlyingType { … };
WebrtcPPID ToPPID(DataMessageType message_type, size_t size) { … }
absl::optional<DataMessageType> ToDataMessageType(dcsctp::PPID ppid) { … }
absl::optional<cricket::SctpErrorCauseCode> ToErrorCauseCode(
dcsctp::ErrorKind error) { … }
bool IsEmptyPPID(dcsctp::PPID ppid) { … }
}
DcSctpTransport::DcSctpTransport(const Environment& env,
rtc::Thread* network_thread,
rtc::PacketTransportInternal* transport)
: … { … }
DcSctpTransport::DcSctpTransport(
const Environment& env,
rtc::Thread* network_thread,
rtc::PacketTransportInternal* transport,
std::unique_ptr<dcsctp::DcSctpSocketFactory> socket_factory)
: … { … }
DcSctpTransport::~DcSctpTransport() { … }
void DcSctpTransport::SetOnConnectedCallback(std::function<void()> callback) { … }
void DcSctpTransport::SetDataChannelSink(DataChannelSink* sink) { … }
void DcSctpTransport::SetDtlsTransport(
rtc::PacketTransportInternal* transport) { … }
bool DcSctpTransport::Start(int local_sctp_port,
int remote_sctp_port,
int max_message_size) { … }
bool DcSctpTransport::OpenStream(int sid, PriorityValue priority) { … }
bool DcSctpTransport::ResetStream(int sid) { … }
RTCError DcSctpTransport::SendData(int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload) { … }
bool DcSctpTransport::ReadyToSendData() { … }
int DcSctpTransport::max_message_size() const { … }
absl::optional<int> DcSctpTransport::max_outbound_streams() const { … }
absl::optional<int> DcSctpTransport::max_inbound_streams() const { … }
size_t DcSctpTransport::buffered_amount(int sid) const { … }
size_t DcSctpTransport::buffered_amount_low_threshold(int sid) const { … }
void DcSctpTransport::SetBufferedAmountLowThreshold(int sid, size_t bytes) { … }
void DcSctpTransport::set_debug_name_for_testing(const char* debug_name) { … }
SendPacketStatus DcSctpTransport::SendPacketWithStatus(
rtc::ArrayView<const uint8_t> data) { … }
std::unique_ptr<dcsctp::Timeout> DcSctpTransport::CreateTimeout(
TaskQueueBase::DelayPrecision precision) { … }
dcsctp::TimeMs DcSctpTransport::TimeMillis() { … }
uint32_t DcSctpTransport::GetRandomInt(uint32_t low, uint32_t high) { … }
void DcSctpTransport::OnTotalBufferedAmountLow() { … }
void DcSctpTransport::OnBufferedAmountLow(dcsctp::StreamID stream_id) { … }
void DcSctpTransport::OnMessageReceived(dcsctp::DcSctpMessage message) { … }
void DcSctpTransport::OnError(dcsctp::ErrorKind error,
absl::string_view message) { … }
void DcSctpTransport::OnAborted(dcsctp::ErrorKind error,
absl::string_view message) { … }
void DcSctpTransport::OnConnected() { … }
void DcSctpTransport::OnClosed() { … }
void DcSctpTransport::OnConnectionRestarted() { … }
void DcSctpTransport::OnStreamsResetFailed(
rtc::ArrayView<const dcsctp::StreamID> outgoing_streams,
absl::string_view reason) { … }
void DcSctpTransport::OnStreamsResetPerformed(
rtc::ArrayView<const dcsctp::StreamID> outgoing_streams) { … }
void DcSctpTransport::OnIncomingStreamsReset(
rtc::ArrayView<const dcsctp::StreamID> incoming_streams) { … }
void DcSctpTransport::ConnectTransportSignals() { … }
void DcSctpTransport::DisconnectTransportSignals() { … }
void DcSctpTransport::OnTransportWritableState(
rtc::PacketTransportInternal* transport) { … }
void DcSctpTransport::OnTransportReadPacket(
rtc::PacketTransportInternal* transport,
const rtc::ReceivedPacket& packet) { … }
void DcSctpTransport::MaybeConnectSocket() { … }
}