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}
This commit is contained in:
guoweis 2015-11-11 15:04:06 -08:00 committed by Commit bot
parent 33daa7ef85
commit 066ded99cb
2 changed files with 13 additions and 8 deletions

View File

@ -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<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) {

View File

@ -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;