#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;
inline bool TooManyFailures(
const std::vector<Connection::SentPing>& pings_since_last_response,
uint32_t maximum_failures,
int rtt_estimate,
int64_t now) { … }
inline bool TooLongWithoutResponse(
const std::vector<Connection::SentPing>& pings_since_last_response,
int64_t maximum_time,
int64_t now) { … }
IceCandidateType GetRtcEventLogCandidateType(const Candidate& c) { … }
webrtc::IceCandidatePairProtocol GetProtocolByString(
absl::string_view protocol) { … }
webrtc::IceCandidatePairAddressFamily GetAddressFamilyByInt(
int address_family) { … }
webrtc::IceCandidateNetworkType ConvertNetworkType(rtc::AdapterType type) { … }
const int DEFAULT_RTT = …;
const int MINIMUM_RTT = …;
const int MAXIMUM_RTT = …;
const int DEFAULT_RTT_ESTIMATE_HALF_TIME_MS = …;
const int RTT_RATIO = …;
constexpr int64_t kMinExtraPingDelayMs = …;
const IceFieldTrials kDefaultFieldTrials;
constexpr int kSupportGoogPingVersionRequestIndex = …;
constexpr int kSupportGoogPingVersionResponseIndex = …;
}
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 { … }
int Connection::rtt_samples() const { … }
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 { … }
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() { … }
}