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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; | 73 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; |
74 | 74 |
75 // Writable connections are pinged at a faster rate while stabilizing. | 75 // Writable connections are pinged at a faster rate while stabilizing. |
76 const int STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900; // ms | 76 const int STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900; // ms |
77 | 77 |
78 // Writable connections are pinged at a slower rate once stabilized. | 78 // Writable connections are pinged at a slower rate once stabilized. |
79 const int STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms | 79 const int STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms |
80 | 80 |
81 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms | 81 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms |
82 | 82 |
83 static const int RECEIVING_SWITCHING_DELAY = 900; // ms | |
pthatcher1
2016/07/14 18:01:44
I don't quite follow the distinction between 900ms
| |
84 | |
83 // We periodically check if any existing networks do not have any connection | 85 // We periodically check if any existing networks do not have any connection |
84 // and regather on those networks. | 86 // and regather on those networks. |
85 static const int DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000; | 87 static const int DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000; |
86 static constexpr int a_is_better = 1; | 88 static constexpr int a_is_better = 1; |
87 static constexpr int b_is_better = -1; | 89 static constexpr int b_is_better = -1; |
88 | 90 |
89 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 91 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
90 int component, | 92 int component, |
91 P2PTransport* transport, | 93 P2PTransport* transport, |
92 PortAllocator* allocator) | 94 PortAllocator* allocator) |
(...skipping 12 matching lines...) Expand all Loading... | |
105 ice_role_(ICEROLE_UNKNOWN), | 107 ice_role_(ICEROLE_UNKNOWN), |
106 tiebreaker_(0), | 108 tiebreaker_(0), |
107 gathering_state_(kIceGatheringNew), | 109 gathering_state_(kIceGatheringNew), |
108 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), | 110 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), |
109 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, | 111 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, |
110 0 /* backup_connection_ping_interval */, | 112 0 /* backup_connection_ping_interval */, |
111 GATHER_ONCE /* continual_gathering_policy */, | 113 GATHER_ONCE /* continual_gathering_policy */, |
112 false /* prioritize_most_likely_candidate_pairs */, | 114 false /* prioritize_most_likely_candidate_pairs */, |
113 STABLE_WRITABLE_CONNECTION_PING_INTERVAL, | 115 STABLE_WRITABLE_CONNECTION_PING_INTERVAL, |
114 true /* presume_writable_when_fully_relayed */, | 116 true /* presume_writable_when_fully_relayed */, |
115 DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL) { | 117 DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL, |
118 RECEIVING_SWITCHING_DELAY) { | |
116 uint32_t weak_ping_interval = ::strtoul( | 119 uint32_t weak_ping_interval = ::strtoul( |
117 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), | 120 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), |
118 nullptr, 10); | 121 nullptr, 10); |
119 if (weak_ping_interval) { | 122 if (weak_ping_interval) { |
120 weak_ping_interval_ = static_cast<int>(weak_ping_interval); | 123 weak_ping_interval_ = static_cast<int>(weak_ping_interval); |
121 } | 124 } |
122 } | 125 } |
123 | 126 |
124 P2PTransportChannel::~P2PTransportChannel() { | 127 P2PTransportChannel::~P2PTransportChannel() { |
125 ASSERT(worker_thread_ == rtc::Thread::Current()); | 128 ASSERT(worker_thread_ == rtc::Thread::Current()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 // criteria is as follows: | 180 // criteria is as follows: |
178 // i) write/receiving/connected states | 181 // i) write/receiving/connected states |
179 // ii) For controlled side, | 182 // ii) For controlled side, |
180 // a) nomination state, | 183 // a) nomination state, |
181 // b) last data received time. | 184 // b) last data received time. |
182 // iii) Lower cost / higher priority. | 185 // iii) Lower cost / higher priority. |
183 // iv) rtt. | 186 // iv) rtt. |
184 // TODO(honghaiz): Stop the aggressive nomination on the controlling side and | 187 // TODO(honghaiz): Stop the aggressive nomination on the controlling side and |
185 // implement the ice-renomination option. | 188 // implement the ice-renomination option. |
186 bool P2PTransportChannel::ShouldSwitchSelectedConnection( | 189 bool P2PTransportChannel::ShouldSwitchSelectedConnection( |
187 Connection* new_connection) const { | 190 Connection* new_connection) { |
188 if (!new_connection || selected_connection_ == new_connection) { | 191 if (!new_connection || selected_connection_ == new_connection) { |
189 return false; | 192 return false; |
190 } | 193 } |
191 | 194 |
192 if (selected_connection_ == nullptr) { | 195 if (selected_connection_ == nullptr) { |
193 return true; | 196 return true; |
194 } | 197 } |
195 | 198 |
196 int cmp = CompareConnections(selected_connection_, new_connection); | 199 bool switching_dampened = false; |
200 int64_t new_conn_receiving_threshold = | |
201 (*config_.receiving_switching_delay) + | |
pthatcher1
2016/07/14 18:01:44
Don't we have to make sure config_.receiving_switc
honghaiz3
2016/07/14 23:15:01
We set the default value at the beginning and only
| |
202 new_connection->continuously_receiving_since(); | |
pthatcher1
2016/07/14 18:01:44
I was thinking of it the other way around:
int64_
honghaiz3
2016/07/14 23:15:01
Done. If it is not set, it will just get a default
| |
203 int cmp = | |
204 CompareConnections(selected_connection_, new_connection, | |
205 new_conn_receiving_threshold, &switching_dampened); | |
206 // If a connection switching is dampened, the new connection is in a better | |
207 // receiving state than the currently selected connection. So we need to | |
208 // re-check whether it needs to be switched at a later time. | |
209 if (switching_dampened && cmp >= 0) { | |
210 thread()->PostDelayed(RTC_FROM_HERE, *config_.receiving_switching_delay, | |
211 this, MSG_SORT_AND_UPDATE_STATE); | |
212 } | |
pthatcher1
2016/07/14 18:01:44
If ShoudlSwitchSelectedConnection also takes/retur
honghaiz3
2016/07/14 23:15:01
Done.
| |
197 if (cmp != 0) { | 213 if (cmp != 0) { |
198 return cmp < 0; | 214 return cmp < 0; |
199 } | 215 } |
200 | 216 |
201 // If everything else is the same, switch only if rtt has improved by | 217 // If everything else is the same, switch only if rtt has improved by |
202 // a margin. | 218 // a margin. |
203 return new_connection->rtt() <= selected_connection_->rtt() - kMinImprovement; | 219 return new_connection->rtt() <= selected_connection_->rtt() - kMinImprovement; |
204 } | 220 } |
205 | 221 |
206 void P2PTransportChannel::SetIceRole(IceRole ice_role) { | 222 void P2PTransportChannel::SetIceRole(IceRole ice_role) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 << config_.presume_writable_when_fully_relayed; | 378 << config_.presume_writable_when_fully_relayed; |
363 } | 379 } |
364 } | 380 } |
365 | 381 |
366 if (config.regather_on_failed_networks_interval) { | 382 if (config.regather_on_failed_networks_interval) { |
367 config_.regather_on_failed_networks_interval = | 383 config_.regather_on_failed_networks_interval = |
368 config.regather_on_failed_networks_interval; | 384 config.regather_on_failed_networks_interval; |
369 LOG(LS_INFO) << "Set regather_on_failed_networks_interval to " | 385 LOG(LS_INFO) << "Set regather_on_failed_networks_interval to " |
370 << *config_.regather_on_failed_networks_interval; | 386 << *config_.regather_on_failed_networks_interval; |
371 } | 387 } |
388 if (config.receiving_switching_delay) { | |
389 config_.receiving_switching_delay = config.receiving_switching_delay; | |
390 LOG(LS_INFO) << "Set receiving_switching_delay to" | |
391 << *config_.receiving_switching_delay; | |
392 } | |
372 } | 393 } |
373 | 394 |
374 const IceConfig& P2PTransportChannel::config() const { | 395 const IceConfig& P2PTransportChannel::config() const { |
375 return config_; | 396 return config_; |
376 } | 397 } |
377 | 398 |
378 void P2PTransportChannel::MaybeStartGathering() { | 399 void P2PTransportChannel::MaybeStartGathering() { |
379 if (ice_ufrag_.empty() || ice_pwd_.empty()) { | 400 if (ice_ufrag_.empty() || ice_pwd_.empty()) { |
380 return; | 401 return; |
381 } | 402 } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 } | 649 } |
629 | 650 |
630 if (!ShouldSwitchSelectedConnection(conn)) { | 651 if (!ShouldSwitchSelectedConnection(conn)) { |
631 LOG(LS_INFO) | 652 LOG(LS_INFO) |
632 << "Not switching the selected connection on controlled side yet: " | 653 << "Not switching the selected connection on controlled side yet: " |
633 << conn->ToString(); | 654 << conn->ToString(); |
634 return; | 655 return; |
635 } | 656 } |
636 | 657 |
637 LOG(LS_INFO) | 658 LOG(LS_INFO) |
638 << "Switching selected connection on controlled side due to nomination: " | 659 << "Switching selected connection on controlled side due to nomination"; |
639 << conn->ToString(); | |
640 SwitchSelectedConnection(conn); | 660 SwitchSelectedConnection(conn); |
641 // Now that we have selected a connection, it is time to prune other | 661 // Now that we have selected a connection, it is time to prune other |
642 // connections and update the read/write state of the channel. | 662 // connections and update the read/write state of the channel. |
643 RequestSortAndStateUpdate(); | 663 RequestSortAndStateUpdate(); |
644 } | 664 } |
645 | 665 |
646 void P2PTransportChannel::AddRemoteCandidate(const Candidate& candidate) { | 666 void P2PTransportChannel::AddRemoteCandidate(const Candidate& candidate) { |
647 ASSERT(worker_thread_ == rtc::Thread::Current()); | 667 ASSERT(worker_thread_ == rtc::Thread::Current()); |
648 | 668 |
649 uint32_t generation = GetRemoteCandidateGeneration(candidate); | 669 uint32_t generation = GetRemoteCandidateGeneration(candidate); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
949 | 969 |
950 // Monitor connection states. | 970 // Monitor connection states. |
951 void P2PTransportChannel::UpdateConnectionStates() { | 971 void P2PTransportChannel::UpdateConnectionStates() { |
952 int64_t now = rtc::TimeMillis(); | 972 int64_t now = rtc::TimeMillis(); |
953 | 973 |
954 // We need to copy the list of connections since some may delete themselves | 974 // We need to copy the list of connections since some may delete themselves |
955 // when we call UpdateState. | 975 // when we call UpdateState. |
956 for (Connection* c : connections_) { | 976 for (Connection* c : connections_) { |
957 c->UpdateState(now); | 977 c->UpdateState(now); |
958 } | 978 } |
979 if (!selected_connection_) { | |
980 was_strong_ = false; | |
981 return; | |
982 } | |
983 bool is_strong = !selected_connection_->weak(); | |
984 if (was_strong_ && !is_strong) { | |
985 // If the selected connection just changes to weak, | |
986 // reset the continuously_receiving_since time for each connection. | |
987 for (Connection* c : connections_) { | |
988 c->reset_continuously_receiving_since(now); | |
pthatcher1
2016/07/14 18:01:44
I don't think we need this. Won't the dampening w
| |
989 } | |
990 } | |
991 was_strong_ = is_strong; | |
959 } | 992 } |
960 | 993 |
961 // Prepare for best candidate sorting. | 994 // Prepare for best candidate sorting. |
962 void P2PTransportChannel::RequestSortAndStateUpdate() { | 995 void P2PTransportChannel::RequestSortAndStateUpdate() { |
963 if (!sort_dirty_) { | 996 if (!sort_dirty_) { |
964 worker_thread_->Post(RTC_FROM_HERE, this, MSG_SORT_AND_UPDATE_STATE); | 997 worker_thread_->Post(RTC_FROM_HERE, this, MSG_SORT_AND_UPDATE_STATE); |
965 sort_dirty_ = true; | 998 sort_dirty_ = true; |
966 } | 999 } |
967 } | 1000 } |
968 | 1001 |
(...skipping 11 matching lines...) Expand all Loading... | |
980 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING); | 1013 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING); |
981 thread()->PostDelayed(RTC_FROM_HERE, | 1014 thread()->PostDelayed(RTC_FROM_HERE, |
982 *config_.regather_on_failed_networks_interval, this, | 1015 *config_.regather_on_failed_networks_interval, this, |
983 MSG_REGATHER_ON_FAILED_NETWORKS); | 1016 MSG_REGATHER_ON_FAILED_NETWORKS); |
984 started_pinging_ = true; | 1017 started_pinging_ = true; |
985 } | 1018 } |
986 } | 1019 } |
987 | 1020 |
988 // Compare two connections based on their writing, receiving, and connected | 1021 // Compare two connections based on their writing, receiving, and connected |
989 // states. | 1022 // states. |
990 int P2PTransportChannel::CompareConnectionStates(const Connection* a, | 1023 int P2PTransportChannel::CompareConnectionStates( |
991 const Connection* b) const { | 1024 const Connection* a, |
1025 const Connection* b, | |
1026 int64_t b_receiving_threshold, | |
1027 bool* switching_dampened) const { | |
992 // First, prefer a connection that's writable or presumed writable over | 1028 // First, prefer a connection that's writable or presumed writable over |
993 // one that's not writable. | 1029 // one that's not writable. |
994 bool a_writable = a->writable() || PresumedWritable(a); | 1030 bool a_writable = a->writable() || PresumedWritable(a); |
995 bool b_writable = b->writable() || PresumedWritable(b); | 1031 bool b_writable = b->writable() || PresumedWritable(b); |
996 if (a_writable && !b_writable) { | 1032 if (a_writable && !b_writable) { |
997 return a_is_better; | 1033 return a_is_better; |
998 } | 1034 } |
999 if (!a_writable && b_writable) { | 1035 if (!a_writable && b_writable) { |
1000 return b_is_better; | 1036 return b_is_better; |
1001 } | 1037 } |
1002 | 1038 |
1003 // Sort based on write-state. Better states have lower values. | 1039 // Better write-states have lower values, and a negative return value |
1004 if (a->write_state() < b->write_state()) { | 1040 // indicates b is better. |
1005 return a_is_better; | 1041 int cmp = b->write_state() - a->write_state(); |
1006 } | 1042 if (cmp != 0) { |
1007 if (b->write_state() < a->write_state()) { | 1043 return cmp; |
1008 return b_is_better; | |
1009 } | 1044 } |
pthatcher1
2016/07/14 18:01:44
Might as well just leave this part unchanged, sinc
honghaiz3
2016/07/14 23:15:01
Done.
| |
1010 | 1045 |
1011 // We prefer a receiving connection to a non-receiving, higher-priority | 1046 // We prefer a receiving connection to a non-receiving, higher-priority |
1012 // connection when sorting connections and choosing which connection to | 1047 // connection when sorting connections. |
1013 // switch to. | |
1014 if (a->receiving() && !b->receiving()) { | 1048 if (a->receiving() && !b->receiving()) { |
1015 return a_is_better; | 1049 return a_is_better; |
1016 } | 1050 } |
1017 if (!a->receiving() && b->receiving()) { | 1051 if (!a->receiving() && b->receiving()) { |
1018 return b_is_better; | 1052 if (b_receiving_threshold == 0 || |
1053 rtc::TimeMillis() >= b_receiving_threshold) { | |
pthatcher1
2016/07/14 18:01:44
With my alternate definition of "threshold", this
honghaiz3
2016/07/14 23:15:01
Done. Use an optional now.
We still need to check
| |
1054 return b_is_better; | |
1055 } | |
1056 *switching_dampened = true; | |
1019 } | 1057 } |
1020 | 1058 |
1021 // WARNING: Some complexity here about TCP reconnecting. | 1059 // WARNING: Some complexity here about TCP reconnecting. |
1022 // When a TCP connection fails because of a TCP socket disconnecting, the | 1060 // When a TCP connection fails because of a TCP socket disconnecting, the |
1023 // active side of the connection will attempt to reconnect for 5 seconds while | 1061 // active side of the connection will attempt to reconnect for 5 seconds while |
1024 // pretending to be writable (the connection is not set to the unwritable | 1062 // pretending to be writable (the connection is not set to the unwritable |
1025 // state). On the passive side, the connection also remains writable even | 1063 // state). On the passive side, the connection also remains writable even |
1026 // though it is disconnected, and a new connection is created when the active | 1064 // though it is disconnected, and a new connection is created when the active |
1027 // side connects. At that point, there are two TCP connections on the passive | 1065 // side connects. At that point, there are two TCP connections on the passive |
1028 // side: 1. the old, disconnected one that is pretending to be writable, and | 1066 // side: 1. the old, disconnected one that is pretending to be writable, and |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1076 return b_is_better; | 1114 return b_is_better; |
1077 } | 1115 } |
1078 | 1116 |
1079 // If we're still tied at this point, prefer a younger generation. | 1117 // If we're still tied at this point, prefer a younger generation. |
1080 // (Younger generation means a larger generation number). | 1118 // (Younger generation means a larger generation number). |
1081 return (a->remote_candidate().generation() + a->port()->generation()) - | 1119 return (a->remote_candidate().generation() + a->port()->generation()) - |
1082 (b->remote_candidate().generation() + b->port()->generation()); | 1120 (b->remote_candidate().generation() + b->port()->generation()); |
1083 } | 1121 } |
1084 | 1122 |
1085 int P2PTransportChannel::CompareConnections(const Connection* a, | 1123 int P2PTransportChannel::CompareConnections(const Connection* a, |
1086 const Connection* b) const { | 1124 const Connection* b, |
1125 int64_t b_receiving_threshold, | |
1126 bool* switching_dampened) const { | |
1087 RTC_CHECK(a != nullptr); | 1127 RTC_CHECK(a != nullptr); |
1088 RTC_CHECK(b != nullptr); | 1128 RTC_CHECK(b != nullptr); |
1089 | 1129 |
1090 // We prefer to switch to a writable and receiving connection over a | 1130 // We prefer to switch to a writable and receiving connection over a |
1091 // non-writable or non-receiving connection, even if the latter has | 1131 // non-writable or non-receiving connection, even if the latter has |
1092 // been nominated by the controlling side. | 1132 // been nominated by the controlling side. |
1093 int state_cmp = CompareConnectionStates(a, b); | 1133 int state_cmp = |
1134 CompareConnectionStates(a, b, b_receiving_threshold, switching_dampened); | |
1094 if (state_cmp != 0) { | 1135 if (state_cmp != 0) { |
1095 return state_cmp; | 1136 return state_cmp; |
1096 } | 1137 } |
1097 | 1138 |
1098 if (ice_role_ == ICEROLE_CONTROLLED) { | 1139 if (ice_role_ == ICEROLE_CONTROLLED) { |
1099 // Compare the connections based on the nomination states and the last data | 1140 // Compare the connections based on the nomination states and the last data |
1100 // received time if this is on the controlled side. | 1141 // received time if this is on the controlled side. |
1101 if (a->nominated() && !b->nominated()) { | 1142 if (a->nominated() && !b->nominated()) { |
1102 return a_is_better; | 1143 return a_is_better; |
1103 } | 1144 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1136 | 1177 |
1137 // Any changes after this point will require a re-sort. | 1178 // Any changes after this point will require a re-sort. |
1138 sort_dirty_ = false; | 1179 sort_dirty_ = false; |
1139 | 1180 |
1140 // Find the best alternative connection by sorting. It is important to note | 1181 // Find the best alternative connection by sorting. It is important to note |
1141 // that amongst equal preference, writable connections, this will choose the | 1182 // that amongst equal preference, writable connections, this will choose the |
1142 // one whose estimated latency is lowest. So it is the only one that we | 1183 // one whose estimated latency is lowest. So it is the only one that we |
1143 // need to consider switching to. | 1184 // need to consider switching to. |
1144 std::stable_sort(connections_.begin(), connections_.end(), | 1185 std::stable_sort(connections_.begin(), connections_.end(), |
1145 [this](const Connection* a, const Connection* b) { | 1186 [this](const Connection* a, const Connection* b) { |
1146 int cmp = CompareConnections(a, b); | 1187 int cmp = CompareConnections(a, b, 0, nullptr); |
1147 if (cmp != 0) { | 1188 if (cmp != 0) { |
1148 return cmp > 0; | 1189 return cmp > 0; |
1149 } | 1190 } |
1150 | |
1151 // Otherwise, sort based on latency estimate. | 1191 // Otherwise, sort based on latency estimate. |
1152 return a->rtt() < b->rtt(); | 1192 return a->rtt() < b->rtt(); |
1153 }); | 1193 }); |
1154 | 1194 |
1155 LOG(LS_VERBOSE) << "Sorting " << connections_.size() | 1195 LOG(LS_VERBOSE) << "Sorting " << connections_.size() |
1156 << " available connections:"; | 1196 << " available connections:"; |
1157 for (size_t i = 0; i < connections_.size(); ++i) { | 1197 for (size_t i = 0; i < connections_.size(); ++i) { |
1158 LOG(LS_VERBOSE) << connections_[i]->ToString(); | 1198 LOG(LS_VERBOSE) << connections_[i]->ToString(); |
1159 } | 1199 } |
1160 | 1200 |
1161 Connection* top_connection = | 1201 Connection* top_connection = |
1162 (connections_.size() > 0) ? connections_[0] : nullptr; | 1202 (connections_.size() > 0) ? connections_[0] : nullptr; |
1163 | 1203 |
1164 // If necessary, switch to the new choice. Note that |top_connection| doesn't | 1204 // If necessary, switch to the new choice. Note that |top_connection| doesn't |
1165 // have to be writable to become the selected connection although it will | 1205 // have to be writable to become the selected connection although it will |
1166 // have higher priority if it is writable. | 1206 // have higher priority if it is writable. |
1167 if (ShouldSwitchSelectedConnection(top_connection)) { | 1207 if (ShouldSwitchSelectedConnection(top_connection)) { |
1168 LOG(LS_INFO) << "Switching selected connection after sorting: " | 1208 LOG(LS_INFO) << "Switching selected connection after sorting"; |
1169 << top_connection->ToString(); | |
1170 SwitchSelectedConnection(top_connection); | 1209 SwitchSelectedConnection(top_connection); |
1171 } | 1210 } |
1172 | 1211 |
1173 // The controlled side can prune only if the selected connection has been | 1212 // The controlled side can prune only if the selected connection has been |
1174 // nominated because otherwise it may prune the connection that will be | 1213 // nominated because otherwise it may prune the connection that will be |
1175 // selected by the controlling side. | 1214 // selected by the controlling side. |
1176 // TODO(honghaiz): This is not enough to prevent a connection from being | 1215 // TODO(honghaiz): This is not enough to prevent a connection from being |
1177 // pruned too early because with aggressive nomination, the controlling side | 1216 // pruned too early because with aggressive nomination, the controlling side |
1178 // will nominate every connection until it becomes writable. | 1217 // will nominate every connection until it becomes writable. |
1179 if (ice_role_ == ICEROLE_CONTROLLING || | 1218 if (ice_role_ == ICEROLE_CONTROLLING || |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1408 ASSERT(false); | 1447 ASSERT(false); |
1409 break; | 1448 break; |
1410 } | 1449 } |
1411 } | 1450 } |
1412 | 1451 |
1413 // Handle queued up check-and-ping request | 1452 // Handle queued up check-and-ping request |
1414 void P2PTransportChannel::OnCheckAndPing() { | 1453 void P2PTransportChannel::OnCheckAndPing() { |
1415 // Make sure the states of the connections are up-to-date (since this affects | 1454 // Make sure the states of the connections are up-to-date (since this affects |
1416 // which ones are pingable). | 1455 // which ones are pingable). |
1417 UpdateConnectionStates(); | 1456 UpdateConnectionStates(); |
1457 | |
1418 // When the selected connection is not receiving or not writable, or any | 1458 // When the selected connection is not receiving or not writable, or any |
1419 // active connection has not been pinged enough times, use the weak ping | 1459 // active connection has not been pinged enough times, use the weak ping |
1420 // interval. | 1460 // interval. |
1421 bool need_more_pings_at_weak_interval = std::any_of( | 1461 bool need_more_pings_at_weak_interval = std::any_of( |
1422 connections_.begin(), connections_.end(), [](Connection* conn) { | 1462 connections_.begin(), connections_.end(), [](Connection* conn) { |
1423 return conn->active() && | 1463 return conn->active() && |
1424 conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL; | 1464 conn->num_pings_sent() < MIN_PINGS_AT_WEAK_PING_INTERVAL; |
1425 }); | 1465 }); |
1426 int ping_interval = (weak() || need_more_pings_at_weak_interval) | 1466 int ping_interval = (weak() || need_more_pings_at_weak_interval) |
1427 ? weak_ping_interval_ | 1467 ? weak_ping_interval_ |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1615 LOG_J(LS_INFO, this) << "Removed connection (" | 1655 LOG_J(LS_INFO, this) << "Removed connection (" |
1616 << static_cast<int>(connections_.size()) << " remaining)"; | 1656 << static_cast<int>(connections_.size()) << " remaining)"; |
1617 | 1657 |
1618 // If this is currently the selected connection, then we need to pick a new | 1658 // If this is currently the selected connection, then we need to pick a new |
1619 // one. The call to SortConnectionsAndUpdateState will pick a new one. It | 1659 // one. The call to SortConnectionsAndUpdateState will pick a new one. It |
1620 // looks at the current selected connection in order to avoid switching | 1660 // looks at the current selected connection in order to avoid switching |
1621 // between fairly similar ones. Since this connection is no longer an option, | 1661 // between fairly similar ones. Since this connection is no longer an option, |
1622 // we can just set selected to nullptr and re-choose a best assuming that | 1662 // we can just set selected to nullptr and re-choose a best assuming that |
1623 // there was no selected connection. | 1663 // there was no selected connection. |
1624 if (selected_connection_ == connection) { | 1664 if (selected_connection_ == connection) { |
1625 LOG(LS_INFO) << "selected connection destroyed. Will choose a new one."; | 1665 LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one."; |
1626 SwitchSelectedConnection(nullptr); | 1666 SwitchSelectedConnection(nullptr); |
1627 RequestSortAndStateUpdate(); | 1667 RequestSortAndStateUpdate(); |
1628 } else { | 1668 } else { |
1629 // If a non-selected connection was destroyed, we don't need to re-sort but | 1669 // If a non-selected connection was destroyed, we don't need to re-sort but |
1630 // we do need to update state, because we could be switching to "failed" or | 1670 // we do need to update state, because we could be switching to "failed" or |
1631 // "completed". | 1671 // "completed". |
1632 UpdateState(); | 1672 UpdateState(); |
1633 } | 1673 } |
1634 } | 1674 } |
1635 | 1675 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1722 return; | 1762 return; |
1723 | 1763 |
1724 // Let the client know of an incoming packet | 1764 // Let the client know of an incoming packet |
1725 SignalReadPacket(this, data, len, packet_time, 0); | 1765 SignalReadPacket(this, data, len, packet_time, 0); |
1726 | 1766 |
1727 // May need to switch the sending connection based on the receiving media path | 1767 // May need to switch the sending connection based on the receiving media path |
1728 // if this is the controlled side. | 1768 // if this is the controlled side. |
1729 if (ice_role_ == ICEROLE_CONTROLLED && | 1769 if (ice_role_ == ICEROLE_CONTROLLED && |
1730 ShouldSwitchSelectedConnection(connection)) { | 1770 ShouldSwitchSelectedConnection(connection)) { |
1731 LOG(LS_INFO) << "Switching selected connection on controlled side due to " | 1771 LOG(LS_INFO) << "Switching selected connection on controlled side due to " |
1732 << "data received: " << connection->ToString(); | 1772 << "data received"; |
1733 SwitchSelectedConnection(connection); | 1773 SwitchSelectedConnection(connection); |
1734 } | 1774 } |
1735 } | 1775 } |
1736 | 1776 |
1737 void P2PTransportChannel::OnSentPacket(const rtc::SentPacket& sent_packet) { | 1777 void P2PTransportChannel::OnSentPacket(const rtc::SentPacket& sent_packet) { |
1738 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1778 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1739 | 1779 |
1740 SignalSentPacket(this, sent_packet); | 1780 SignalSentPacket(this, sent_packet); |
1741 } | 1781 } |
1742 | 1782 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1857 | 1897 |
1858 // During the initial state when nothing has been pinged yet, return the first | 1898 // During the initial state when nothing has been pinged yet, return the first |
1859 // one in the ordered |connections_|. | 1899 // one in the ordered |connections_|. |
1860 return *(std::find_if(connections_.begin(), connections_.end(), | 1900 return *(std::find_if(connections_.begin(), connections_.end(), |
1861 [conn1, conn2](Connection* conn) { | 1901 [conn1, conn2](Connection* conn) { |
1862 return conn == conn1 || conn == conn2; | 1902 return conn == conn1 || conn == conn2; |
1863 })); | 1903 })); |
1864 } | 1904 } |
1865 | 1905 |
1866 } // namespace cricket | 1906 } // namespace cricket |
OLD | NEW |