commit 604a8de79856b2f18eac2f3014fac150d25bc98d
parent 8ee52a2d34dc565d21f3f81e5fadfe3fd70c90ff
Author: Dan Baker <dbaker@mozilla.com>
Date: Mon, 1 Dec 2025 19:37:44 -0700
Bug 2000941 - Vendor libwebrtc from 3c35dd3c93
Upstream commit: https://webrtc.googlesource.com/src/+/3c35dd3c9358303aa0a3e66767bf7a77f4a58175
In p2p tests use Connection functions taking TimeDelta/Timestamp
Thus reduce usage of functions that use raw ints to represent time
Bug: webrtc:42223979
Change-Id: Ic03bee25bcf4c6f15397d6662741c84c42ccda0b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/408823
Commit-Queue: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Auto-Submit: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45626}
Diffstat:
5 files changed, 172 insertions(+), 194 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-02T02:34:37.298808+00:00.
+libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-02T02:37:24.059453+00:00.
# base of lastest vendoring
-dc5f3e9b89
+3c35dd3c93
diff --git a/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc b/third_party/libwebrtc/p2p/base/p2p_transport_channel_unittest.cc
@@ -131,7 +131,7 @@ constexpr TimeDelta kShortTimeout = TimeDelta::Seconds(1);
constexpr int kOnlyLocalPorts = PORTALLOCATOR_DISABLE_STUN |
PORTALLOCATOR_DISABLE_RELAY |
PORTALLOCATOR_DISABLE_TCP;
-constexpr int LOW_RTT = 20;
+constexpr TimeDelta kLowRtt = TimeDelta::Millis(20);
// Addresses on the public internet.
const SocketAddress kPublicAddrs[2] = {SocketAddress("11.11.11.11", 0),
SocketAddress("22.22.22.22", 0)};
@@ -2761,7 +2761,7 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverWithManyConnections) {
Connection* per_network_best_connection1 =
GetConnection(ep1_ch1(), cellularIpv6[0], wifiIpv6[1]);
ASSERT_NE(nullptr, per_network_best_connection1);
- int64_t last_ping_sent1 = per_network_best_connection1->last_ping_sent();
+ Timestamp last_ping_sent1 = per_network_best_connection1->LastPingSent();
int num_pings_sent1 = per_network_best_connection1->num_pings_sent();
EXPECT_THAT(
WaitUntil([&] { return per_network_best_connection1->num_pings_sent(); },
@@ -2770,13 +2770,12 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailoverWithManyConnections) {
IsRtcOk());
ASSERT_GT(per_network_best_connection1->num_pings_sent() - num_pings_sent1,
0);
- int64_t ping_interval1 =
- (per_network_best_connection1->last_ping_sent() - last_ping_sent1) /
+ TimeDelta ping_interval1 =
+ (per_network_best_connection1->LastPingSent() - last_ping_sent1) /
(per_network_best_connection1->num_pings_sent() - num_pings_sent1);
- constexpr int SCHEDULING_DELAY = 200;
- EXPECT_LT(
- ping_interval1,
- kWeakOrStabilizingWritableConnectionPingInterval.ms() + SCHEDULING_DELAY);
+ constexpr TimeDelta kSchedulingDelay = TimeDelta::Millis(200);
+ EXPECT_LT(ping_interval1, kWeakOrStabilizingWritableConnectionPingInterval +
+ kSchedulingDelay);
// It should switch over to use the cellular IPv6 addr on endpoint 1 before
// it timed out on writing.
@@ -3683,7 +3682,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
Connection* conn = GetConnectionTo(channel, ip_addr, port);
if (conn && writable) {
- conn->ReceivedPingResponse(LOW_RTT, "id"); // make it writable
+ conn->ReceivedPingResponse(kLowRtt, "id"); // make it writable
}
return conn;
}
@@ -3782,7 +3781,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
last_selected_pair.remote_candidate().IsEquivalent(
conn->remote_candidate()) &&
last_candidate_change_event_->last_data_received_ms ==
- conn->last_data_received() &&
+ conn->LastDataReceived().ms() &&
last_candidate_change_event_->reason == reason;
}
}
@@ -3859,7 +3858,7 @@ TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
// Low-priority connection becomes writable so that the other connection
// is not pruned.
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_TRUE(WaitUntil(
[&] {
return conn1->num_pings_sent() >= kMinPingsAtWeakPingInterval &&
@@ -3873,8 +3872,8 @@ TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
ScopedFakeClock clock;
const Environment env = CreateEnvironment();
int RTT_RATIO = 4;
- int SCHEDULING_RANGE = 200;
- int RTT_RANGE = 10;
+ constexpr TimeDelta kSchedulingRange = TimeDelta::Millis(200);
+ constexpr TimeDelta kRttRange = TimeDelta::Millis(10);
FakePortAllocator pa(env, ss());
P2PTransportChannel ch(env, "TestChannel", 1, &pa);
@@ -3889,76 +3888,69 @@ TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
// Initializing.
- int64_t start = clock.TimeNanos();
+ Timestamp start = env.clock().CurrentTime();
SIMULATED_WAIT(conn->num_pings_sent() >= kMinPingsAtWeakPingInterval,
kDefaultTimeout.ms(), clock);
- int64_t ping_interval_ms = (clock.TimeNanos() - start) /
- kNumNanosecsPerMillisec /
- (kMinPingsAtWeakPingInterval - 1);
- EXPECT_EQ(ping_interval_ms, kWeakPingInterval.ms());
+ TimeDelta ping_interval =
+ (env.clock().CurrentTime() - start) / (kMinPingsAtWeakPingInterval - 1);
+ EXPECT_EQ(ping_interval, kWeakPingInterval);
// Stabilizing.
- conn->ReceivedPingResponse(LOW_RTT, "id");
+ conn->ReceivedPingResponse(kLowRtt, "id");
int ping_sent_before = conn->num_pings_sent();
- start = clock.TimeNanos();
+ start = env.clock().CurrentTime();
// The connection becomes strong but not stable because we haven't been able
// to converge the RTT.
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,
- kWeakOrStabilizingWritableConnectionPingInterval.ms());
- EXPECT_LE(
- ping_interval_ms,
- kWeakOrStabilizingWritableConnectionPingInterval.ms() + SCHEDULING_RANGE);
+ ping_interval = env.clock().CurrentTime() - start;
+ EXPECT_GE(ping_interval, kWeakOrStabilizingWritableConnectionPingInterval);
+ EXPECT_LE(ping_interval, kWeakOrStabilizingWritableConnectionPingInterval +
+ kSchedulingRange);
// Stabilized.
// The connection becomes stable after receiving more than RTT_RATIO rtt
// samples.
for (int i = 0; i < RTT_RATIO; i++) {
- conn->ReceivedPingResponse(LOW_RTT, "id");
+ conn->ReceivedPingResponse(kLowRtt, "id");
}
ping_sent_before = conn->num_pings_sent();
- start = clock.TimeNanos();
+ start = env.clock().CurrentTime();
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,
- kStrongAndStableWritableConnectionPingInterval.ms());
- EXPECT_LE(
- ping_interval_ms,
- kStrongAndStableWritableConnectionPingInterval.ms() + SCHEDULING_RANGE);
+ ping_interval = env.clock().CurrentTime() - start;
+ EXPECT_GE(ping_interval, kStrongAndStableWritableConnectionPingInterval);
+ EXPECT_LE(ping_interval,
+ kStrongAndStableWritableConnectionPingInterval + kSchedulingRange);
// Destabilized.
- conn->ReceivedPingResponse(LOW_RTT, "id");
+ conn->ReceivedPingResponse(kLowRtt, "id");
// Create a in-flight ping.
- conn->Ping(clock.TimeNanos() / kNumNanosecsPerMillisec);
- start = clock.TimeNanos();
+ conn->Ping();
+ start = env.clock().CurrentTime();
// In-flight ping timeout and the connection will be unstable.
- SIMULATED_WAIT(!conn->stable(clock.TimeNanos() / kNumNanosecsPerMillisec),
- kMediumTimeout.ms(), clock);
- int64_t duration_ms = (clock.TimeNanos() - start) / kNumNanosecsPerMillisec;
- EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE);
- EXPECT_LE(duration_ms, 2 * conn->rtt() + RTT_RANGE);
+ SIMULATED_WAIT(!conn->stable(env.clock().CurrentTime()), kMediumTimeout.ms(),
+ clock);
+ TimeDelta duration = env.clock().CurrentTime() - start;
+ EXPECT_GE(duration, 2 * conn->Rtt() - kRttRange);
+ EXPECT_LE(duration, 2 * conn->Rtt() + kRttRange);
// The connection become unstable due to not receiving ping responses.
ping_sent_before = conn->num_pings_sent();
SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1,
kMediumTimeout.ms(), clock);
// The interval is expected to be
// kWeakOrStabilizingWritableConnectionPingInterval.
- start = clock.TimeNanos();
+ start = env.clock().CurrentTime();
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,
- kWeakOrStabilizingWritableConnectionPingInterval.ms());
- EXPECT_LE(
- ping_interval_ms,
- kWeakOrStabilizingWritableConnectionPingInterval.ms() + SCHEDULING_RANGE);
+ ping_interval = env.clock().CurrentTime() - start;
+ EXPECT_GE(ping_interval, kWeakOrStabilizingWritableConnectionPingInterval);
+ EXPECT_LE(ping_interval, kWeakOrStabilizingWritableConnectionPingInterval +
+ kSchedulingRange);
}
// Test that we start pinging as soon as we have a connection and remote ICE
@@ -4024,7 +4016,7 @@ TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
ASSERT_TRUE(conn1->writable());
conn1->ReceivedPing();
@@ -4154,7 +4146,7 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing();
- conn2->ReceivedPingResponse(LOW_RTT, "id");
+ conn2->ReceivedPingResponse(kLowRtt, "id");
// Wait for conn2 to be selected.
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn2),
@@ -4247,7 +4239,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
EXPECT_EQ(-1, last_sent_packet_id());
// A connection needs to be writable before it is selected for transmission.
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4262,7 +4254,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 10));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
- conn2->ReceivedPingResponse(LOW_RTT, "id");
+ conn2->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn2),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4282,7 +4274,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
ASSERT_TRUE(conn3 != nullptr);
// Because it has a lower priority, the selected connection is still conn2.
EXPECT_EQ(conn2, ch.selected_connection());
- conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
+ conn3->ReceivedPingResponse(kLowRtt, "id"); // Become writable.
// But if it is nominated via use_candidate, it is chosen as the selected
// connection.
NominateConnection(conn3);
@@ -4310,7 +4302,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
EXPECT_EQ(conn3, ch.selected_connection());
reset_channel_ready_to_send();
// The selected connection switches after conn4 becomes writable.
- conn4->ReceivedPingResponse(LOW_RTT, "id");
+ conn4->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn4),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4340,7 +4332,7 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnNomination) {
ASSERT_TRUE(conn1 != nullptr);
// A connection needs to be writable before it is selected for transmission.
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4352,7 +4344,7 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnNomination) {
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 10));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
- conn2->ReceivedPingResponse(LOW_RTT, "id");
+ conn2->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn2),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4386,7 +4378,7 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSwitch) {
ASSERT_TRUE(conn1 != nullptr);
// A connection needs to be writable before it is selected for transmission.
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4401,7 +4393,7 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSwitch) {
const int before = conn2->num_pings_sent();
- conn2->ReceivedPingResponse(LOW_RTT, "id");
+ conn2->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn2),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4431,7 +4423,7 @@ TEST_F(P2PTransportChannelPingTest, TestPingOnSelected) {
const int before = conn1->num_pings_sent();
// A connection needs to be writable before it is selected for transmission.
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4468,7 +4460,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1->stats().sent_ping_responses, 1u);
EXPECT_NE(conn1, ch.selected_connection());
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4482,7 +4474,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
EXPECT_EQ(conn1, ch.selected_connection());
// When it is nominated via use_candidate and writable, it is chosen as the
// selected connection.
- conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
+ conn2->ReceivedPingResponse(kLowRtt, "id"); // Become writable.
NominateConnection(conn2);
EXPECT_EQ(conn2, ch.selected_connection());
@@ -4494,7 +4486,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
EXPECT_EQ(conn3->stats().sent_ping_responses, 1u);
- conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
+ conn3->ReceivedPingResponse(kLowRtt, "id"); // Become writable.
EXPECT_EQ(conn2, ch.selected_connection());
// However if the request contains use_candidate attribute, it will be
@@ -4508,7 +4500,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
EXPECT_EQ(conn4->stats().sent_ping_responses, 1u);
// conn4 is not the selected connection yet because it is not writable.
EXPECT_EQ(conn2, ch.selected_connection());
- conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
+ conn4->ReceivedPingResponse(kLowRtt, "id"); // Become writable.
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn4),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4541,7 +4533,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 10));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4553,11 +4545,11 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 1));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
- conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable and receiving.
+ conn2->ReceivedPingResponse(kLowRtt, "id"); // Become writable and receiving.
conn2->OnReadPacket(ReceivedIpPacket::CreateFromLegacy(
"ABC", 3, env.clock().TimeInMicroseconds()));
EXPECT_EQ(conn2, ch.selected_connection());
- conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
+ conn2->ReceivedPingResponse(kLowRtt, "id"); // Become writable.
// Now another STUN message with an unknown address and use_candidate will
// nominate the selected connection.
@@ -4575,7 +4567,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
EXPECT_NE(conn3, ch.selected_connection()); // Not writable yet.
- conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
+ conn3->ReceivedPingResponse(kLowRtt, "id"); // Become writable.
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn3),
{.timeout = kDefaultTimeout}),
IsRtcOk());
@@ -4583,7 +4575,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
// Now another data packet will not switch the selected connection because the
// selected connection was nominated by the controlling side.
conn2->ReceivedPing();
- conn2->ReceivedPingResponse(LOW_RTT, "id");
+ conn2->ReceivedPingResponse(kLowRtt, "id");
conn2->OnReadPacket(ReceivedIpPacket::CreateFromLegacy(
"XYZ", 3, env.clock().TimeInMicroseconds()));
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn3),
@@ -4633,7 +4625,7 @@ TEST_F(P2PTransportChannelPingTest,
// received data more recently.
SIMULATED_WAIT(false, 1, clock);
// Need to become writable again because it was pruned.
- conn2->ReceivedPingResponse(LOW_RTT, "id");
+ conn2->ReceivedPingResponse(kLowRtt, "id");
conn2->OnReadPacket(ReceivedIpPacket::CreateFromLegacy(
"ABC", 3, env.clock().TimeInMicroseconds()));
EXPECT_EQ(1, reset_selected_candidate_pair_switches());
@@ -4840,7 +4832,7 @@ TEST_F(P2PTransportChannelPingTest,
EXPECT_EQ(0, reset_selected_candidate_pair_switches());
// conn2 becomes writable; it is selected even though it is not nominated.
- conn2->ReceivedPingResponse(LOW_RTT, "id");
+ conn2->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(
WaitUntil([&] { return reset_selected_candidate_pair_switches(); }, Eq(1),
{.timeout = kDefaultTimeout, .clock = &clock}),
@@ -4851,7 +4843,7 @@ TEST_F(P2PTransportChannelPingTest,
EXPECT_TRUE(CandidatePairMatchesNetworkRoute(conn2));
// If conn1 is also writable, it will become selected.
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(
WaitUntil([&] { return reset_selected_candidate_pair_switches(); }, Eq(1),
{.timeout = kDefaultTimeout, .clock = &clock}),
@@ -4900,9 +4892,9 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
// Verify that a ping with the new ufrag can be received on the new
// connection.
- EXPECT_EQ(0, conn2->last_ping_received());
+ EXPECT_EQ(conn2->LastPingReceived(), Timestamp::Zero());
ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */);
- EXPECT_GT(conn2->last_ping_received(), 0);
+ EXPECT_GT(conn2->LastPingReceived(), Timestamp::Zero());
}
// When the current selected connection is strong, lower-priority connections
@@ -4921,7 +4913,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
- conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
+ conn1->ReceivedPingResponse(kLowRtt, "id"); // Becomes writable and receiving
// When a higher-priority, nominated candidate comes in, the connections with
// lower-priority are pruned.
@@ -4929,7 +4921,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 10));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
ASSERT_TRUE(conn2 != nullptr);
- conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
+ conn2->ReceivedPingResponse(kLowRtt, "id"); // Becomes writable and receiving
NominateConnection(conn2);
EXPECT_TRUE(WaitUntil([&] { return conn1->pruned(); },
{.timeout = kMediumTimeout, .clock = &clock}));
@@ -5005,7 +4997,7 @@ TEST_F(P2PTransportChannelPingTest, TestGetState) {
// state.
EXPECT_EQ(IceTransportState::kChecking, ch.GetIceTransportState());
// `conn1` becomes writable and receiving; it then should prune `conn2`.
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_TRUE(WaitUntil([&] { return conn2->pruned(); },
{.timeout = kShortTimeout, .clock = &clock}));
EXPECT_EQ(IceTransportStateInternal::STATE_COMPLETED, ch.GetState());
@@ -5038,7 +5030,7 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
- conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
+ conn1->ReceivedPingResponse(kLowRtt, "id"); // Becomes writable and receiving
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1),
{.timeout = kDefaultTimeout, .clock = &clock}),
IsRtcOk());
@@ -5066,14 +5058,14 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
Eq(IceCandidatePairState::IN_PROGRESS),
{.timeout = kDefaultTimeout, .clock = &clock}),
IsRtcOk());
- conn2->ReceivedPingResponse(LOW_RTT, "id");
+ conn2->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn2),
{.timeout = kDefaultTimeout, .clock = &clock}),
IsRtcOk());
EXPECT_EQ(IceTransportStateInternal::STATE_CONNECTING, ch.GetState());
// When `conn1` comes back again, `conn2` will be pruned again.
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch.selected_connection(); }, Eq(conn1),
{.timeout = kDefaultTimeout, .clock = &clock}),
IsRtcOk());
@@ -5134,7 +5126,7 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
CreateUdpCandidate(IceCandidateType::kHost, "1.1.1.1", 1, 100));
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
- conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
+ conn1->ReceivedPingResponse(kLowRtt, "id"); // Becomes writable and receiving
EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
// Start a new session. Even though conn1, which belongs to an older
@@ -5143,7 +5135,7 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
ch.SetIceParameters(kIceParams[1]);
ch.MaybeStartGathering();
conn1->Prune();
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_TRUE(ch.allocator_session()->IsGettingPorts());
// But if a new connection created from the new session becomes writable,
@@ -5152,7 +5144,7 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
CreateUdpCandidate(IceCandidateType::kHost, "2.2.2.2", 2, 100));
Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
- conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
+ conn2->ReceivedPingResponse(kLowRtt, "id"); // Becomes writable and receiving
EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
}
@@ -5385,7 +5377,7 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
ASSERT_TRUE(conn3 != nullptr);
EXPECT_TRUE(conn3->local_candidate().is_local());
EXPECT_TRUE(conn3->remote_candidate().is_relay());
- conn3->ReceivedPingResponse(LOW_RTT, "id");
+ conn3->ReceivedPingResponse(kLowRtt, "id");
ASSERT_TRUE(conn3->writable());
conn3->ReceivedPing();
@@ -5403,7 +5395,7 @@ TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
// pingable connection.
EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), kDefaultTimeout);
WAIT(false, max_strong_interval + 100);
- conn3->ReceivedPingResponse(LOW_RTT, "id");
+ conn3->ReceivedPingResponse(kLowRtt, "id");
ASSERT_TRUE(conn3->writable());
EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch));
@@ -6524,7 +6516,7 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampening0) {
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
- conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
+ conn1->ReceivedPingResponse(kLowRtt, "id"); // Becomes writable and receiving
// It shall not be selected until 0ms has passed....i.e it should be connected
// directly.
EXPECT_THAT(
@@ -6551,7 +6543,7 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampening) {
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
- conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
+ conn1->ReceivedPingResponse(kLowRtt, "id"); // Becomes writable and receiving
// It shall not be selected until 100ms has passed.
SIMULATED_WAIT(conn1 == ch.selected_connection(), 100 - kMargin, clock);
EXPECT_THAT(
@@ -6578,7 +6570,7 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningPingReceived) {
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
- conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
+ conn1->ReceivedPingResponse(kLowRtt, "id"); // Becomes writable and receiving
conn1->ReceivedPing("id1"); //
// It shall not be selected until 100ms has passed.
SIMULATED_WAIT(conn1 == ch.selected_connection(), 100 - kMargin, clock);
@@ -6608,7 +6600,7 @@ TEST_F(P2PTransportChannelPingTest, TestInitialSelectDampeningBoth) {
Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(nullptr, ch.selected_connection());
- conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
+ conn1->ReceivedPingResponse(kLowRtt, "id"); // Becomes writable and receiving
// It shall not be selected until 100ms has passed....but only wait ~50 now.
SIMULATED_WAIT(conn1 == ch.selected_connection(), 50 - kMargin, clock);
// Now receiving ping and new timeout should kick in.
@@ -6712,12 +6704,12 @@ TEST_F(P2PTransportChannelPingTest, TestForgetLearnedState) {
ASSERT_TRUE(conn2 != nullptr);
// Wait for conn1 to be selected.
- conn1->ReceivedPingResponse(LOW_RTT, "id");
+ conn1->ReceivedPingResponse(kLowRtt, "id");
EXPECT_THAT(WaitUntil([&] { return ch->selected_connection(); }, Eq(conn1),
{.timeout = kMediumTimeout}),
IsRtcOk());
- conn2->ReceivedPingResponse(LOW_RTT, "id");
+ conn2->ReceivedPingResponse(kLowRtt, "id");
EXPECT_TRUE(conn2->writable());
// Now let the ice controller signal to P2PTransportChannel that it
diff --git a/third_party/libwebrtc/p2p/base/port_unittest.cc b/third_party/libwebrtc/p2p/base/port_unittest.cc
@@ -35,6 +35,7 @@
#include "api/test/rtc_error_matchers.h"
#include "api/transport/stun.h"
#include "api/units/time_delta.h"
+#include "api/units/timestamp.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/connection.h"
#include "p2p/base/p2p_constants.h"
@@ -70,7 +71,6 @@
#include "rtc_base/socket_address.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "rtc_base/thread.h"
-#include "rtc_base/time_utils.h"
#include "rtc_base/virtual_socket_server.h"
#include "test/create_test_environment.h"
#include "test/create_test_field_trials.h"
@@ -78,32 +78,18 @@
#include "test/gtest.h"
#include "test/wait_until.h"
+namespace webrtc {
+namespace {
+
using ::testing::Eq;
using ::testing::IsNull;
using ::testing::IsTrue;
using ::testing::NotNull;
-using ::webrtc::AsyncListenSocket;
-using webrtc::AsyncPacketSocket;
-using webrtc::ByteBufferReader;
-using webrtc::ByteBufferWriter;
-using ::webrtc::CreateEnvironment;
-using ::webrtc::Environment;
-using ::webrtc::IceCandidateType;
-using ::webrtc::NAT_ADDR_RESTRICTED;
-using ::webrtc::NAT_OPEN_CONE;
-using ::webrtc::NAT_PORT_RESTRICTED;
-using ::webrtc::NAT_SYMMETRIC;
-using ::webrtc::NATType;
-using webrtc::PacketSocketFactory;
-using ::webrtc::Socket;
-using ::webrtc::SocketAddress;
-
-namespace webrtc {
-namespace {
constexpr int kDefaultTimeout = 3000;
constexpr int kShortTimeout = 1000;
-constexpr int kMaxExpectedSimulatedRtt = 200;
+constexpr TimeDelta kMaxExpectedSimulatedRtt = TimeDelta::Millis(200);
+constexpr TimeDelta kEpsilon = TimeDelta::Millis(1);
const SocketAddress kLocalAddr1("192.168.1.2", 0);
const SocketAddress kLocalAddr2("192.168.1.3", 0);
const SocketAddress kLinkLocalIPv6Addr("fe80::aabb:ccff:fedd:eeff", 0);
@@ -274,7 +260,7 @@ static void SendPingAndReceiveResponse(Connection* lconn,
TestPort* rport,
ScopedFakeClock* clock,
int64_t ms) {
- lconn->Ping(TimeMillis());
+ lconn->Ping();
ASSERT_THAT(WaitUntil([&] { return lport->last_stun_msg(); }, IsTrue(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -346,8 +332,8 @@ class TestChannel : public sigslot::has_slots<> {
conn_->SendStunBindingResponse(remote_request_.get());
remote_request_.reset();
}
- void Ping() { Ping(0); }
- void Ping(int64_t now) { conn_->Ping(now); }
+ void Ping() { conn_->Ping(); }
+ void Ping(Timestamp now) { conn_->Ping(now); }
void Stop() {
if (conn_) {
port_->DestroyConnection(conn_);
@@ -1469,22 +1455,22 @@ TEST_F(PortTest, TestConnectionDead) {
IsRtcOk());
// Test case that the connection has never received anything.
- int64_t before_created = TimeMillis();
+ Timestamp before_created = env().clock().CurrentTime();
ch1.CreateConnection(GetCandidate(ch2.port()));
- int64_t after_created = TimeMillis();
+ Timestamp after_created = env().clock().CurrentTime();
Connection* conn = ch1.conn();
ASSERT_NE(conn, nullptr);
// It is not dead if it is after kMinConnectionLifetime but not pruned.
- conn->UpdateState(after_created + kMinConnectionLifetime.ms() + 1);
+ conn->UpdateState(after_created + kMinConnectionLifetime + kEpsilon);
Thread::Current()->ProcessMessages(0);
EXPECT_TRUE(ch1.conn() != nullptr);
// It is not dead if it is before kMinConnectionLifetime and pruned.
- conn->UpdateState(before_created + kMinConnectionLifetime.ms() - 1);
+ conn->UpdateState(before_created + kMinConnectionLifetime - kEpsilon);
conn->Prune();
Thread::Current()->ProcessMessages(0);
EXPECT_TRUE(ch1.conn() != nullptr);
// It will be dead after kMinConnectionLifetime and pruned.
- conn->UpdateState(after_created + kMinConnectionLifetime.ms() + 1);
+ conn->UpdateState(after_created + kMinConnectionLifetime + kEpsilon);
EXPECT_THAT(WaitUntil([&] { return ch1.conn(); }, Eq(nullptr),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -1494,16 +1480,16 @@ TEST_F(PortTest, TestConnectionDead) {
ch1.CreateConnection(GetCandidate(ch2.port()));
conn = ch1.conn();
ASSERT_NE(conn, nullptr);
- int64_t before_last_receiving = TimeMillis();
+ Timestamp before_last_receiving = env().clock().CurrentTime();
conn->ReceivedPing();
- int64_t after_last_receiving = TimeMillis();
+ Timestamp after_last_receiving = env().clock().CurrentTime();
// The connection will be dead after kDeadConnectionReceiveTimeout
- conn->UpdateState(before_last_receiving + kDeadConnectionReceiveTimeout.ms() -
- 1);
+ conn->UpdateState(before_last_receiving + kDeadConnectionReceiveTimeout -
+ kEpsilon);
Thread::Current()->ProcessMessages(100);
EXPECT_TRUE(ch1.conn() != nullptr);
- conn->UpdateState(after_last_receiving + kDeadConnectionReceiveTimeout.ms() +
- 1);
+ conn->UpdateState(after_last_receiving + kDeadConnectionReceiveTimeout +
+ kEpsilon);
EXPECT_THAT(WaitUntil([&] { return ch1.conn(); }, Eq(nullptr),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -1533,14 +1519,14 @@ TEST_F(PortTest, TestConnectionDeadWithDeadConnectionTimeout) {
conn->SetIceFieldTrials(&field_trials);
ASSERT_NE(conn, nullptr);
- int64_t before_last_receiving = TimeMillis();
+ Timestamp before_last_receiving = env().clock().CurrentTime();
conn->ReceivedPing();
- int64_t after_last_receiving = TimeMillis();
+ Timestamp after_last_receiving = env().clock().CurrentTime();
// The connection will be dead after 90s
- conn->UpdateState(before_last_receiving + 90000 - 1);
+ conn->UpdateState(before_last_receiving + TimeDelta::Seconds(90) - kEpsilon);
Thread::Current()->ProcessMessages(100);
EXPECT_TRUE(ch1.conn() != nullptr);
- conn->UpdateState(after_last_receiving + 90000 + 1);
+ conn->UpdateState(after_last_receiving + TimeDelta::Seconds(90) + kEpsilon);
EXPECT_THAT(WaitUntil([&] { return ch1.conn(); }, Eq(nullptr),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -1579,16 +1565,16 @@ TEST_F(PortTest, TestConnectionDeadOutstandingPing) {
ASSERT_NE(conn, nullptr);
conn->ReceivedPing();
- int64_t send_ping_timestamp = TimeMillis();
+ Timestamp send_ping_timestamp = env().clock().CurrentTime();
conn->Ping(send_ping_timestamp);
// The connection will be dead 30s after the ping was sent.
- conn->UpdateState(send_ping_timestamp + kDeadConnectionReceiveTimeout.ms() -
- 1);
+ conn->UpdateState(send_ping_timestamp + kDeadConnectionReceiveTimeout -
+ kEpsilon);
Thread::Current()->ProcessMessages(100);
EXPECT_TRUE(ch1.conn() != nullptr);
- conn->UpdateState(send_ping_timestamp + kDeadConnectionReceiveTimeout.ms() +
- 1);
+ conn->UpdateState(send_ping_timestamp + kDeadConnectionReceiveTimeout +
+ kEpsilon);
EXPECT_THAT(WaitUntil([&] { return ch1.conn(); }, Eq(nullptr),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -1621,7 +1607,7 @@ TEST_F(PortTest, TestLoopbackCall) {
ASSERT_FALSE(lport->Candidates().empty());
Connection* conn =
lport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
- conn->Ping(0);
+ conn->Ping();
ASSERT_THAT(WaitUntil([&] { return lport->last_stun_msg(); }, NotNull(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
@@ -1643,7 +1629,7 @@ TEST_F(PortTest, TestLoopbackCall) {
// Creating a different connection as `conn` is receiving.
Connection* conn1 =
lport->CreateConnection(lport->Candidates()[1], Port::ORIGIN_MESSAGE);
- conn1->Ping(0);
+ conn1->Ping();
ASSERT_THAT(WaitUntil([&] { return lport->last_stun_msg(); }, NotNull(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
@@ -1697,7 +1683,7 @@ TEST_F(PortTest, TestIceRoleConflict) {
lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
Connection* rconn =
rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
- rconn->Ping(0);
+ rconn->Ping();
ASSERT_THAT(WaitUntil([&] { return rport->last_stun_msg(); }, NotNull(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
@@ -1819,7 +1805,7 @@ TEST_F(PortTest, TestDisableInterfaceOfTcpPort) {
lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
ASSERT_NE(lconn, nullptr);
socket->NotifyConnect(socket);
- lconn->Ping(0);
+ lconn->Ping();
// Now disconnect the client socket...
socket->NotifyClosedForTest(1);
@@ -1828,7 +1814,7 @@ TEST_F(PortTest, TestDisableInterfaceOfTcpPort) {
socket_factory.set_next_client_tcp_socket(nullptr);
// Test that Ping() does not cause SEGV.
- lconn->Ping(0);
+ lconn->Ping();
}
void PortTest::TestCrossFamilyPorts(int type) {
@@ -2013,7 +1999,7 @@ TEST_F(PortTest, TestSendStunMessage) {
lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
Connection* rconn =
rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
- lconn->Ping(0);
+ lconn->Ping();
// Check that it's a proper BINDING-REQUEST.
ASSERT_THAT(WaitUntil([&] { return lport->last_stun_msg(); }, NotNull(),
@@ -2117,9 +2103,9 @@ TEST_F(PortTest, TestSendStunMessage) {
// and (incremented) RETRANSMIT_COUNT attributes.
rport->Reset();
rport->set_send_retransmit_count_attribute(true);
- rconn->Ping(0);
- rconn->Ping(0);
- rconn->Ping(0);
+ rconn->Ping();
+ rconn->Ping();
+ rconn->Ping();
ASSERT_THAT(WaitUntil([&] { return rport->last_stun_msg(); }, NotNull(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -2153,8 +2139,8 @@ TEST_F(PortTest, TestSendStunMessage) {
EXPECT_EQ(1U, lconn->stats().sent_ping_responses);
EXPECT_EQ(1U, lconn->stats().recv_ping_requests);
// Ping after receiver the first response
- rconn->Ping(0);
- rconn->Ping(0);
+ rconn->Ping();
+ rconn->Ping();
EXPECT_EQ(5U, rconn->stats().sent_ping_requests_total);
EXPECT_EQ(3U, rconn->stats().sent_ping_requests_before_first_response);
@@ -2192,7 +2178,7 @@ TEST_F(PortTest, TestNomination) {
// Send ping (including the nomination value) from `lconn` to `rconn`. This
// should set the remote nomination of `rconn`.
- lconn->Ping(0);
+ lconn->Ping();
ASSERT_THAT(WaitUntil([&] { return lport->last_stun_msg(); }, IsTrue(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -2277,7 +2263,7 @@ TEST_F(PortTest, TestUseCandidateAttribute) {
ASSERT_FALSE(rport->Candidates().empty());
Connection* lconn =
lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
- lconn->Ping(0);
+ lconn->Ping();
ASSERT_THAT(WaitUntil([&] { return lport->last_stun_msg(); }, NotNull(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -2332,7 +2318,7 @@ TEST_F(PortTest, TestNetworkCostChange) {
Connection* rconn =
rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
test_network->set_type(ADAPTER_TYPE_CELLULAR);
- lconn->Ping(0);
+ lconn->Ping();
// The rconn's remote candidate cost is kNetworkCostLow, but the ping
// contains an attribute of network cost of kNetworkCostHigh. Once the
// message is handled in rconn, The rconn's remote candidate will have cost
@@ -2370,7 +2356,7 @@ TEST_F(PortTest, TestNetworkInfoAttribute) {
rport->PrepareAddress();
Connection* lconn =
lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
- lconn->Ping(0);
+ lconn->Ping();
ASSERT_THAT(WaitUntil([&] { return lport->last_stun_msg(); }, NotNull(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -2390,7 +2376,7 @@ TEST_F(PortTest, TestNetworkInfoAttribute) {
test_network->set_id(rnetwork_id);
Connection* rconn =
rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
- rconn->Ping(0);
+ rconn->Ping();
ASSERT_THAT(WaitUntil([&] { return rport->last_stun_msg(); }, NotNull(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -2679,7 +2665,7 @@ TEST_F(PortTest,
rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
// Send request.
- lconn->Ping(0);
+ lconn->Ping();
ASSERT_THAT(WaitUntil([&] { return lport->last_stun_msg(); }, NotNull(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -2728,7 +2714,7 @@ TEST_F(PortTest,
WriteStunMessage(*in_msg, &buf);
lconn->OnReadPacket(ReceivedIpPacket::CreateFromLegacy(
buf.Data(), buf.Length(), /*packet_time_us=*/-1));
- EXPECT_EQ(0u, lconn->last_ping_received());
+ EXPECT_EQ(lconn->LastPingReceived(), Timestamp::Zero());
}
// Test handling of STUN binding indication messages . STUN binding
@@ -2767,7 +2753,7 @@ TEST_F(PortTest, TestHandleStunBindingIndication) {
lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
Connection* rconn =
rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
- rconn->Ping(0);
+ rconn->Ping();
ASSERT_THAT(WaitUntil([&] { return rport->last_stun_msg(); }, NotNull(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
@@ -2782,14 +2768,14 @@ TEST_F(PortTest, TestHandleStunBindingIndication) {
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type());
- int64_t last_ping_received1 = lconn->last_ping_received();
+ Timestamp last_ping_received1 = lconn->LastPingReceived();
// Adding a delay of 100ms.
Thread::Current()->ProcessMessages(100);
// Pinging lconn using stun indication message.
lconn->OnReadPacket(ReceivedIpPacket::CreateFromLegacy(
buf->Data(), buf->Length(), /*packet_time_us=*/-1));
- int64_t last_ping_received2 = lconn->last_ping_received();
+ Timestamp last_ping_received2 = lconn->LastPingReceived();
EXPECT_GT(last_ping_received2, last_ping_received1);
}
@@ -3151,10 +3137,11 @@ TEST_F(PortTest, TestWritableState) {
// 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 <= kConnectionWriteConnectFailures; ++i) {
- ch1.Ping(i);
+ ch1.Ping(Timestamp::Millis(i));
}
- int unreliable_timeout_delay =
- kConnectionWriteConnectTimeout.ms() + kMaxExpectedSimulatedRtt;
+ Timestamp unreliable_timeout_delay = Timestamp::Zero() +
+ kConnectionWriteConnectTimeout +
+ kMaxExpectedSimulatedRtt;
ch1.conn()->UpdateState(unreliable_timeout_delay);
EXPECT_EQ(Connection::STATE_WRITE_UNRELIABLE, ch1.conn()->write_state());
@@ -3171,10 +3158,9 @@ TEST_F(PortTest, TestWritableState) {
// Wait long enough for a full timeout (past however long we've already
// waited).
for (uint32_t i = 1; i <= kConnectionWriteConnectFailures; ++i) {
- ch1.Ping(unreliable_timeout_delay + i);
+ ch1.Ping(unreliable_timeout_delay + TimeDelta::Millis(i));
}
- ch1.conn()->UpdateState(unreliable_timeout_delay +
- kConnectionWriteTimeout.ms() +
+ ch1.conn()->UpdateState(unreliable_timeout_delay + kConnectionWriteTimeout +
kMaxExpectedSimulatedRtt);
EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state());
@@ -3227,26 +3213,26 @@ TEST_F(PortTest, TestWritableStateWithConfiguredThreshold) {
.clock = &clock}),
IsRtcOk());
- ch1.conn()->set_unwritable_timeout(1000);
+ ch1.conn()->SetUnwritableTimeout(TimeDelta::Seconds(1));
ch1.conn()->set_unwritable_min_checks(3);
// Send two checks.
- ch1.Ping(1);
- ch1.Ping(2);
+ ch1.Ping(Timestamp::Millis(1));
+ ch1.Ping(Timestamp::Millis(2));
// We have not reached the timeout nor have we sent the minimum number of
// checks to change the state to Unreliable.
- ch1.conn()->UpdateState(999);
+ ch1.conn()->UpdateState(Timestamp::Seconds(1) - kEpsilon);
EXPECT_EQ(Connection::STATE_WRITABLE, ch1.conn()->write_state());
// We have not sent the minimum number of checks without responses.
- ch1.conn()->UpdateState(1000 + kMaxExpectedSimulatedRtt);
+ ch1.conn()->UpdateState(Timestamp::Seconds(1) + kMaxExpectedSimulatedRtt);
EXPECT_EQ(Connection::STATE_WRITABLE, ch1.conn()->write_state());
// Last ping after which the candidate pair should become Unreliable after
// timeout.
- ch1.Ping(3);
+ ch1.Ping(Timestamp::Millis(3));
// We have not reached the timeout.
- ch1.conn()->UpdateState(999);
+ ch1.conn()->UpdateState(Timestamp::Seconds(1) - kEpsilon);
EXPECT_EQ(Connection::STATE_WRITABLE, ch1.conn()->write_state());
// We should be in the state Unreliable now.
- ch1.conn()->UpdateState(1000 + kMaxExpectedSimulatedRtt);
+ ch1.conn()->UpdateState(Timestamp::Seconds(1) + kMaxExpectedSimulatedRtt);
EXPECT_EQ(Connection::STATE_WRITE_UNRELIABLE, ch1.conn()->write_state());
ch1.Stop();
@@ -3273,9 +3259,9 @@ TEST_F(PortTest, TestTimeoutForNeverWritable) {
// Attempt to go directly to write timeout.
for (uint32_t i = 1; i <= kConnectionWriteConnectFailures; ++i) {
- ch1.Ping(i);
+ ch1.Ping(Timestamp::Millis(i));
}
- ch1.conn()->UpdateState(kConnectionWriteTimeout.ms() +
+ ch1.conn()->UpdateState(Timestamp::Zero() + kConnectionWriteTimeout +
kMaxExpectedSimulatedRtt);
EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state());
}
@@ -4117,7 +4103,7 @@ class ConnectionTest : public PortTest {
lconn->PortForTest() == lport_.get() ? lport_.get() : rport_.get();
TestPort* rport =
rconn->PortForTest() == rport_.get() ? rport_.get() : lport_.get();
- lconn->Ping(TimeMillis());
+ lconn->Ping();
ASSERT_THAT(WaitUntil([&] { return lport->last_stun_msg(); }, IsTrue(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -4269,7 +4255,7 @@ TEST_F(ConnectionTest, SendReceiveGoogDelta) {
// DeltaAckReceived
[](RTCErrorOr<const StunUInt64Attribute*> error_or__ack) {});
- lconn->Ping(TimeMillis(), std::move(delta));
+ lconn->Ping(env().clock().CurrentTime(), std::move(delta));
ASSERT_THAT(WaitUntil([&] { return lport_->last_stun_msg(); }, IsTrue(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
@@ -4311,7 +4297,7 @@ TEST_F(ConnectionTest, SendGoogDeltaNoReply) {
EXPECT_FALSE(error_or_ack.ok());
});
- lconn->Ping(TimeMillis(), std::move(delta));
+ lconn->Ping(env().clock().CurrentTime(), std::move(delta));
ASSERT_THAT(WaitUntil([&] { return lport_->last_stun_msg(); }, IsTrue(),
{.timeout = TimeDelta::Millis(kDefaultTimeout)}),
IsRtcOk());
diff --git a/third_party/libwebrtc/p2p/base/tcp_port_unittest.cc b/third_party/libwebrtc/p2p/base/tcp_port_unittest.cc
@@ -291,8 +291,8 @@ TEST_F(TCPPortTest, SignalSentPacket) {
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
- client_conn->Ping(env_.clock().TimeInMilliseconds());
- server_conn->Ping(env_.clock().TimeInMilliseconds());
+ client_conn->Ping(env_.clock().CurrentTime());
+ server_conn->Ping(env_.clock().CurrentTime());
ASSERT_THAT(
webrtc::WaitUntil([&] { return client_conn->writable(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
@@ -355,7 +355,7 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
webrtc::IsRtcOk());
EXPECT_FALSE(client_conn->writable());
- client_conn->Ping(env_.clock().TimeInMilliseconds());
+ client_conn->Ping(env_.clock().CurrentTime());
ASSERT_THAT(
webrtc::WaitUntil([&] { return client_conn->writable(); }, IsTrue(),
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
@@ -423,7 +423,7 @@ TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
webrtc::IsRtcOk());
// Send Stun Binding request.
- client_conn->Ping(env_.clock().TimeInMilliseconds());
+ client_conn->Ping(env_.clock().CurrentTime());
// The Stun Binding request is reported as sent.
EXPECT_THAT(
webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(2),
diff --git a/third_party/libwebrtc/p2p/base/turn_port_unittest.cc b/third_party/libwebrtc/p2p/base/turn_port_unittest.cc
@@ -659,7 +659,7 @@ class TurnPortTest : public ::testing::Test,
Connection* conn1 = udp_port_->CreateConnection(turn_port_->Candidates()[0],
Port::ORIGIN_MESSAGE);
ASSERT_TRUE(conn1 != nullptr);
- conn1->Ping(0);
+ conn1->Ping();
SIMULATED_WAIT(!turn_unknown_address_, kSimulatedRtt * 2, fake_clock_);
EXPECT_FALSE(turn_unknown_address_);
EXPECT_FALSE(conn1->receiving());
@@ -674,7 +674,7 @@ class TurnPortTest : public ::testing::Test,
{.timeout = TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
IsRtcOk());
- conn2->Ping(0);
+ conn2->Ping();
// Two hops from TURN port to UDP port through TURN server, thus two RTTs.
EXPECT_THAT(WaitUntil([&] { return conn2->write_state(); },
@@ -687,7 +687,7 @@ class TurnPortTest : public ::testing::Test,
EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state());
// Send another ping from UDP to TURN.
- conn1->Ping(0);
+ conn1->Ping();
EXPECT_THAT(WaitUntil([&] { return conn1->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = TimeDelta::Millis(kSimulatedRtt * 2),
@@ -716,7 +716,7 @@ class TurnPortTest : public ::testing::Test,
.clock = &fake_clock_}),
IsRtcOk());
// Make sure turn connection can receive.
- conn1->Ping(0);
+ conn1->Ping();
EXPECT_THAT(WaitUntil([&] { return conn1->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = TimeDelta::Millis(kSimulatedRtt * 2),
@@ -728,7 +728,7 @@ class TurnPortTest : public ::testing::Test,
// the TURN port should still process a ping from an unknown address.
turn_port_->DestroyConnection(conn2);
- conn1->Ping(0);
+ conn1->Ping();
EXPECT_THAT(WaitUntil([&] { return turn_unknown_address_; }, IsTrue(),
{.timeout = TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
@@ -763,7 +763,7 @@ class TurnPortTest : public ::testing::Test,
// Now restore the password before continuing.
conn1->set_remote_password_for_test(pwd);
- conn1->Ping(0);
+ conn1->Ping();
EXPECT_THAT(WaitUntil([&] { return turn_unknown_address_; }, IsTrue(),
{.timeout = TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
@@ -772,7 +772,7 @@ class TurnPortTest : public ::testing::Test,
// If the connection is created again, it will start to receive pings.
conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
Port::ORIGIN_MESSAGE);
- conn1->Ping(0);
+ conn1->Ping();
EXPECT_THAT(WaitUntil([&] { return conn2->receiving(); }, IsTrue(),
{.timeout = TimeDelta::Millis(kSimulatedRtt),
.clock = &fake_clock_}),
@@ -806,13 +806,13 @@ class TurnPortTest : public ::testing::Test,
conn2->SubscribeDestroyed(this, [this](Connection* connection) {
OnConnectionSignalDestroyed(connection);
});
- conn1->Ping(0);
+ conn1->Ping();
EXPECT_THAT(WaitUntil([&] { return conn1->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
IsRtcOk());
- conn2->Ping(0);
+ conn2->Ping();
EXPECT_THAT(WaitUntil([&] { return conn2->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = TimeDelta::Millis(kSimulatedRtt * 2),
@@ -883,13 +883,13 @@ class TurnPortTest : public ::testing::Test,
OnConnectionSignalDestroyed(connection);
});
- conn1->Ping(0);
+ conn1->Ping();
EXPECT_THAT(WaitUntil([&] { return conn1->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),
IsRtcOk());
- conn2->Ping(0);
+ conn2->Ping();
EXPECT_THAT(WaitUntil([&] { return conn2->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = TimeDelta::Millis(kSimulatedRtt * 2),
@@ -1474,7 +1474,7 @@ TEST_F(TurnPortTest, TestStopProcessingPacketsAfterClosed) {
ASSERT_TRUE(conn1 != nullptr);
ASSERT_TRUE(conn2 != nullptr);
// Make sure conn2 is writable.
- conn2->Ping(0);
+ conn2->Ping();
EXPECT_THAT(WaitUntil([&] { return conn2->write_state(); },
Eq(Connection::STATE_WRITABLE),
{.timeout = TimeDelta::Millis(kSimulatedRtt * 2),
@@ -1484,7 +1484,7 @@ TEST_F(TurnPortTest, TestStopProcessingPacketsAfterClosed) {
turn_port_->CloseForTest();
SIMULATED_WAIT(false, kSimulatedRtt, fake_clock_);
turn_unknown_address_ = false;
- conn2->Ping(0);
+ conn2->Ping();
SIMULATED_WAIT(false, kSimulatedRtt, fake_clock_);
// Since the turn port does not handle packets any more, it should not
// SignalUnknownAddress.
@@ -1703,7 +1703,7 @@ TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) {
Port::ORIGIN_MESSAGE);
ASSERT_TRUE(conn2 != nullptr);
- conn1->Ping(0);
+ conn1->Ping();
EXPECT_THAT(WaitUntil([&] { return conn1->writable(); }, IsTrue(),
{.timeout = TimeDelta::Millis(kSimulatedRtt * 2),
.clock = &fake_clock_}),