diff --git a/api/stats/rtcstats_objects.h b/api/stats/rtcstats_objects.h index 3fb68ae5e7..373a2cd324 100644 --- a/api/stats/rtcstats_objects.h +++ b/api/stats/rtcstats_objects.h @@ -709,6 +709,7 @@ class RTC_EXPORT RTCTransportStats final : public RTCStats { RTCStatsMember srtp_cipher; RTCStatsMember selected_candidate_pair_changes; RTCStatsMember ice_role; + RTCStatsMember ice_local_username_fragment; }; } // namespace webrtc diff --git a/p2p/base/ice_transport_internal.h b/p2p/base/ice_transport_internal.h index 3992de219e..97ce21c164 100644 --- a/p2p/base/ice_transport_internal.h +++ b/p2p/base/ice_transport_internal.h @@ -49,6 +49,7 @@ struct IceTransportStats { uint64_t packets_received = 0; IceRole ice_role = ICEROLE_UNKNOWN; + std::string ice_local_username_fragment; }; typedef std::vector Candidates; diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index bc68911695..c85b56fc95 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -1665,6 +1665,7 @@ bool P2PTransportChannel::GetStats(IceTransportStats* ice_transport_stats) { ice_transport_stats->packets_received = packets_received_; ice_transport_stats->ice_role = GetIceRole(); + ice_transport_stats->ice_local_username_fragment = ice_parameters_.ufrag; return true; } diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index b3378cec20..c68f019ee3 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -2116,6 +2116,8 @@ void RTCStatsCollector::ProduceTransportStats_n( channel_stats.ice_transport_stats.selected_candidate_pair_changes; transport_stats->ice_role = IceRoleToRTCIceRole(channel_stats.ice_transport_stats.ice_role); + transport_stats->ice_local_username_fragment = + channel_stats.ice_transport_stats.ice_local_username_fragment; for (const cricket::ConnectionInfo& info : channel_stats.ice_transport_stats.connection_infos) { if (info.best_connection) { diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc index b07085215a..17f706f0ca 100644 --- a/pc/rtc_stats_collector_unittest.cc +++ b/pc/rtc_stats_collector_unittest.cc @@ -2449,6 +2449,8 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { rtp_transport_channel_stats.ice_transport_stats.packets_received = 4; rtp_transport_channel_stats.ice_transport_stats .selected_candidate_pair_changes = 1; + rtp_transport_channel_stats.ice_transport_stats.ice_local_username_fragment = + "thelocalufrag"; pc_->SetTransportStats(kTransportName, {rtp_transport_channel_stats}); // Get stats without RTCP, an active connection or certificates. @@ -2466,6 +2468,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { expected_rtp_transport.dtls_role = RTCDtlsRole::kUnknown; expected_rtp_transport.selected_candidate_pair_changes = 1; expected_rtp_transport.ice_role = RTCIceRole::kUnknown; + expected_rtp_transport.ice_local_username_fragment = "thelocalufrag"; ASSERT_TRUE(report->Get(expected_rtp_transport.id())); EXPECT_EQ( @@ -2491,6 +2494,8 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { rtcp_transport_channel_stats.ice_transport_stats.packets_sent = 1; rtcp_transport_channel_stats.ice_transport_stats.bytes_received = 42; rtcp_transport_channel_stats.ice_transport_stats.packets_received = 4; + rtcp_transport_channel_stats.ice_transport_stats.ice_local_username_fragment = + "thelocalufrag"; pc_->SetTransportStats(kTransportName, {rtp_transport_channel_stats, rtcp_transport_channel_stats}); @@ -2509,6 +2514,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { expected_rtcp_transport.dtls_role = RTCDtlsRole::kUnknown; expected_rtcp_transport.selected_candidate_pair_changes = 0; expected_rtcp_transport.ice_role = RTCIceRole::kUnknown; + expected_rtcp_transport.ice_local_username_fragment = "thelocalufrag"; expected_rtp_transport.rtcp_transport_stats_id = expected_rtcp_transport.id(); ASSERT_TRUE(report->Get(expected_rtp_transport.id())); @@ -2610,6 +2616,8 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStatsWithCrypto) { rtp_transport_channel_stats.dtls_role = rtc::SSL_CLIENT; rtp_transport_channel_stats.ice_transport_stats.ice_role = cricket::ICEROLE_CONTROLLING; + rtp_transport_channel_stats.ice_transport_stats.ice_local_username_fragment = + "thelocalufrag"; // 0x2F is TLS_RSA_WITH_AES_128_CBC_SHA according to IANA rtp_transport_channel_stats.ssl_cipher_suite = 0x2F; rtp_transport_channel_stats.srtp_crypto_suite = rtc::kSrtpAes128CmSha1_80; @@ -2629,10 +2637,11 @@ TEST_F(RTCStatsCollectorTest, CollectRTCTransportStatsWithCrypto) { expected_rtp_transport.bytes_received = 0; expected_rtp_transport.packets_sent = 0; expected_rtp_transport.packets_received = 0; + expected_rtp_transport.ice_role = RTCIceRole::kControlling; + expected_rtp_transport.ice_local_username_fragment = "thelocalufrag"; // Crypto parameters expected_rtp_transport.tls_version = "0203"; expected_rtp_transport.dtls_role = RTCDtlsRole::kClient; - expected_rtp_transport.ice_role = RTCIceRole::kControlling; expected_rtp_transport.dtls_cipher = "TLS_RSA_WITH_AES_128_CBC_SHA"; expected_rtp_transport.srtp_cipher = "AES_CM_128_HMAC_SHA1_80"; diff --git a/pc/rtc_stats_integrationtest.cc b/pc/rtc_stats_integrationtest.cc index c1404042e8..db49d80d4a 100644 --- a/pc/rtc_stats_integrationtest.cc +++ b/pc/rtc_stats_integrationtest.cc @@ -1144,6 +1144,7 @@ class RTCStatsReportVerifier { verifier.TestMemberIsPositive( transport.selected_candidate_pair_changes); verifier.TestMemberIsDefined(transport.ice_role); + verifier.TestMemberIsDefined(transport.ice_local_username_fragment); return verifier.ExpectAllMembersSuccessfullyTested(); } diff --git a/stats/rtcstats_objects.cc b/stats/rtcstats_objects.cc index 0362f6b51f..44cb4c79c3 100644 --- a/stats/rtcstats_objects.cc +++ b/stats/rtcstats_objects.cc @@ -1098,7 +1098,8 @@ WEBRTC_RTCSTATS_IMPL(RTCTransportStats, RTCStats, "transport", &dtls_role, &srtp_cipher, &selected_candidate_pair_changes, - &ice_role) + &ice_role, + &ice_local_username_fragment) // clang-format on RTCTransportStats::RTCTransportStats(const std::string& id, @@ -1121,7 +1122,8 @@ RTCTransportStats::RTCTransportStats(std::string&& id, int64_t timestamp_us) dtls_role("dtlsRole"), srtp_cipher("srtpCipher"), selected_candidate_pair_changes("selectedCandidatePairChanges"), - ice_role("iceRole") {} + ice_role("iceRole"), + ice_local_username_fragment("iceLocalUsernameFragment") {} RTCTransportStats::RTCTransportStats(const RTCTransportStats& other) : RTCStats(other.id(), other.timestamp_us()), @@ -1139,7 +1141,8 @@ RTCTransportStats::RTCTransportStats(const RTCTransportStats& other) dtls_role(other.dtls_role), srtp_cipher(other.srtp_cipher), selected_candidate_pair_changes(other.selected_candidate_pair_changes), - ice_role(other.ice_role) {} + ice_role(other.ice_role), + ice_local_username_fragment(other.ice_local_username_fragment) {} RTCTransportStats::~RTCTransportStats() {}