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...) 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...) 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...) 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...) 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 | 1597 void P2PTransportChannel::PingConnection(Connection* conn) { |
1591 // a) Channel is in FULL ICE AND | 1598 bool use_candidate_attr = false; |
1599 int nomination = 0; | |
1600 if (ice_role_ == ICEROLE_CONTROLLING) { | |
1601 if (remote_supports_renomination_) { | |
1602 nomination = GetNominationAttr(conn); | |
1603 } else { | |
1604 use_candidate_attr = | |
1605 GetUseCandidateAttr(conn, config_.default_nomination_mode); | |
1606 } | |
1607 } | |
1608 conn->set_nomination(nomination); | |
1609 conn->set_use_candidate_attr(use_candidate_attr); | |
1610 last_ping_sent_ms_ = rtc::TimeMillis(); | |
1611 conn->Ping(last_ping_sent_ms_); | |
1612 } | |
1613 | |
1614 int P2PTransportChannel::GetNominationAttr(Connection* conn) const { | |
1615 return (conn == selected_connection_) ? nomination_ : 0; | |
1616 } | |
1617 | |
1618 // Nominate a connection based on the NominationMode. | |
1619 // REGULAR: To be implemented yet. | |
pthatcher1
2016/08/03 22:13:25
To be implemented yet => Nominate once per ICE res
honghaiz3
2016/08/03 23:39:51
Done.
| |
1620 // AGGRESSIVE: Nominate every connection except that when the remote is at | |
1621 // ICE_LITE mode, it will behave as if REGULAR. | |
pthatcher1
2016/08/03 22:13:25
except that when => except when
is at ICE_LITE mod
honghaiz3
2016/08/03 23:39:51
Done.
| |
1622 // SEMI-AGGRESSIVE: Nominate if | |
1623 // a) Remote is in FULL ICE AND | |
1592 // a.1) |conn| is the selected connection OR | 1624 // a.1) |conn| is the selected connection OR |
1593 // a.2) there is no selected connection OR | 1625 // a.2) there is no selected connection OR |
1594 // a.3) the selected connection is unwritable OR | 1626 // a.3) the selected connection is unwritable OR |
1595 // a.4) |conn| has higher priority than selected_connection. | 1627 // a.4) |conn| has higher priority than selected_connection. |
1596 // b) we're doing LITE ICE AND | 1628 // b) Remote is in LITE ICE AND |
1597 // b.1) |conn| is the selected_connection AND | 1629 // b.1) |conn| is the selected_connection AND |
1598 // b.2) |conn| is writable. | 1630 // b.2) |conn| is writable. |
1599 void P2PTransportChannel::PingConnection(Connection* conn) { | 1631 bool P2PTransportChannel::GetUseCandidateAttr(Connection* conn, |
1600 bool use_candidate = false; | 1632 NominationMode mode) const { |
1601 if (remote_ice_mode_ == ICEMODE_FULL && ice_role_ == ICEROLE_CONTROLLING) { | 1633 switch (mode) { |
1602 use_candidate = | 1634 case NominationMode::REGULAR: |
1603 (conn == selected_connection_) || (selected_connection_ == NULL) || | 1635 // TODO(honghaiz): Implement regular nomination. |
1604 (!selected_connection_->writable()) || | 1636 return false; |
1605 (CompareConnectionCandidates(selected_connection_, conn) < 0); | 1637 case NominationMode::AGGRESSIVE: |
1606 } else if (remote_ice_mode_ == ICEMODE_LITE && conn == selected_connection_) { | 1638 if (remote_ice_mode_ == ICEMODE_LITE) { |
1607 use_candidate = selected_connection_->writable(); | 1639 return GetUseCandidateAttr(conn, NominationMode::REGULAR); |
1640 } | |
1641 return true; | |
1642 case NominationMode::SEMI_AGGRESSIVE: { | |
1643 bool selected = conn == selected_connection_; | |
1644 if (remote_ice_mode_ == ICEMODE_LITE) { | |
1645 return selected && conn->writable(); | |
1646 } | |
1647 bool better_than_selected = | |
1648 !selected_connection_ || !selected_connection_->writable() || | |
1649 CompareConnectionCandidates(selected_connection_, conn) < 0; | |
1650 return selected || better_than_selected; | |
1651 } | |
1652 default: | |
1653 RTC_DCHECK(false); | |
1654 return false; | |
1608 } | 1655 } |
1609 conn->set_use_candidate_attr(use_candidate); | |
1610 last_ping_sent_ms_ = rtc::TimeMillis(); | |
1611 conn->Ping(last_ping_sent_ms_); | |
1612 } | 1656 } |
1613 | 1657 |
1614 // When a connection's state changes, we need to figure out who to use as | 1658 // 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 | 1659 // the selected connection again. It could have become usable, or become |
1616 // unusable. | 1660 // unusable. |
1617 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { | 1661 void P2PTransportChannel::OnConnectionStateChange(Connection* connection) { |
1618 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1662 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1619 | 1663 |
1620 // May stop the allocator session when at least one connection becomes | 1664 // May stop the allocator session when at least one connection becomes |
1621 // strongly connected after starting to get ports and the local candidate of | 1665 // strongly connected after starting to get ports and the local candidate of |
(...skipping 266 matching lines...) Loading... | |
1888 | 1932 |
1889 // During the initial state when nothing has been pinged yet, return the first | 1933 // During the initial state when nothing has been pinged yet, return the first |
1890 // one in the ordered |connections_|. | 1934 // one in the ordered |connections_|. |
1891 return *(std::find_if(connections_.begin(), connections_.end(), | 1935 return *(std::find_if(connections_.begin(), connections_.end(), |
1892 [conn1, conn2](Connection* conn) { | 1936 [conn1, conn2](Connection* conn) { |
1893 return conn == conn1 || conn == conn2; | 1937 return conn == conn1 || conn == conn2; |
1894 })); | 1938 })); |
1895 } | 1939 } |
1896 | 1940 |
1897 } // namespace cricket | 1941 } // namespace cricket |
OLD | NEW |