chromium/third_party/webrtc/pc/sctp_data_channel.cc

/*
 *  Copyright 2020 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "pc/sctp_data_channel.h"

#include <limits>
#include <memory>
#include <string>
#include <utility>

#include "api/priority.h"
#include "media/sctp/sctp_transport_internal.h"
#include "pc/proxy.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/system/unused.h"
#include "rtc_base/thread.h"

namespace webrtc {

namespace {

static size_t kMaxQueuedReceivedDataBytes =;

static std::atomic<int> g_unique_id{};

int GenerateUniqueId() {}

// Define proxy for DataChannelInterface.
BEGIN_PROXY_MAP(DataChannel)
PROXY_PRIMARY_THREAD_DESTRUCTOR()
BYPASS_PROXY_METHOD1(void, RegisterObserver, DataChannelObserver*)
BYPASS_PROXY_METHOD0(void, UnregisterObserver)
BYPASS_PROXY_CONSTMETHOD0(std::string, label)
BYPASS_PROXY_CONSTMETHOD0(bool, reliable)
BYPASS_PROXY_CONSTMETHOD0(bool, ordered)
BYPASS_PROXY_CONSTMETHOD0(uint16_t, maxRetransmitTime)
BYPASS_PROXY_CONSTMETHOD0(uint16_t, maxRetransmits)
BYPASS_PROXY_CONSTMETHOD0(absl::optional<int>, maxRetransmitsOpt)
BYPASS_PROXY_CONSTMETHOD0(absl::optional<int>, maxPacketLifeTime)
BYPASS_PROXY_CONSTMETHOD0(std::string, protocol)
BYPASS_PROXY_CONSTMETHOD0(bool, negotiated)
// Can't bypass the proxy since the id may change.
PROXY_SECONDARY_CONSTMETHOD0(int, id)
BYPASS_PROXY_CONSTMETHOD0(PriorityValue, priority)
BYPASS_PROXY_CONSTMETHOD0(DataState, state)
BYPASS_PROXY_CONSTMETHOD0(RTCError, error)
PROXY_SECONDARY_CONSTMETHOD0(uint32_t, messages_sent)
PROXY_SECONDARY_CONSTMETHOD0(uint64_t, bytes_sent)
PROXY_SECONDARY_CONSTMETHOD0(uint32_t, messages_received)
PROXY_SECONDARY_CONSTMETHOD0(uint64_t, bytes_received)
PROXY_SECONDARY_CONSTMETHOD0(uint64_t, buffered_amount)
PROXY_SECONDARY_METHOD0(void, Close)
PROXY_SECONDARY_METHOD1(bool, Send, const DataBuffer&)
BYPASS_PROXY_METHOD2(void,
                     SendAsync,
                     DataBuffer,
                     absl::AnyInvocable<void(RTCError) &&>)
END_PROXY_MAP(DataChannel)
}  // namespace

InternalDataChannelInit::InternalDataChannelInit(const DataChannelInit& base)
    :{}

bool InternalDataChannelInit::IsValid() const {}

absl::optional<StreamId> SctpSidAllocator::AllocateSid(rtc::SSLRole role) {}

bool SctpSidAllocator::ReserveSid(StreamId sid) {}

void SctpSidAllocator::ReleaseSid(StreamId sid) {}

// A DataChannelObserver implementation that offers backwards compatibility with
// implementations that aren't yet ready to be called back on the network
// thread. This implementation posts events to the signaling thread where
// events are delivered.
// In the class, and together with the `SctpDataChannel` implementation, there's
// special handling for the `state()` property whereby if that property is
// queried on the channel object while inside an event callback, we return
// the state that was active at the time the event was issued. This is to avoid
// a problem with calling the `state()` getter on the proxy, which would do
// a blocking call to the network thread, effectively flushing operations on
// the network thread that could cause the state to change and eventually return
// a misleading or arguably, wrong, state value to the callback implementation.
// As a future improvement to the ObserverAdapter, we could do the same for
// other properties that need to be read on the network thread. Eventually
// all implementations should expect to be called on the network thread though
// and the ObserverAdapter no longer be necessary.
class SctpDataChannel::ObserverAdapter : public DataChannelObserver {};

// static
rtc::scoped_refptr<SctpDataChannel> SctpDataChannel::Create(
    rtc::WeakPtr<SctpDataChannelControllerInterface> controller,
    const std::string& label,
    bool connected_to_transport,
    const InternalDataChannelInit& config,
    rtc::Thread* signaling_thread,
    rtc::Thread* network_thread) {}

// static
rtc::scoped_refptr<DataChannelInterface> SctpDataChannel::CreateProxy(
    rtc::scoped_refptr<SctpDataChannel> channel,
    rtc::scoped_refptr<PendingTaskSafetyFlag> signaling_safety) {}

SctpDataChannel::SctpDataChannel(
    const InternalDataChannelInit& config,
    rtc::WeakPtr<SctpDataChannelControllerInterface> controller,
    const std::string& label,
    bool connected_to_transport,
    rtc::Thread* signaling_thread,
    rtc::Thread* network_thread)
    :{}

SctpDataChannel::~SctpDataChannel() {}

void SctpDataChannel::RegisterObserver(DataChannelObserver* observer) {}

void SctpDataChannel::UnregisterObserver() {}

std::string SctpDataChannel::label() const {}

bool SctpDataChannel::reliable() const {}

bool SctpDataChannel::ordered() const {}

uint16_t SctpDataChannel::maxRetransmitTime() const {}

uint16_t SctpDataChannel::maxRetransmits() const {}

absl::optional<int> SctpDataChannel::maxPacketLifeTime() const {}

absl::optional<int> SctpDataChannel::maxRetransmitsOpt() const {}

std::string SctpDataChannel::protocol() const {}

bool SctpDataChannel::negotiated() const {}

int SctpDataChannel::id() const {}

PriorityValue SctpDataChannel::priority() const {}

uint64_t SctpDataChannel::buffered_amount() const {}

void SctpDataChannel::Close() {}

SctpDataChannel::DataState SctpDataChannel::state() const {}

RTCError SctpDataChannel::error() const {}

uint32_t SctpDataChannel::messages_sent() const {}

uint64_t SctpDataChannel::bytes_sent() const {}

uint32_t SctpDataChannel::messages_received() const {}

uint64_t SctpDataChannel::bytes_received() const {}

bool SctpDataChannel::Send(const DataBuffer& buffer) {}

// RTC_RUN_ON(network_thread_);
RTCError SctpDataChannel::SendImpl(DataBuffer buffer) {}

void SctpDataChannel::SendAsync(
    DataBuffer buffer,
    absl::AnyInvocable<void(RTCError) &&> on_complete) {}

void SctpDataChannel::SetSctpSid_n(StreamId sid) {}

void SctpDataChannel::OnClosingProcedureStartedRemotely() {}

void SctpDataChannel::OnClosingProcedureComplete() {}

void SctpDataChannel::OnTransportChannelCreated() {}

void SctpDataChannel::OnTransportChannelClosed(RTCError error) {}

void SctpDataChannel::OnBufferedAmountLow() {}

DataChannelStats SctpDataChannel::GetStats() const {}

void SctpDataChannel::OnDataReceived(DataMessageType type,
                                     const rtc::CopyOnWriteBuffer& payload) {}

void SctpDataChannel::OnTransportReady() {}

void SctpDataChannel::CloseAbruptlyWithError(RTCError error) {}

void SctpDataChannel::CloseAbruptlyWithDataChannelFailure(
    const std::string& message) {}

// RTC_RUN_ON(network_thread_).
void SctpDataChannel::UpdateState() {}

// RTC_RUN_ON(network_thread_).
void SctpDataChannel::SetState(DataState state) {}

// RTC_RUN_ON(network_thread_).
void SctpDataChannel::DeliverQueuedReceivedData() {}

// RTC_RUN_ON(network_thread_)
void SctpDataChannel::MaybeSendOnBufferedAmountChanged() {}

// RTC_RUN_ON(network_thread_).
RTCError SctpDataChannel::SendDataMessage(const DataBuffer& buffer,
                                          bool queue_if_blocked) {}

// RTC_RUN_ON(network_thread_).
bool SctpDataChannel::SendControlMessage(const rtc::CopyOnWriteBuffer& buffer) {}

// static
void SctpDataChannel::ResetInternalIdAllocatorForTesting(int new_value) {}

}  // namespace webrtc