Remove fields from remote candidates that could cause crashes in GetStats
Typically, remote candidates come from signalling and are deserialized into C++ objects. The network_type field of these candidates is always ADAPTER_TYPE_UNKNOWN. However, in tests it is common to pass SDP and remote candidates as C++ objects. In this case, the network_type property of remote candidates is preserved, so DCHECK might be triggered when GetStats is called. Clearing fields that are not suitable as remote candidates fixes this issue. Bug: None Change-Id: Ida01b0224bce5cf3e87bcad1ddaca35c9f4fffe7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/279680 Reviewed-by: Henrik Boström <hbos@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Auto-Submit: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38436}
This commit is contained in:
parent
720bc4df3d
commit
5a92577a94
@ -22,6 +22,7 @@ Candidate::Candidate()
|
|||||||
component_(0),
|
component_(0),
|
||||||
priority_(0),
|
priority_(0),
|
||||||
network_type_(rtc::ADAPTER_TYPE_UNKNOWN),
|
network_type_(rtc::ADAPTER_TYPE_UNKNOWN),
|
||||||
|
underlying_type_for_vpn_(rtc::ADAPTER_TYPE_UNKNOWN),
|
||||||
generation_(0),
|
generation_(0),
|
||||||
network_id_(0),
|
network_id_(0),
|
||||||
network_cost_(0) {}
|
network_cost_(0) {}
|
||||||
@ -46,6 +47,7 @@ Candidate::Candidate(int component,
|
|||||||
password_(password),
|
password_(password),
|
||||||
type_(type),
|
type_(type),
|
||||||
network_type_(rtc::ADAPTER_TYPE_UNKNOWN),
|
network_type_(rtc::ADAPTER_TYPE_UNKNOWN),
|
||||||
|
underlying_type_for_vpn_(rtc::ADAPTER_TYPE_UNKNOWN),
|
||||||
generation_(generation),
|
generation_(generation),
|
||||||
foundation_(foundation),
|
foundation_(foundation),
|
||||||
network_id_(network_id),
|
network_id_(network_id),
|
||||||
|
|||||||
@ -2605,8 +2605,19 @@ void PeerConnection::AddRemoteCandidate(const std::string& mid,
|
|||||||
const cricket::Candidate& candidate) {
|
const cricket::Candidate& candidate) {
|
||||||
RTC_DCHECK_RUN_ON(signaling_thread());
|
RTC_DCHECK_RUN_ON(signaling_thread());
|
||||||
|
|
||||||
|
if (candidate.network_type() != rtc::ADAPTER_TYPE_UNKNOWN) {
|
||||||
|
RTC_DLOG(LS_WARNING) << "Using candidate with adapter type set - this "
|
||||||
|
"should only happen in test";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear fields that do not make sense as remote candidates.
|
||||||
|
cricket::Candidate new_candidate(candidate);
|
||||||
|
new_candidate.set_network_type(rtc::ADAPTER_TYPE_UNKNOWN);
|
||||||
|
new_candidate.set_relay_protocol("");
|
||||||
|
new_candidate.set_underlying_type_for_vpn(rtc::ADAPTER_TYPE_UNKNOWN);
|
||||||
|
|
||||||
network_thread()->PostTask(SafeTask(
|
network_thread()->PostTask(SafeTask(
|
||||||
network_thread_safety_, [this, mid = mid, candidate = candidate] {
|
network_thread_safety_, [this, mid = mid, candidate = new_candidate] {
|
||||||
RTC_DCHECK_RUN_ON(network_thread());
|
RTC_DCHECK_RUN_ON(network_thread());
|
||||||
std::vector<cricket::Candidate> candidates = {candidate};
|
std::vector<cricket::Candidate> candidates = {candidate};
|
||||||
RTCError error =
|
RTCError error =
|
||||||
|
|||||||
@ -934,6 +934,9 @@ const std::string& ProduceIceCandidateStats(int64_t timestamp_us,
|
|||||||
} else {
|
} else {
|
||||||
// We don't expect to know the adapter type of remote candidates.
|
// We don't expect to know the adapter type of remote candidates.
|
||||||
RTC_DCHECK_EQ(rtc::ADAPTER_TYPE_UNKNOWN, candidate.network_type());
|
RTC_DCHECK_EQ(rtc::ADAPTER_TYPE_UNKNOWN, candidate.network_type());
|
||||||
|
RTC_DCHECK_EQ(0, candidate.relay_protocol().compare(""));
|
||||||
|
RTC_DCHECK_EQ(rtc::ADAPTER_TYPE_UNKNOWN,
|
||||||
|
candidate.underlying_type_for_vpn());
|
||||||
}
|
}
|
||||||
candidate_stats->ip = candidate.address().ipaddr().ToString();
|
candidate_stats->ip = candidate.address().ipaddr().ToString();
|
||||||
candidate_stats->address = candidate.address().ipaddr().ToString();
|
candidate_stats->address = candidate.address().ipaddr().ToString();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user