Relax the stun ping check on valid result.
1. allow situation where all ping is lost
2. use the raw count to calculate the interval.
Since we now send 1 request per IP, the chance of losing all of them is higher and we shouldn't just quit if we don't have any response.
BUG=
Review URL: https://codereview.webrtc.org/1406223011
Cr-Commit-Position: refs/heads/master@{#10613}
diff --git a/webrtc/p2p/stunprober/stunprober.cc b/webrtc/p2p/stunprober/stunprober.cc
index ee9eb22..9316ea8 100644
--- a/webrtc/p2p/stunprober/stunprober.cc
+++ b/webrtc/p2p/stunprober/stunprober.cc
@@ -460,6 +460,7 @@
continue;
}
+ ++stats.raw_num_request_sent;
IncrementCounterByAddress(&num_request_per_server, request->server_addr);
if (!first_sent_time) {
@@ -503,11 +504,6 @@
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 @@
// 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 @@
stats.success_percent = static_cast<int>(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 9d2ad22..b725cbe 100644
--- a/webrtc/p2p/stunprober/stunprober.h
+++ b/webrtc/p2p/stunprober/stunprober.h
@@ -71,7 +71,14 @@
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;