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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 uint32_t weak_ping_interval = ::strtoul( | 254 uint32_t weak_ping_interval = ::strtoul( |
255 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), | 255 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), |
256 nullptr, 10); | 256 nullptr, 10); |
257 if (weak_ping_interval) { | 257 if (weak_ping_interval) { |
258 weak_ping_interval_ = static_cast<int>(weak_ping_interval); | 258 weak_ping_interval_ = static_cast<int>(weak_ping_interval); |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 P2PTransportChannel::~P2PTransportChannel() { | 262 P2PTransportChannel::~P2PTransportChannel() { |
263 ASSERT(worker_thread_ == rtc::Thread::Current()); | 263 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 264 |
| 265 for (size_t i = 0; i < allocator_sessions_.size(); ++i) |
| 266 delete allocator_sessions_[i]; |
264 } | 267 } |
265 | 268 |
266 // Add the allocator session to our list so that we know which sessions | 269 // Add the allocator session to our list so that we know which sessions |
267 // are still active. | 270 // are still active. |
268 void P2PTransportChannel::AddAllocatorSession( | 271 void P2PTransportChannel::AddAllocatorSession(PortAllocatorSession* session) { |
269 std::unique_ptr<PortAllocatorSession> session) { | |
270 ASSERT(worker_thread_ == rtc::Thread::Current()); | 272 ASSERT(worker_thread_ == rtc::Thread::Current()); |
271 | 273 |
272 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); | 274 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); |
273 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); | 275 allocator_sessions_.push_back(session); |
274 session->SignalCandidatesReady.connect( | |
275 this, &P2PTransportChannel::OnCandidatesReady); | |
276 session->SignalCandidatesAllocationDone.connect( | |
277 this, &P2PTransportChannel::OnCandidatesAllocationDone); | |
278 | 276 |
279 // We now only want to apply new candidates that we receive to the ports | 277 // We now only want to apply new candidates that we receive to the ports |
280 // created by this new session because these are replacing those of the | 278 // created by this new session because these are replacing those of the |
281 // previous sessions. | 279 // previous sessions. |
282 ports_.clear(); | 280 ports_.clear(); |
283 | 281 |
284 allocator_sessions_.push_back(std::move(session)); | 282 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); |
| 283 session->SignalCandidatesReady.connect( |
| 284 this, &P2PTransportChannel::OnCandidatesReady); |
| 285 session->SignalCandidatesAllocationDone.connect( |
| 286 this, &P2PTransportChannel::OnCandidatesAllocationDone); |
| 287 session->StartGettingPorts(); |
285 } | 288 } |
286 | 289 |
287 void P2PTransportChannel::AddConnection(Connection* connection) { | 290 void P2PTransportChannel::AddConnection(Connection* connection) { |
288 connections_.push_back(connection); | 291 connections_.push_back(connection); |
289 unpinged_connections_.insert(connection); | 292 unpinged_connections_.insert(connection); |
290 connection->set_remote_ice_mode(remote_ice_mode_); | 293 connection->set_remote_ice_mode(remote_ice_mode_); |
291 connection->set_receiving_timeout(config_.receiving_timeout); | 294 connection->set_receiving_timeout(config_.receiving_timeout); |
292 connection->SignalReadPacket.connect( | 295 connection->SignalReadPacket.connect( |
293 this, &P2PTransportChannel::OnReadPacket); | 296 this, &P2PTransportChannel::OnReadPacket); |
294 connection->SignalReadyToSend.connect( | 297 connection->SignalReadyToSend.connect( |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 void P2PTransportChannel::MaybeStartGathering() { | 465 void P2PTransportChannel::MaybeStartGathering() { |
463 // Start gathering if we never started before, or if an ICE restart occurred. | 466 // Start gathering if we never started before, or if an ICE restart occurred. |
464 if (allocator_sessions_.empty() || | 467 if (allocator_sessions_.empty() || |
465 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), | 468 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), |
466 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, | 469 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, |
467 ice_pwd_)) { | 470 ice_pwd_)) { |
468 if (gathering_state_ != kIceGatheringGathering) { | 471 if (gathering_state_ != kIceGatheringGathering) { |
469 gathering_state_ = kIceGatheringGathering; | 472 gathering_state_ = kIceGatheringGathering; |
470 SignalGatheringState(this); | 473 SignalGatheringState(this); |
471 } | 474 } |
472 // Time for a new allocator. | 475 // Time for a new allocator |
473 std::unique_ptr<PortAllocatorSession> pooled_session = | 476 AddAllocatorSession(allocator_->CreateSession( |
474 allocator_->TakePooledSession(transport_name(), component(), ice_ufrag_, | 477 SessionId(), transport_name(), component(), ice_ufrag_, ice_pwd_)); |
475 ice_pwd_); | |
476 if (pooled_session) { | |
477 AddAllocatorSession(std::move(pooled_session)); | |
478 PortAllocatorSession* raw_pooled_session = | |
479 allocator_sessions_.back().get(); | |
480 // Process the pooled session's existing candidates/ports, if they exist. | |
481 OnCandidatesReady(raw_pooled_session, | |
482 raw_pooled_session->ReadyCandidates()); | |
483 for (PortInterface* port : allocator_sessions_.back()->ReadyPorts()) { | |
484 OnPortReady(raw_pooled_session, port); | |
485 } | |
486 if (allocator_sessions_.back()->CandidatesAllocationDone()) { | |
487 OnCandidatesAllocationDone(raw_pooled_session); | |
488 } | |
489 } else { | |
490 AddAllocatorSession(allocator_->CreateSession( | |
491 SessionId(), transport_name(), component(), ice_ufrag_, ice_pwd_)); | |
492 allocator_sessions_.back()->StartGettingPorts(); | |
493 } | |
494 } | 478 } |
495 } | 479 } |
496 | 480 |
497 // A new port is available, attempt to make connections for it | 481 // A new port is available, attempt to make connections for it |
498 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, | 482 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, |
499 PortInterface* port) { | 483 PortInterface* port) { |
500 ASSERT(worker_thread_ == rtc::Thread::Current()); | 484 ASSERT(worker_thread_ == rtc::Thread::Current()); |
501 | 485 |
502 // Set in-effect options on the new port | 486 // Set in-effect options on the new port |
503 for (OptionMap::const_iterator it = options_.begin(); | 487 for (OptionMap::const_iterator it = options_.begin(); |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 } | 1206 } |
1223 } | 1207 } |
1224 set_receiving(receiving); | 1208 set_receiving(receiving); |
1225 } | 1209 } |
1226 | 1210 |
1227 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { | 1211 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { |
1228 if (!IsGettingPorts()) { | 1212 if (!IsGettingPorts()) { |
1229 return; | 1213 return; |
1230 } | 1214 } |
1231 | 1215 |
1232 for (const auto& session : allocator_sessions_) { | 1216 for (PortAllocatorSession* session : allocator_sessions_) { |
1233 if (!session->IsGettingPorts()) { | 1217 if (!session->IsGettingPorts()) { |
1234 continue; | 1218 continue; |
1235 } | 1219 } |
1236 // If gathering continually, keep the last session running so that it | 1220 // If gathering continually, keep the last session running so that it |
1237 // will gather candidates if the networks change. | 1221 // will gather candidates if the networks change. |
1238 if (config_.gather_continually && session == allocator_sessions_.back()) { | 1222 if (config_.gather_continually && session == allocator_sessions_.back()) { |
1239 session->ClearGettingPorts(); | 1223 session->ClearGettingPorts(); |
1240 break; | 1224 break; |
1241 } | 1225 } |
1242 session->StopGettingPorts(); | 1226 session->StopGettingPorts(); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 | 1642 |
1659 // During the initial state when nothing has been pinged yet, return the first | 1643 // During the initial state when nothing has been pinged yet, return the first |
1660 // one in the ordered |connections_|. | 1644 // one in the ordered |connections_|. |
1661 return *(std::find_if(connections_.begin(), connections_.end(), | 1645 return *(std::find_if(connections_.begin(), connections_.end(), |
1662 [conn1, conn2](Connection* conn) { | 1646 [conn1, conn2](Connection* conn) { |
1663 return conn == conn1 || conn == conn2; | 1647 return conn == conn1 || conn == conn2; |
1664 })); | 1648 })); |
1665 } | 1649 } |
1666 | 1650 |
1667 } // namespace cricket | 1651 } // namespace cricket |
OLD | NEW |