chromium/third_party/webrtc/p2p/base/dtls_transport.cc

/*
 *  Copyright 2011 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 "p2p/base/dtls_transport.h"

#include <algorithm>
#include <cstdint>
#include <memory>
#include <utility>

#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "api/dtls_transport_interface.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "logging/rtc_event_log/events/rtc_event_dtls_transport_state.h"
#include "logging/rtc_event_log/events/rtc_event_dtls_writable_state.h"
#include "p2p/base/packet_transport_internal.h"
#include "rtc_base/buffer.h"
#include "rtc_base/checks.h"
#include "rtc_base/dscp.h"
#include "rtc_base/logging.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/rtc_certificate.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/ssl_stream_adapter.h"
#include "rtc_base/stream.h"
#include "rtc_base/thread.h"
#include "rtc_base/time_utils.h"

namespace cricket {

// We don't pull the RTP constants from rtputils.h, to avoid a layer violation.
static const size_t kDtlsRecordHeaderLen =;
static const size_t kMaxDtlsPacketLen =;
static const size_t kMinRtpPacketLen =;

// Maximum number of pending packets in the queue. Packets are read immediately
// after they have been written, so a capacity of "1" is sufficient.
//
// However, this bug seems to indicate that's not the case: crbug.com/1063834
// So, temporarily increasing it to 2 to see if that makes a difference.
static const size_t kMaxPendingPackets =;

// Minimum and maximum values for the initial DTLS handshake timeout. We'll pick
// an initial timeout based on ICE RTT estimates, but clamp it to this range.
static const int kMinHandshakeTimeout =;
static const int kMaxHandshakeTimeout =;

static bool IsDtlsPacket(rtc::ArrayView<const uint8_t> payload) {}
static bool IsDtlsClientHelloPacket(rtc::ArrayView<const uint8_t> payload) {}
static bool IsRtpPacket(rtc::ArrayView<const uint8_t> payload) {}

StreamInterfaceChannel::StreamInterfaceChannel(
    IceTransportInternal* ice_transport)
    :{}

rtc::StreamResult StreamInterfaceChannel::Read(rtc::ArrayView<uint8_t> buffer,
                                               size_t& read,
                                               int& error) {}

rtc::StreamResult StreamInterfaceChannel::Write(
    rtc::ArrayView<const uint8_t> data,
    size_t& written,
    int& error) {}

bool StreamInterfaceChannel::OnPacketReceived(const char* data, size_t size) {}

rtc::StreamState StreamInterfaceChannel::GetState() const {}

void StreamInterfaceChannel::Close() {}

DtlsTransport::DtlsTransport(IceTransportInternal* ice_transport,
                             const webrtc::CryptoOptions& crypto_options,
                             webrtc::RtcEventLog* event_log,
                             rtc::SSLProtocolVersion max_version)
    :{}

DtlsTransport::~DtlsTransport() {}

webrtc::DtlsTransportState DtlsTransport::dtls_state() const {}

const std::string& DtlsTransport::transport_name() const {}

int DtlsTransport::component() const {}

bool DtlsTransport::IsDtlsActive() const {}

bool DtlsTransport::SetLocalCertificate(
    const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {}

rtc::scoped_refptr<rtc::RTCCertificate> DtlsTransport::GetLocalCertificate()
    const {}

bool DtlsTransport::SetDtlsRole(rtc::SSLRole role) {}

bool DtlsTransport::GetDtlsRole(rtc::SSLRole* role) const {}

bool DtlsTransport::GetSslCipherSuite(int* cipher) {}

webrtc::RTCError DtlsTransport::SetRemoteParameters(
    absl::string_view digest_alg,
    const uint8_t* digest,
    size_t digest_len,
    absl::optional<rtc::SSLRole> role) {}

bool DtlsTransport::SetRemoteFingerprint(absl::string_view digest_alg,
                                         const uint8_t* digest,
                                         size_t digest_len) {}

std::unique_ptr<rtc::SSLCertChain> DtlsTransport::GetRemoteSSLCertChain()
    const {}

bool DtlsTransport::ExportKeyingMaterial(absl::string_view label,
                                         const uint8_t* context,
                                         size_t context_len,
                                         bool use_context,
                                         uint8_t* result,
                                         size_t result_len) {}

bool DtlsTransport::SetupDtls() {}

bool DtlsTransport::GetSrtpCryptoSuite(int* cipher) {}

bool DtlsTransport::GetSslVersionBytes(int* version) const {}

uint16_t DtlsTransport::GetSslPeerSignatureAlgorithm() const {}

// Called from upper layers to send a media packet.
int DtlsTransport::SendPacket(const char* data,
                              size_t size,
                              const rtc::PacketOptions& options,
                              int flags) {}

IceTransportInternal* DtlsTransport::ice_transport() {}

bool DtlsTransport::IsDtlsConnected() {}

bool DtlsTransport::receiving() const {}

bool DtlsTransport::writable() const {}

int DtlsTransport::GetError() {}

absl::optional<rtc::NetworkRoute> DtlsTransport::network_route() const {}

bool DtlsTransport::GetOption(rtc::Socket::Option opt, int* value) {}

int DtlsTransport::SetOption(rtc::Socket::Option opt, int value) {}

void DtlsTransport::ConnectToIceTransport() {}

// The state transition logic here is as follows:
// (1) If we're not doing DTLS-SRTP, then the state is just the
//     state of the underlying impl()
// (2) If we're doing DTLS-SRTP:
//     - Prior to the DTLS handshake, the state is neither receiving nor
//       writable
//     - When the impl goes writable for the first time we
//       start the DTLS handshake
//     - Once the DTLS handshake completes, the state is that of the
//       impl again
void DtlsTransport::OnWritableState(rtc::PacketTransportInternal* transport) {}

void DtlsTransport::OnReceivingState(rtc::PacketTransportInternal* transport) {}

void DtlsTransport::OnReadPacket(rtc::PacketTransportInternal* transport,
                                 const rtc::ReceivedPacket& packet) {}

void DtlsTransport::OnSentPacket(rtc::PacketTransportInternal* transport,
                                 const rtc::SentPacket& sent_packet) {}

void DtlsTransport::OnReadyToSend(rtc::PacketTransportInternal* transport) {}

void DtlsTransport::OnDtlsEvent(int sig, int err) {}

void DtlsTransport::OnNetworkRouteChanged(
    absl::optional<rtc::NetworkRoute> network_route) {}

void DtlsTransport::MaybeStartDtls() {}

// Called from OnReadPacket when a DTLS packet is received.
bool DtlsTransport::HandleDtlsPacket(rtc::ArrayView<const uint8_t> payload) {}

void DtlsTransport::set_receiving(bool receiving) {}

void DtlsTransport::set_writable(bool writable) {}

void DtlsTransport::set_dtls_state(webrtc::DtlsTransportState state) {}

void DtlsTransport::OnDtlsHandshakeError(rtc::SSLHandshakeError error) {}

void DtlsTransport::ConfigureHandshakeTimeout() {}

}  // namespace cricket