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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 config_.regather_on_failed_networks_interval = | 396 config_.regather_on_failed_networks_interval = |
397 config.regather_on_failed_networks_interval; | 397 config.regather_on_failed_networks_interval; |
398 LOG(LS_INFO) << "Set regather_on_failed_networks_interval to " | 398 LOG(LS_INFO) << "Set regather_on_failed_networks_interval to " |
399 << *config_.regather_on_failed_networks_interval; | 399 << *config_.regather_on_failed_networks_interval; |
400 } | 400 } |
401 if (config.receiving_switching_delay) { | 401 if (config.receiving_switching_delay) { |
402 config_.receiving_switching_delay = config.receiving_switching_delay; | 402 config_.receiving_switching_delay = config.receiving_switching_delay; |
403 LOG(LS_INFO) << "Set receiving_switching_delay to" | 403 LOG(LS_INFO) << "Set receiving_switching_delay to" |
404 << *config_.receiving_switching_delay; | 404 << *config_.receiving_switching_delay; |
405 } | 405 } |
| 406 |
| 407 if (config_.default_nomination_mode != config.default_nomination_mode) { |
| 408 config_.default_nomination_mode = config.default_nomination_mode; |
| 409 LOG(LS_INFO) << "Set default nomination mode to " |
| 410 << static_cast<int>(config_.default_nomination_mode); |
| 411 } |
406 } | 412 } |
407 | 413 |
408 const IceConfig& P2PTransportChannel::config() const { | 414 const IceConfig& P2PTransportChannel::config() const { |
409 return config_; | 415 return config_; |
410 } | 416 } |
411 | 417 |
412 void P2PTransportChannel::MaybeStartGathering() { | 418 void P2PTransportChannel::MaybeStartGathering() { |
413 if (ice_ufrag_.empty() || ice_pwd_.empty()) { | 419 if (ice_ufrag_.empty() || ice_pwd_.empty()) { |
414 return; | 420 return; |
415 } | 421 } |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 // been nominated by the controlling side. | 1139 // been nominated by the controlling side. |
1134 int state_cmp = CompareConnectionStates(a, b, receiving_unchanged_threshold, | 1140 int state_cmp = CompareConnectionStates(a, b, receiving_unchanged_threshold, |
1135 missed_receiving_unchanged_threshold); | 1141 missed_receiving_unchanged_threshold); |
1136 if (state_cmp != 0) { | 1142 if (state_cmp != 0) { |
1137 return state_cmp; | 1143 return state_cmp; |
1138 } | 1144 } |
1139 | 1145 |
1140 if (ice_role_ == ICEROLE_CONTROLLED) { | 1146 if (ice_role_ == ICEROLE_CONTROLLED) { |
1141 // Compare the connections based on the nomination states and the last data | 1147 // Compare the connections based on the nomination states and the last data |
1142 // received time if this is on the controlled side. | 1148 // received time if this is on the controlled side. |
1143 if (a->nominated() && !b->nominated()) { | 1149 if (a->remote_nomination() > b->remote_nomination()) { |
1144 return a_is_better; | 1150 return a_is_better; |
1145 } | 1151 } |
1146 if (!a->nominated() && b->nominated()) { | 1152 if (a->remote_nomination() < b->remote_nomination()) { |
1147 return b_is_better; | 1153 return b_is_better; |
1148 } | 1154 } |
1149 | 1155 |
1150 if (a->last_data_received() > b->last_data_received()) { | 1156 if (a->last_data_received() > b->last_data_received()) { |
1151 return a_is_better; | 1157 return a_is_better; |
1152 } | 1158 } |
1153 if (a->last_data_received() < b->last_data_received()) { | 1159 if (a->last_data_received() < b->last_data_received()) { |
1154 return b_is_better; | 1160 return b_is_better; |
1155 } | 1161 } |
1156 } | 1162 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 } | 1284 } |
1279 } | 1285 } |
1280 | 1286 |
1281 // Change the selected connection, and let listeners know. | 1287 // Change the selected connection, and let listeners know. |
1282 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) { | 1288 void P2PTransportChannel::SwitchSelectedConnection(Connection* conn) { |
1283 // Note: if conn is NULL, the previous |selected_connection_| has been | 1289 // Note: if conn is NULL, the previous |selected_connection_| has been |
1284 // destroyed, so don't use it. | 1290 // destroyed, so don't use it. |
1285 Connection* old_selected_connection = selected_connection_; | 1291 Connection* old_selected_connection = selected_connection_; |
1286 selected_connection_ = conn; | 1292 selected_connection_ = conn; |
1287 if (selected_connection_) { | 1293 if (selected_connection_) { |
| 1294 ++nomination_; |
1288 if (old_selected_connection) { | 1295 if (old_selected_connection) { |
1289 LOG_J(LS_INFO, this) << "Previous selected connection: " | 1296 LOG_J(LS_INFO, this) << "Previous selected connection: " |
1290 << old_selected_connection->ToString(); | 1297 << old_selected_connection->ToString(); |
1291 } | 1298 } |
1292 LOG_J(LS_INFO, this) << "New selected connection: " | 1299 LOG_J(LS_INFO, this) << "New selected connection: " |
1293 << selected_connection_->ToString(); | 1300 << selected_connection_->ToString(); |
1294 SignalRouteChange(this, selected_connection_->remote_candidate()); | 1301 SignalRouteChange(this, selected_connection_->remote_candidate()); |
1295 // This is a temporary, but safe fix to webrtc issue 5705. | 1302 // This is a temporary, but safe fix to webrtc issue 5705. |
1296 // TODO(honghaiz): Make all ENOTCONN error routed through the transport | 1303 // TODO(honghaiz): Make all ENOTCONN error routed through the transport |
1297 // channel so that it knows whether the media channel is allowed to | 1304 // 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... |
1578 return conn_to_ping; | 1585 return conn_to_ping; |
1579 } | 1586 } |
1580 | 1587 |
1581 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { | 1588 void P2PTransportChannel::MarkConnectionPinged(Connection* conn) { |
1582 if (conn && pinged_connections_.insert(conn).second) { | 1589 if (conn && pinged_connections_.insert(conn).second) { |
1583 unpinged_connections_.erase(conn); | 1590 unpinged_connections_.erase(conn); |
1584 } | 1591 } |
1585 } | 1592 } |
1586 | 1593 |
1587 // Apart from sending ping from |conn| this method also updates | 1594 // Apart from sending ping from |conn| this method also updates |
1588 // |use_candidate_attr| flag. The criteria to update this flag is | 1595 // |use_candidate_attr| and |nomination| flags. One of the flags is set to |
1589 // explained below. | 1596 // nominate |conn| if this channel is in CONTROLLING. |
1590 // Set USE-CANDIDATE if doing ICE AND this channel is in CONTROLLING AND | |
1591 // a) Channel is in FULL ICE AND | |
1592 // a.1) |conn| is the selected connection OR | |
1593 // a.2) there is no selected connection OR | |
1594 // a.3) the selected connection is unwritable OR | |
1595 // a.4) |conn| has higher priority than selected_connection. | |
1596 // b) we're doing LITE ICE AND | |
1597 // b.1) |conn| is the selected_connection AND | |
1598 // b.2) |conn| is writable. | |
1599 void P2PTransportChannel::PingConnection(Connection* conn) { | 1597 void P2PTransportChannel::PingConnection(Connection* conn) { |
1600 bool use_candidate = false; | 1598 bool use_candidate_attr = false; |
1601 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { | 1599 uint32_t nomination = 0; |
1602 use_candidate = | 1600 if (ice_role_ == ICEROLE_CONTROLLING) { |
1603 (conn == selected_connection_) || (selected_connection_ == NULL) || | 1601 if (remote_supports_renomination_) { |
1604 (!selected_connection_->writable()) || | 1602 nomination = GetNominationAttr(conn); |
1605 (CompareConnectionCandidates(selected_connection_, conn) < 0); | 1603 } else { |
1606 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == selected_connection_) { | 1604 use_candidate_attr = |
1607 use_candidate = selected_connection_->writable(); | 1605 GetUseCandidateAttr(conn, config_.default_nomination_mode); |
| 1606 } |
1608 } | 1607 } |
1609 conn->set_use_candidate_attr(use_candidate); | 1608 conn->set_nomination(nomination); |
| 1609 conn->set_use_candidate_attr(use_candidate_attr); |
1610 last_ping_sent_ms_ = rtc::TimeMillis(); | 1610 last_ping_sent_ms_ = rtc::TimeMillis(); |
1611 conn->Ping(last_ping_sent_ms_); | 1611 conn->Ping(last_ping_sent_ms_); |
1612 } | 1612 } |
1613 | 1613 |
| 1614 uint32_t P2PTransportChannel::GetNominationAttr(Connection* conn) const { |
| 1615 return (conn == selected_connection_) ? nomination_ : 0; |
| 1616 } |
| 1617 |
| 1618 // Nominate a connection based on the NominationMode. |
| 1619 bool P2PTransportChannel::GetUseCandidateAttr(Connection* conn, |
| 1620 NominationMode mode) const { |
| 1621 switch (mode) { |
| 1622 case NominationMode::REGULAR: |
| 1623 // TODO(honghaiz): Implement regular nomination. |
| 1624 return false; |
| 1625 case NominationMode::AGGRESSIVE: |
| 1626 if (remote_ice_mode_ == ICEMODE_LITE) { |
| 1627 return GetUseCandidateAttr(conn, NominationMode::REGULAR); |
| 1628 } |
| 1629 return true; |
| 1630 case NominationMode::SEMI_AGGRESSIVE: { |
| 1631 // Nominate if |
| 1632 // a) Remote is in FULL ICE AND |
| 1633 // a.1) |conn| is the selected connection OR |
| 1634 // a.2) there is no selected connection OR |
| 1635 // a.3) the selected connection is unwritable OR |
| 1636 // a.4) |conn| has higher priority than selected_connection. |
| 1637 // b) Remote is in LITE ICE AND |
| 1638 // b.1) |conn| is the selected_connection AND |
| 1639 // b.2) |conn| is writable. |
| 1640 bool selected = conn == selected_connection_; |
| 1641 if (remote_ice_mode_ == ICEMODE_LITE) { |
| 1642 return selected && conn->writable(); |
| 1643 } |
| 1644 bool better_than_selected = |
| 1645 !selected_connection_ || !selected_connection_->writable() || |
| 1646 CompareConnectionCandidates(selected_connection_, conn) < 0; |
| 1647 return selected || better_than_selected; |
| 1648 } |
| 1649 default: |
| 1650 RTC_DCHECK(false); |
| 1651 return false; |
| 1652 } |
| 1653 } |
| 1654 |
1614 // When a connection's state changes, we need to figure out who to use as | 1655 // When a connection's state changes, we need to figure out who to use as |
1615 // the selected connection again. It could have become usable, or become | 1656 // the selected connection again. It could have become usable, or become |
1616 // unusable. | 1657 // unusable. |
1617 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { | 1658 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { |
1618 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1659 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1619 | 1660 |
1620 // May stop the allocator session when at least one connection becomes | 1661 // May stop the allocator session when at least one connection becomes |
1621 // strongly connected after starting to get ports and the local candidate of | 1662 // strongly connected after starting to get ports and the local candidate of |
1622 // the connection is at the latest generation. It is not enough to check | 1663 // the connection is at the latest generation. It is not enough to check |
1623 // that the connection becomes weakly connected because the connection may be | 1664 // that the connection becomes weakly connected because the connection may be |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 | 1929 |
1889 // During the initial state when nothing has been pinged yet, return the first | 1930 // During the initial state when nothing has been pinged yet, return the first |
1890 // one in the ordered |connections_|. | 1931 // one in the ordered |connections_|. |
1891 return *(std::find_if(connections_.begin(), connections_.end(), | 1932 return *(std::find_if(connections_.begin(), connections_.end(), |
1892 [conn1, conn2](Connection* conn) { | 1933 [conn1, conn2](Connection* conn) { |
1893 return conn == conn1 || conn == conn2; | 1934 return conn == conn1 || conn == conn2; |
1894 })); | 1935 })); |
1895 } | 1936 } |
1896 | 1937 |
1897 } // namespace cricket | 1938 } // namespace cricket |
OLD | NEW |