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 |
11 #include "webrtc/p2p/base/p2ptransportchannel.h" | 11 #include "webrtc/p2p/base/p2ptransportchannel.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <set> | 14 #include <set> |
15 | 15 |
16 #include "webrtc/base/common.h" | 16 #include "webrtc/base/common.h" |
17 #include "webrtc/base/crc32.h" | 17 #include "webrtc/base/crc32.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/stringencode.h" | 19 #include "webrtc/base/stringencode.h" |
20 #include "webrtc/p2p/base/candidate.h" | 20 #include "webrtc/p2p/base/candidate.h" |
21 #include "webrtc/p2p/base/candidatepairinterface.h" | 21 #include "webrtc/p2p/base/candidatepairinterface.h" |
22 #include "webrtc/p2p/base/common.h" | 22 #include "webrtc/p2p/base/common.h" |
23 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE. | 23 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE. |
24 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE. | 24 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE. |
25 #include "webrtc/system_wrappers/include/field_trial.h" | 25 #include "webrtc/system_wrappers/include/field_trial.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // messages for queuing up work for ourselves | 29 // messages for queuing up work for ourselves |
30 enum { MSG_SORT = 1, MSG_CHECK_AND_PING }; | 30 enum { |
| 31 MSG_SORT = 1, |
| 32 MSG_CHECK_AND_PING, |
| 33 MSG_REGATHER_ON_FAILED_NETWORKS, |
| 34 MSG_SIGNAL_CANDIDATES_REMOVED |
| 35 }; |
31 | 36 |
32 // The minimum improvement in RTT that justifies a switch. | 37 // The minimum improvement in RTT that justifies a switch. |
33 static const double kMinImprovement = 10; | 38 const double kMinImprovement = 10; |
34 | 39 |
35 bool IsRelayRelay(cricket::Connection* conn) { | 40 bool IsRelayRelay(cricket::Connection* conn) { |
36 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE && | 41 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE && |
37 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE; | 42 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE; |
38 } | 43 } |
39 | 44 |
40 bool IsUdp(cricket::Connection* conn) { | 45 bool IsUdp(cricket::Connection* conn) { |
41 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME; | 46 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME; |
42 } | 47 } |
43 | 48 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // writable or not receiving. | 222 // writable or not receiving. |
218 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; | 223 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; |
219 | 224 |
220 // If the current best connection is both writable and receiving, then we will | 225 // If the current best connection is both writable and receiving, then we will |
221 // also try hard to make sure it is pinged at this rate (a little less than | 226 // also try hard to make sure it is pinged at this rate (a little less than |
222 // 2 * STRONG_PING_INTERVAL). | 227 // 2 * STRONG_PING_INTERVAL). |
223 static const int MAX_CURRENT_STRONG_INTERVAL = 900; // ms | 228 static const int MAX_CURRENT_STRONG_INTERVAL = 900; // ms |
224 | 229 |
225 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms | 230 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms |
226 | 231 |
| 232 // We periodically check if any existing networks do not have any connection |
| 233 // and regather on those failed networks. |
| 234 static const int DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000; |
| 235 |
227 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 236 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
228 int component, | 237 int component, |
229 P2PTransport* transport, | 238 P2PTransport* transport, |
230 PortAllocator* allocator) | 239 PortAllocator* allocator) |
231 : P2PTransportChannel(transport_name, component, allocator) {} | 240 : P2PTransportChannel(transport_name, component, allocator) {} |
232 | 241 |
233 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 242 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
234 int component, | 243 int component, |
235 PortAllocator* allocator) | 244 PortAllocator* allocator) |
236 : TransportChannelImpl(transport_name, component), | 245 : TransportChannelImpl(transport_name, component), |
237 allocator_(allocator), | 246 allocator_(allocator), |
238 worker_thread_(rtc::Thread::Current()), | 247 worker_thread_(rtc::Thread::Current()), |
239 incoming_only_(false), | 248 incoming_only_(false), |
240 error_(0), | 249 error_(0), |
241 best_connection_(NULL), | 250 best_connection_(NULL), |
242 pending_best_connection_(NULL), | 251 pending_best_connection_(NULL), |
243 sort_dirty_(false), | 252 sort_dirty_(false), |
244 remote_ice_mode_(ICEMODE_FULL), | 253 remote_ice_mode_(ICEMODE_FULL), |
245 ice_role_(ICEROLE_UNKNOWN), | 254 ice_role_(ICEROLE_UNKNOWN), |
246 tiebreaker_(0), | 255 tiebreaker_(0), |
247 gathering_state_(kIceGatheringNew), | 256 gathering_state_(kIceGatheringNew), |
248 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), | 257 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), |
249 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, | 258 config_( |
250 0 /* backup_connection_ping_interval */, | 259 MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, |
251 false /* gather_continually */, | 260 0 /* backup_connection_ping_interval */, |
252 false /* prioritize_most_likely_candidate_pairs */, | 261 GATHER_ONCE, |
253 MAX_CURRENT_STRONG_INTERVAL /* max_strong_interval */) { | 262 false /* prioritize_most_likely_candidate_pairs */, |
| 263 MAX_CURRENT_STRONG_INTERVAL /* max_strong_interval */, |
| 264 DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL) { |
254 uint32_t weak_ping_interval = ::strtoul( | 265 uint32_t weak_ping_interval = ::strtoul( |
255 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), | 266 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), |
256 nullptr, 10); | 267 nullptr, 10); |
257 if (weak_ping_interval) { | 268 if (weak_ping_interval) { |
258 weak_ping_interval_ = static_cast<int>(weak_ping_interval); | 269 weak_ping_interval_ = static_cast<int>(weak_ping_interval); |
259 } | 270 } |
260 } | 271 } |
261 | 272 |
262 P2PTransportChannel::~P2PTransportChannel() { | 273 P2PTransportChannel::~P2PTransportChannel() { |
263 ASSERT(worker_thread_ == rtc::Thread::Current()); | 274 ASSERT(worker_thread_ == rtc::Thread::Current()); |
264 } | 275 } |
265 | 276 |
266 // Add the allocator session to our list so that we know which sessions | 277 // Add the allocator session to our list so that we know which sessions |
267 // are still active. | 278 // are still active. |
268 void P2PTransportChannel::AddAllocatorSession( | 279 void P2PTransportChannel::AddAllocatorSession( |
269 std::unique_ptr<PortAllocatorSession> session) { | 280 std::unique_ptr<PortAllocatorSession> session) { |
270 ASSERT(worker_thread_ == rtc::Thread::Current()); | 281 ASSERT(worker_thread_ == rtc::Thread::Current()); |
271 | 282 |
272 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); | 283 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); |
273 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); | 284 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); |
274 session->SignalCandidatesReady.connect( | 285 session->SignalCandidatesReady.connect( |
275 this, &P2PTransportChannel::OnCandidatesReady); | 286 this, &P2PTransportChannel::OnCandidatesReady); |
| 287 session->SignalCandidatesRemoved.connect( |
| 288 this, &P2PTransportChannel::OnCandidatesRemoved); |
276 session->SignalCandidatesAllocationDone.connect( | 289 session->SignalCandidatesAllocationDone.connect( |
277 this, &P2PTransportChannel::OnCandidatesAllocationDone); | 290 this, &P2PTransportChannel::OnCandidatesAllocationDone); |
278 | 291 |
279 // We now only want to apply new candidates that we receive to the ports | 292 // 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 | 293 // created by this new session because these are replacing those of the |
281 // previous sessions. | 294 // previous sessions. |
282 ports_.clear(); | 295 ports_.clear(); |
283 | 296 |
284 allocator_sessions_.push_back(std::move(session)); | 297 allocator_sessions_.push_back(std::move(session)); |
285 } | 298 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 } | 408 } |
396 // Updating the remote ICE candidate generation could change the sort order. | 409 // Updating the remote ICE candidate generation could change the sort order. |
397 RequestSort(); | 410 RequestSort(); |
398 } | 411 } |
399 | 412 |
400 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { | 413 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { |
401 remote_ice_mode_ = mode; | 414 remote_ice_mode_ = mode; |
402 } | 415 } |
403 | 416 |
404 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { | 417 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { |
405 config_.gather_continually = config.gather_continually; | 418 config_.gathering_policy = config.gathering_policy; |
406 LOG(LS_INFO) << "Set gather_continually to " << config_.gather_continually; | 419 LOG(LS_INFO) << "Set gathering_policy to " << config_.gathering_policy; |
407 | 420 |
408 if (config.backup_connection_ping_interval >= 0 && | 421 if (config.backup_connection_ping_interval >= 0 && |
409 config_.backup_connection_ping_interval != | 422 config_.backup_connection_ping_interval != |
410 config.backup_connection_ping_interval) { | 423 config.backup_connection_ping_interval) { |
411 config_.backup_connection_ping_interval = | 424 config_.backup_connection_ping_interval = |
412 config.backup_connection_ping_interval; | 425 config.backup_connection_ping_interval; |
413 LOG(LS_INFO) << "Set backup connection ping interval to " | 426 LOG(LS_INFO) << "Set backup connection ping interval to " |
414 << config_.backup_connection_ping_interval << " milliseconds."; | 427 << config_.backup_connection_ping_interval << " milliseconds."; |
415 } | 428 } |
416 | 429 |
(...skipping 14 matching lines...) Expand all Loading... |
431 config.prioritize_most_likely_candidate_pairs; | 444 config.prioritize_most_likely_candidate_pairs; |
432 LOG(LS_INFO) << "Set ping most likely connection to " | 445 LOG(LS_INFO) << "Set ping most likely connection to " |
433 << config_.prioritize_most_likely_candidate_pairs; | 446 << config_.prioritize_most_likely_candidate_pairs; |
434 | 447 |
435 if (config.max_strong_interval >= 0 && | 448 if (config.max_strong_interval >= 0 && |
436 config_.max_strong_interval != config.max_strong_interval) { | 449 config_.max_strong_interval != config.max_strong_interval) { |
437 config_.max_strong_interval = config.max_strong_interval; | 450 config_.max_strong_interval = config.max_strong_interval; |
438 LOG(LS_INFO) << "Set max strong interval to " | 451 LOG(LS_INFO) << "Set max strong interval to " |
439 << config_.max_strong_interval; | 452 << config_.max_strong_interval; |
440 } | 453 } |
| 454 |
| 455 if (config.regather_on_failed_networks_interval >= 0 && |
| 456 config.regather_on_failed_networks_interval != |
| 457 config_.regather_on_failed_networks_interval) { |
| 458 config_.regather_on_failed_networks_interval = |
| 459 config.regather_on_failed_networks_interval; |
| 460 LOG(LS_INFO) << "Set regather_on_failed_networks_interval to " |
| 461 << config_.regather_on_failed_networks_interval; |
| 462 } |
441 } | 463 } |
442 | 464 |
443 const IceConfig& P2PTransportChannel::config() const { | 465 const IceConfig& P2PTransportChannel::config() const { |
444 return config_; | 466 return config_; |
445 } | 467 } |
446 | 468 |
447 // Go into the state of processing candidates, and running in general | 469 // Go into the state of processing candidates, and running in general |
448 void P2PTransportChannel::Connect() { | 470 void P2PTransportChannel::Connect() { |
449 ASSERT(worker_thread_ == rtc::Thread::Current()); | 471 ASSERT(worker_thread_ == rtc::Thread::Current()); |
450 if (ice_ufrag_.empty() || ice_pwd_.empty()) { | 472 if (ice_ufrag_.empty() || ice_pwd_.empty()) { |
451 ASSERT(false); | 473 ASSERT(false); |
452 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the " | 474 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the " |
453 << "ice_pwd_ are not set."; | 475 << "ice_pwd_ are not set."; |
454 return; | 476 return; |
455 } | 477 } |
456 | 478 |
457 // Start checking and pinging as the ports come in. | 479 // Start checking and pinging as the ports come in. |
458 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING); | 480 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING); |
| 481 thread()->PostDelayed(RTC_FROM_HERE, |
| 482 config_.regather_on_failed_networks_interval, this, |
| 483 MSG_REGATHER_ON_FAILED_NETWORKS); |
459 } | 484 } |
460 | 485 |
461 void P2PTransportChannel::MaybeStartGathering() { | 486 void P2PTransportChannel::MaybeStartGathering() { |
462 // Start gathering if we never started before, or if an ICE restart occurred. | 487 // Start gathering if we never started before, or if an ICE restart occurred. |
463 if (allocator_sessions_.empty() || | 488 if (allocator_sessions_.empty() || |
464 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), | 489 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), |
465 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, | 490 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, |
466 ice_pwd_)) { | 491 ice_pwd_)) { |
467 if (gathering_state_ != kIceGatheringGathering) { | 492 if (gathering_state_ != kIceGatheringGathering) { |
468 gathering_state_ = kIceGatheringGathering; | 493 gathering_state_ = kIceGatheringGathering; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 // Remember the ports and candidates, and signal that candidates are ready. | 538 // Remember the ports and candidates, and signal that candidates are ready. |
514 // The session will handle this, and send an initiate/accept/modify message | 539 // The session will handle this, and send an initiate/accept/modify message |
515 // if one is pending. | 540 // if one is pending. |
516 | 541 |
517 port->SetIceRole(ice_role_); | 542 port->SetIceRole(ice_role_); |
518 port->SetIceTiebreaker(tiebreaker_); | 543 port->SetIceTiebreaker(tiebreaker_); |
519 ports_.push_back(port); | 544 ports_.push_back(port); |
520 port->SignalUnknownAddress.connect( | 545 port->SignalUnknownAddress.connect( |
521 this, &P2PTransportChannel::OnUnknownAddress); | 546 this, &P2PTransportChannel::OnUnknownAddress); |
522 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); | 547 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); |
523 port->SignalNetworkInactive.connect( | 548 port->SignalClosed.connect(this, &P2PTransportChannel::OnPortClosed); |
524 this, &P2PTransportChannel::OnPortNetworkInactive); | 549 |
525 port->SignalRoleConflict.connect( | 550 port->SignalRoleConflict.connect( |
526 this, &P2PTransportChannel::OnRoleConflict); | 551 this, &P2PTransportChannel::OnRoleConflict); |
527 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); | 552 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); |
528 | 553 |
529 // Attempt to create a connection from this new port to all of the remote | 554 // Attempt to create a connection from this new port to all of the remote |
530 // candidates that we were given so far. | 555 // candidates that we were given so far. |
531 | 556 |
532 std::vector<RemoteCandidate>::iterator iter; | 557 std::vector<RemoteCandidate>::iterator iter; |
533 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); | 558 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); |
534 ++iter) { | 559 ++iter) { |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 } | 1274 } |
1250 set_receiving(receiving); | 1275 set_receiving(receiving); |
1251 } | 1276 } |
1252 | 1277 |
1253 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { | 1278 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { |
1254 if (!IsGettingPorts()) { | 1279 if (!IsGettingPorts()) { |
1255 return; | 1280 return; |
1256 } | 1281 } |
1257 | 1282 |
1258 for (const auto& session : allocator_sessions_) { | 1283 for (const auto& session : allocator_sessions_) { |
1259 if (!session->IsGettingPorts()) { | 1284 if (!session->CanGetPorts()) { |
| 1285 // The session has completely stopped. |
1260 continue; | 1286 continue; |
1261 } | 1287 } |
1262 // If gathering continually, keep the last session running so that it | 1288 // If gathering continually, keep the last session at STATE_CLEARED so that |
1263 // will gather candidates if the networks change. | 1289 // it can gather candidates if the networks change. |
1264 if (config_.gather_continually && session == allocator_sessions_.back()) { | 1290 if (config_.gather_continually() && session == allocator_sessions_.back()) { |
1265 session->ClearGettingPorts(); | 1291 session->ClearGettingPorts(); |
1266 break; | 1292 } else { |
| 1293 session->StopGettingPorts(); |
1267 } | 1294 } |
1268 session->StopGettingPorts(); | |
1269 } | 1295 } |
1270 } | 1296 } |
1271 | 1297 |
1272 // If all connections timed out, delete them all. | 1298 // If all connections timed out, delete them all. |
1273 void P2PTransportChannel::HandleAllTimedOut() { | 1299 void P2PTransportChannel::HandleAllTimedOut() { |
1274 for (Connection* connection : connections_) { | 1300 for (Connection* connection : connections_) { |
1275 connection->Destroy(); | 1301 connection->Destroy(); |
1276 } | 1302 } |
1277 } | 1303 } |
1278 | 1304 |
(...skipping 20 matching lines...) Expand all Loading... |
1299 | 1325 |
1300 // Handle any queued up requests | 1326 // Handle any queued up requests |
1301 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) { | 1327 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) { |
1302 switch (pmsg->message_id) { | 1328 switch (pmsg->message_id) { |
1303 case MSG_SORT: | 1329 case MSG_SORT: |
1304 OnSort(); | 1330 OnSort(); |
1305 break; | 1331 break; |
1306 case MSG_CHECK_AND_PING: | 1332 case MSG_CHECK_AND_PING: |
1307 OnCheckAndPing(); | 1333 OnCheckAndPing(); |
1308 break; | 1334 break; |
| 1335 case MSG_REGATHER_ON_FAILED_NETWORKS: |
| 1336 RegatherOnFailedNetworks(); |
| 1337 break; |
| 1338 case MSG_SIGNAL_CANDIDATES_REMOVED: |
| 1339 if (!candidates_to_remove_.empty()) { |
| 1340 LOG(LS_INFO) << "Signal removing " << candidates_to_remove_.size() |
| 1341 << " candidates"; |
| 1342 SignalCandidatesRemoved(this, candidates_to_remove_); |
| 1343 candidates_to_remove_.clear(); |
| 1344 } |
| 1345 break; |
1309 default: | 1346 default: |
1310 ASSERT(false); | 1347 ASSERT(false); |
1311 break; | 1348 break; |
1312 } | 1349 } |
1313 } | 1350 } |
1314 | 1351 |
1315 // Handle queued up sort request | 1352 // Handle queued up sort request |
1316 void P2PTransportChannel::OnSort() { | 1353 void P2PTransportChannel::OnSort() { |
1317 // Resort the connections based on the new statistics. | 1354 // Resort the connections based on the new statistics. |
1318 SortConnections(); | 1355 SortConnections(); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 // and re-choose a best assuming that there was no best connection. | 1537 // and re-choose a best assuming that there was no best connection. |
1501 if (best_connection_ == connection) { | 1538 if (best_connection_ == connection) { |
1502 LOG(LS_INFO) << "Best connection destroyed. Will choose a new one."; | 1539 LOG(LS_INFO) << "Best connection destroyed. Will choose a new one."; |
1503 SwitchBestConnectionTo(NULL); | 1540 SwitchBestConnectionTo(NULL); |
1504 RequestSort(); | 1541 RequestSort(); |
1505 } | 1542 } |
1506 | 1543 |
1507 UpdateState(); | 1544 UpdateState(); |
1508 } | 1545 } |
1509 | 1546 |
1510 // When a port is destroyed remove it from our list of ports to use for | |
1511 // connection attempts. | |
1512 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { | 1547 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { |
1513 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1548 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1514 | 1549 |
1515 // Remove this port from the list (if we didn't drop it already). | 1550 if (RemovePort(port)) { |
1516 std::vector<PortInterface*>::iterator iter = | 1551 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size() |
1517 std::find(ports_.begin(), ports_.end(), port); | 1552 << " remaining"; |
1518 if (iter != ports_.end()) | 1553 } |
1519 ports_.erase(iter); | |
1520 | |
1521 LOG(INFO) << "Removed port from p2p socket: " | |
1522 << static_cast<int>(ports_.size()) << " remaining"; | |
1523 } | 1554 } |
1524 | 1555 |
1525 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { | 1556 void P2PTransportChannel::OnPortClosed(PortInterface* port) { |
1526 // If it does not gather continually, the port will be removed from the list | 1557 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1527 // when ICE restarts. | 1558 |
1528 if (!config_.gather_continually) { | 1559 if (RemovePort(port)) { |
| 1560 LOG(INFO) << "Removed port because it is closed: " << ports_.size() |
| 1561 << " remaining"; |
| 1562 } |
| 1563 } |
| 1564 |
| 1565 bool P2PTransportChannel::RemovePort(PortInterface* port) { |
| 1566 auto new_end = std::remove(ports_.begin(), ports_.end(), port); |
| 1567 if (new_end != ports_.end()) { |
| 1568 ports_.erase(new_end, ports_.end()); |
| 1569 return true; |
| 1570 } |
| 1571 return false; |
| 1572 } |
| 1573 |
| 1574 void P2PTransportChannel::OnCandidatesRemoved( |
| 1575 PortAllocatorSession* session, |
| 1576 const std::vector<Candidate>& candidates) { |
| 1577 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 1578 // Do not signal candidate removals if continual gathering is not enabled. |
| 1579 // Do not signal candidate removals if this is not the last session because |
| 1580 // an ICE restart would have signaled the remote side about all candidate |
| 1581 // removals in previous sessions. |
| 1582 if (!config_.gather_continually() || session != allocator_session()) { |
1529 return; | 1583 return; |
1530 } | 1584 } |
1531 auto it = std::find(ports_.begin(), ports_.end(), port); | 1585 |
1532 // Don't need to do anything if the port has been deleted from the port list. | 1586 // If |candidates_to_remove_| is not empty, a msg |
1533 if (it == ports_.end()) { | 1587 // MSG_SIGNAL_CANDIDATES_REMOVED should have been posted. |
| 1588 if (candidates_to_remove_.empty()) { |
| 1589 thread()->Post(this, MSG_SIGNAL_CANDIDATES_REMOVED); |
| 1590 } |
| 1591 |
| 1592 for (Candidate candidate : candidates) { |
| 1593 candidate.set_transport_name(transport_name()); |
| 1594 candidates_to_remove_.push_back(candidate); |
| 1595 } |
| 1596 } |
| 1597 |
| 1598 void P2PTransportChannel::OnRegatherOnFailedNetworks() { |
| 1599 if (!config_.gather_continually() || allocator_sessions_.empty()) { |
1534 return; | 1600 return; |
1535 } | 1601 } |
1536 ports_.erase(it); | 1602 allocator_session()->RegatherOnFailedNetworks(); |
1537 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() | 1603 |
1538 << " remaining"; | 1604 thread()->PostDelayed(config_.regather_on_failed_network_interval_, this, |
1539 std::vector<Candidate> candidates = port->Candidates(); | 1605 MSG_REGATHER_ON_FAILED_NETWORKS); |
1540 for (Candidate& candidate : candidates) { | |
1541 candidate.set_transport_name(transport_name()); | |
1542 } | |
1543 SignalCandidatesRemoved(this, candidates); | |
1544 } | 1606 } |
1545 | 1607 |
1546 // We data is available, let listeners know | 1608 // We data is available, let listeners know |
1547 void P2PTransportChannel::OnReadPacket(Connection* connection, | 1609 void P2PTransportChannel::OnReadPacket(Connection* connection, |
1548 const char* data, | 1610 const char* data, |
1549 size_t len, | 1611 size_t len, |
1550 const rtc::PacketTime& packet_time) { | 1612 const rtc::PacketTime& packet_time) { |
1551 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1613 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1552 | 1614 |
1553 // Do not deliver, if packet doesn't belong to the correct transport channel. | 1615 // Do not deliver, if packet doesn't belong to the correct transport channel. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1688 | 1750 |
1689 // During the initial state when nothing has been pinged yet, return the first | 1751 // During the initial state when nothing has been pinged yet, return the first |
1690 // one in the ordered |connections_|. | 1752 // one in the ordered |connections_|. |
1691 return *(std::find_if(connections_.begin(), connections_.end(), | 1753 return *(std::find_if(connections_.begin(), connections_.end(), |
1692 [conn1, conn2](Connection* conn) { | 1754 [conn1, conn2](Connection* conn) { |
1693 return conn == conn1 || conn == conn2; | 1755 return conn == conn1 || conn == conn2; |
1694 })); | 1756 })); |
1695 } | 1757 } |
1696 | 1758 |
1697 } // namespace cricket | 1759 } // namespace cricket |
OLD | NEW |