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

/*
 *  Copyright 2004 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/p2p_transport_channel.h"

#include <errno.h>
#include <stdlib.h>

#include <algorithm>
#include <functional>
#include <memory>
#include <set>
#include <utility>

#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "api/async_dns_resolver.h"
#include "api/candidate.h"
#include "api/field_trials_view.h"
#include "api/units/time_delta.h"
#include "logging/rtc_event_log/ice_logger.h"
#include "p2p/base/basic_ice_controller.h"
#include "p2p/base/connection.h"
#include "p2p/base/connection_info.h"
#include "p2p/base/port.h"
#include "p2p/base/wrapping_active_ice_controller.h"
#include "rtc_base/checks.h"
#include "rtc_base/experiments/struct_parameters_parser.h"
#include "rtc_base/ip_address.h"
#include "rtc_base/logging.h"
#include "rtc_base/net_helper.h"
#include "rtc_base/network.h"
#include "rtc_base/network_constants.h"
#include "rtc_base/string_encode.h"
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"
#include "system_wrappers/include/metrics.h"

namespace cricket {
namespace {
IceCandidateType;
RTCError;
RTCErrorType;
SafeTask;
TimeDelta;

cricket::PortInterface::CandidateOrigin GetOrigin(
    cricket::PortInterface* port,
    cricket::PortInterface* origin_port) {}

uint32_t GetWeakPingIntervalInFieldTrial(
    const webrtc::FieldTrialsView* field_trials) {}

rtc::RouteEndpoint CreateRouteEndpointFromCandidate(
    bool local,
    const cricket::Candidate& candidate,
    bool uses_turn) {}

}  // unnamed namespace

bool IceCredentialsChanged(absl::string_view old_ufrag,
                           absl::string_view old_pwd,
                           absl::string_view new_ufrag,
                           absl::string_view new_pwd) {}

std::unique_ptr<P2PTransportChannel> P2PTransportChannel::Create(
    absl::string_view transport_name,
    int component,
    webrtc::IceTransportInit init) {}

P2PTransportChannel::P2PTransportChannel(
    absl::string_view transport_name,
    int component,
    PortAllocator* allocator,
    const webrtc::FieldTrialsView* field_trials)
    :{}

// Private constructor, called from Create()
P2PTransportChannel::P2PTransportChannel(
    absl::string_view transport_name,
    int component,
    PortAllocator* allocator,
    webrtc::AsyncDnsResolverFactoryInterface* async_dns_resolver_factory,
    std::unique_ptr<webrtc::AsyncDnsResolverFactoryInterface>
        owned_dns_resolver_factory,
    webrtc::RtcEventLog* event_log,
    IceControllerFactoryInterface* ice_controller_factory,
    ActiveIceControllerFactoryInterface* active_ice_controller_factory,
    const webrtc::FieldTrialsView* field_trials)
    :{}

P2PTransportChannel::~P2PTransportChannel() {}

// Add the allocator session to our list so that we know which sessions
// are still active.
void P2PTransportChannel::AddAllocatorSession(
    std::unique_ptr<PortAllocatorSession> session) {}

void P2PTransportChannel::AddConnection(Connection* connection) {}

void P2PTransportChannel::ForgetLearnedStateForConnections(
    rtc::ArrayView<const Connection* const> connections) {}

void P2PTransportChannel::SetIceRole(IceRole ice_role) {}

IceRole P2PTransportChannel::GetIceRole() const {}

IceTransportState P2PTransportChannel::GetState() const {}

webrtc::IceTransportState P2PTransportChannel::GetIceTransportState() const {}

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

int P2PTransportChannel::component() const {}

bool P2PTransportChannel::writable() const {}

bool P2PTransportChannel::receiving() const {}

IceGatheringState P2PTransportChannel::gathering_state() const {}

absl::optional<int> P2PTransportChannel::GetRttEstimate() {}

absl::optional<const CandidatePair>
P2PTransportChannel::GetSelectedCandidatePair() const {}

// A channel is considered ICE completed once there is at most one active
// connection per network and at least one active connection.
IceTransportState P2PTransportChannel::ComputeState() const {}

// Compute the current RTCIceTransportState as described in
// https://www.w3.org/TR/webrtc/#dom-rtcicetransportstate
// TODO(bugs.webrtc.org/9218): Start signaling kCompleted once we have
// implemented end-of-candidates signalling.
webrtc::IceTransportState P2PTransportChannel::ComputeIceTransportState()
    const {}

void P2PTransportChannel::SetIceParameters(const IceParameters& ice_params) {}

void P2PTransportChannel::SetRemoteIceParameters(
    const IceParameters& ice_params) {}

void P2PTransportChannel::SetRemoteIceMode(IceMode mode) {}

// TODO(qingsi): We apply the convention that setting a absl::optional parameter
// to null restores its default value in the implementation. However, some
// absl::optional parameters are only processed below if non-null, e.g.,
// regather_on_failed_networks_interval, and thus there is no way to restore the
// defaults. Fix this issue later for consistency.
void P2PTransportChannel::SetIceConfig(const IceConfig& config) {}

void P2PTransportChannel::ParseFieldTrials(
    const webrtc::FieldTrialsView* field_trials) {}

const IceConfig& P2PTransportChannel::config() const {}

// TODO(qingsi): Add tests for the config validation starting from
// PeerConnection::SetConfiguration.
// Static
RTCError P2PTransportChannel::ValidateIceConfig(const IceConfig& config) {}

const Connection* P2PTransportChannel::selected_connection() const {}

int P2PTransportChannel::check_receiving_interval() const {}

void P2PTransportChannel::MaybeStartGathering() {}

// A new port is available, attempt to make connections for it
void P2PTransportChannel::OnPortReady(PortAllocatorSession* session,
                                      PortInterface* port) {}

// A new candidate is available, let listeners know
void P2PTransportChannel::OnCandidatesReady(
    PortAllocatorSession* session,
    const std::vector<Candidate>& candidates) {}

void P2PTransportChannel::OnCandidateError(
    PortAllocatorSession* session,
    const IceCandidateErrorEvent& event) {}

void P2PTransportChannel::OnCandidatesAllocationDone(
    PortAllocatorSession* session) {}

// Handle stun packets
void P2PTransportChannel::OnUnknownAddress(PortInterface* port,
                                           const rtc::SocketAddress& address,
                                           ProtocolType proto,
                                           IceMessage* stun_msg,
                                           const std::string& remote_username,
                                           bool port_muxed) {}

void P2PTransportChannel::OnCandidateFilterChanged(uint32_t prev_filter,
                                                   uint32_t cur_filter) {}

void P2PTransportChannel::OnRoleConflict(PortInterface* port) {}

const IceParameters* P2PTransportChannel::FindRemoteIceFromUfrag(
    absl::string_view ufrag,
    uint32_t* generation) {}

void P2PTransportChannel::OnNominated(Connection* conn) {}

void P2PTransportChannel::ResolveHostnameCandidate(const Candidate& candidate) {}

void P2PTransportChannel::AddRemoteCandidate(const Candidate& candidate) {}

P2PTransportChannel::CandidateAndResolver::CandidateAndResolver(
    const Candidate& candidate,
    std::unique_ptr<webrtc::AsyncDnsResolverInterface>&& resolver)
    :{}

P2PTransportChannel::CandidateAndResolver::~CandidateAndResolver() {}

void P2PTransportChannel::OnCandidateResolved(
    webrtc::AsyncDnsResolverInterface* resolver) {}

void P2PTransportChannel::AddRemoteCandidateWithResult(
    Candidate candidate,
    const webrtc::AsyncDnsResolverResult& result) {}

void P2PTransportChannel::FinishAddingRemoteCandidate(
    const Candidate& new_remote_candidate) {}

void P2PTransportChannel::RemoveRemoteCandidate(
    const Candidate& cand_to_remove) {}

void P2PTransportChannel::RemoveAllRemoteCandidates() {}

// Creates connections from all of the ports that we care about to the given
// remote candidate.  The return value is true if we created a connection from
// the origin port.
bool P2PTransportChannel::CreateConnections(const Candidate& remote_candidate,
                                            PortInterface* origin_port) {}

// Setup a connection object for the local and remote candidate combination.
// And then listen to connection object for changes.
bool P2PTransportChannel::CreateConnection(PortInterface* port,
                                           const Candidate& remote_candidate,
                                           PortInterface* origin_port) {}

bool P2PTransportChannel::FindConnection(const Connection* connection) const {}

uint32_t P2PTransportChannel::GetRemoteCandidateGeneration(
    const Candidate& candidate) {}

// Check if remote candidate is already cached.
bool P2PTransportChannel::IsDuplicateRemoteCandidate(
    const Candidate& candidate) {}

// Maintain our remote candidate list, adding this new remote one.
void P2PTransportChannel::RememberRemoteCandidate(
    const Candidate& remote_candidate,
    PortInterface* origin_port) {}

// Set options on ourselves is simply setting options on all of our available
// port objects.
int P2PTransportChannel::SetOption(rtc::Socket::Option opt, int value) {}

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

int P2PTransportChannel::GetError() {}

// Send data to the other side, using our selected connection.
int P2PTransportChannel::SendPacket(const char* data,
                                    size_t len,
                                    const rtc::PacketOptions& options,
                                    int flags) {}

bool P2PTransportChannel::GetStats(IceTransportStats* ice_transport_stats) {}

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

rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const {}

rtc::ArrayView<Connection* const> P2PTransportChannel::connections() const {}

void P2PTransportChannel::RemoveConnectionForTest(Connection* connection) {}

// Monitor connection states.
void P2PTransportChannel::UpdateConnectionStates() {}

void P2PTransportChannel::OnStartedPinging() {}

bool P2PTransportChannel::IsPortPruned(const PortInterface* port) const {}

bool P2PTransportChannel::IsRemoteCandidatePruned(const Candidate& cand) const {}

bool P2PTransportChannel::PresumedWritable(const Connection* conn) const {}

void P2PTransportChannel::UpdateState() {}

bool P2PTransportChannel::AllowedToPruneConnections() const {}

bool P2PTransportChannel::PruneConnections(
    rtc::ArrayView<const Connection* const> connections) {}

rtc::NetworkRoute P2PTransportChannel::ConfigureNetworkRoute(
    const Connection* conn) {}

void P2PTransportChannel::SwitchSelectedConnection(
    const Connection* new_connection,
    IceSwitchReason reason) {}

// Change the selected connection, and let listeners know.
void P2PTransportChannel::SwitchSelectedConnectionInternal(
    Connection* conn,
    IceSwitchReason reason) {}

int64_t P2PTransportChannel::ComputeEstimatedDisconnectedTimeMs(
    int64_t now_ms,
    Connection* old_connection) {}

// Warning: UpdateTransportState should eventually be called whenever a
// connection is added, deleted, or the write state of any connection changes so
// that the transport controller will get the up-to-date channel state. However
// it should not be called too often; in the case that multiple connection
// states change, it should be called after all the connection states have
// changed. For example, we call this at the end of
// SortConnectionsAndUpdateState.
void P2PTransportChannel::UpdateTransportState() {}

void P2PTransportChannel::MaybeStopPortAllocatorSessions() {}

void P2PTransportChannel::OnSelectedConnectionDestroyed() {}

// If all connections timed out, delete them all.
void P2PTransportChannel::HandleAllTimedOut() {}

bool P2PTransportChannel::ReadyToSend(const Connection* connection) const {}

// This method is only for unit testing.
Connection* P2PTransportChannel::FindNextPingableConnection() {}

int64_t P2PTransportChannel::GetLastPingSentMs() const {}

void P2PTransportChannel::SendPingRequest(const Connection* connection) {}

void P2PTransportChannel::SendPingRequestInternal(Connection* connection) {}

// A connection is considered a backup connection if the channel state
// is completed, the connection is not the selected connection and it is
// active.
void P2PTransportChannel::MarkConnectionPinged(Connection* conn) {}

// Apart from sending ping from `conn` this method also updates
// `use_candidate_attr` and `nomination` flags. One of the flags is set to
// nominate `conn` if this channel is in CONTROLLING.
void P2PTransportChannel::PingConnection(Connection* conn) {}

uint32_t P2PTransportChannel::GetNominationAttr(Connection* conn) const {}

// Nominate a connection based on the NominationMode.
bool P2PTransportChannel::GetUseCandidateAttr(Connection* conn) const {}

// When a connection's state changes, we need to figure out who to use as
// the selected connection again.  It could have become usable, or become
// unusable.
void P2PTransportChannel::OnConnectionStateChange(Connection* connection) {}

// When a connection is removed, edit it out, and then update our best
// connection.
void P2PTransportChannel::OnConnectionDestroyed(Connection* connection) {}

void P2PTransportChannel::RemoveConnection(Connection* connection) {}

// When a port is destroyed, remove it from our list of ports to use for
// connection attempts.
void P2PTransportChannel::OnPortDestroyed(PortInterface* port) {}

void P2PTransportChannel::OnPortsPruned(
    PortAllocatorSession* session,
    const std::vector<PortInterface*>& ports) {}

void P2PTransportChannel::OnCandidatesRemoved(
    PortAllocatorSession* session,
    const std::vector<Candidate>& candidates) {}

void P2PTransportChannel::PruneAllPorts() {}

bool P2PTransportChannel::PrunePort(PortInterface* port) {}

// We data is available, let listeners know
void P2PTransportChannel::OnReadPacket(Connection* connection,
                                       const rtc::ReceivedPacket& packet) {}

void P2PTransportChannel::OnSentPacket(const rtc::SentPacket& sent_packet) {}

void P2PTransportChannel::OnReadyToSend(Connection* connection) {}

void P2PTransportChannel::SetWritable(bool writable) {}

void P2PTransportChannel::SetReceiving(bool receiving) {}

Candidate P2PTransportChannel::SanitizeLocalCandidate(
    const Candidate& c) const {}

Candidate P2PTransportChannel::SanitizeRemoteCandidate(
    const Candidate& c) const {}

void P2PTransportChannel::LogCandidatePairConfig(
    Connection* conn,
    webrtc::IceCandidatePairConfigType type) {}

std::unique_ptr<StunAttribute> P2PTransportChannel::GoogDeltaReceived(
    const StunByteStringAttribute* delta) {}

void P2PTransportChannel::GoogDeltaAckReceived(
    webrtc::RTCErrorOr<const StunUInt64Attribute*> error_or_ack) {}

}  // namespace cricket