| 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 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 } | 1085 } |
| 1086 | 1086 |
| 1087 bool P2PTransportChannel::PresumedWritable(const Connection* conn) const { | 1087 bool P2PTransportChannel::PresumedWritable(const Connection* conn) const { |
| 1088 return (conn->write_state() == Connection::STATE_WRITE_INIT && | 1088 return (conn->write_state() == Connection::STATE_WRITE_INIT && |
| 1089 config_.presume_writable_when_fully_relayed && | 1089 config_.presume_writable_when_fully_relayed && |
| 1090 conn->local_candidate().type() == RELAY_PORT_TYPE && | 1090 conn->local_candidate().type() == RELAY_PORT_TYPE && |
| 1091 (conn->remote_candidate().type() == RELAY_PORT_TYPE || | 1091 (conn->remote_candidate().type() == RELAY_PORT_TYPE || |
| 1092 conn->remote_candidate().type() == PRFLX_PORT_TYPE)); | 1092 conn->remote_candidate().type() == PRFLX_PORT_TYPE)); |
| 1093 } | 1093 } |
| 1094 | 1094 |
| 1095 // Determines whether we should switch between two connections, based first on | |
| 1096 // connection states, static preferences, and then (if those are equal) on | |
| 1097 // latency estimates. | |
| 1098 bool P2PTransportChannel::ShouldSwitchSelectedConnection( | |
| 1099 const Connection* selected, | |
| 1100 const Connection* conn) const { | |
| 1101 if (selected == conn) { | |
| 1102 return false; | |
| 1103 } | |
| 1104 | |
| 1105 if (!selected || !conn) { // don't think the latter should happen | |
| 1106 return true; | |
| 1107 } | |
| 1108 | |
| 1109 // We prefer to switch to a writable and receiving connection over a | |
| 1110 // non-writable or non-receiving connection, even if the latter has | |
| 1111 // been nominated by the controlling side. | |
| 1112 int state_cmp = CompareConnectionStates(selected, conn); | |
| 1113 if (state_cmp != 0) { | |
| 1114 return state_cmp < 0; | |
| 1115 } | |
| 1116 if (ice_role_ == ICEROLE_CONTROLLED && selected->nominated()) { | |
| 1117 LOG(LS_VERBOSE) << "Controlled side did not switch due to nominated status"; | |
| 1118 return false; | |
| 1119 } | |
| 1120 | |
| 1121 int prefs_cmp = CompareConnectionCandidates(selected, conn); | |
| 1122 if (prefs_cmp != 0) { | |
| 1123 return prefs_cmp < 0; | |
| 1124 } | |
| 1125 | |
| 1126 return selected->rtt() - conn->rtt() >= kMinImprovement; | |
| 1127 } | |
| 1128 | |
| 1129 // Sort the available connections to find the best one. We also monitor | 1095 // Sort the available connections to find the best one. We also monitor |
| 1130 // the number of available connections and the current state. | 1096 // the number of available connections and the current state. |
| 1131 void P2PTransportChannel::SortConnections() { | 1097 void P2PTransportChannel::SortConnections() { |
| 1132 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1098 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 1133 | 1099 |
| 1134 // Make sure the connection states are up-to-date since this affects how they | 1100 // Make sure the connection states are up-to-date since this affects how they |
| 1135 // will be sorted. | 1101 // will be sorted. |
| 1136 UpdateConnectionStates(); | 1102 UpdateConnectionStates(); |
| 1137 | 1103 |
| 1138 // Any changes after this point will require a re-sort. | 1104 // Any changes after this point will require a re-sort. |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 | 1765 |
| 1800 // During the initial state when nothing has been pinged yet, return the first | 1766 // During the initial state when nothing has been pinged yet, return the first |
| 1801 // one in the ordered |connections_|. | 1767 // one in the ordered |connections_|. |
| 1802 return *(std::find_if(connections_.begin(), connections_.end(), | 1768 return *(std::find_if(connections_.begin(), connections_.end(), |
| 1803 [conn1, conn2](Connection* conn) { | 1769 [conn1, conn2](Connection* conn) { |
| 1804 return conn == conn1 || conn == conn2; | 1770 return conn == conn1 || conn == conn2; |
| 1805 })); | 1771 })); |
| 1806 } | 1772 } |
| 1807 | 1773 |
| 1808 } // namespace cricket | 1774 } // namespace cricket |
| OLD | NEW |