diff --git a/webrtc/p2p/stunprober/stunprober.cc b/webrtc/p2p/stunprober/stunprober.cc index ee9eb2258c..9316ea89bd 100644 --- a/webrtc/p2p/stunprober/stunprober.cc +++ b/webrtc/p2p/stunprober/stunprober.cc @@ -460,6 +460,7 @@ bool StunProber::GetStats(StunProber::Stats* prob_stats) const { continue; } + ++stats.raw_num_request_sent; IncrementCounterByAddress(&num_request_per_server, request->server_addr); if (!first_sent_time) { @@ -503,11 +504,6 @@ bool StunProber::GetStats(StunProber::Stats* prob_stats) const { num_sent += num_request_per_server[kv.first]; } - // Not receiving any response, the trial is inconclusive. - if (!num_received) { - return false; - } - // Shared mode is only true if we use the shared socket and there are more // than 1 responding servers. stats.shared_socket_mode = @@ -519,7 +515,8 @@ bool StunProber::GetStats(StunProber::Stats* prob_stats) const { // If we could find a local IP matching srflx, we're not behind a NAT. rtc::SocketAddress srflx_addr; - if (!srflx_addr.FromString(*(stats.srflx_addrs.begin()))) { + if (stats.srflx_addrs.size() && + !srflx_addr.FromString(*(stats.srflx_addrs.begin()))) { return false; } for (const auto& net : networks_) { @@ -544,9 +541,10 @@ bool StunProber::GetStats(StunProber::Stats* prob_stats) const { stats.success_percent = static_cast(100 * num_received / num_sent); } - if (num_sent > 1) { + if (stats.raw_num_request_sent > 1) { stats.actual_request_interval_ns = - (1000 * (last_sent_time - first_sent_time)) / (num_sent - 1); + (1000 * (last_sent_time - first_sent_time)) / + (stats.raw_num_request_sent - 1); } if (num_received) { diff --git a/webrtc/p2p/stunprober/stunprober.h b/webrtc/p2p/stunprober/stunprober.h index 9d2ad222e5..b725cbef0a 100644 --- a/webrtc/p2p/stunprober/stunprober.h +++ b/webrtc/p2p/stunprober/stunprober.h @@ -71,7 +71,14 @@ class StunProber : public sigslot::has_slots<> { struct Stats { Stats() {} + // |raw_num_request_sent| is the total number of requests + // sent. |num_request_sent| is the count of requests against a server where + // we see at least one response. |num_request_sent| is designed to protect + // against DNS resolution failure or the STUN server is not responsive + // which could skew the result. + int raw_num_request_sent = 0; int num_request_sent = 0; + int num_response_received = 0; NatType nat_type = NATTYPE_INVALID; int average_rtt_ms = -1;