Use TimeDelta to represent p2p constants
Rename them to follow constant name rule
https://google.github.io/styleguide/cppguide.html#Constant_Names
instead of of naming those constans like macros.
Bug: webrtc:42223979
Change-Id: I5b8d41709cdc6092fa92276a6f5e15b27d9a14da
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/407541
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45541}
diff --git a/p2p/base/basic_ice_controller.cc b/p2p/base/basic_ice_controller.cc
index ca8f826..6a82a3e 100644
--- a/p2p/base/basic_ice_controller.cc
+++ b/p2p/base/basic_ice_controller.cc
@@ -130,7 +130,7 @@
bool need_more_pings_at_weak_interval =
absl::c_any_of(connections_, [](const Connection* conn) {
return conn->active() &&
- conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL;
+ conn->num_pings_sent() < kMinPingsAtWeakPingInterval;
});
int ping_interval = (weak() || need_more_pings_at_weak_interval)
? weak_ping_interval()
@@ -273,15 +273,15 @@
const Connection* conn,
int64_t now) const {
// Ping each connection at a higher rate at least
- // MIN_PINGS_AT_WEAK_PING_INTERVAL times.
- if (conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL) {
+ // kMinPingsAtWeakPingInterval times.
+ if (conn->num_pings_sent() < kMinPingsAtWeakPingInterval) {
return weak_ping_interval();
}
int stable_interval =
config_.stable_writable_connection_ping_interval_or_default();
- int weak_or_stablizing_interval = std::min(
- stable_interval, WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
+ int weak_or_stablizing_interval = std::min<int>(
+ stable_interval, kWeakOrStabilizingWritableConnectionPingInterval.ms());
// 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
diff --git a/p2p/base/basic_ice_controller.h b/p2p/base/basic_ice_controller.h
index b2aa3c3..ed1494f 100644
--- a/p2p/base/basic_ice_controller.h
+++ b/p2p/base/basic_ice_controller.h
@@ -87,8 +87,8 @@
}
int check_receiving_interval() const {
- return std::max(MIN_CHECK_RECEIVING_INTERVAL,
- config_.receiving_timeout_or_default() / 10);
+ return std::max<int>(kMinCheckReceivingInterval.ms(),
+ config_.receiving_timeout_or_default() / 10);
}
const Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now);
diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc
index 1afd41b..73124aa 100644
--- a/p2p/base/connection.cc
+++ b/p2p/base/connection.cc
@@ -225,7 +225,7 @@
}
int Connection::ConnectionRequest::resend_delay() {
- return CONNECTION_RESPONSE_TIMEOUT;
+ return kConnectionResponseTimeout.ms();
}
Connection::Connection(const Environment& env,
@@ -419,7 +419,7 @@
int Connection::unwritable_min_checks() const {
RTC_DCHECK_RUN_ON(network_thread_);
- return unwritable_min_checks_.value_or(CONNECTION_WRITE_CONNECT_FAILURES);
+ return unwritable_min_checks_.value_or(kConnectionWriteConnectFailures);
}
void Connection::set_unwritable_min_checks(const std::optional<int>& value) {
@@ -795,7 +795,7 @@
response.AddAttribute(std::make_unique<StunUInt32Attribute>(
STUN_ATTR_RETRANSMIT_COUNT, retransmit_attr->value()));
- if (retransmit_attr->value() > CONNECTION_WRITE_CONNECT_FAILURES) {
+ if (retransmit_attr->value() > kConnectionWriteConnectFailures) {
RTC_LOG(LS_INFO)
<< ToString()
<< ": Received a remote ping with high retransmit count: "
diff --git a/p2p/base/ice_transport_internal.cc b/p2p/base/ice_transport_internal.cc
index 89a2207..d6a80e8 100644
--- a/p2p/base/ice_transport_internal.cc
+++ b/p2p/base/ice_transport_internal.cc
@@ -145,48 +145,49 @@
IceConfig::~IceConfig() = default;
int IceConfig::receiving_timeout_or_default() const {
- return receiving_timeout.value_or(RECEIVING_TIMEOUT);
+ return receiving_timeout.value_or(kReceivingTimeout.ms());
}
int IceConfig::backup_connection_ping_interval_or_default() const {
return backup_connection_ping_interval.value_or(
- BACKUP_CONNECTION_PING_INTERVAL);
+ kBackupConnectionPingInterval.ms());
}
int IceConfig::stable_writable_connection_ping_interval_or_default() const {
return stable_writable_connection_ping_interval.value_or(
- STRONG_AND_STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
+ kStrongAndStableWritableConnectionPingInterval.ms());
}
int IceConfig::regather_on_failed_networks_interval_or_default() const {
return regather_on_failed_networks_interval.value_or(
- REGATHER_ON_FAILED_NETWORKS_INTERVAL);
+ kRegatherOnFailedNetworksInterval.ms());
}
int IceConfig::receiving_switching_delay_or_default() const {
- return receiving_switching_delay.value_or(RECEIVING_SWITCHING_DELAY);
+ return receiving_switching_delay.value_or(kReceivingSwitchingDelay.ms());
}
int IceConfig::ice_check_interval_strong_connectivity_or_default() const {
- return ice_check_interval_strong_connectivity.value_or(STRONG_PING_INTERVAL);
+ return ice_check_interval_strong_connectivity.value_or(
+ kStrongPingInterval.ms());
}
int IceConfig::ice_check_interval_weak_connectivity_or_default() const {
- return ice_check_interval_weak_connectivity.value_or(WEAK_PING_INTERVAL);
+ return ice_check_interval_weak_connectivity.value_or(kWeakPingInterval.ms());
}
int IceConfig::ice_check_min_interval_or_default() const {
return ice_check_min_interval.value_or(-1);
}
int IceConfig::ice_unwritable_timeout_or_default() const {
- return ice_unwritable_timeout.value_or(CONNECTION_WRITE_CONNECT_TIMEOUT);
+ return ice_unwritable_timeout.value_or(kConnectionWriteConnectTimeout.ms());
}
int IceConfig::ice_unwritable_min_checks_or_default() const {
- return ice_unwritable_min_checks.value_or(CONNECTION_WRITE_CONNECT_FAILURES);
+ return ice_unwritable_min_checks.value_or(kConnectionWriteConnectFailures);
}
int IceConfig::ice_inactive_timeout_or_default() const {
- return ice_inactive_timeout.value_or(CONNECTION_WRITE_TIMEOUT);
+ return ice_inactive_timeout.value_or(kConnectionWriteTimeout.ms());
}
int IceConfig::stun_keepalive_interval_or_default() const {
- return stun_keepalive_interval.value_or(STUN_KEEPALIVE_INTERVAL);
+ return stun_keepalive_interval.value_or(kStunKeepaliveInterval.ms());
}
RTCError IceConfig::IsValid() const {
if (ice_check_interval_strong_connectivity_or_default() <
- ice_check_interval_weak_connectivity.value_or(WEAK_PING_INTERVAL)) {
+ ice_check_interval_weak_connectivity.value_or(kWeakPingInterval.ms())) {
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/p2p/base/ice_transport_internal.h b/p2p/base/ice_transport_internal.h
index ff11eaf..d3bd319 100644
--- a/p2p/base/ice_transport_internal.h
+++ b/p2p/base/ice_transport_internal.h
@@ -169,12 +169,12 @@
// 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
- // `STRONG_PING_INTERVAL` in p2ptransport.h if set.
+ // `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
- // `WEAK_PING_INTERVAL` in p2ptransport.h if set.
+ // `kWeakPingInterval` in p2ptransport.h if set.
std::optional<int> 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.
@@ -192,13 +192,13 @@
// The min number of connectivity checks that a candidate pair must sent
// without receiving response before it becomes unwritable. This parameter
- // overrides the default value given by `CONNECTION_WRITE_CONNECT_FAILURES` in
+ // 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_min_checks;
// The min time period for which a candidate pair must wait for response to
// connectivity checks it becomes inactive. This parameter overrides the
- // default value given by `CONNECTION_WRITE_TIMEOUT` in port.h if set, when
+ // default value given by `kConnectionWriteTimeout` in port.h if set, when
// determining the writability of a candidate pair.
std::optional<int> ice_inactive_timeout;
diff --git a/p2p/base/p2p_constants.cc b/p2p/base/p2p_constants.cc
index 2db5223..4ec4834 100644
--- a/p2p/base/p2p_constants.cc
+++ b/p2p/base/p2p_constants.cc
@@ -50,12 +50,6 @@
const char LOCAL_TLD[] = ".local";
-const int MIN_CHECK_RECEIVING_INTERVAL = 50;
-const int RECEIVING_TIMEOUT = MIN_CHECK_RECEIVING_INTERVAL * 50;
-const int RECEIVING_SWITCHING_DELAY = 1000;
-const int BACKUP_CONNECTION_PING_INTERVAL = 25 * 1000;
-const int REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000;
-
// When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers)
// for pinging. When the socket is writable, we will use only 1 Kbps because we
// don't want to degrade the quality on a modem. These numbers should work well
@@ -67,12 +61,4 @@
static_assert(kWeakPingInterval ==
kStunPingPacketSize / DataRate::BitsPerSec(10'000));
-const uint32_t CONNECTION_WRITE_CONNECT_FAILURES = 5; // 5 pings
-
-const int STUN_KEEPALIVE_INTERVAL = 10 * 1000; // 10 seconds
-
-// There is no harm to keep this value high other than a small amount
-// of increased memory, but in some networks (2G), we observe up to 60s RTTs.
-const int CONNECTION_RESPONSE_TIMEOUT = 60 * 1000; // 60 seconds
-
} // namespace webrtc
diff --git a/p2p/base/p2p_constants.h b/p2p/base/p2p_constants.h
index 72aaf34e..fa702ce 100644
--- a/p2p/base/p2p_constants.h
+++ b/p2p/base/p2p_constants.h
@@ -56,63 +56,54 @@
// RFC 6762, the .local pseudo-top-level domain used for mDNS names.
extern const char LOCAL_TLD[];
-// Constants for time intervals are in milliseconds unless otherwise stated.
-//
// Most of the following constants are the default values of IceConfig
// paramters. See IceConfig for detailed definition.
//
-// Default value of IceConfig.receiving_timeout.
-extern const int RECEIVING_TIMEOUT;
// Default value IceConfig.ice_check_min_interval.
-extern const int MIN_CHECK_RECEIVING_INTERVAL;
+inline constexpr TimeDelta kMinCheckReceivingInterval = TimeDelta::Millis(50);
+// Default value of IceConfig.receiving_timeout.
+inline constexpr TimeDelta kReceivingTimeout = kMinCheckReceivingInterval * 50;
// The next two ping intervals are at the ICE transport level.
//
-// STRONG_PING_INTERVAL is applied when the selected connection is both
+// kStrongPingInterval is applied when the selected connection is both
// writable and receiving.
//
// Default value of IceConfig.ice_check_interval_strong_connectivity.
inline constexpr TimeDelta kStrongPingInterval = TimeDelta::Millis(480);
-inline constexpr int STRONG_PING_INTERVAL = kStrongPingInterval.ms();
-// WEAK_PING_INTERVAL is applied when the selected connection is either
+// kWeakPingInterval is applied when the selected connection is either
// not writable or not receiving.
//
// Defaul value of IceConfig.ice_check_interval_weak_connectivity.
inline constexpr TimeDelta kWeakPingInterval = TimeDelta::Millis(48);
-inline constexpr int WEAK_PING_INTERVAL = kWeakPingInterval.ms();
// The next two ping intervals are at the candidate pair level.
//
// Writable candidate pairs are pinged at a slower rate once they are stabilized
// and the channel is strongly connected.
inline constexpr TimeDelta kStrongAndStableWritableConnectionPingInterval =
TimeDelta::Millis(2'500);
-inline constexpr int STRONG_AND_STABLE_WRITABLE_CONNECTION_PING_INTERVAL =
- kStrongAndStableWritableConnectionPingInterval.ms();
// Writable candidate pairs are pinged at a faster rate while the connections
// are stabilizing or the channel is weak.
inline constexpr TimeDelta kWeakOrStabilizingWritableConnectionPingInterval =
TimeDelta::Millis(900);
-inline constexpr int WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL =
- kWeakOrStabilizingWritableConnectionPingInterval.ms();
// Default value of IceConfig.backup_connection_ping_interval
-extern const int BACKUP_CONNECTION_PING_INTERVAL;
+inline constexpr TimeDelta kBackupConnectionPingInterval =
+ TimeDelta::Seconds(25);
// Defualt value of IceConfig.receiving_switching_delay.
-extern const int RECEIVING_SWITCHING_DELAY;
+inline constexpr TimeDelta kReceivingSwitchingDelay = TimeDelta::Seconds(1);
// Default value of IceConfig.regather_on_failed_networks_interval.
-extern const int REGATHER_ON_FAILED_NETWORKS_INTERVAL;
+inline constexpr TimeDelta kRegatherOnFailedNetworksInterval =
+ TimeDelta::Seconds(5 * 60);
// Default vaule of IceConfig.ice_unwritable_timeout.
inline constexpr TimeDelta kConnectionWriteConnectTimeout =
TimeDelta::Seconds(5);
-inline constexpr int CONNECTION_WRITE_CONNECT_TIMEOUT =
- kConnectionWriteConnectTimeout.ms();
// Default vaule of IceConfig.ice_unwritable_min_checks.
-extern const uint32_t CONNECTION_WRITE_CONNECT_FAILURES;
+inline constexpr int kConnectionWriteConnectFailures = 5; // 5 pings
// Default value of IceConfig.ice_inactive_timeout;
inline constexpr TimeDelta kConnectionWriteTimeout = TimeDelta::Seconds(15);
-inline constexpr int CONNECTION_WRITE_TIMEOUT = kConnectionWriteTimeout.ms();
// Default value of IceConfig.stun_keepalive_interval;
-extern const int STUN_KEEPALIVE_INTERVAL;
+inline constexpr TimeDelta kStunKeepaliveInterval = TimeDelta::Seconds(10);
-inline constexpr int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3;
+inline constexpr int kMinPingsAtWeakPingInterval = 3;
// The following constants are used at the candidate pair level to determine the
// state of a candidate pair.
@@ -124,14 +115,13 @@
// long.
inline constexpr TimeDelta kDeadConnectionReceiveTimeout =
TimeDelta::Seconds(30);
-inline constexpr int DEAD_CONNECTION_RECEIVE_TIMEOUT =
- kDeadConnectionReceiveTimeout.ms();
// This is the length of time that we wait for a ping response to come back.
-extern const int CONNECTION_RESPONSE_TIMEOUT;
+// There is no harm to keep this value high other than a small amount
+// of increased memory, but in some networks (2G), we observe up to 60s RTTs.
+inline constexpr TimeDelta kConnectionResponseTimeout = TimeDelta::Seconds(60);
// The minimum time we will wait before destroying a connection after creating
// it.
inline constexpr TimeDelta kMinConnectionLifetime = TimeDelta::Seconds(10);
-inline constexpr int MIN_CONNECTION_LIFETIME = kMinConnectionLifetime.ms();
// The type preference MUST be an integer from 0 to 126 inclusive.
// https://datatracker.ietf.org/doc/html/rfc5245#section-4.1.2.1
diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc
index a2d0b9c..bddda64 100644
--- a/p2p/base/p2p_transport_channel.cc
+++ b/p2p/base/p2p_transport_channel.cc
@@ -97,7 +97,7 @@
if (weak_ping_interval) {
return static_cast<int>(weak_ping_interval);
}
- return WEAK_PING_INTERVAL;
+ return kWeakPingInterval.ms();
}
RouteEndpoint CreateRouteEndpointFromCandidate(bool local,
@@ -187,14 +187,14 @@
ice_role_(ICEROLE_UNKNOWN),
gathering_state_(kIceGatheringNew),
weak_ping_interval_(GetWeakPingIntervalInFieldTrial(env_.field_trials())),
- config_(RECEIVING_TIMEOUT,
- BACKUP_CONNECTION_PING_INTERVAL,
+ config_(kReceivingTimeout.ms(),
+ kBackupConnectionPingInterval.ms(),
GATHER_ONCE /* continual_gathering_policy */,
false /* prioritize_most_likely_candidate_pairs */,
- STRONG_AND_STABLE_WRITABLE_CONNECTION_PING_INTERVAL,
+ kStrongAndStableWritableConnectionPingInterval.ms(),
true /* presume_writable_when_fully_relayed */,
- REGATHER_ON_FAILED_NETWORKS_INTERVAL,
- RECEIVING_SWITCHING_DELAY) {
+ kRegatherOnFailedNetworksInterval.ms(),
+ kReceivingSwitchingDelay.ms()) {
TRACE_EVENT0("webrtc", "P2PTransportChannel::P2PTransportChannel");
RTC_DCHECK(allocator_ != nullptr);
RTC_DCHECK(!transport_name_.empty());
@@ -828,8 +828,8 @@
int P2PTransportChannel::check_receiving_interval() const {
RTC_DCHECK_RUN_ON(network_thread_);
- return std::max(MIN_CHECK_RECEIVING_INTERVAL,
- config_.receiving_timeout_or_default() / 10);
+ return std::max<int>(kMinCheckReceivingInterval.ms(),
+ config_.receiving_timeout_or_default() / 10);
}
void P2PTransportChannel::MaybeStartGathering() {
diff --git a/p2p/base/p2p_transport_channel.h b/p2p/base/p2p_transport_channel.h
index 29d59e5..c399e62 100644
--- a/p2p/base/p2p_transport_channel.h
+++ b/p2p/base/p2p_transport_channel.h
@@ -484,7 +484,8 @@
std::unique_ptr<BasicRegatheringController> regathering_controller_
RTC_GUARDED_BY(network_thread_);
Timestamp last_ping_sent_ RTC_GUARDED_BY(network_thread_) = Timestamp::Zero();
- int weak_ping_interval_ RTC_GUARDED_BY(network_thread_) = WEAK_PING_INTERVAL;
+ int weak_ping_interval_ RTC_GUARDED_BY(network_thread_) =
+ kWeakPingInterval.ms();
// TODO(jonasolsson): Remove state_ and rename standardized_state_ once state_
// is no longer used to compute the ICE connection state.
IceTransportStateInternal state_ RTC_GUARDED_BY(network_thread_) =
diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc
index 42beff4..856f3de 100644
--- a/p2p/base/p2p_transport_channel_unittest.cc
+++ b/p2p/base/p2p_transport_channel_unittest.cc
@@ -2763,7 +2763,7 @@
constexpr int SCHEDULING_DELAY = 200;
EXPECT_LT(
ping_interval1,
- WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_DELAY);
+ kWeakOrStabilizingWritableConnectionPingInterval.ms() + SCHEDULING_DELAY);
// It should switch over to use the cellular IPv6 addr on endpoint 1 before
// it timed out on writing.
@@ -3849,8 +3849,8 @@
conn1->ReceivedPingResponse(LOW_RTT, "id");
EXPECT_TRUE(WaitUntil(
[&] {
- return conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL &&
- conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL;
+ return conn1->num_pings_sent() >= kMinPingsAtWeakPingInterval &&
+ conn2->num_pings_sent() >= kMinPingsAtWeakPingInterval;
},
{.timeout = kDefaultTimeout}));
}
@@ -3877,12 +3877,12 @@
// Initializing.
int64_t start = clock.TimeNanos();
- SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
+ SIMULATED_WAIT(conn->num_pings_sent() >= kMinPingsAtWeakPingInterval,
kDefaultTimeout.ms(), clock);
int64_t ping_interval_ms = (clock.TimeNanos() - start) /
kNumNanosecsPerMillisec /
- (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1);
- EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL);
+ (kMinPingsAtWeakPingInterval - 1);
+ EXPECT_EQ(ping_interval_ms, kWeakPingInterval.ms());
// Stabilizing.
@@ -3895,10 +3895,10 @@
kMediumTimeout.ms(), clock);
ping_interval_ms = (clock.TimeNanos() - start) / kNumNanosecsPerMillisec;
EXPECT_GE(ping_interval_ms,
- WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
+ kWeakOrStabilizingWritableConnectionPingInterval.ms());
EXPECT_LE(
ping_interval_ms,
- WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
+ kWeakOrStabilizingWritableConnectionPingInterval.ms() + SCHEDULING_RANGE);
// Stabilized.
@@ -3913,10 +3913,10 @@
kMediumTimeout.ms(), clock);
ping_interval_ms = (clock.TimeNanos() - start) / kNumNanosecsPerMillisec;
EXPECT_GE(ping_interval_ms,
- STRONG_AND_STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
+ kStrongAndStableWritableConnectionPingInterval.ms());
EXPECT_LE(
ping_interval_ms,
- STRONG_AND_STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
+ kStrongAndStableWritableConnectionPingInterval.ms() + SCHEDULING_RANGE);
// Destabilized.
@@ -3935,17 +3935,17 @@
SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1,
kMediumTimeout.ms(), clock);
// The interval is expected to be
- // WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL.
+ // kWeakOrStabilizingWritableConnectionPingInterval.
start = clock.TimeNanos();
ping_sent_before = conn->num_pings_sent();
SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1,
kMediumTimeout.ms(), clock);
ping_interval_ms = (clock.TimeNanos() - start) / kNumNanosecsPerMillisec;
EXPECT_GE(ping_interval_ms,
- WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
+ kWeakOrStabilizingWritableConnectionPingInterval.ms());
EXPECT_LE(
ping_interval_ms,
- WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
+ kWeakOrStabilizingWritableConnectionPingInterval.ms() + SCHEDULING_RANGE);
}
// Test that we start pinging as soon as we have a connection and remote ICE
diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc
index 4196c02..899d4f3 100644
--- a/p2p/base/port_unittest.cc
+++ b/p2p/base/port_unittest.cc
@@ -1444,10 +1444,10 @@
*/
// Test that a connection will be dead and deleted if
-// i) it has never received anything for MIN_CONNECTION_LIFETIME milliseconds
-// since it was created, or
-// ii) it has not received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT
-// milliseconds since last receiving.
+// i) it has never received anything for kMinConnectionLifetime since
+// it was created, or
+// ii) it has not received anything for kDeadConnectionReceiveTimeout since
+// last receiving.
TEST_F(PortTest, TestConnectionDead) {
TestChannel ch1(CreateUdpPort(kLocalAddr1));
TestChannel ch2(CreateUdpPort(kLocalAddr2));
@@ -1467,17 +1467,17 @@
int64_t after_created = TimeMillis();
Connection* conn = ch1.conn();
ASSERT_NE(conn, nullptr);
- // It is not dead if it is after MIN_CONNECTION_LIFETIME but not pruned.
- conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1);
+ // It is not dead if it is after kMinConnectionLifetime but not pruned.
+ conn->UpdateState(after_created + kMinConnectionLifetime.ms() + 1);
Thread::Current()->ProcessMessages(0);
EXPECT_TRUE(ch1.conn() != nullptr);
- // It is not dead if it is before MIN_CONNECTION_LIFETIME and pruned.
- conn->UpdateState(before_created + MIN_CONNECTION_LIFETIME - 1);
+ // It is not dead if it is before kMinConnectionLifetime and pruned.
+ conn->UpdateState(before_created + kMinConnectionLifetime.ms() - 1);
conn->Prune();
Thread::Current()->ProcessMessages(0);
EXPECT_TRUE(ch1.conn() != nullptr);
- // It will be dead after MIN_CONNECTION_LIFETIME and pruned.
- conn->UpdateState(after_created + MIN_CONNECTION_LIFETIME + 1);
+ // It will be dead after kMinConnectionLifetime and pruned.
+ conn->UpdateState(after_created + kMinConnectionLifetime.ms() + 1);
EXPECT_THAT(WaitUntil([&] { return ch1.conn(); }, Eq(nullptr),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -1490,12 +1490,13 @@
int64_t before_last_receiving = TimeMillis();
conn->ReceivedPing();
int64_t after_last_receiving = TimeMillis();
- // The connection will be dead after DEAD_CONNECTION_RECEIVE_TIMEOUT
- conn->UpdateState(before_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT -
+ // The connection will be dead after kDeadConnectionReceiveTimeout
+ conn->UpdateState(before_last_receiving + kDeadConnectionReceiveTimeout.ms() -
1);
Thread::Current()->ProcessMessages(100);
EXPECT_TRUE(ch1.conn() != nullptr);
- conn->UpdateState(after_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT + 1);
+ conn->UpdateState(after_last_receiving + kDeadConnectionReceiveTimeout.ms() +
+ 1);
EXPECT_THAT(WaitUntil([&] { return ch1.conn(); }, Eq(nullptr),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -1575,10 +1576,12 @@
conn->Ping(send_ping_timestamp);
// The connection will be dead 30s after the ping was sent.
- conn->UpdateState(send_ping_timestamp + DEAD_CONNECTION_RECEIVE_TIMEOUT - 1);
+ conn->UpdateState(send_ping_timestamp + kDeadConnectionReceiveTimeout.ms() -
+ 1);
Thread::Current()->ProcessMessages(100);
EXPECT_TRUE(ch1.conn() != nullptr);
- conn->UpdateState(send_ping_timestamp + DEAD_CONNECTION_RECEIVE_TIMEOUT + 1);
+ conn->UpdateState(send_ping_timestamp + kDeadConnectionReceiveTimeout.ms() +
+ 1);
EXPECT_THAT(WaitUntil([&] { return ch1.conn(); }, Eq(nullptr),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -3140,11 +3143,11 @@
// Ask the connection to update state as if enough time has passed to lose
// full writability and 5 pings went unresponded to. We'll accomplish the
// latter by sending pings but not pumping messages.
- for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) {
+ for (uint32_t i = 1; i <= kConnectionWriteConnectFailures; ++i) {
ch1.Ping(i);
}
int unreliable_timeout_delay =
- CONNECTION_WRITE_CONNECT_TIMEOUT + kMaxExpectedSimulatedRtt;
+ kConnectionWriteConnectTimeout.ms() + kMaxExpectedSimulatedRtt;
ch1.conn()->UpdateState(unreliable_timeout_delay);
EXPECT_EQ(Connection::STATE_WRITE_UNRELIABLE, ch1.conn()->write_state());
@@ -3160,10 +3163,11 @@
IsRtcOk());
// Wait long enough for a full timeout (past however long we've already
// waited).
- for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) {
+ for (uint32_t i = 1; i <= kConnectionWriteConnectFailures; ++i) {
ch1.Ping(unreliable_timeout_delay + i);
}
- ch1.conn()->UpdateState(unreliable_timeout_delay + CONNECTION_WRITE_TIMEOUT +
+ ch1.conn()->UpdateState(unreliable_timeout_delay +
+ kConnectionWriteTimeout.ms() +
kMaxExpectedSimulatedRtt);
EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state());
@@ -3176,8 +3180,8 @@
}
// Test writability states using the configured threshold value to replace
-// the default value given by `CONNECTION_WRITE_CONNECT_TIMEOUT` and
-// `CONNECTION_WRITE_CONNECT_FAILURES`.
+// the default value given by `kConnectionWriteConnectTimeout` and
+// `kConnectionWriteConnectFailures`.
TEST_F(PortTest, TestWritableStateWithConfiguredThreshold) {
ScopedFakeClock clock;
auto port1 = CreateUdpPort(kLocalAddr1);
@@ -3261,10 +3265,11 @@
EXPECT_EQ(Connection::STATE_WRITE_INIT, ch1.conn()->write_state());
// Attempt to go directly to write timeout.
- for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) {
+ for (uint32_t i = 1; i <= kConnectionWriteConnectFailures; ++i) {
ch1.Ping(i);
}
- ch1.conn()->UpdateState(CONNECTION_WRITE_TIMEOUT + kMaxExpectedSimulatedRtt);
+ ch1.conn()->UpdateState(kConnectionWriteTimeout.ms() +
+ kMaxExpectedSimulatedRtt);
EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state());
}
diff --git a/p2p/base/regathering_controller.h b/p2p/base/regathering_controller.h
index 8a138ec..6cd1486 100644
--- a/p2p/base/regathering_controller.h
+++ b/p2p/base/regathering_controller.h
@@ -50,7 +50,7 @@
public:
struct Config {
int regather_on_failed_networks_interval =
- REGATHER_ON_FAILED_NETWORKS_INTERVAL;
+ kRegatherOnFailedNetworksInterval.ms();
};
BasicRegatheringController() = delete;
diff --git a/p2p/base/stun_port.cc b/p2p/base/stun_port.cc
index 9903a16..9adfeeb 100644
--- a/p2p/base/stun_port.cc
+++ b/p2p/base/stun_port.cc
@@ -190,7 +190,7 @@
socket_(socket),
error_(0),
ready_(false),
- stun_keepalive_delay_(STUN_KEEPALIVE_INTERVAL),
+ stun_keepalive_delay_(kStunKeepaliveInterval.ms()),
dscp_(DSCP_NO_CHANGE),
emit_local_for_anyaddress_(emit_local_for_anyaddress) {}
@@ -208,7 +208,7 @@
socket_(nullptr),
error_(0),
ready_(false),
- stun_keepalive_delay_(STUN_KEEPALIVE_INTERVAL),
+ stun_keepalive_delay_(kStunKeepaliveInterval.ms()),
dscp_(DSCP_NO_CHANGE),
emit_local_for_anyaddress_(emit_local_for_anyaddress) {}
@@ -364,7 +364,7 @@
}
void UDPPort::set_stun_keepalive_delay(const std::optional<int>& delay) {
- stun_keepalive_delay_ = delay.value_or(STUN_KEEPALIVE_INTERVAL);
+ stun_keepalive_delay_ = delay.value_or(kStunKeepaliveInterval.ms());
}
void UDPPort::OnLocalAddressReady(AsyncPacketSocket* /* socket */,
diff --git a/p2p/base/tcp_port.cc b/p2p/base/tcp_port.cc
index 6ea2ddd..1e72b11 100644
--- a/p2p/base/tcp_port.cc
+++ b/p2p/base/tcp_port.cc
@@ -340,7 +340,7 @@
Port::OnReadyToSend();
}
-// TODO(qingsi): `CONNECTION_WRITE_CONNECT_TIMEOUT` is overriden by
+// TODO(qingsi): `kConnectionWriteConnectTimeout` is overriden by
// `ice_unwritable_timeout` in IceConfig when determining the writability state.
// Replace this constant with the config parameter assuming the default value if
// we decide it is also applicable here.
@@ -354,7 +354,7 @@
outgoing_(socket == nullptr),
connection_pending_(false),
pretending_to_be_writable_(false),
- reconnection_timeout_(CONNECTION_WRITE_CONNECT_TIMEOUT) {
+ reconnection_timeout_(kConnectionWriteConnectTimeout.ms()) {
RTC_DCHECK_RUN_ON(network_thread());
RTC_DCHECK_EQ(port()->GetProtocol(),
PROTO_TCP); // Needs to be TCPPort.