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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 PortAllocator* allocator) | 208 PortAllocator* allocator) |
209 : TransportChannelImpl(transport_name, component), | 209 : TransportChannelImpl(transport_name, component), |
210 transport_(transport), | 210 transport_(transport), |
211 allocator_(allocator), | 211 allocator_(allocator), |
212 worker_thread_(rtc::Thread::Current()), | 212 worker_thread_(rtc::Thread::Current()), |
213 incoming_only_(false), | 213 incoming_only_(false), |
214 error_(0), | 214 error_(0), |
215 best_connection_(NULL), | 215 best_connection_(NULL), |
216 pending_best_connection_(NULL), | 216 pending_best_connection_(NULL), |
217 sort_dirty_(false), | 217 sort_dirty_(false), |
218 was_writable_(false), | |
219 remote_ice_mode_(ICEMODE_FULL), | 218 remote_ice_mode_(ICEMODE_FULL), |
220 ice_role_(ICEROLE_UNKNOWN), | 219 ice_role_(ICEROLE_UNKNOWN), |
221 tiebreaker_(0), | 220 tiebreaker_(0), |
222 remote_candidate_generation_(0), | 221 remote_candidate_generation_(0), |
223 gathering_state_(kIceGatheringNew), | 222 gathering_state_(kIceGatheringNew), |
224 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5), | 223 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5), |
225 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) { | 224 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) { |
226 uint32_t weak_ping_delay = ::strtoul( | 225 uint32_t weak_ping_delay = ::strtoul( |
227 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), | 226 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), |
228 nullptr, 10); | 227 nullptr, 10); |
229 if (weak_ping_delay) { | 228 if (weak_ping_delay) { |
230 weak_ping_delay_ = weak_ping_delay; | 229 weak_ping_delay_ = weak_ping_delay; |
231 } | 230 } |
232 } | 231 } |
233 | 232 |
234 P2PTransportChannel::~P2PTransportChannel() { | 233 P2PTransportChannel::~P2PTransportChannel() { |
235 ASSERT(worker_thread_ == rtc::Thread::Current()); | 234 ASSERT(worker_thread_ == rtc::Thread::Current()); |
236 | 235 |
237 for (size_t i = 0; i < allocator_sessions_.size(); ++i) | 236 for (size_t i = 0; i < allocator_sessions_.size(); ++i) |
238 delete allocator_sessions_[i]; | 237 delete allocator_sessions_[i]; |
239 } | 238 } |
240 | 239 |
241 // Add the allocator session to our list so that we know which sessions | 240 // Add the allocator session to our list so that we know which sessions |
242 // are still active. | 241 // are still active. |
243 void P2PTransportChannel::AddAllocatorSession(PortAllocatorSession* session) { | 242 void P2PTransportChannel::AddAllocatorSession(PortAllocatorSession* session) { |
| 243 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 244 |
244 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); | 245 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); |
245 allocator_sessions_.push_back(session); | 246 allocator_sessions_.push_back(session); |
246 | 247 |
247 // We now only want to apply new candidates that we receive to the ports | 248 // We now only want to apply new candidates that we receive to the ports |
248 // created by this new session because these are replacing those of the | 249 // created by this new session because these are replacing those of the |
249 // previous sessions. | 250 // previous sessions. |
250 ports_.clear(); | 251 ports_.clear(); |
251 | 252 |
252 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); | 253 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); |
253 session->SignalCandidatesReady.connect( | 254 session->SignalCandidatesReady.connect( |
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 bool receiving = false; | 1072 bool receiving = false; |
1072 for (const Connection* connection : connections_) { | 1073 for (const Connection* connection : connections_) { |
1073 if (connection->receiving()) { | 1074 if (connection->receiving()) { |
1074 receiving = true; | 1075 receiving = true; |
1075 break; | 1076 break; |
1076 } | 1077 } |
1077 } | 1078 } |
1078 set_receiving(receiving); | 1079 set_receiving(receiving); |
1079 } | 1080 } |
1080 | 1081 |
1081 // We checked the status of our connections and we had at least one that | 1082 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { |
1082 // was writable, go into the writable state. | 1083 if (!IsGettingPorts()) { |
1083 void P2PTransportChannel::HandleWritable() { | |
1084 ASSERT(worker_thread_ == rtc::Thread::Current()); | |
1085 if (writable()) { | |
1086 return; | 1084 return; |
1087 } | 1085 } |
1088 | 1086 |
1089 for (PortAllocatorSession* session : allocator_sessions_) { | 1087 for (PortAllocatorSession* session : allocator_sessions_) { |
1090 if (!session->IsGettingPorts()) { | 1088 if (!session->IsGettingPorts()) { |
1091 continue; | 1089 continue; |
1092 } | 1090 } |
1093 // If gathering continually, keep the last session running so that it | 1091 // If gathering continually, keep the last session running so that it |
1094 // will gather candidates if the networks change. | 1092 // will gather candidates if the networks change. |
1095 if (gather_continually_ && session == allocator_sessions_.back()) { | 1093 if (gather_continually_ && session == allocator_sessions_.back()) { |
1096 session->ClearGettingPorts(); | 1094 session->ClearGettingPorts(); |
1097 break; | 1095 break; |
1098 } | 1096 } |
1099 session->StopGettingPorts(); | 1097 session->StopGettingPorts(); |
1100 } | 1098 } |
| 1099 } |
1101 | 1100 |
1102 was_writable_ = true; | 1101 // Go into the writable state and notify upper layer if it was not before. |
1103 set_writable(true); | 1102 void P2PTransportChannel::HandleWritable() { |
| 1103 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 1104 if (!writable()) { |
| 1105 set_writable(true); |
| 1106 } |
1104 } | 1107 } |
1105 | 1108 |
1106 // Notify upper layer about channel not writable state, if it was before. | 1109 // Notify upper layer about channel not writable state, if it was before. |
1107 void P2PTransportChannel::HandleNotWritable() { | 1110 void P2PTransportChannel::HandleNotWritable() { |
1108 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1111 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1109 if (was_writable_) { | 1112 if (writable()) { |
1110 was_writable_ = false; | |
1111 set_writable(false); | 1113 set_writable(false); |
1112 } | 1114 } |
1113 } | 1115 } |
1114 | 1116 |
1115 // If all connections timed out, delete them all. | 1117 // If all connections timed out, delete them all. |
1116 void P2PTransportChannel::HandleAllTimedOut() { | 1118 void P2PTransportChannel::HandleAllTimedOut() { |
1117 for (Connection* connection : connections_) { | 1119 for (Connection* connection : connections_) { |
1118 connection->Destroy(); | 1120 connection->Destroy(); |
1119 } | 1121 } |
1120 } | 1122 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 // connection and role is controlled. | 1286 // connection and role is controlled. |
1285 if (ice_role_ == ICEROLE_CONTROLLED) { | 1287 if (ice_role_ == ICEROLE_CONTROLLED) { |
1286 if (connection == pending_best_connection_ && connection->writable()) { | 1288 if (connection == pending_best_connection_ && connection->writable()) { |
1287 pending_best_connection_ = NULL; | 1289 pending_best_connection_ = NULL; |
1288 LOG(LS_INFO) << "Switching best connection on controlled side" | 1290 LOG(LS_INFO) << "Switching best connection on controlled side" |
1289 << " because it's now writable: " << connection->ToString(); | 1291 << " because it's now writable: " << connection->ToString(); |
1290 SwitchBestConnectionTo(connection); | 1292 SwitchBestConnectionTo(connection); |
1291 } | 1293 } |
1292 } | 1294 } |
1293 | 1295 |
| 1296 // May stop the allocator session when at least one connection becomes |
| 1297 // strongly connected after starting to get ports. It is not enough to check |
| 1298 // that the connection becomes weakly connected because the connection may be |
| 1299 // changing from (writable, receiving) to (writable, not receiving). |
| 1300 if (!connection->weak()) { |
| 1301 MaybeStopPortAllocatorSessions(); |
| 1302 } |
| 1303 |
1294 // We have to unroll the stack before doing this because we may be changing | 1304 // We have to unroll the stack before doing this because we may be changing |
1295 // the state of connections while sorting. | 1305 // the state of connections while sorting. |
1296 RequestSort(); | 1306 RequestSort(); |
1297 } | 1307 } |
1298 | 1308 |
1299 // When a connection is removed, edit it out, and then update our best | 1309 // When a connection is removed, edit it out, and then update our best |
1300 // connection. | 1310 // connection. |
1301 void P2PTransportChannel::OnConnectionDestroyed(Connection* connection) { | 1311 void P2PTransportChannel::OnConnectionDestroyed(Connection* connection) { |
1302 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1312 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1303 | 1313 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 SignalSentPacket(this, sent_packet); | 1385 SignalSentPacket(this, sent_packet); |
1376 } | 1386 } |
1377 | 1387 |
1378 void P2PTransportChannel::OnReadyToSend(Connection* connection) { | 1388 void P2PTransportChannel::OnReadyToSend(Connection* connection) { |
1379 if (connection == best_connection_ && writable()) { | 1389 if (connection == best_connection_ && writable()) { |
1380 SignalReadyToSend(this); | 1390 SignalReadyToSend(this); |
1381 } | 1391 } |
1382 } | 1392 } |
1383 | 1393 |
1384 } // namespace cricket | 1394 } // namespace cricket |
OLD | NEW |