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

/*
 *  Copyright 2019 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/connection.h"

#include <math.h>

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

#include "absl/algorithm/container.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/units/timestamp.h"
#include "p2p/base/p2p_constants.h"
#include "rtc_base/byte_buffer.h"
#include "rtc_base/checks.h"
#include "rtc_base/crypto_random.h"
#include "rtc_base/logging.h"
#include "rtc_base/net_helper.h"
#include "rtc_base/network.h"
#include "rtc_base/network/sent_packet.h"
#include "rtc_base/network_constants.h"
#include "rtc_base/numerics/safe_minmax.h"
#include "rtc_base/socket.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/string_encode.h"
#include "rtc_base/string_utils.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/time_utils.h"

namespace cricket {
namespace {

IceCandidateType;

// Determines whether we have seen at least the given maximum number of
// pings fail to have a response.
inline bool TooManyFailures(
    const std::vector<Connection::SentPing>& pings_since_last_response,
    uint32_t maximum_failures,
    int rtt_estimate,
    int64_t now) {}

// Determines whether we have gone too long without seeing any response.
inline bool TooLongWithoutResponse(
    const std::vector<Connection::SentPing>& pings_since_last_response,
    int64_t maximum_time,
    int64_t now) {}

// Helper methods for converting string values of log description fields to
// enum.
IceCandidateType GetRtcEventLogCandidateType(const Candidate& c) {}

webrtc::IceCandidatePairProtocol GetProtocolByString(
    absl::string_view protocol) {}

webrtc::IceCandidatePairAddressFamily GetAddressFamilyByInt(
    int address_family) {}

webrtc::IceCandidateNetworkType ConvertNetworkType(rtc::AdapterType type) {}

// When we don't have any RTT data, we have to pick something reasonable.  We
// use a large value just in case the connection is really slow.
const int DEFAULT_RTT =;  // 3 seconds

// We will restrict RTT estimates (when used for determining state) to be
// within a reasonable range.
const int MINIMUM_RTT =;    // 0.1 seconds
const int MAXIMUM_RTT =;  // 60 seconds

const int DEFAULT_RTT_ESTIMATE_HALF_TIME_MS =;
// Weighting of the old rtt value to new data.
const int RTT_RATIO =;  // 3 : 1

constexpr int64_t kMinExtraPingDelayMs =;

// Default field trials.
const IceFieldTrials kDefaultFieldTrials;

constexpr int kSupportGoogPingVersionRequestIndex =;

constexpr int kSupportGoogPingVersionResponseIndex =;

}  // namespace

// A ConnectionRequest is a STUN binding used to determine writability.
class Connection::ConnectionRequest : public StunRequest {};

Connection::ConnectionRequest::ConnectionRequest(
    StunRequestManager& manager,
    Connection* connection,
    std::unique_ptr<IceMessage> message)
    :{}

void Connection::ConnectionRequest::OnResponse(StunMessage* response) {}

void Connection::ConnectionRequest::OnErrorResponse(StunMessage* response) {}

void Connection::ConnectionRequest::OnTimeout() {}

void Connection::ConnectionRequest::OnSent() {}

int Connection::ConnectionRequest::resend_delay() {}

Connection::Connection(rtc::WeakPtr<PortInterface> port,
                       size_t index,
                       const Candidate& remote_candidate)
    :{}

Connection::~Connection() {}

webrtc::TaskQueueBase* Connection::network_thread() const {}

const Candidate& Connection::local_candidate() const {}

const Candidate& Connection::remote_candidate() const {}

const rtc::Network* Connection::network() const {}

int Connection::generation() const {}

uint64_t Connection::priority() const {}

void Connection::set_write_state(WriteState value) {}

void Connection::UpdateReceiving(int64_t now) {}

void Connection::set_state(IceCandidatePairState state) {}

void Connection::set_connected(bool value) {}

bool Connection::use_candidate_attr() const {}

void Connection::set_use_candidate_attr(bool enable) {}

void Connection::set_nomination(uint32_t value) {}

uint32_t Connection::remote_nomination() const {}

bool Connection::nominated() const {}

int Connection::unwritable_timeout() const {}

void Connection::set_unwritable_timeout(const absl::optional<int>& value_ms) {}

int Connection::unwritable_min_checks() const {}

void Connection::set_unwritable_min_checks(const absl::optional<int>& value) {}

int Connection::inactive_timeout() const {}

void Connection::set_inactive_timeout(const absl::optional<int>& value) {}

int Connection::receiving_timeout() const {}

void Connection::set_receiving_timeout(
    absl::optional<int> receiving_timeout_ms) {}

void Connection::SetIceFieldTrials(const IceFieldTrials* field_trials) {}

void Connection::OnSendStunPacket(const void* data,
                                  size_t size,
                                  StunRequest* req) {}

void Connection::RegisterReceivedPacketCallback(
    absl::AnyInvocable<void(Connection*, const rtc::ReceivedPacket&)>
        received_packet_callback) {}

void Connection::DeregisterReceivedPacketCallback() {}

void Connection::OnReadPacket(const char* data,
                              size_t size,
                              int64_t packet_time_us) {}
void Connection::OnReadPacket(const rtc::ReceivedPacket& packet) {}

void Connection::HandleStunBindingOrGoogPingRequest(IceMessage* msg) {}

void Connection::SendStunBindingResponse(const StunMessage* message) {}

void Connection::SendGoogPingResponse(const StunMessage* message) {}

void Connection::SendResponseMessage(const StunMessage& response) {}

uint32_t Connection::acked_nomination() const {}

void Connection::set_remote_nomination(uint32_t remote_nomination) {}

void Connection::OnReadyToSend() {}

bool Connection::pruned() const {}

void Connection::Prune() {}

void Connection::Destroy() {}

bool Connection::Shutdown() {}

void Connection::FailAndPrune() {}

void Connection::PrintPingsSinceLastResponse(std::string* s, size_t max) {}

bool Connection::selected() const {}

void Connection::set_selected(bool selected) {}

void Connection::UpdateState(int64_t now) {}

void Connection::UpdateLocalIceParameters(int component,
                                          absl::string_view username_fragment,
                                          absl::string_view password) {}

int64_t Connection::last_ping_sent() const {}

void Connection::Ping(int64_t now,
                      std::unique_ptr<StunByteStringAttribute> delta) {}

std::unique_ptr<IceMessage> Connection::BuildPingRequest(
    std::unique_ptr<StunByteStringAttribute> delta) {}

int64_t Connection::last_ping_response_received() const {}

const absl::optional<std::string>& Connection::last_ping_id_received() const {}

// Used to check if any STUN ping response has been received.
int Connection::rtt_samples() const {}

// Called whenever a valid ping is received on this connection.  This is
// public because the connection intercepts the first ping for us.
int64_t Connection::last_ping_received() const {}

void Connection::ReceivedPing(const absl::optional<std::string>& request_id) {}

void Connection::HandlePiggybackCheckAcknowledgementIfAny(StunMessage* msg) {}

int64_t Connection::last_send_data() const {}

int64_t Connection::last_data_received() const {}

void Connection::ReceivedPingResponse(
    int rtt,
    absl::string_view request_id,
    const absl::optional<uint32_t>& nomination) {}

Connection::WriteState Connection::write_state() const {}

bool Connection::writable() const {}

bool Connection::receiving() const {}

// Determines whether the connection has finished connecting.  This can only
// be false for TCP connections.
bool Connection::connected() const {}

bool Connection::weak() const {}

bool Connection::active() const {}

bool Connection::dead(int64_t now) const {}

int Connection::rtt() const {}

bool Connection::stable(int64_t now) const {}

std::string Connection::ToDebugId() const {}

uint32_t Connection::ComputeNetworkCost() const {}

std::string Connection::ToString() const {}

std::string Connection::ToSensitiveString() const {}

const webrtc::IceCandidatePairDescription& Connection::ToLogDescription() {}

void Connection::set_ice_event_log(webrtc::IceEventLog* ice_event_log) {}

void Connection::LogCandidatePairConfig(
    webrtc::IceCandidatePairConfigType type) {}

void Connection::LogCandidatePairEvent(webrtc::IceCandidatePairEventType type,
                                       uint32_t transaction_id) {}

void Connection::OnConnectionRequestResponse(StunRequest* request,
                                             StunMessage* response) {}

void Connection::OnConnectionRequestErrorResponse(ConnectionRequest* request,
                                                  StunMessage* response) {}

void Connection::OnConnectionRequestTimeout(ConnectionRequest* request) {}

void Connection::OnConnectionRequestSent(ConnectionRequest* request) {}

IceCandidatePairState Connection::state() const {}

int Connection::num_pings_sent() const {}

void Connection::MaybeSetRemoteIceParametersAndGeneration(
    const IceParameters& ice_params,
    int generation) {}

void Connection::MaybeUpdatePeerReflexiveCandidate(
    const Candidate& new_candidate) {}

int64_t Connection::last_received() const {}

int64_t Connection::receiving_unchanged_since() const {}

uint32_t Connection::prflx_priority() const {}

ConnectionInfo Connection::stats() {}

void Connection::MaybeUpdateLocalCandidate(StunRequest* request,
                                           StunMessage* response) {}

bool Connection::rtt_converged() const {}

bool Connection::missing_responses(int64_t now) const {}

bool Connection::TooManyOutstandingPings(
    const absl::optional<int>& max_outstanding_pings) const {}

void Connection::SetLocalCandidateNetworkCost(uint16_t cost) {}

bool Connection::ShouldSendGoogPing(const StunMessage* message) {}

void Connection::ForgetLearnedState() {}

ProxyConnection::ProxyConnection(rtc::WeakPtr<PortInterface> port,
                                 size_t index,
                                 const Candidate& remote_candidate)
    :{}

int ProxyConnection::Send(const void* data,
                          size_t size,
                          const rtc::PacketOptions& options) {}

int ProxyConnection::GetError() {}

}  // namespace cricket