tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 763e5000b7bf81f08d72cb29c93582e47c655858
parent 6db2310096e74485802169e830f2afaa7cc459cd
Author: Dan Baker <dbaker@mozilla.com>
Date:   Mon,  1 Dec 2025 16:55:26 -0700

Bug 2000941 - Vendor libwebrtc from 176f169606

Upstream commit: https://webrtc.googlesource.com/src/+/176f1696068740960f8d8b8d7b971358ef071a0b
    Use TimeDelta type for IceConfig values

    Bug: webrtc:42223979
    Change-Id: I7ae5a45ce35ba049cd4ee92d61af7ce9ca9669b3
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/407640
    Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
    Reviewed-by: Per Kjellander <perkj@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#45571}

Diffstat:
Mthird_party/libwebrtc/README.mozilla.last-vendor | 4++--
Mthird_party/libwebrtc/p2p/base/basic_ice_controller.cc | 34+++++++++++++++++-----------------
Mthird_party/libwebrtc/p2p/base/basic_ice_controller.h | 14+++++++-------
Mthird_party/libwebrtc/p2p/base/ice_controller_interface.h | 7+++++++
Mthird_party/libwebrtc/p2p/base/ice_transport_internal.cc | 96+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Mthird_party/libwebrtc/p2p/base/ice_transport_internal.h | 83+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mthird_party/libwebrtc/p2p/base/p2p_transport_channel.cc | 32++++++++++++++++----------------
Mthird_party/libwebrtc/p2p/base/p2p_transport_channel.h | 2+-
Mthird_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc | 160++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Mthird_party/libwebrtc/p2p/base/port_allocator.cc | 5++++-
Mthird_party/libwebrtc/p2p/base/port_allocator.h | 6+++---
Mthird_party/libwebrtc/p2p/base/stun_port.cc | 10+++++-----
Mthird_party/libwebrtc/p2p/base/stun_port.h | 14++++++--------
Mthird_party/libwebrtc/p2p/base/stun_port_unittest.cc | 12++++++------
Mthird_party/libwebrtc/p2p/client/basic_port_allocator.cc | 2+-
Mthird_party/libwebrtc/p2p/client/basic_port_allocator.h | 2+-
Mthird_party/libwebrtc/p2p/test/fake_ice_transport.h | 2+-
Mthird_party/libwebrtc/pc/jsep_transport_controller_unittest.cc | 197+++++++++++++++++++++++++++++++++----------------------------------------------
Mthird_party/libwebrtc/pc/peer_connection_ice_unittest.cc | 10++++------
19 files changed, 342 insertions(+), 350 deletions(-)

diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor @@ -1,4 +1,4 @@ # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc -libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-01T23:52:14.394175+00:00. +libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-01T23:55:14.213672+00:00. # base of lastest vendoring -e45e523f79 +176f169606 diff --git a/third_party/libwebrtc/p2p/base/basic_ice_controller.cc b/third_party/libwebrtc/p2p/base/basic_ice_controller.cc @@ -132,16 +132,15 @@ IceControllerInterface::PingResult BasicIceController::SelectConnectionToPing( return conn->active() && conn->num_pings_sent() < kMinPingsAtWeakPingInterval; }); - int ping_interval = (weak() || need_more_pings_at_weak_interval) - ? weak_ping_interval() - : strong_ping_interval(); + TimeDelta ping_interval = (weak() || need_more_pings_at_weak_interval) + ? weak_ping_interval() + : strong_ping_interval(); const Connection* conn = nullptr; - if (TimeMillis() >= last_ping_sent_ms + ping_interval) { + if (TimeMillis() >= last_ping_sent_ms + ping_interval.ms()) { conn = FindNextPingableConnection(); } - PingResult res(conn, std::min(ping_interval, check_receiving_interval())); - return res; + return PingResult(conn, std::min(ping_interval, check_receiving_interval())); } void BasicIceController::MarkConnectionPinged(const Connection* conn) { @@ -265,11 +264,11 @@ const Connection* BasicIceController::FindOldestConnectionNeedingTriggeredCheck( bool BasicIceController::WritableConnectionPastPingInterval( const Connection* conn, int64_t now) const { - int interval = CalculateActiveWritablePingInterval(conn, now); - return conn->last_ping_sent() + interval <= now; + TimeDelta interval = CalculateActiveWritablePingInterval(conn, now); + return conn->LastPingSent() + interval <= Timestamp::Millis(now); } -int BasicIceController::CalculateActiveWritablePingInterval( +TimeDelta BasicIceController::CalculateActiveWritablePingInterval( const Connection* conn, int64_t now) const { // Ping each connection at a higher rate at least @@ -278,10 +277,10 @@ int BasicIceController::CalculateActiveWritablePingInterval( return weak_ping_interval(); } - int stable_interval = + TimeDelta stable_interval = config_.stable_writable_connection_ping_interval_or_default(); - int weak_or_stablizing_interval = std::min<int>( - stable_interval, kWeakOrStabilizingWritableConnectionPingInterval.ms()); + TimeDelta weak_or_stablizing_interval = std::min( + stable_interval, kWeakOrStabilizingWritableConnectionPingInterval); // If the channel is weak or the connection is not stable yet, use the // weak_or_stablizing_interval. return (!weak() && conn->stable(now)) ? stable_interval @@ -327,8 +326,9 @@ bool BasicIceController::IsPingable(const Connection* conn, int64_t now) const { // or not, but backup connections are pinged at a slower rate. if (IsBackupConnection(conn)) { return conn->rtt_samples() == 0 || - (now >= conn->last_ping_response_received() + - config_.backup_connection_ping_interval_or_default()); + (now >= + conn->last_ping_response_received() + + config_.backup_connection_ping_interval_or_default().ms()); } // Don't ping inactive non-backup connections. if (!conn->active()) { @@ -519,20 +519,20 @@ IceControllerInterface::SwitchResult BasicIceController::ShouldSwitchConnection( bool missed_receiving_unchanged_threshold = false; std::optional<int64_t> receiving_unchanged_threshold( - TimeMillis() - config_.receiving_switching_delay_or_default()); + TimeMillis() - config_.receiving_switching_delay_or_default().ms()); int cmp = CompareConnections(selected_connection_, new_connection, receiving_unchanged_threshold, &missed_receiving_unchanged_threshold); std::optional<IceRecheckEvent> recheck_event; if (missed_receiving_unchanged_threshold && - config_.receiving_switching_delay_or_default()) { + config_.receiving_switching_delay_or_default() > TimeDelta::Zero()) { // If we do not switch to the connection because it missed the receiving // threshold, the new connection is in a better receiving state than the // currently selected connection. So we need to re-check whether it needs // to be switched at a later time. recheck_event.emplace(reason, - config_.receiving_switching_delay_or_default()); + config_.receiving_switching_delay_or_default().ms()); } if (cmp < 0) { diff --git a/third_party/libwebrtc/p2p/base/basic_ice_controller.h b/third_party/libwebrtc/p2p/base/basic_ice_controller.h @@ -76,19 +76,19 @@ class BasicIceController : public IceControllerInterface { return !selected_connection_ || selected_connection_->weak(); } - int weak_ping_interval() const { + TimeDelta weak_ping_interval() const { return std::max(config_.ice_check_interval_weak_connectivity_or_default(), config_.ice_check_min_interval_or_default()); } - int strong_ping_interval() const { + TimeDelta strong_ping_interval() const { return std::max(config_.ice_check_interval_strong_connectivity_or_default(), config_.ice_check_min_interval_or_default()); } - int check_receiving_interval() const { - return std::max<int>(kMinCheckReceivingInterval.ms(), - config_.receiving_timeout_or_default() / 10); + TimeDelta check_receiving_interval() const { + return std::max(kMinCheckReceivingInterval, + config_.receiving_timeout_or_default() / 10); } const Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); @@ -110,8 +110,8 @@ class BasicIceController : public IceControllerInterface { // pinged again. bool WritableConnectionPastPingInterval(const Connection* conn, int64_t now) const; - int CalculateActiveWritablePingInterval(const Connection* conn, - int64_t now) const; + TimeDelta CalculateActiveWritablePingInterval(const Connection* conn, + int64_t now) const; std::map<const Network*, const Connection*> GetBestConnectionByNetwork() const; diff --git a/third_party/libwebrtc/p2p/base/ice_controller_interface.h b/third_party/libwebrtc/p2p/base/ice_controller_interface.h @@ -81,6 +81,13 @@ class IceControllerInterface { : connection(conn ? std::optional<const Connection*>(conn) : std::nullopt), recheck_delay_ms(_recheck_delay_ms) {} + PingResult(const Connection* conn, TimeDelta recheck_delay) + : connection(conn ? std::optional(conn) : std::nullopt), + recheck_delay_ms(recheck_delay.ms()) {} + + TimeDelta recheck_delay() const { + return TimeDelta::Millis(recheck_delay_ms); + } // Connection that we should (optionally) ping. const std::optional<const Connection*> connection; diff --git a/third_party/libwebrtc/p2p/base/ice_transport_internal.cc b/third_party/libwebrtc/p2p/base/ice_transport_internal.cc @@ -29,13 +29,20 @@ namespace webrtc { namespace { // RTCConfiguration uses kUndefined (-1) to indicate unset optional parameters. -std::optional<int> RTCConfigurationToIceConfigOptionalInt( +std::optional<TimeDelta> RTCConfigurationToIceConfigOptionalMillis( int rtc_configuration_parameter) { if (rtc_configuration_parameter == PeerConnectionInterface::RTCConfiguration::kUndefined) { return std::nullopt; } - return rtc_configuration_parameter; + return TimeDelta::Millis(rtc_configuration_parameter); +} + +std::optional<TimeDelta> ToOptionalMillis(std::optional<int> ms) { + if (ms == std::nullopt) { + return std::nullopt; + } + return TimeDelta::Millis(*ms); } ContinualGatheringPolicy GetContinualGatheringPolicy( @@ -97,97 +104,98 @@ RTCError VerifyCandidates(const Candidates& candidates) { IceConfig::IceConfig() = default; -IceConfig::IceConfig(int receiving_timeout_ms, - int backup_connection_ping_interval, +IceConfig::IceConfig(TimeDelta receiving_timeout, + TimeDelta backup_connection_ping_interval, ContinualGatheringPolicy gathering_policy, bool prioritize_most_likely_candidate_pairs, - int stable_writable_connection_ping_interval_ms, + TimeDelta stable_writable_connection_ping_interval, bool presume_writable_when_fully_relayed, - int regather_on_failed_networks_interval_ms, - int receiving_switching_delay_ms) - : receiving_timeout(receiving_timeout_ms), + TimeDelta regather_on_failed_networks_interval, + TimeDelta receiving_switching_delay) + : receiving_timeout(receiving_timeout), backup_connection_ping_interval(backup_connection_ping_interval), continual_gathering_policy(gathering_policy), prioritize_most_likely_candidate_pairs( prioritize_most_likely_candidate_pairs), stable_writable_connection_ping_interval( - stable_writable_connection_ping_interval_ms), + stable_writable_connection_ping_interval), presume_writable_when_fully_relayed(presume_writable_when_fully_relayed), regather_on_failed_networks_interval( - regather_on_failed_networks_interval_ms), - receiving_switching_delay(receiving_switching_delay_ms) {} + regather_on_failed_networks_interval), + receiving_switching_delay(receiving_switching_delay) {} IceConfig::IceConfig(const PeerConnectionInterface::RTCConfiguration& config) - : receiving_timeout(RTCConfigurationToIceConfigOptionalInt( + : receiving_timeout(RTCConfigurationToIceConfigOptionalMillis( config.ice_connection_receiving_timeout)), - backup_connection_ping_interval(RTCConfigurationToIceConfigOptionalInt( + backup_connection_ping_interval(RTCConfigurationToIceConfigOptionalMillis( config.ice_backup_candidate_pair_ping_interval)), continual_gathering_policy(GetContinualGatheringPolicy(config)), prioritize_most_likely_candidate_pairs( config.prioritize_most_likely_ice_candidate_pairs), stable_writable_connection_ping_interval( - config.stable_writable_connection_ping_interval_ms), + ToOptionalMillis(config.stable_writable_connection_ping_interval_ms)), presume_writable_when_fully_relayed( config.presume_writable_when_fully_relayed), surface_ice_candidates_on_ice_transport_type_changed( config.surface_ice_candidates_on_ice_transport_type_changed), ice_check_interval_strong_connectivity( - config.ice_check_interval_strong_connectivity), + ToOptionalMillis(config.ice_check_interval_strong_connectivity)), ice_check_interval_weak_connectivity( - config.ice_check_interval_weak_connectivity), - ice_check_min_interval(config.ice_check_min_interval), - ice_unwritable_timeout(config.ice_unwritable_timeout), + ToOptionalMillis(config.ice_check_interval_weak_connectivity)), + ice_check_min_interval(ToOptionalMillis(config.ice_check_min_interval)), + ice_unwritable_timeout(ToOptionalMillis(config.ice_unwritable_timeout)), ice_unwritable_min_checks(config.ice_unwritable_min_checks), - ice_inactive_timeout(config.ice_inactive_timeout), - stun_keepalive_interval(config.stun_candidate_keepalive_interval), + ice_inactive_timeout(ToOptionalMillis(config.ice_inactive_timeout)), + stun_keepalive_interval( + ToOptionalMillis(config.stun_candidate_keepalive_interval)), network_preference(config.network_preference) {} IceConfig::~IceConfig() = default; -int IceConfig::receiving_timeout_or_default() const { - return receiving_timeout.value_or(kReceivingTimeout.ms()); +TimeDelta IceConfig::receiving_timeout_or_default() const { + return receiving_timeout.value_or(kReceivingTimeout); } -int IceConfig::backup_connection_ping_interval_or_default() const { +TimeDelta IceConfig::backup_connection_ping_interval_or_default() const { return backup_connection_ping_interval.value_or( - kBackupConnectionPingInterval.ms()); + kBackupConnectionPingInterval); } -int IceConfig::stable_writable_connection_ping_interval_or_default() const { +TimeDelta IceConfig::stable_writable_connection_ping_interval_or_default() + const { return stable_writable_connection_ping_interval.value_or( - kStrongAndStableWritableConnectionPingInterval.ms()); + kStrongAndStableWritableConnectionPingInterval); } -int IceConfig::regather_on_failed_networks_interval_or_default() const { +TimeDelta IceConfig::regather_on_failed_networks_interval_or_default() const { return regather_on_failed_networks_interval.value_or( - kRegatherOnFailedNetworksInterval.ms()); + kRegatherOnFailedNetworksInterval); } -int IceConfig::receiving_switching_delay_or_default() const { - return receiving_switching_delay.value_or(kReceivingSwitchingDelay.ms()); +TimeDelta IceConfig::receiving_switching_delay_or_default() const { + return receiving_switching_delay.value_or(kReceivingSwitchingDelay); } -int IceConfig::ice_check_interval_strong_connectivity_or_default() const { - return ice_check_interval_strong_connectivity.value_or( - kStrongPingInterval.ms()); +TimeDelta IceConfig::ice_check_interval_strong_connectivity_or_default() const { + return ice_check_interval_strong_connectivity.value_or(kStrongPingInterval); } -int IceConfig::ice_check_interval_weak_connectivity_or_default() const { - return ice_check_interval_weak_connectivity.value_or(kWeakPingInterval.ms()); +TimeDelta IceConfig::ice_check_interval_weak_connectivity_or_default() const { + return ice_check_interval_weak_connectivity.value_or(kWeakPingInterval); } -int IceConfig::ice_check_min_interval_or_default() const { - return ice_check_min_interval.value_or(-1); +TimeDelta IceConfig::ice_check_min_interval_or_default() const { + return ice_check_min_interval.value_or(TimeDelta::Millis(-1)); } -int IceConfig::ice_unwritable_timeout_or_default() const { - return ice_unwritable_timeout.value_or(kConnectionWriteConnectTimeout.ms()); +TimeDelta IceConfig::ice_unwritable_timeout_or_default() const { + return ice_unwritable_timeout.value_or(kConnectionWriteConnectTimeout); } int IceConfig::ice_unwritable_min_checks_or_default() const { return ice_unwritable_min_checks.value_or(kConnectionWriteConnectFailures); } -int IceConfig::ice_inactive_timeout_or_default() const { - return ice_inactive_timeout.value_or(kConnectionWriteTimeout.ms()); +TimeDelta IceConfig::ice_inactive_timeout_or_default() const { + return ice_inactive_timeout.value_or(kConnectionWriteTimeout); } -int IceConfig::stun_keepalive_interval_or_default() const { - return stun_keepalive_interval.value_or(kStunKeepaliveInterval.ms()); +TimeDelta IceConfig::stun_keepalive_interval_or_default() const { + return stun_keepalive_interval.value_or(kStunKeepaliveInterval); } RTCError IceConfig::IsValid() const { if (ice_check_interval_strong_connectivity_or_default() < - ice_check_interval_weak_connectivity.value_or(kWeakPingInterval.ms())) { + ice_check_interval_weak_connectivity.value_or(kWeakPingInterval)) { return RTCError(RTCErrorType::INVALID_PARAMETER, "Ping interval of candidate pairs is shorter when ICE is " "strongly connected than that when ICE is weakly " diff --git a/third_party/libwebrtc/p2p/base/ice_transport_internal.h b/third_party/libwebrtc/p2p/base/ice_transport_internal.h @@ -123,11 +123,11 @@ RTCError VerifyCandidates(const Candidates& candidates); // Information about ICE configuration. // TODO(bugs.webrtc.org/15609): Define a public API for this. struct RTC_EXPORT IceConfig { - // The ICE connection receiving timeout value in milliseconds. - std::optional<int> receiving_timeout; - // Time interval in milliseconds to ping a backup connection when the ICE - // channel is strongly connected. - std::optional<int> backup_connection_ping_interval; + // The ICE connection receiving timeout value. + std::optional<TimeDelta> receiving_timeout; + // Time interval to ping a backup connection when the ICE channel is strongly + // connected. + std::optional<TimeDelta> backup_connection_ping_interval; ContinualGatheringPolicy continual_gathering_policy = GATHER_ONCE; @@ -140,7 +140,7 @@ struct RTC_EXPORT IceConfig { bool prioritize_most_likely_candidate_pairs = false; // Writable connections are pinged at a slower rate once stablized. - std::optional<int> stable_writable_connection_ping_interval; + std::optional<TimeDelta> stable_writable_connection_ping_interval; // If set to true, this means the ICE transport should presume TURN-to-TURN // candidate pairs will succeed, even before a binding response is received. @@ -155,40 +155,39 @@ struct RTC_EXPORT IceConfig { // Interval to check on all networks and to perform ICE regathering on any // active network having no connection on it. - std::optional<int> regather_on_failed_networks_interval; + std::optional<TimeDelta> regather_on_failed_networks_interval; // The time period in which we will not switch the selected connection // when a new connection becomes receiving but the selected connection is not // in case that the selected connection may become receiving soon. - std::optional<int> receiving_switching_delay; + std::optional<TimeDelta> receiving_switching_delay; // TODO(honghaiz): Change the default to regular nomination. // Default nomination mode if the remote does not support renomination. NominationMode default_nomination_mode = NominationMode::SEMI_AGGRESSIVE; - // The interval in milliseconds at which ICE checks (STUN pings) will be sent - // for a candidate pair when it is both writable and receiving (strong - // connectivity). This parameter overrides the default value given by - // `kStrongPingInterval` in p2ptransport.h if set. - std::optional<int> ice_check_interval_strong_connectivity; - // The interval in milliseconds at which ICE checks (STUN pings) will be sent - // for a candidate pair when it is either not writable or not receiving (weak - // connectivity). This parameter overrides the default value given by - // `kWeakPingInterval` in p2ptransport.h if set. - std::optional<int> ice_check_interval_weak_connectivity; + // The interval at which ICE checks (STUN pings) will be sent for a candidate + // pair when it is both writable and receiving (strong connectivity). This + // parameter overrides the default value given by `kStrongPingInterval` in + // p2ptransport.h if set. + std::optional<TimeDelta> ice_check_interval_strong_connectivity; + // The interval \at which ICE checks (STUN pings) will be sent for a candidate + // pair when it is either not writable or not receiving (weak connectivity). + // This parameter overrides the default value given by `kWeakPingInterval` in + // p2ptransport.h if set. + std::optional<TimeDelta> ice_check_interval_weak_connectivity; // ICE checks (STUN pings) will not be sent at higher rate (lower interval) // than this, no matter what other settings there are. - // Measure in milliseconds. // // Note that this parameter overrides both the above check intervals for // candidate pairs with strong or weak connectivity, if either of the above // interval is shorter than the min interval. - std::optional<int> ice_check_min_interval; + std::optional<TimeDelta> ice_check_min_interval; // The min time period for which a candidate pair must wait for response to // connectivity checks before it becomes unwritable. This parameter - // overrides the default value given by `CONNECTION_WRITE_CONNECT_TIMEOUT` + // overrides the default value given by `kConnectionWriteConnectTimeout` // in port.h if set, when determining the writability of a candidate pair. - std::optional<int> ice_unwritable_timeout; + std::optional<TimeDelta> ice_unwritable_timeout; // The min number of connectivity checks that a candidate pair must sent // without receiving response before it becomes unwritable. This parameter @@ -200,11 +199,11 @@ struct RTC_EXPORT IceConfig { // connectivity checks it becomes inactive. This parameter overrides the // default value given by `kConnectionWriteTimeout` in port.h if set, when // determining the writability of a candidate pair. - std::optional<int> ice_inactive_timeout; + std::optional<TimeDelta> ice_inactive_timeout; - // The interval in milliseconds at which STUN candidates will resend STUN - // binding requests to keep NAT bindings open. - std::optional<int> stun_keepalive_interval; + // The interval at which STUN candidates will resend STUN binding requests to + // keep NAT bindings open. + std::optional<TimeDelta> stun_keepalive_interval; std::optional<AdapterType> network_preference; @@ -214,14 +213,14 @@ struct RTC_EXPORT IceConfig { bool dtls_handshake_in_stun = false; IceConfig(); - IceConfig(int receiving_timeout_ms, - int backup_connection_ping_interval, + IceConfig(TimeDelta receiving_timeout, + TimeDelta backup_connection_ping_interval, ContinualGatheringPolicy gathering_policy, bool prioritize_most_likely_candidate_pairs, - int stable_writable_connection_ping_interval_ms, + TimeDelta stable_writable_connection_ping_interval, bool presume_writable_when_fully_relayed, - int regather_on_failed_networks_interval_ms, - int receiving_switching_delay_ms); + TimeDelta regather_on_failed_networks_interval, + TimeDelta receiving_switching_delay); // Construct an IceConfig object from an RTCConfiguration object. // This will check the `config` settings and set the associated IceConfig // member properties. @@ -234,18 +233,18 @@ struct RTC_EXPORT IceConfig { // Helper getters for parameters with implementation-specific default value. // By convention, parameters with default value are represented by // std::optional and setting a parameter to null restores its default value. - int receiving_timeout_or_default() const; - int backup_connection_ping_interval_or_default() const; - int stable_writable_connection_ping_interval_or_default() const; - int regather_on_failed_networks_interval_or_default() const; - int receiving_switching_delay_or_default() const; - int ice_check_interval_strong_connectivity_or_default() const; - int ice_check_interval_weak_connectivity_or_default() const; - int ice_check_min_interval_or_default() const; - int ice_unwritable_timeout_or_default() const; + TimeDelta receiving_timeout_or_default() const; + TimeDelta backup_connection_ping_interval_or_default() const; + TimeDelta stable_writable_connection_ping_interval_or_default() const; + TimeDelta regather_on_failed_networks_interval_or_default() const; + TimeDelta receiving_switching_delay_or_default() const; + TimeDelta ice_check_interval_strong_connectivity_or_default() const; + TimeDelta ice_check_interval_weak_connectivity_or_default() const; + TimeDelta ice_check_min_interval_or_default() const; + TimeDelta ice_unwritable_timeout_or_default() const; int ice_unwritable_min_checks_or_default() const; - int ice_inactive_timeout_or_default() const; - int stun_keepalive_interval_or_default() const; + TimeDelta ice_inactive_timeout_or_default() const; + TimeDelta stun_keepalive_interval_or_default() const; }; // IceTransportInternal is an internal abstract class that does ICE. diff --git a/third_party/libwebrtc/p2p/base/p2p_transport_channel.cc b/third_party/libwebrtc/p2p/base/p2p_transport_channel.cc @@ -187,14 +187,14 @@ P2PTransportChannel::P2PTransportChannel( ice_role_(ICEROLE_UNKNOWN), gathering_state_(kIceGatheringNew), weak_ping_interval_(GetWeakPingIntervalInFieldTrial(env_.field_trials())), - config_(kReceivingTimeout.ms(), - kBackupConnectionPingInterval.ms(), + config_(kReceivingTimeout, + kBackupConnectionPingInterval, GATHER_ONCE /* continual_gathering_policy */, false /* prioritize_most_likely_candidate_pairs */, - kStrongAndStableWritableConnectionPingInterval.ms(), + kStrongAndStableWritableConnectionPingInterval, true /* presume_writable_when_fully_relayed */, - kRegatherOnFailedNetworksInterval.ms(), - kReceivingSwitchingDelay.ms()) { + kRegatherOnFailedNetworksInterval, + kReceivingSwitchingDelay) { TRACE_EVENT0("webrtc", "P2PTransportChannel::P2PTransportChannel"); RTC_DCHECK(allocator_ != nullptr); RTC_DCHECK(!transport_name_.empty()); @@ -203,7 +203,7 @@ P2PTransportChannel::P2PTransportChannel( RTC_DCHECK(config_.IsValid().ok()); BasicRegatheringController::Config regathering_config; regathering_config.regather_on_failed_networks_interval = - config_.regather_on_failed_networks_interval_or_default(); + config_.regather_on_failed_networks_interval_or_default().ms(); regathering_controller_ = std::make_unique<BasicRegatheringController>( regathering_config, this, network_thread_); // We populate the change in the candidate filter to the session taken by @@ -279,10 +279,10 @@ void P2PTransportChannel::AddAllocatorSession( void P2PTransportChannel::AddConnection(Connection* connection) { RTC_DCHECK_RUN_ON(network_thread_); - connection->set_receiving_timeout(config_.receiving_timeout); - connection->set_unwritable_timeout(config_.ice_unwritable_timeout); + connection->SetReceivingTimeout(config_.receiving_timeout); + connection->SetUnwritableTimeout(config_.ice_unwritable_timeout); connection->set_unwritable_min_checks(config_.ice_unwritable_min_checks); - connection->set_inactive_timeout(config_.ice_inactive_timeout); + connection->SetInactiveTimeout(config_.ice_inactive_timeout); connection->RegisterReceivedPacketCallback( [&](Connection* connection, const ReceivedIpPacket& packet) { OnReadPacket(connection, packet); @@ -554,7 +554,7 @@ void P2PTransportChannel::SetIceConfig(const IceConfig& config) { if (config_.receiving_timeout != config.receiving_timeout) { config_.receiving_timeout = config.receiving_timeout; for (Connection* connection : connections_) { - connection->set_receiving_timeout(config_.receiving_timeout); + connection->SetReceivingTimeout(config_.receiving_timeout); } RTC_LOG(LS_INFO) << "Set ICE receiving timeout to " << config_.receiving_timeout_or_default() @@ -645,7 +645,7 @@ void P2PTransportChannel::SetIceConfig(const IceConfig& config) { if (config_.ice_unwritable_timeout != config.ice_unwritable_timeout) { config_.ice_unwritable_timeout = config.ice_unwritable_timeout; for (Connection* conn : connections_) { - conn->set_unwritable_timeout(config_.ice_unwritable_timeout); + conn->SetUnwritableTimeout(config_.ice_unwritable_timeout); } RTC_LOG(LS_INFO) << "Set unwritable timeout to " << config_.ice_unwritable_timeout_or_default(); @@ -663,7 +663,7 @@ void P2PTransportChannel::SetIceConfig(const IceConfig& config) { if (config_.ice_inactive_timeout != config.ice_inactive_timeout) { config_.ice_inactive_timeout = config.ice_inactive_timeout; for (Connection* conn : connections_) { - conn->set_inactive_timeout(config_.ice_inactive_timeout); + conn->SetInactiveTimeout(config_.ice_inactive_timeout); } RTC_LOG(LS_INFO) << "Set inactive timeout to " << config_.ice_inactive_timeout_or_default(); @@ -692,7 +692,7 @@ void P2PTransportChannel::SetIceConfig(const IceConfig& config) { BasicRegatheringController::Config regathering_config; regathering_config.regather_on_failed_networks_interval = - config_.regather_on_failed_networks_interval_or_default(); + config_.regather_on_failed_networks_interval_or_default().ms(); regathering_controller_->SetConfig(regathering_config); config_.vpn_preference = config.vpn_preference; @@ -826,10 +826,10 @@ const Connection* P2PTransportChannel::selected_connection() const { return selected_connection_; } -int P2PTransportChannel::check_receiving_interval() const { +TimeDelta P2PTransportChannel::check_receiving_interval() const { RTC_DCHECK_RUN_ON(network_thread_); - return std::max<int>(kMinCheckReceivingInterval.ms(), - config_.receiving_timeout_or_default() / 10); + return std::max(kMinCheckReceivingInterval, + config_.receiving_timeout_or_default() / 10); } void P2PTransportChannel::MaybeStartGathering() { diff --git a/third_party/libwebrtc/p2p/base/p2p_transport_channel.h b/third_party/libwebrtc/p2p/base/p2p_transport_channel.h @@ -197,7 +197,7 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal, } void PruneAllPorts(); - int check_receiving_interval() const; + TimeDelta check_receiving_interval() const; std::optional<NetworkRoute> network_route() const override; void RemoveConnection(Connection* connection); diff --git a/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc b/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc @@ -176,9 +176,9 @@ const IceParameters kIceParams[4] = {{kIceUfrag[0], kIcePwd[0], false}, {kIceUfrag[3], kIcePwd[3], false}}; IceConfig CreateIceConfig( - int receiving_timeout, + TimeDelta receiving_timeout, ContinualGatheringPolicy continual_gathering_policy, - std::optional<int> backup_ping_interval = std::nullopt) { + std::optional<TimeDelta> backup_ping_interval = std::nullopt) { IceConfig config; config.receiving_timeout = receiving_timeout; config.continual_gathering_policy = continual_gathering_policy; @@ -1363,7 +1363,7 @@ TEST_F(P2PTransportChannelTest, GetStatsSwitchConnection) { ScopedFakeClock clock; const Environment env = CreateEnvironment(); IceConfig continual_gathering_config = - CreateIceConfig(1000, GATHER_CONTINUALLY); + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); ConfigureEndpoints(env, OPEN, OPEN, kDefaultPortAllocatorFlags, kDefaultPortAllocatorFlags); @@ -1444,7 +1444,7 @@ TEST_F(P2PTransportChannelTest, // ep1 gathers continually but ep2 does not. IceConfig continual_gathering_config = - CreateIceConfig(1000, GATHER_CONTINUALLY); + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); IceConfig default_config; CreateChannels(env, continual_gathering_config, default_config); @@ -1484,10 +1484,11 @@ TEST_F(P2PTransportChannelTest, ConfigureEndpoints(env, OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts); // ep1 gathers continually but ep2 does not. - IceConfig config1 = CreateIceConfig(1000, GATHER_CONTINUALLY); - config1.regather_on_failed_networks_interval = 2000; + IceConfig config1 = + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); + config1.regather_on_failed_networks_interval = TimeDelta::Seconds(2); IceConfig config2; - config2.regather_on_failed_networks_interval = 2000; + config2.regather_on_failed_networks_interval = TimeDelta::Seconds(2); CreateChannels(env, config1, config2); EXPECT_TRUE(WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, @@ -2078,7 +2079,7 @@ TEST_F(P2PTransportChannelTest, TestContinualGathering) { SetAllocationStepDelay(0, kDefaultStepDelay); SetAllocationStepDelay(1, kDefaultStepDelay); IceConfig continual_gathering_config = - CreateIceConfig(1000, GATHER_CONTINUALLY); + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); // By default, ep2 does not gather continually. IceConfig default_config; CreateChannels(env, continual_gathering_config, default_config); @@ -2421,14 +2422,15 @@ TEST_F(P2PTransportChannelTest, "WebRTC-PiggybackIceCheckAcknowledgement/Enabled/")); ConfigureEndpoints(env, OPEN, OPEN, kOnlyLocalPorts, kOnlyLocalPorts); IceConfig ep1_config; - IceConfig ep2_config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig ep2_config = + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); // Let ep2 be tolerable of the loss of connectivity checks, so that it keeps // sending pings even after ep1 becomes unwritable as we configure the // firewall below. - ep2_config.receiving_timeout = 30 * 1000; - ep2_config.ice_unwritable_timeout = 30 * 1000; + ep2_config.receiving_timeout = TimeDelta::Seconds(30); + ep2_config.ice_unwritable_timeout = TimeDelta::Seconds(30); ep2_config.ice_unwritable_min_checks = 30; - ep2_config.ice_inactive_timeout = 60 * 1000; + ep2_config.ice_inactive_timeout = TimeDelta::Seconds(60); CreateChannels(env, ep1_config, ep2_config); @@ -2597,7 +2599,7 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) { SetAllocatorFlags(1, kOnlyLocalPorts); // Make the receiving timeout shorter for testing. - IceConfig config = CreateIceConfig(1000, GATHER_ONCE); + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_ONCE); // Create channels and let them go writable, as usual. CreateChannels(env, config, config); @@ -2650,7 +2652,7 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { SetAllocatorFlags(1, kOnlyLocalPorts); // Make the receiving timeout shorter for testing. - IceConfig config = CreateIceConfig(1000, GATHER_ONCE); + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_ONCE); // Create channels and let them go writable, as usual. CreateChannels(env, config, config); EXPECT_TRUE(WaitUntil( @@ -2718,7 +2720,7 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverWithManyConnections) { virtual_socket_server()->UpdateDelayDistribution(); // Make the receiving timeout shorter for testing. - IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); // Create channels and let them go writable, as usual. CreateChannels(env, config, config, true /* ice_renomination */); EXPECT_TRUE(WaitUntil( @@ -2796,7 +2798,7 @@ TEST_F(P2PTransportChannelMultihomedTest, TestIceRenomination) { // We want it to set the remote ICE parameters when creating channels. set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); // Make the receiving timeout shorter for testing. - IceConfig config = CreateIceConfig(1000, GATHER_ONCE); + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_ONCE); // Create channels with ICE renomination and let them go writable as usual. CreateChannels(env, config, config, true); ASSERT_TRUE(WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, @@ -2868,7 +2870,7 @@ TEST_F(P2PTransportChannelMultihomedTest, {.timeout = kMediumTimeout, .clock = &clock})); // Make the receiving timeout shorter for testing. - IceConfig config = CreateIceConfig(1000, GATHER_ONCE); + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_ONCE); ep1_ch1()->SetIceConfig(config); ep2_ch1()->SetIceConfig(config); reset_selected_candidate_pair_switches(); @@ -2927,7 +2929,7 @@ TEST_F(P2PTransportChannelMultihomedTest, {.timeout = kMediumTimeout, .clock = &clock})); // Make the receiving timeout shorter for testing. - IceConfig config = CreateIceConfig(1000, GATHER_ONCE); + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_ONCE); ep1_ch1()->SetIceConfig(config); ep2_ch1()->SetIceConfig(config); reset_selected_candidate_pair_switches(); @@ -2977,9 +2979,10 @@ TEST_F(P2PTransportChannelMultihomedTest, TestRemoteFailover) { CreateChannels(env); // Make the receiving timeout shorter for testing. // Set the backup connection ping interval to 25s. - IceConfig config = CreateIceConfig(1000, GATHER_ONCE, 25000); + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_ONCE, + TimeDelta::Seconds(25)); // Ping the best connection more frequently since we don't have traffic. - config.stable_writable_connection_ping_interval = 900; + config.stable_writable_connection_ping_interval = TimeDelta::Millis(900); ep1_ch1()->SetIceConfig(config); ep2_ch1()->SetIceConfig(config); // Need to wait to make sure the connections on both networks are writable. @@ -3084,9 +3087,9 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { // Create channels and let them go writable, as usual. CreateChannels(env); EXPECT_TRUE(WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); })); - int backup_ping_interval = 2000; - ep2_ch1()->SetIceConfig( - CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval)); + TimeDelta backup_ping_interval = TimeDelta::Seconds(2); + ep2_ch1()->SetIceConfig(CreateIceConfig(TimeDelta::Seconds(2), GATHER_ONCE, + backup_ping_interval)); // After the state becomes COMPLETED, the backup connection will be pinged // once every `backup_ping_interval` milliseconds. ASSERT_THAT(WaitUntil([&] { return ep2_ch1()->GetState(); }, @@ -3097,13 +3100,12 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { Connection* backup_conn = GetBackupConnection(ep2_ch1()); EXPECT_TRUE(WaitUntil([&] { return backup_conn->writable(); }, {.timeout = kMediumTimeout})); - int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); - EXPECT_THAT( - WaitUntil([&] { return backup_conn->last_ping_response_received(); }, - Gt(last_ping_response_ms), {.timeout = kDefaultTimeout}), - IsRtcOk()); - int time_elapsed = - backup_conn->last_ping_response_received() - last_ping_response_ms; + Timestamp last_ping_response = backup_conn->LastPingResponseReceived(); + EXPECT_THAT(WaitUntil([&] { return backup_conn->LastPingResponseReceived(); }, + Gt(last_ping_response), {.timeout = kDefaultTimeout}), + IsRtcOk()); + TimeDelta time_elapsed = + backup_conn->LastPingResponseReceived() - last_ping_response; RTC_LOG(LS_INFO) << "Time elapsed: " << time_elapsed; EXPECT_GE(time_elapsed, backup_ping_interval); @@ -3129,12 +3131,12 @@ TEST_F(P2PTransportChannelMultihomedTest, TestStableWritableRate) { CreateChannels(env); EXPECT_TRUE(WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); })); // Set a value larger than the default value of 2500 ms - int ping_interval_ms = 3456; - IceConfig config = CreateIceConfig(2 * ping_interval_ms, GATHER_ONCE); - config.stable_writable_connection_ping_interval = ping_interval_ms; + TimeDelta ping_interval = TimeDelta::Millis(3'456); + IceConfig config = CreateIceConfig(2 * ping_interval, GATHER_ONCE); + config.stable_writable_connection_ping_interval = ping_interval; ep2_ch1()->SetIceConfig(config); // After the state becomes COMPLETED and is stable and writable, the - // connection will be pinged once every `ping_interval_ms` milliseconds. + // connection will be pinged once every `ping_interval`. ASSERT_THAT(WaitUntil([&] { return ep2_ch1()->GetState(); }, Eq(IceTransportStateInternal::STATE_COMPLETED)), IsRtcOk()); @@ -3144,20 +3146,19 @@ TEST_F(P2PTransportChannelMultihomedTest, TestStableWritableRate) { EXPECT_TRUE( WaitUntil([&] { return conn->writable(); }, {.timeout = kMediumTimeout})); - int64_t last_ping_response_ms; + Timestamp last_ping_response = Timestamp::Zero(); // Burn through some pings so the connection is stable. for (int i = 0; i < 5; i++) { - last_ping_response_ms = conn->last_ping_response_received(); - EXPECT_THAT( - WaitUntil([&] { return conn->last_ping_response_received(); }, - Gt(last_ping_response_ms), {.timeout = kDefaultTimeout}), - IsRtcOk()); + last_ping_response = conn->LastPingResponseReceived(); + EXPECT_THAT(WaitUntil([&] { return conn->LastPingResponseReceived(); }, + Gt(last_ping_response), {.timeout = kDefaultTimeout}), + IsRtcOk()); } - EXPECT_TRUE(conn->stable(last_ping_response_ms)) << "Connection not stable"; - int time_elapsed = - conn->last_ping_response_received() - last_ping_response_ms; + EXPECT_TRUE(conn->stable(last_ping_response)) << "Connection not stable"; + TimeDelta time_elapsed = + conn->LastPingResponseReceived() - last_ping_response; RTC_LOG(LS_INFO) << "Time elapsed: " << time_elapsed; - EXPECT_GE(time_elapsed, ping_interval_ms); + EXPECT_GE(time_elapsed, ping_interval); DestroyChannels(); } @@ -3195,8 +3196,9 @@ TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { AddAddress(0, kPublicAddrs[0]); AddAddress(1, kPublicAddrs[1]); // Create channels and let them go writable, as usual. - IceConfig ep1_config = CreateIceConfig(2000, GATHER_CONTINUALLY); - IceConfig ep2_config = CreateIceConfig(2000, GATHER_ONCE); + IceConfig ep1_config = + CreateIceConfig(TimeDelta::Seconds(2), GATHER_CONTINUALLY); + IceConfig ep2_config = CreateIceConfig(TimeDelta::Seconds(2), GATHER_ONCE); CreateChannels(env, ep1_config, ep2_config); SetAllocatorFlags(0, kOnlyLocalPorts); @@ -3242,7 +3244,7 @@ TEST_F(P2PTransportChannelMultihomedTest, AddAddress(1, cellular[1], "test_cell1", ADAPTER_TYPE_CELLULAR); // Set continual gathering policy. IceConfig continual_gathering_config = - CreateIceConfig(1000, GATHER_CONTINUALLY); + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); CreateChannels(env, continual_gathering_config, continual_gathering_config); SetAllocatorFlags(0, kOnlyLocalPorts); SetAllocatorFlags(1, kOnlyLocalPorts); @@ -3313,7 +3315,7 @@ TEST_F(P2PTransportChannelMultihomedTest, // Set continual gathering policy. IceConfig continual_gathering_config = - CreateIceConfig(1000, GATHER_CONTINUALLY); + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); // Create channels and let them go writable, as usual. CreateChannels(env, continual_gathering_config, continual_gathering_config); EXPECT_TRUE(WaitUntil( @@ -3365,8 +3367,8 @@ TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { SetAllocatorFlags(1, kOnlyLocalPorts); // Create channels and let them go writable, as usual. - IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); - config.regather_on_failed_networks_interval = 2000; + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); + config.regather_on_failed_networks_interval = TimeDelta::Seconds(2); CreateChannels(env, config, config); EXPECT_TRUE(WaitUntil( [&] { @@ -4186,11 +4188,11 @@ TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { PrepareChannel(&ch); // Default receiving timeout and checking receiving interval should not be too // small. - EXPECT_LE(1000, ch.config().receiving_timeout_or_default()); - EXPECT_LE(200, ch.check_receiving_interval()); - ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); - EXPECT_EQ(500, ch.config().receiving_timeout_or_default()); - EXPECT_EQ(50, ch.check_receiving_interval()); + EXPECT_GE(ch.config().receiving_timeout_or_default(), TimeDelta::Seconds(1)); + EXPECT_GE(ch.check_receiving_interval(), TimeDelta::Millis(200)); + ch.SetIceConfig(CreateIceConfig(TimeDelta::Millis(500), GATHER_ONCE)); + EXPECT_EQ(ch.config().receiving_timeout_or_default(), TimeDelta::Millis(500)); + EXPECT_EQ(ch.check_receiving_interval(), TimeDelta::Millis(50)); ch.MaybeStartGathering(); ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 1)); @@ -4921,7 +4923,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { EXPECT_TRUE(WaitUntil([&] { return conn1->pruned(); }, {.timeout = kMediumTimeout, .clock = &clock})); - ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); + ch.SetIceConfig(CreateIceConfig(TimeDelta::Millis(500), GATHER_ONCE)); // Wait until conn2 becomes not receiving. EXPECT_TRUE(WaitUntil([&] { return !conn2->receiving(); }, {.timeout = kMediumTimeout, .clock = &clock})); @@ -5016,8 +5018,8 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { FakePortAllocator pa(env, ss()); P2PTransportChannel ch(env, "test channel", 1, &pa); PrepareChannel(&ch); - IceConfig config = CreateIceConfig(1000, GATHER_ONCE); - config.receiving_switching_delay = 800; + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_ONCE); + config.receiving_switching_delay = TimeDelta::Millis(800); ch.SetIceConfig(config); ch.MaybeStartGathering(); ch.AddRemoteCandidate( @@ -5115,7 +5117,7 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { FakePortAllocator pa(env, ss()); P2PTransportChannel ch(env, "test channel", 1, &pa); PrepareChannel(&ch); - ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); + ch.SetIceConfig(CreateIceConfig(TimeDelta::Seconds(2), GATHER_ONCE)); ch.MaybeStartGathering(); ch.AddRemoteCandidate( CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100)); @@ -5153,7 +5155,7 @@ TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) { &pa); // Starts with ICEROLE_CONTROLLING. PrepareChannel(&ch); - IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); ch.SetIceConfig(config); ch.MaybeStartGathering(); ch.AddRemoteCandidate( @@ -5288,7 +5290,7 @@ class P2PTransportChannelMostLikelyToWorkFirstTest P2PTransportChannel& StartTransportChannel( const Environment& env, bool prioritize_most_likely_to_work, - int stable_writable_connection_ping_interval) { + TimeDelta stable_writable_connection_ping_interval) { channel_ = std::make_unique<P2PTransportChannel>(env, "checks", 1, port_allocator_.get()); IceConfig config = channel_->config(); @@ -5333,7 +5335,7 @@ class P2PTransportChannelMostLikelyToWorkFirstTest TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestRelayRelayFirstWhenNothingPingedYet) { const Environment env = CreateEnvironment(); - const int max_strong_interval = 500; + const TimeDelta max_strong_interval = TimeDelta::Millis(500); CreatePortAllocator(env); P2PTransportChannel& ch = StartTransportChannel(env, true, max_strong_interval); @@ -5403,7 +5405,8 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestRelayRelayFirstWhenEverythingPinged) { const Environment env = CreateEnvironment(); CreatePortAllocator(env); - P2PTransportChannel& ch = StartTransportChannel(env, true, 500); + P2PTransportChannel& ch = + StartTransportChannel(env, true, TimeDelta::Millis(500)); EXPECT_THAT(WaitUntil([&] { return ch.ports().size(); }, Eq(2), {.timeout = kDefaultTimeout}), IsRtcOk()); @@ -5449,7 +5452,8 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestNoStarvationOnNonRelayConnection) { const Environment env = CreateEnvironment(); CreatePortAllocator(env); - P2PTransportChannel& ch = StartTransportChannel(env, true, 500); + P2PTransportChannel& ch = + StartTransportChannel(env, true, TimeDelta::Millis(500)); EXPECT_THAT(WaitUntil([&] { return ch.ports().size(); }, Eq(2), {.timeout = kDefaultTimeout}), IsRtcOk()); @@ -5498,7 +5502,8 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, const Environment env = CreateEnvironment(CreateTestFieldTrialsPtr( "WebRTC-IceFieldTrials/skip_relay_to_non_relay_connections:true/")); CreatePortAllocator(env); - P2PTransportChannel& ch = StartTransportChannel(env, true, 500); + P2PTransportChannel& ch = + StartTransportChannel(env, true, TimeDelta::Millis(500)); EXPECT_THAT(WaitUntil([&] { return ch.ports().size(); }, Eq(2), {.timeout = kDefaultTimeout}), IsRtcOk()); @@ -5531,7 +5536,8 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) { config.ports.push_back(ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP)); CreatePortAllocator(env).AddTurnServerForTesting(config); - P2PTransportChannel& ch = StartTransportChannel(env, true, 500); + P2PTransportChannel& ch = + StartTransportChannel(env, true, TimeDelta::Millis(500)); EXPECT_THAT(WaitUntil([&] { return ch.ports().size(); }, Eq(3), {.timeout = kDefaultTimeout}), IsRtcOk()); @@ -6162,7 +6168,8 @@ TEST_F(P2PTransportChannelTest, ep2->allocator_->SetCandidateFilter(CF_RELAY); // Enable continual gathering and also resurfacing gathered candidates upon // the candidate filter changed in the ICE configuration. - IceConfig ice_config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig ice_config = + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); ice_config.surface_ice_candidates_on_ice_transport_type_changed = true; CreateChannels(env, ice_config, ice_config); ASSERT_THAT( @@ -6237,7 +6244,8 @@ TEST_F(P2PTransportChannelTest, ep2->allocator_->SetCandidateFilter(CF_RELAY); // Enable continual gathering and also resurfacing gathered candidates upon // the candidate filter changed in the ICE configuration. - IceConfig ice_config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig ice_config = + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); ice_config.surface_ice_candidates_on_ice_transport_type_changed = true; CreateChannels(env, ice_config, ice_config); ASSERT_THAT( @@ -6304,7 +6312,7 @@ TEST_F(P2PTransportChannelTest, ep1->allocator_->SetCandidateFilter(CF_RELAY); ep2->allocator_->SetCandidateFilter(CF_RELAY); // Only gather once. - IceConfig ice_config = CreateIceConfig(1000, GATHER_ONCE); + IceConfig ice_config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_ONCE); ice_config.surface_ice_candidates_on_ice_transport_type_changed = true; CreateChannels(env, ice_config, ice_config); ASSERT_THAT( @@ -6345,7 +6353,8 @@ TEST_F(P2PTransportChannelTest, ep2->allocator_->SetCandidateFilter(CF_ALL); // Enable continual gathering and also resurfacing gathered candidates upon // the candidate filter changed in the ICE configuration. - IceConfig ice_config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig ice_config = + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); ice_config.surface_ice_candidates_on_ice_transport_type_changed = true; // Pause candidates so we can gather all types of candidates. See // P2PTransportChannel::OnConnectionStateChange, where we would stop the @@ -6426,7 +6435,8 @@ TEST_F(P2PTransportChannelTest, SurfaceRequiresCoordination) { ep2->allocator_->SetCandidateFilter(CF_ALL); // Enable continual gathering and also resurfacing gathered candidates upon // the candidate filter changed in the ICE configuration. - IceConfig ice_config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig ice_config = + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); ice_config.surface_ice_candidates_on_ice_transport_type_changed = true; // Pause candidates gathering so we can gather all types of candidates. See // P2PTransportChannel::OnConnectionStateChange, where we would stop the @@ -6910,7 +6920,8 @@ TEST_P(GatherAfterConnectedTest, GatherAfterConnected) { int delay = 3000; SetAllocationStepDelay(0, delay); SetAllocationStepDelay(1, delay); - IceConfig ice_config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig ice_config = + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); CreateChannels(env, ice_config, ice_config); PauseCandidates(0); @@ -6983,7 +6994,8 @@ TEST_P(GatherAfterConnectedTest, GatherAfterConnectedMultiHomed) { int delay = 3000; SetAllocationStepDelay(0, delay); SetAllocationStepDelay(1, delay); - IceConfig ice_config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig ice_config = + CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); CreateChannels(env, ice_config, ice_config); PauseCandidates(0); @@ -7040,7 +7052,7 @@ TEST_F(P2PTransportChannelTest, TestIceNoOldCandidatesAfterIceRestart) { kDefaultPortAllocatorFlags); // gathers continually. - IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); + IceConfig config = CreateIceConfig(TimeDelta::Seconds(1), GATHER_CONTINUALLY); CreateChannels(env, config, config); EXPECT_TRUE(WaitUntil([&] { return CheckConnected(ep1_ch1(), ep2_ch1()); }, diff --git a/third_party/libwebrtc/p2p/base/port_allocator.cc b/third_party/libwebrtc/p2p/base/port_allocator.cc @@ -183,7 +183,10 @@ bool PortAllocator::SetConfiguration( // in future sessions. We also update the ready ports in the pooled sessions. // Ports in sessions that are taken and owned by P2PTransportChannel will be // updated there via IceConfig. - stun_candidate_keepalive_interval_ = stun_candidate_keepalive_interval; + stun_candidate_keepalive_interval_ = + stun_candidate_keepalive_interval.has_value() + ? std::optional(TimeDelta::Millis(*stun_candidate_keepalive_interval)) + : std::nullopt; for (const auto& session : pooled_sessions_) { session->SetStunKeepaliveIntervalForReadyPorts( stun_candidate_keepalive_interval_); diff --git a/third_party/libwebrtc/p2p/base/port_allocator.h b/third_party/libwebrtc/p2p/base/port_allocator.h @@ -249,7 +249,7 @@ class RTC_EXPORT PortAllocatorSession : public sigslot::has_slots<> { // The default value of the interval in implementation is restored if a null // optional value is passed. virtual void SetStunKeepaliveIntervalForReadyPorts( - const std::optional<int>& /* stun_keepalive_interval */) {} + const std::optional<TimeDelta>& /* stun_keepalive_interval */) {} // Another way of getting the information provided by the signals below. // // Ports and candidates are not guaranteed to be in the same order as the @@ -396,7 +396,7 @@ class RTC_EXPORT PortAllocator : public sigslot::has_slots<> { return candidate_pool_size_; } - const std::optional<int>& stun_candidate_keepalive_interval() const { + const std::optional<TimeDelta>& stun_candidate_keepalive_interval() const { CheckRunOnValidThreadIfInitialized(); return stun_candidate_keepalive_interval_; } @@ -633,7 +633,7 @@ class RTC_EXPORT PortAllocator : public sigslot::has_slots<> { // all TurnPort(s) created. TurnCustomizer* turn_customizer_ = nullptr; - std::optional<int> stun_candidate_keepalive_interval_; + std::optional<TimeDelta> stun_candidate_keepalive_interval_; // If true, TakePooledSession() will only return sessions that has same ice // credentials as requested. diff --git a/third_party/libwebrtc/p2p/base/stun_port.cc b/third_party/libwebrtc/p2p/base/stun_port.cc @@ -190,7 +190,7 @@ UDPPort::UDPPort(const PortParametersRef& args, socket_(socket), error_(0), ready_(false), - stun_keepalive_delay_(kStunKeepaliveInterval.ms()), + stun_keepalive_delay_(kStunKeepaliveInterval), dscp_(DSCP_NO_CHANGE), emit_local_for_anyaddress_(emit_local_for_anyaddress) {} @@ -208,7 +208,7 @@ UDPPort::UDPPort(const PortParametersRef& args, socket_(nullptr), error_(0), ready_(false), - stun_keepalive_delay_(kStunKeepaliveInterval.ms()), + stun_keepalive_delay_(kStunKeepaliveInterval), dscp_(DSCP_NO_CHANGE), emit_local_for_anyaddress_(emit_local_for_anyaddress) {} @@ -362,8 +362,8 @@ void UDPPort::GetStunStats(std::optional<StunStats>* stats) { *stats = stats_; } -void UDPPort::set_stun_keepalive_delay(const std::optional<int>& delay) { - stun_keepalive_delay_ = delay.value_or(kStunKeepaliveInterval.ms()); +void UDPPort::set_stun_keepalive_delay(const std::optional<TimeDelta>& delay) { + stun_keepalive_delay_ = delay.value_or(kStunKeepaliveInterval); } void UDPPort::OnLocalAddressReady(AsyncPacketSocket* /* socket */, @@ -650,7 +650,7 @@ std::unique_ptr<StunPort> StunPort::Create( uint16_t min_port, uint16_t max_port, const ServerAddresses& servers, - std::optional<int> stun_keepalive_interval) { + std::optional<TimeDelta> stun_keepalive_interval) { // Using `new` to access a non-public constructor. auto port = absl::WrapUnique(new StunPort(args, min_port, max_port, servers)); port->set_stun_keepalive_delay(stun_keepalive_interval); diff --git a/third_party/libwebrtc/p2p/base/stun_port.h b/third_party/libwebrtc/p2p/base/stun_port.h @@ -51,7 +51,7 @@ class RTC_EXPORT UDPPort : public Port { const PortParametersRef& args, AsyncPacketSocket* socket, bool emit_local_for_anyaddress, - std::optional<int> stun_keepalive_interval) { + std::optional<TimeDelta> stun_keepalive_interval) { // Using `new` to access a non-public constructor. auto port = absl::WrapUnique(new UDPPort( args, IceCandidateType::kHost, socket, emit_local_for_anyaddress)); @@ -67,7 +67,7 @@ class RTC_EXPORT UDPPort : public Port { uint16_t min_port, uint16_t max_port, bool emit_local_for_anyaddress, - std::optional<int> stun_keepalive_interval) { + std::optional<TimeDelta> stun_keepalive_interval) { // Using `new` to access a non-public constructor. auto port = absl::WrapUnique(new UDPPort(args, IceCandidateType::kHost, min_port, @@ -104,10 +104,8 @@ class RTC_EXPORT UDPPort : public Port { void GetStunStats(std::optional<StunStats>* stats) override; - void set_stun_keepalive_delay(const std::optional<int>& delay); - TimeDelta stun_keepalive_delay() const { - return TimeDelta::Millis(stun_keepalive_delay_); - } + void set_stun_keepalive_delay(const std::optional<TimeDelta>& delay); + TimeDelta stun_keepalive_delay() const { return stun_keepalive_delay_; } // Visible for testing. TimeDelta stun_keepalive_lifetime() const { return stun_keepalive_lifetime_; } @@ -239,7 +237,7 @@ class RTC_EXPORT UDPPort : public Port { int send_error_count_ = 0; std::unique_ptr<AddressResolver> resolver_; bool ready_; - int stun_keepalive_delay_; + TimeDelta stun_keepalive_delay_; TimeDelta stun_keepalive_lifetime_ = TimeDelta::PlusInfinity(); DiffServCodePoint dscp_; @@ -259,7 +257,7 @@ class StunPort : public UDPPort { uint16_t min_port, uint16_t max_port, const ServerAddresses& servers, - std::optional<int> stun_keepalive_interval); + std::optional<TimeDelta> stun_keepalive_interval); void PrepareAddress() override; diff --git a/third_party/libwebrtc/p2p/base/stun_port_unittest.cc b/third_party/libwebrtc/p2p/base/stun_port_unittest.cc @@ -153,7 +153,7 @@ class StunPortTestBase : public ::testing::Test, public sigslot::has_slots<> { nat_server_(CreateNatServer(nat_server_address, webrtc::NAT_OPEN_CONE)), done_(false), error_(false), - stun_keepalive_delay_(1) { + stun_keepalive_delay_(TimeDelta::Millis(1)) { network_ = MakeNetwork(address); RTC_CHECK(address.family() == nat_server_address.family()); for (const auto& addr : stun_server_addresses) { @@ -287,7 +287,7 @@ class StunPortTestBase : public ::testing::Test, public sigslot::has_slots<> { const webrtc::IceCandidateErrorEvent& event) { error_event_ = event; } - void SetKeepaliveDelay(int delay) { stun_keepalive_delay_ = delay; } + void SetKeepaliveDelay(TimeDelta delay) { stun_keepalive_delay_ = delay; } void SetKeepaliveLifetime(TimeDelta lifetime) { stun_keepalive_lifetime_ = lifetime; @@ -320,7 +320,7 @@ class StunPortTestBase : public ::testing::Test, public sigslot::has_slots<> { std::unique_ptr<webrtc::NATServer> nat_server_; bool done_; bool error_; - int stun_keepalive_delay_; + TimeDelta stun_keepalive_delay_; std::optional<TimeDelta> stun_keepalive_lifetime_; protected: @@ -500,7 +500,7 @@ TEST_F(StunPortTestWithRealClock, TestPrepareAddressHostnameFail) { // This test verifies keepalive response messages don't result in // additional candidate generation. TEST_F(StunPortTest, TestKeepAliveResponse) { - SetKeepaliveDelay(500); // 500ms of keepalive delay. + SetKeepaliveDelay(TimeDelta::Millis(500)); CreateStunPort(kStunServerAddr1); PrepareAddress(); EXPECT_THAT( @@ -683,7 +683,7 @@ TEST_F(StunPortTest, TestUdpPortGetStunKeepaliveLifetime) { // Test that STUN binding requests will be stopped shortly if the keep-alive // lifetime is short. TEST_F(StunPortTest, TestStunBindingRequestShortLifetime) { - SetKeepaliveDelay(101); + SetKeepaliveDelay(TimeDelta::Millis(101)); SetKeepaliveLifetime(TimeDelta::Millis(100)); CreateStunPort(kStunServerAddr1); PrepareAddress(); @@ -701,7 +701,7 @@ TEST_F(StunPortTest, TestStunBindingRequestShortLifetime) { // Test that by default, the STUN binding requests will last for a long time. TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { - SetKeepaliveDelay(101); + SetKeepaliveDelay(TimeDelta::Millis(101)); CreateStunPort(kStunServerAddr1); PrepareAddress(); EXPECT_THAT( diff --git a/third_party/libwebrtc/p2p/client/basic_port_allocator.cc b/third_party/libwebrtc/p2p/client/basic_port_allocator.cc @@ -487,7 +487,7 @@ void BasicPortAllocatorSession::GetCandidateStatsFromReadyPorts( } void BasicPortAllocatorSession::SetStunKeepaliveIntervalForReadyPorts( - const std::optional<int>& stun_keepalive_interval) { + const std::optional<TimeDelta>& stun_keepalive_interval) { RTC_DCHECK_RUN_ON(network_thread_); auto ports = ReadyPorts(); for (PortInterface* port : ports) { diff --git a/third_party/libwebrtc/p2p/client/basic_port_allocator.h b/third_party/libwebrtc/p2p/client/basic_port_allocator.h @@ -170,7 +170,7 @@ class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession { void GetCandidateStatsFromReadyPorts( CandidateStatsList* candidate_stats_list) const override; void SetStunKeepaliveIntervalForReadyPorts( - const std::optional<int>& stun_keepalive_interval) override; + const std::optional<TimeDelta>& stun_keepalive_interval) override; void PruneAllPorts() override; static std::vector<const Network*> SelectIPv6Networks( std::vector<const Network*>& all_ipv6_networks, diff --git a/third_party/libwebrtc/p2p/test/fake_ice_transport.h b/third_party/libwebrtc/p2p/test/fake_ice_transport.h @@ -176,7 +176,7 @@ class FakeIceTransport : public IceTransportInternal { } // Convenience functions for accessing ICE config and other things. - int receiving_timeout() const { + TimeDelta receiving_timeout() const { RTC_DCHECK_RUN_ON(network_thread_); return ice_config_.receiving_timeout_or_default(); } diff --git a/third_party/libwebrtc/pc/jsep_transport_controller_unittest.cc b/third_party/libwebrtc/pc/jsep_transport_controller_unittest.cc @@ -70,26 +70,23 @@ #include "test/gtest.h" #include "test/wait_until.h" -using webrtc::Candidate; -using ::webrtc::Candidates; -using ::webrtc::FakeDtlsTransport; - -static const int kTimeout = 100; -static const char kIceUfrag1[] = "u0001"; -static const char kIcePwd1[] = "TESTICEPWD00000000000001"; -static const char kIceUfrag2[] = "u0002"; -static const char kIcePwd2[] = "TESTICEPWD00000000000002"; -static const char kIceUfrag3[] = "u0003"; -static const char kIcePwd3[] = "TESTICEPWD00000000000003"; -static const char kIceUfrag4[] = "u0004"; -static const char kIcePwd4[] = "TESTICEPWD00000000000004"; -static const char kAudioMid1[] = "audio1"; -static const char kAudioMid2[] = "audio2"; -static const char kVideoMid1[] = "video1"; -static const char kVideoMid2[] = "video2"; -static const char kDataMid1[] = "data1"; - namespace webrtc { +namespace { + +constexpr TimeDelta kTimeout = TimeDelta::Millis(100); +const char kIceUfrag1[] = "u0001"; +const char kIcePwd1[] = "TESTICEPWD00000000000001"; +const char kIceUfrag2[] = "u0002"; +const char kIcePwd2[] = "TESTICEPWD00000000000002"; +const char kIceUfrag3[] = "u0003"; +const char kIcePwd3[] = "TESTICEPWD00000000000003"; +const char kIceUfrag4[] = "u0004"; +const char kIcePwd4[] = "TESTICEPWD00000000000004"; +const char kAudioMid1[] = "audio1"; +const char kAudioMid2[] = "audio2"; +const char kVideoMid1[] = "video1"; +const char kVideoMid2[] = "video2"; +const char kDataMid1[] = "data1"; class FakeIceTransportFactory : public IceTransportFactory { public: @@ -270,7 +267,7 @@ class JsepTransportControllerTest : public JsepTransportController::Observer, } IceConfig CreateIceConfig( - int receiving_timeout, + TimeDelta receiving_timeout, ContinualGatheringPolicy continual_gathering_policy) { IceConfig config; config.receiving_timeout = receiving_timeout; @@ -561,8 +558,7 @@ TEST_F(JsepTransportControllerTest, MaybeStartGathering) { // candidates. transport_controller_->MaybeStartGathering(); EXPECT_THAT(WaitUntil([&] { return kIceGatheringGathering; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, gathering_state_signal_count_); } @@ -708,22 +704,20 @@ TEST_F(JsepTransportControllerTest, SignalConnectionStateFailed) { fake_ice->SetConnectionCount(1); // The connection stats will be failed if there is no active connection. fake_ice->SetConnectionCount(0); - EXPECT_THAT(WaitUntil([&] { return kIceConnectionFailed; }, - ::testing::Eq(connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), - IsRtcOk()); + EXPECT_THAT( + WaitUntil([&] { return kIceConnectionFailed; }, + ::testing::Eq(connection_state_), {.timeout = kTimeout}), + IsRtcOk()); EXPECT_EQ(1, connection_state_signal_count_); EXPECT_THAT( WaitUntil([&] { return PeerConnectionInterface::kIceConnectionFailed; }, - ::testing::Eq(ice_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(ice_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, ice_connection_state_signal_count_); EXPECT_THAT( WaitUntil( [&] { return PeerConnectionInterface::PeerConnectionState::kFailed; }, - ::testing::Eq(combined_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(combined_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, combined_connection_state_signal_count_); } @@ -753,22 +747,20 @@ TEST_F(JsepTransportControllerTest, fake_video_dtls->fake_ice_transport()->SetConnectionCount(0); fake_video_dtls->fake_ice_transport()->SetCandidatesGatheringComplete(); - EXPECT_THAT(WaitUntil([&] { return kIceConnectionFailed; }, - ::testing::Eq(connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), - IsRtcOk()); + EXPECT_THAT( + WaitUntil([&] { return kIceConnectionFailed; }, + ::testing::Eq(connection_state_), {.timeout = kTimeout}), + IsRtcOk()); EXPECT_EQ(1, connection_state_signal_count_); EXPECT_THAT( WaitUntil([&] { return PeerConnectionInterface::kIceConnectionFailed; }, - ::testing::Eq(ice_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(ice_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, ice_connection_state_signal_count_); EXPECT_THAT( WaitUntil( [&] { return PeerConnectionInterface::PeerConnectionState::kFailed; }, - ::testing::Eq(combined_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(combined_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, combined_connection_state_signal_count_); @@ -778,16 +770,15 @@ TEST_F(JsepTransportControllerTest, // the transport state to be STATE_CONNECTING. fake_video_dtls->fake_ice_transport()->SetConnectionCount(2); fake_video_dtls->SetWritable(true); - EXPECT_THAT(WaitUntil([&] { return kIceConnectionConnected; }, - ::testing::Eq(connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), - IsRtcOk()); + EXPECT_THAT( + WaitUntil([&] { return kIceConnectionConnected; }, + ::testing::Eq(connection_state_), {.timeout = kTimeout}), + IsRtcOk()); EXPECT_EQ(2, connection_state_signal_count_); EXPECT_THAT( WaitUntil( [&] { return PeerConnectionInterface::kIceConnectionConnected; }, - ::testing::Eq(ice_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(ice_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(3, ice_connection_state_signal_count_); EXPECT_THAT( @@ -795,8 +786,7 @@ TEST_F(JsepTransportControllerTest, [&] { return PeerConnectionInterface::PeerConnectionState::kConnected; }, - ::testing::Eq(combined_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(combined_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(3, combined_connection_state_signal_count_); } @@ -825,8 +815,7 @@ TEST_F(JsepTransportControllerTest, SignalConnectionStateComplete) { EXPECT_THAT( WaitUntil([&] { return PeerConnectionInterface::kIceConnectionChecking; }, - ::testing::Eq(ice_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(ice_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, ice_connection_state_signal_count_); EXPECT_THAT( @@ -834,8 +823,7 @@ TEST_F(JsepTransportControllerTest, SignalConnectionStateComplete) { [&] { return PeerConnectionInterface::PeerConnectionState::kConnecting; }, - ::testing::Eq(combined_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(combined_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, combined_connection_state_signal_count_); @@ -843,22 +831,20 @@ TEST_F(JsepTransportControllerTest, SignalConnectionStateComplete) { IceTransportState::kFailed, IceTransportStateInternal::STATE_FAILED); fake_video_dtls->fake_ice_transport()->SetCandidatesGatheringComplete(); - EXPECT_THAT(WaitUntil([&] { return kIceConnectionFailed; }, - ::testing::Eq(connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), - IsRtcOk()); + EXPECT_THAT( + WaitUntil([&] { return kIceConnectionFailed; }, + ::testing::Eq(connection_state_), {.timeout = kTimeout}), + IsRtcOk()); EXPECT_EQ(1, connection_state_signal_count_); EXPECT_THAT( WaitUntil([&] { return PeerConnectionInterface::kIceConnectionFailed; }, - ::testing::Eq(ice_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(ice_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, ice_connection_state_signal_count_); EXPECT_THAT( WaitUntil( [&] { return PeerConnectionInterface::PeerConnectionState::kFailed; }, - ::testing::Eq(combined_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(combined_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, combined_connection_state_signal_count_); @@ -870,16 +856,15 @@ TEST_F(JsepTransportControllerTest, SignalConnectionStateComplete) { IceTransportState::kCompleted, IceTransportStateInternal::STATE_COMPLETED); fake_video_dtls->SetWritable(true); - EXPECT_THAT(WaitUntil([&] { return kIceConnectionCompleted; }, - ::testing::Eq(connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), - IsRtcOk()); + EXPECT_THAT( + WaitUntil([&] { return kIceConnectionCompleted; }, + ::testing::Eq(connection_state_), {.timeout = kTimeout}), + IsRtcOk()); EXPECT_EQ(3, connection_state_signal_count_); EXPECT_THAT( WaitUntil( [&] { return PeerConnectionInterface::kIceConnectionCompleted; }, - ::testing::Eq(ice_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(ice_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(3, ice_connection_state_signal_count_); EXPECT_THAT( @@ -887,8 +872,7 @@ TEST_F(JsepTransportControllerTest, SignalConnectionStateComplete) { [&] { return PeerConnectionInterface::PeerConnectionState::kConnected; }, - ::testing::Eq(combined_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(combined_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(3, combined_connection_state_signal_count_); } @@ -906,8 +890,7 @@ TEST_F(JsepTransportControllerTest, SignalIceGatheringStateGathering) { fake_audio_dtls->fake_ice_transport()->MaybeStartGathering(); // Should be in the gathering state as soon as any transport starts gathering. EXPECT_THAT(WaitUntil([&] { return kIceGatheringGathering; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, gathering_state_signal_count_); } @@ -927,8 +910,7 @@ TEST_F(JsepTransportControllerTest, SignalIceGatheringStateComplete) { fake_audio_dtls->fake_ice_transport()->MaybeStartGathering(); EXPECT_THAT(WaitUntil([&] { return kIceGatheringGathering; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, gathering_state_signal_count_); @@ -939,15 +921,13 @@ TEST_F(JsepTransportControllerTest, SignalIceGatheringStateComplete) { fake_video_dtls->fake_ice_transport()->MaybeStartGathering(); EXPECT_THAT(WaitUntil([&] { return kIceGatheringGathering; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, gathering_state_signal_count_); fake_video_dtls->fake_ice_transport()->SetCandidatesGatheringComplete(); EXPECT_THAT(WaitUntil([&] { return kIceGatheringComplete; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, gathering_state_signal_count_); } @@ -973,8 +953,7 @@ TEST_F(JsepTransportControllerTest, fake_audio_dtls->fake_ice_transport()->MaybeStartGathering(); EXPECT_THAT(WaitUntil([&] { return kIceGatheringGathering; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, gathering_state_signal_count_); @@ -995,17 +974,16 @@ TEST_F(JsepTransportControllerTest, fake_video_dtls = static_cast<FakeDtlsTransport*>( transport_controller_->GetDtlsTransport(kVideoMid1)); EXPECT_EQ(fake_audio_dtls, fake_video_dtls); - EXPECT_THAT(WaitUntil([&] { return kIceConnectionCompleted; }, - ::testing::Eq(connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), - IsRtcOk()); + EXPECT_THAT( + WaitUntil([&] { return kIceConnectionCompleted; }, + ::testing::Eq(connection_state_), {.timeout = kTimeout}), + IsRtcOk()); EXPECT_EQ(PeerConnectionInterface::kIceConnectionCompleted, ice_connection_state_); EXPECT_EQ(PeerConnectionInterface::PeerConnectionState::kConnected, combined_connection_state_); EXPECT_THAT(WaitUntil([&] { return kIceGatheringComplete; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, gathering_state_signal_count_); } @@ -1037,8 +1015,7 @@ TEST_F(JsepTransportControllerTest, IceTransportStateInternal::STATE_CONNECTING); EXPECT_THAT( WaitUntil([&] { return PeerConnectionInterface::kIceConnectionChecking; }, - ::testing::Eq(ice_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(ice_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, ice_connection_state_signal_count_); EXPECT_THAT( @@ -1046,13 +1023,11 @@ TEST_F(JsepTransportControllerTest, [&] { return PeerConnectionInterface::PeerConnectionState::kConnecting; }, - ::testing::Eq(combined_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(combined_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, combined_connection_state_signal_count_); EXPECT_THAT(WaitUntil([&] { return kIceGatheringGathering; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1, gathering_state_signal_count_); @@ -1065,20 +1040,17 @@ TEST_F(JsepTransportControllerTest, .ok()); EXPECT_THAT( WaitUntil([&] { return PeerConnectionInterface::kIceConnectionNew; }, - ::testing::Eq(ice_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(ice_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, ice_connection_state_signal_count_); EXPECT_THAT( WaitUntil( [&] { return PeerConnectionInterface::PeerConnectionState::kNew; }, - ::testing::Eq(combined_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(combined_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, combined_connection_state_signal_count_); EXPECT_THAT(WaitUntil([&] { return kIceGatheringNew; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, gathering_state_signal_count_); @@ -1087,8 +1059,7 @@ TEST_F(JsepTransportControllerTest, EXPECT_TRUE(transport_controller_->RollbackTransports().ok()); EXPECT_THAT( WaitUntil([&] { return PeerConnectionInterface::kIceConnectionChecking; }, - ::testing::Eq(ice_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(ice_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(3, ice_connection_state_signal_count_); EXPECT_THAT( @@ -1096,13 +1067,11 @@ TEST_F(JsepTransportControllerTest, [&] { return PeerConnectionInterface::PeerConnectionState::kConnecting; }, - ::testing::Eq(combined_connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(combined_connection_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(3, combined_connection_state_signal_count_); EXPECT_THAT(WaitUntil([&] { return kIceGatheringGathering; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(3, gathering_state_signal_count_); } @@ -1122,7 +1091,7 @@ TEST_F(JsepTransportControllerTest, SignalCandidatesGathered) { fake_audio_dtls->fake_ice_transport(), CreateCandidate()); EXPECT_THAT( WaitUntil([&] { return 1; }, ::testing::Eq(candidates_signal_count_), - {.timeout = TimeDelta::Millis(kTimeout)}), + {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(1u, candidates_[kAudioMid1].size()); } @@ -1137,27 +1106,24 @@ TEST_F(JsepTransportControllerTest, IceSignalingOccursOnNetworkThread) { CreateLocalDescriptionAndCompleteConnectionOnNetworkThread(); // connecting --> connected --> completed - EXPECT_THAT(WaitUntil([&] { return kIceConnectionCompleted; }, - ::testing::Eq(connection_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), - IsRtcOk()); + EXPECT_THAT( + WaitUntil([&] { return kIceConnectionCompleted; }, + ::testing::Eq(connection_state_), {.timeout = kTimeout}), + IsRtcOk()); EXPECT_EQ(2, connection_state_signal_count_); // new --> gathering --> complete EXPECT_THAT(WaitUntil([&] { return kIceGatheringComplete; }, - ::testing::Eq(gathering_state_), - {.timeout = TimeDelta::Millis(kTimeout)}), + ::testing::Eq(gathering_state_), {.timeout = kTimeout}), IsRtcOk()); EXPECT_EQ(2, gathering_state_signal_count_); - EXPECT_THAT( - WaitUntil([&] { return candidates_[kAudioMid1].size(); }, - ::testing::Eq(1u), {.timeout = TimeDelta::Millis(kTimeout)}), - IsRtcOk()); - EXPECT_THAT( - WaitUntil([&] { return candidates_[kVideoMid1].size(); }, - ::testing::Eq(1u), {.timeout = TimeDelta::Millis(kTimeout)}), - IsRtcOk()); + EXPECT_THAT(WaitUntil([&] { return candidates_[kAudioMid1].size(); }, + ::testing::Eq(1u), {.timeout = kTimeout}), + IsRtcOk()); + EXPECT_THAT(WaitUntil([&] { return candidates_[kVideoMid1].size(); }, + ::testing::Eq(1u), {.timeout = kTimeout}), + IsRtcOk()); EXPECT_EQ(2, candidates_signal_count_); EXPECT_EQ(ice_signaled_on_thread_, network_thread_.get()); @@ -2868,4 +2834,5 @@ TEST_F(JsepTransportControllerTest, EXPECT_NE(other_pt.value(), remote_opus_pt); } +} // namespace } // namespace webrtc diff --git a/third_party/libwebrtc/pc/peer_connection_ice_unittest.cc b/third_party/libwebrtc/pc/peer_connection_ice_unittest.cc @@ -1510,14 +1510,12 @@ TEST_F(PeerConnectionIceConfigTest, SetStunCandidateKeepaliveInterval) { config.ice_candidate_pool_size = 1; CreatePeerConnection(config); ASSERT_NE(port_allocator_, nullptr); - std::optional<int> actual_stun_keepalive_interval = - port_allocator_->stun_candidate_keepalive_interval(); - EXPECT_EQ(actual_stun_keepalive_interval.value_or(-1), 123); + EXPECT_EQ(port_allocator_->stun_candidate_keepalive_interval(), + TimeDelta::Millis(123)); config.stun_candidate_keepalive_interval = 321; ASSERT_TRUE(pc_->SetConfiguration(config).ok()); - actual_stun_keepalive_interval = - port_allocator_->stun_candidate_keepalive_interval(); - EXPECT_EQ(actual_stun_keepalive_interval.value_or(-1), 321); + EXPECT_EQ(port_allocator_->stun_candidate_keepalive_interval(), + TimeDelta::Millis(321)); } TEST_F(PeerConnectionIceConfigTest, SetStableWritableConnectionInterval) {