| Index: webrtc/p2p/base/p2ptransportchannel.cc
|
| diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc
|
| index 83bcf840ee4350e39ad550738e676d1641f5dabd..5461dd6dc4de34bda6a73d60cee9a7712c1ac02a 100644
|
| --- a/webrtc/p2p/base/p2ptransportchannel.cc
|
| +++ b/webrtc/p2p/base/p2ptransportchannel.cc
|
| @@ -25,6 +25,7 @@ namespace {
|
| enum {
|
| MSG_SORT = 1,
|
| MSG_PING,
|
| + MSG_CHECK_FLAKINESS
|
| };
|
|
|
| // When the socket is unwritable, we will use 10 Kbps (ignoring IP+UDP headers)
|
| @@ -40,6 +41,8 @@ static const uint32 UNWRITABLE_DELAY = 1000 * PING_PACKET_SIZE / 10000; // 50ms
|
| // make sure it is pinged at this rate.
|
| static const uint32 MAX_CURRENT_WRITABLE_DELAY = 900; // 2*WRITABLE_DELAY - bit
|
|
|
| +static const uint32 MIN_CHECK_FLAKINESS_DELAY = 50; // ms
|
| +
|
| // The minimum improvement in RTT that justifies a switch.
|
| static const double kMinImprovement = 10;
|
|
|
| @@ -193,7 +196,9 @@ P2PTransportChannel::P2PTransportChannel(const std::string& content_name,
|
| remote_ice_mode_(ICEMODE_FULL),
|
| ice_role_(ICEROLE_UNKNOWN),
|
| tiebreaker_(0),
|
| - remote_candidate_generation_(0) {
|
| + remote_candidate_generation_(0),
|
| + check_flakiness_delay_(MIN_CHECK_FLAKINESS_DELAY * 2),
|
| + check_flakiness_timeout_(MIN_CHECK_FLAKINESS_DELAY * 20) {
|
| }
|
|
|
| P2PTransportChannel::~P2PTransportChannel() {
|
| @@ -369,6 +374,9 @@ void P2PTransportChannel::Connect() {
|
|
|
| // Start pinging as the ports come in.
|
| thread()->Post(this, MSG_PING);
|
| +
|
| + thread()->PostDelayed(
|
| + check_flakiness_delay_, this, MSG_CHECK_FLAKINESS);
|
| }
|
|
|
| // A new port is available, attempt to make connections for it
|
| @@ -1067,6 +1075,9 @@ void P2PTransportChannel::SwitchBestConnectionTo(Connection* conn) {
|
| LOG_J(LS_INFO, this) << "New best connection: "
|
| << best_connection_->ToString();
|
| SignalRouteChange(this, best_connection_->remote_candidate());
|
| + // When it just switched to a best connection, set the channel state to
|
| + // unflaky.
|
| + set_flaky(false);
|
| } else {
|
| LOG_J(LS_INFO, this) << "No best connection";
|
| }
|
| @@ -1148,6 +1159,9 @@ void P2PTransportChannel::OnMessage(rtc::Message *pmsg) {
|
| case MSG_PING:
|
| OnPing();
|
| break;
|
| + case MSG_CHECK_FLAKINESS:
|
| + OnCheckFlakiness();
|
| + break;
|
| default:
|
| ASSERT(false);
|
| break;
|
| @@ -1176,6 +1190,16 @@ void P2PTransportChannel::OnPing() {
|
| thread()->PostDelayed(delay, this, MSG_PING);
|
| }
|
|
|
| +void P2PTransportChannel::OnCheckFlakiness() {
|
| + // Check flakiness only if the best connection has received packets.
|
| + if (best_connection_ && best_connection_->recv_total_bytes() > 0) {
|
| + bool flaky = !best_connection_->CheckReceiving(check_flakiness_timeout_);
|
| + set_flaky(flaky);
|
| + }
|
| +
|
| + thread()->PostDelayed(check_flakiness_delay_, this, MSG_CHECK_FLAKINESS);
|
| +}
|
| +
|
| // Is the connection in a state for us to even consider pinging the other side?
|
| // We consider a connection pingable even if it's not connected because that's
|
| // how a TCP connection is kicked into reconnecting on the active side.
|
|
|