| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const { | 1032 rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const { |
| 1033 OptionMap::const_iterator it = options_.find(rtc::Socket::OPT_DSCP); | 1033 OptionMap::const_iterator it = options_.find(rtc::Socket::OPT_DSCP); |
| 1034 if (it == options_.end()) { | 1034 if (it == options_.end()) { |
| 1035 return rtc::DSCP_NO_CHANGE; | 1035 return rtc::DSCP_NO_CHANGE; |
| 1036 } | 1036 } |
| 1037 return static_cast<rtc::DiffServCodePoint> (it->second); | 1037 return static_cast<rtc::DiffServCodePoint> (it->second); |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 // Monitor connection states. | 1040 // Monitor connection states. |
| 1041 void P2PTransportChannel::UpdateConnectionStates() { | 1041 void P2PTransportChannel::UpdateConnectionStates() { |
| 1042 int64_t now = rtc::Time64(); | 1042 int64_t now = rtc::TimeMillis(); |
| 1043 | 1043 |
| 1044 // We need to copy the list of connections since some may delete themselves | 1044 // We need to copy the list of connections since some may delete themselves |
| 1045 // when we call UpdateState. | 1045 // when we call UpdateState. |
| 1046 for (size_t i = 0; i < connections_.size(); ++i) | 1046 for (size_t i = 0; i < connections_.size(); ++i) |
| 1047 connections_[i]->UpdateState(now); | 1047 connections_[i]->UpdateState(now); |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 // Prepare for best candidate sorting. | 1050 // Prepare for best candidate sorting. |
| 1051 void P2PTransportChannel::RequestSort() { | 1051 void P2PTransportChannel::RequestSort() { |
| 1052 if (!sort_dirty_) { | 1052 if (!sort_dirty_) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 } | 1277 } |
| 1278 | 1278 |
| 1279 // Handle queued up check-and-ping request | 1279 // Handle queued up check-and-ping request |
| 1280 void P2PTransportChannel::OnCheckAndPing() { | 1280 void P2PTransportChannel::OnCheckAndPing() { |
| 1281 // Make sure the states of the connections are up-to-date (since this affects | 1281 // Make sure the states of the connections are up-to-date (since this affects |
| 1282 // which ones are pingable). | 1282 // which ones are pingable). |
| 1283 UpdateConnectionStates(); | 1283 UpdateConnectionStates(); |
| 1284 // When the best connection is either not receiving or not writable, | 1284 // When the best connection is either not receiving or not writable, |
| 1285 // switch to weak ping interval. | 1285 // switch to weak ping interval. |
| 1286 int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL; | 1286 int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL; |
| 1287 if (rtc::Time64() >= last_ping_sent_ms_ + ping_interval) { | 1287 if (rtc::TimeMillis() >= last_ping_sent_ms_ + ping_interval) { |
| 1288 Connection* conn = FindNextPingableConnection(); | 1288 Connection* conn = FindNextPingableConnection(); |
| 1289 if (conn) { | 1289 if (conn) { |
| 1290 PingConnection(conn); | 1290 PingConnection(conn); |
| 1291 MarkConnectionPinged(conn); | 1291 MarkConnectionPinged(conn); |
| 1292 } | 1292 } |
| 1293 } | 1293 } |
| 1294 int delay = std::min(ping_interval, check_receiving_interval_); | 1294 int delay = std::min(ping_interval, check_receiving_interval_); |
| 1295 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING); | 1295 thread()->PostDelayed(delay, this, MSG_CHECK_AND_PING); |
| 1296 } | 1296 } |
| 1297 | 1297 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 // Returns the next pingable connection to ping. This will be the oldest | 1338 // Returns the next pingable connection to ping. This will be the oldest |
| 1339 // pingable connection unless we have a connected, writable connection that is | 1339 // pingable connection unless we have a connected, writable connection that is |
| 1340 // past the maximum acceptable ping interval. When reconnecting a TCP | 1340 // past the maximum acceptable ping interval. When reconnecting a TCP |
| 1341 // connection, the best connection is disconnected, although still WRITABLE | 1341 // connection, the best connection is disconnected, although still WRITABLE |
| 1342 // while reconnecting. The newly created connection should be selected as the | 1342 // while reconnecting. The newly created connection should be selected as the |
| 1343 // ping target to become writable instead. See the big comment in | 1343 // ping target to become writable instead. See the big comment in |
| 1344 // CompareConnections. | 1344 // CompareConnections. |
| 1345 Connection* P2PTransportChannel::FindNextPingableConnection() { | 1345 Connection* P2PTransportChannel::FindNextPingableConnection() { |
| 1346 int64_t now = rtc::Time64(); | 1346 int64_t now = rtc::TimeMillis(); |
| 1347 Connection* conn_to_ping = nullptr; | 1347 Connection* conn_to_ping = nullptr; |
| 1348 if (best_connection_ && best_connection_->connected() && | 1348 if (best_connection_ && best_connection_->connected() && |
| 1349 best_connection_->writable() && | 1349 best_connection_->writable() && |
| 1350 (best_connection_->last_ping_sent() + config_.max_strong_interval <= | 1350 (best_connection_->last_ping_sent() + config_.max_strong_interval <= |
| 1351 now)) { | 1351 now)) { |
| 1352 conn_to_ping = best_connection_; | 1352 conn_to_ping = best_connection_; |
| 1353 } else { | 1353 } else { |
| 1354 conn_to_ping = FindConnectionToPing(now); | 1354 conn_to_ping = FindConnectionToPing(now); |
| 1355 } | 1355 } |
| 1356 return conn_to_ping; | 1356 return conn_to_ping; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1377 void P2PTransportChannel::PingConnection(Connection* conn) { | 1377 void P2PTransportChannel::PingConnection(Connection* conn) { |
| 1378 bool use_candidate = false; | 1378 bool use_candidate = false; |
| 1379 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { | 1379 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { |
| 1380 use_candidate = (conn == best_connection_) || (best_connection_ == NULL) || | 1380 use_candidate = (conn == best_connection_) || (best_connection_ == NULL) || |
| 1381 (!best_connection_->writable()) || | 1381 (!best_connection_->writable()) || |
| 1382 (CompareConnectionCandidates(best_connection_, conn) < 0); | 1382 (CompareConnectionCandidates(best_connection_, conn) < 0); |
| 1383 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == best_connection_) { | 1383 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == best_connection_) { |
| 1384 use_candidate = best_connection_->writable(); | 1384 use_candidate = best_connection_->writable(); |
| 1385 } | 1385 } |
| 1386 conn->set_use_candidate_attr(use_candidate); | 1386 conn->set_use_candidate_attr(use_candidate); |
| 1387 last_ping_sent_ms_ = rtc::Time64(); | 1387 last_ping_sent_ms_ = rtc::TimeMillis(); |
| 1388 conn->Ping(last_ping_sent_ms_); | 1388 conn->Ping(last_ping_sent_ms_); |
| 1389 } | 1389 } |
| 1390 | 1390 |
| 1391 // When a connection's state changes, we need to figure out who to use as | 1391 // When a connection's state changes, we need to figure out who to use as |
| 1392 // the best connection again. It could have become usable, or become unusable. | 1392 // the best connection again. It could have become usable, or become unusable. |
| 1393 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { | 1393 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { |
| 1394 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1394 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 1395 | 1395 |
| 1396 // Update the best connection if the state change is from pending best | 1396 // Update the best connection if the state change is from pending best |
| 1397 // connection and role is controlled. | 1397 // connection and role is controlled. |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 | 1638 |
| 1639 // During the initial state when nothing has been pinged yet, return the first | 1639 // During the initial state when nothing has been pinged yet, return the first |
| 1640 // one in the ordered |connections_|. | 1640 // one in the ordered |connections_|. |
| 1641 return *(std::find_if(connections_.begin(), connections_.end(), | 1641 return *(std::find_if(connections_.begin(), connections_.end(), |
| 1642 [conn1, conn2](Connection* conn) { | 1642 [conn1, conn2](Connection* conn) { |
| 1643 return conn == conn1 || conn == conn2; | 1643 return conn == conn1 || conn == conn2; |
| 1644 })); | 1644 })); |
| 1645 } | 1645 } |
| 1646 | 1646 |
| 1647 } // namespace cricket | 1647 } // namespace cricket |
| OLD | NEW |