#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) { … }
}
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)
: … { … }
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() { … }
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 { … }
IceTransportState P2PTransportChannel::ComputeState() const { … }
webrtc::IceTransportState P2PTransportChannel::ComputeIceTransportState()
const { … }
void P2PTransportChannel::SetIceParameters(const IceParameters& ice_params) { … }
void P2PTransportChannel::SetRemoteIceParameters(
const IceParameters& ice_params) { … }
void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { … }
void P2PTransportChannel::SetIceConfig(const IceConfig& config) { … }
void P2PTransportChannel::ParseFieldTrials(
const webrtc::FieldTrialsView* field_trials) { … }
const IceConfig& P2PTransportChannel::config() const { … }
RTCError P2PTransportChannel::ValidateIceConfig(const IceConfig& config) { … }
const Connection* P2PTransportChannel::selected_connection() const { … }
int P2PTransportChannel::check_receiving_interval() const { … }
void P2PTransportChannel::MaybeStartGathering() { … }
void P2PTransportChannel::OnPortReady(PortAllocatorSession* session,
PortInterface* port) { … }
void P2PTransportChannel::OnCandidatesReady(
PortAllocatorSession* session,
const std::vector<Candidate>& candidates) { … }
void P2PTransportChannel::OnCandidateError(
PortAllocatorSession* session,
const IceCandidateErrorEvent& event) { … }
void P2PTransportChannel::OnCandidatesAllocationDone(
PortAllocatorSession* session) { … }
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() { … }
bool P2PTransportChannel::CreateConnections(const Candidate& remote_candidate,
PortInterface* origin_port) { … }
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) { … }
bool P2PTransportChannel::IsDuplicateRemoteCandidate(
const Candidate& candidate) { … }
void P2PTransportChannel::RememberRemoteCandidate(
const Candidate& remote_candidate,
PortInterface* origin_port) { … }
int P2PTransportChannel::SetOption(rtc::Socket::Option opt, int value) { … }
bool P2PTransportChannel::GetOption(rtc::Socket::Option opt, int* value) { … }
int P2PTransportChannel::GetError() { … }
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) { … }
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) { … }
void P2PTransportChannel::SwitchSelectedConnectionInternal(
Connection* conn,
IceSwitchReason reason) { … }
int64_t P2PTransportChannel::ComputeEstimatedDisconnectedTimeMs(
int64_t now_ms,
Connection* old_connection) { … }
void P2PTransportChannel::UpdateTransportState() { … }
void P2PTransportChannel::MaybeStopPortAllocatorSessions() { … }
void P2PTransportChannel::OnSelectedConnectionDestroyed() { … }
void P2PTransportChannel::HandleAllTimedOut() { … }
bool P2PTransportChannel::ReadyToSend(const Connection* connection) const { … }
Connection* P2PTransportChannel::FindNextPingableConnection() { … }
int64_t P2PTransportChannel::GetLastPingSentMs() const { … }
void P2PTransportChannel::SendPingRequest(const Connection* connection) { … }
void P2PTransportChannel::SendPingRequestInternal(Connection* connection) { … }
void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { … }
void P2PTransportChannel::PingConnection(Connection* conn) { … }
uint32_t P2PTransportChannel::GetNominationAttr(Connection* conn) const { … }
bool P2PTransportChannel::GetUseCandidateAttr(Connection* conn) const { … }
void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { … }
void P2PTransportChannel::OnConnectionDestroyed(Connection* connection) { … }
void P2PTransportChannel::RemoveConnection(Connection* connection) { … }
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) { … }
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) { … }
}