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 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1134 // been nominated by the controlling side. | 1134 // been nominated by the controlling side. |
1135 int state_cmp = CompareConnectionStates(a, b, receiving_unchanged_threshold, | 1135 int state_cmp = CompareConnectionStates(a, b, receiving_unchanged_threshold, |
1136 missed_receiving_unchanged_threshold); | 1136 missed_receiving_unchanged_threshold); |
1137 if (state_cmp != 0) { | 1137 if (state_cmp != 0) { |
1138 return state_cmp; | 1138 return state_cmp; |
1139 } | 1139 } |
1140 | 1140 |
1141 if (ice_role_ == ICEROLE_CONTROLLED) { | 1141 if (ice_role_ == ICEROLE_CONTROLLED) { |
1142 // Compare the connections based on the nomination states and the last data | 1142 // Compare the connections based on the nomination states and the last data |
1143 // received time if this is on the controlled side. | 1143 // received time if this is on the controlled side. |
1144 if (a->nominated() && !b->nominated()) { | 1144 int cmp = a->nominated_value() - b->nominated_value(); |
1145 return a_is_better; | 1145 if (cmp != 0) { |
1146 } | 1146 // A positive value indicates |a| is better. |
1147 if (!a->nominated() && b->nominated()) { | 1147 return cmp; |
1148 return b_is_better; | |
1149 } | 1148 } |
1150 | 1149 |
1151 if (a->last_data_received() > b->last_data_received()) { | 1150 if (a->last_data_received() > b->last_data_received()) { |
1152 return a_is_better; | 1151 return a_is_better; |
1153 } | 1152 } |
1154 if (a->last_data_received() < b->last_data_received()) { | 1153 if (a->last_data_received() < b->last_data_received()) { |
1155 return b_is_better; | 1154 return b_is_better; |
1156 } | 1155 } |
1157 } | 1156 } |
1158 | 1157 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1209 // have higher priority if it is writable. | 1208 // have higher priority if it is writable. |
1210 MaybeSwitchSelectedConnection(top_connection, "sorting"); | 1209 MaybeSwitchSelectedConnection(top_connection, "sorting"); |
1211 | 1210 |
1212 // The controlled side can prune only if the selected connection has been | 1211 // The controlled side can prune only if the selected connection has been |
1213 // nominated because otherwise it may prune the connection that will be | 1212 // nominated because otherwise it may prune the connection that will be |
1214 // selected by the controlling side. | 1213 // selected by the controlling side. |
1215 // TODO(honghaiz): This is not enough to prevent a connection from being | 1214 // TODO(honghaiz): This is not enough to prevent a connection from being |
1216 // pruned too early because with aggressive nomination, the controlling side | 1215 // pruned too early because with aggressive nomination, the controlling side |
1217 // will nominate every connection until it becomes writable. | 1216 // will nominate every connection until it becomes writable. |
1218 if (ice_role_ == ICEROLE_CONTROLLING || | 1217 if (ice_role_ == ICEROLE_CONTROLLING || |
1219 (selected_connection_ && selected_connection_->nominated())) { | 1218 (selected_connection_ && selected_connection_->nominated_value() > 0)) { |
1220 PruneConnections(); | 1219 PruneConnections(); |
1221 } | 1220 } |
1222 | 1221 |
1223 // Check if all connections are timedout. | 1222 // Check if all connections are timedout. |
1224 bool all_connections_timedout = true; | 1223 bool all_connections_timedout = true; |
1225 for (size_t i = 0; i < connections_.size(); ++i) { | 1224 for (size_t i = 0; i < connections_.size(); ++i) { |
1226 if (connections_[i]->write_state() != Connection::STATE_WRITE_TIMEOUT) { | 1225 if (connections_[i]->write_state() != Connection::STATE_WRITE_TIMEOUT) { |
1227 all_connections_timedout = false; | 1226 all_connections_timedout = false; |
1228 break; | 1227 break; |
1229 } | 1228 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1279 } | 1278 } |
1280 } | 1279 } |
1281 | 1280 |
1282 // Change the selected connection, and let listeners know. | 1281 // Change the selected connection, and let listeners know. |
1283 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) { | 1282 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) { |
1284 // Note: if conn is NULL, the previous |selected_connection_| has been | 1283 // Note: if conn is NULL, the previous |selected_connection_| has been |
1285 // destroyed, so don't use it. | 1284 // destroyed, so don't use it. |
1286 Connection* old_selected_connection = selected_connection_; | 1285 Connection* old_selected_connection = selected_connection_; |
1287 selected_connection_ = conn; | 1286 selected_connection_ = conn; |
1288 if (selected_connection_) { | 1287 if (selected_connection_) { |
1288 if (peer_supports_renomination_) { | |
1289 ++nominating_value_; | |
1290 } | |
1289 if (old_selected_connection) { | 1291 if (old_selected_connection) { |
1290 LOG_J(LS_INFO, this) << "Previous selected connection: " | 1292 LOG_J(LS_INFO, this) << "Previous selected connection: " |
1291 << old_selected_connection->ToString(); | 1293 << old_selected_connection->ToString(); |
1292 } | 1294 } |
1293 LOG_J(LS_INFO, this) << "New selected connection: " | 1295 LOG_J(LS_INFO, this) << "New selected connection: " |
1294 << selected_connection_->ToString(); | 1296 << selected_connection_->ToString(); |
1295 SignalRouteChange(this, selected_connection_->remote_candidate()); | 1297 SignalRouteChange(this, selected_connection_->remote_candidate()); |
1296 // This is a temporary, but safe fix to webrtc issue 5705. | 1298 // This is a temporary, but safe fix to webrtc issue 5705. |
1297 // TODO(honghaiz): Make all EWOULDBLOCK error routed through the transport | 1299 // TODO(honghaiz): Make all EWOULDBLOCK error routed through the transport |
1298 // channel so that it knows whether the media channel is allowed to | 1300 // channel so that it knows whether the media channel is allowed to |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1579 return conn_to_ping; | 1581 return conn_to_ping; |
1580 } | 1582 } |
1581 | 1583 |
1582 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { | 1584 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { |
1583 if (conn && pinged_connections_.insert(conn).second) { | 1585 if (conn && pinged_connections_.insert(conn).second) { |
1584 unpinged_connections_.erase(conn); | 1586 unpinged_connections_.erase(conn); |
1585 } | 1587 } |
1586 } | 1588 } |
1587 | 1589 |
1588 // Apart from sending ping from |conn| this method also updates | 1590 // Apart from sending ping from |conn| this method also updates |
1589 // |use_candidate_attr| flag. The criteria to update this flag is | 1591 // |use_candidate_attr| and |nominating_value| flags. One of the flags is set to |
1590 // explained below. | 1592 // nominate |conn| if this channel is in CONTROLLING AND |
1591 // Set USE-CANDIDATE if doing ICE AND this channel is in CONTROLLING AND | |
1592 // a) Channel is in FULL ICE AND | 1593 // a) Channel is in FULL ICE AND |
1593 // a.1) |conn| is the selected connection OR | 1594 // a.1) |conn| is the selected connection OR |
1594 // a.2) there is no selected connection OR | 1595 // a.2) there is no selected connection OR |
1595 // a.3) the selected connection is unwritable OR | 1596 // a.3) the selected connection is unwritable OR |
1596 // a.4) |conn| has higher priority than selected_connection. | 1597 // a.4) |conn| has higher priority than selected_connection. |
1597 // b) we're doing LITE ICE AND | 1598 // b) we're doing LITE ICE AND |
1598 // b.1) |conn| is the selected_connection AND | 1599 // b.1) |conn| is the selected_connection AND |
1599 // b.2) |conn| is writable. | 1600 // b.2) |conn| is writable. |
1600 void P2PTransportChannel::PingConnection(Connection* conn) { | 1601 void P2PTransportChannel::PingConnection(Connection* conn) { |
1601 bool use_candidate = false; | 1602 bool use_candidate_attr = false; |
1602 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { | 1603 int nominating_value = 0; |
1603 use_candidate = | 1604 if (ice_role_ == ICEROLE_CONTROLLING) { |
1604 (conn == selected_connection_) || (selected_connection_ == NULL) || | 1605 bool should_nominate = false; |
1605 (!selected_connection_->writable()) || | 1606 if (remote_ice_mode_ == ICEMODE_FULL) { |
1606 (CompareConnectionCandidates(selected_connection_, conn) < 0); | 1607 should_nominate = |
1607 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == selected_connection_) { | 1608 (conn == selected_connection_) || (selected_connection_ == NULL) || |
1608 use_candidate = selected_connection_->writable(); | 1609 (!selected_connection_->writable()) || |
1610 CompareConnectionCandidates(selected_connection_, conn) < 0; | |
1611 } else if (remote_ice_mode_ == ICEMODE_LITE) { | |
1612 should_nominate = | |
1613 (conn == selected_connection_) && selected_connection_->writable(); | |
1614 } | |
1615 if (should_nominate) { | |
1616 if (peer_supports_renomination_) { | |
1617 nominating_value = nominating_value_; | |
Taylor Brandstetter
2016/07/27 22:20:55
If using renomination, shouldn't we only nominate
honghaiz3
2016/07/28 04:19:14
Done.
Although the previous implementation should
| |
1618 } else { | |
1619 use_candidate_attr = true; | |
1620 } | |
1621 } | |
1609 } | 1622 } |
1610 conn->set_use_candidate_attr(use_candidate); | 1623 // A connection may be the selected one earlier, but be switched later, |
1624 // so its nominating_value may be set to 0. | |
1625 conn->set_nominating_value(nominating_value); | |
1626 conn->set_use_candidate_attr(use_candidate_attr); | |
1611 last_ping_sent_ms_ = rtc::TimeMillis(); | 1627 last_ping_sent_ms_ = rtc::TimeMillis(); |
1612 conn->Ping(last_ping_sent_ms_); | 1628 conn->Ping(last_ping_sent_ms_); |
1613 } | 1629 } |
1614 | 1630 |
1615 // When a connection's state changes, we need to figure out who to use as | 1631 // When a connection's state changes, we need to figure out who to use as |
1616 // the selected connection again. It could have become usable, or become | 1632 // the selected connection again. It could have become usable, or become |
1617 // unusable. | 1633 // unusable. |
1618 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { | 1634 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { |
1619 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1635 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1620 | 1636 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1893 | 1909 |
1894 // During the initial state when nothing has been pinged yet, return the first | 1910 // During the initial state when nothing has been pinged yet, return the first |
1895 // one in the ordered |connections_|. | 1911 // one in the ordered |connections_|. |
1896 return *(std::find_if(connections_.begin(), connections_.end(), | 1912 return *(std::find_if(connections_.begin(), connections_.end(), |
1897 [conn1, conn2](Connection* conn) { | 1913 [conn1, conn2](Connection* conn) { |
1898 return conn == conn1 || conn == conn2; | 1914 return conn == conn1 || conn == conn2; |
1899 })); | 1915 })); |
1900 } | 1916 } |
1901 | 1917 |
1902 } // namespace cricket | 1918 } // namespace cricket |
OLD | NEW |