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_AND_UPDATE_STATE = 1, MSG_CHECK_AND_PING }; | 30 enum { |
| 31 MSG_SORT_AND_UPDATE_STATE = 1, |
| 32 MSG_CHECK_AND_PING, |
| 33 MSG_REGATHER_ON_FAILED_NETWORKS |
| 34 }; |
31 | 35 |
32 // The minimum improvement in RTT that justifies a switch. | 36 // The minimum improvement in RTT that justifies a switch. |
33 static const double kMinImprovement = 10; | 37 const int kMinImprovement = 10; |
34 | 38 |
35 bool IsRelayRelay(const cricket::Connection* conn) { | 39 bool IsRelayRelay(const cricket::Connection* conn) { |
36 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE && | 40 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE && |
37 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE; | 41 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE; |
38 } | 42 } |
39 | 43 |
40 bool IsUdp(cricket::Connection* conn) { | 44 bool IsUdp(cricket::Connection* conn) { |
41 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME; | 45 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME; |
42 } | 46 } |
43 | 47 |
(...skipping 25 matching lines...) Expand all Loading... |
69 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; | 73 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; |
70 | 74 |
71 // Writable connections are pinged at a faster rate while stabilizing. | 75 // Writable connections are pinged at a faster rate while stabilizing. |
72 const int STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900; // ms | 76 const int STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900; // ms |
73 | 77 |
74 // Writable connections are pinged at a slower rate once stabilized. | 78 // Writable connections are pinged at a slower rate once stabilized. |
75 const int STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms | 79 const int STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms |
76 | 80 |
77 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms | 81 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms |
78 | 82 |
| 83 // We periodically check if any existing networks do not have any connection |
| 84 // and regather on those networks. |
| 85 static const int DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000; |
79 static constexpr int a_is_better = 1; | 86 static constexpr int a_is_better = 1; |
80 static constexpr int b_is_better = -1; | 87 static constexpr int b_is_better = -1; |
81 | 88 |
82 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 89 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
83 int component, | 90 int component, |
84 P2PTransport* transport, | 91 P2PTransport* transport, |
85 PortAllocator* allocator) | 92 PortAllocator* allocator) |
86 : P2PTransportChannel(transport_name, component, allocator) {} | 93 : P2PTransportChannel(transport_name, component, allocator) {} |
87 | 94 |
88 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 95 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
89 int component, | 96 int component, |
90 PortAllocator* allocator) | 97 PortAllocator* allocator) |
91 : TransportChannelImpl(transport_name, component), | 98 : TransportChannelImpl(transport_name, component), |
92 allocator_(allocator), | 99 allocator_(allocator), |
93 worker_thread_(rtc::Thread::Current()), | 100 worker_thread_(rtc::Thread::Current()), |
94 incoming_only_(false), | 101 incoming_only_(false), |
95 error_(0), | 102 error_(0), |
96 sort_dirty_(false), | 103 sort_dirty_(false), |
97 remote_ice_mode_(ICEMODE_FULL), | 104 remote_ice_mode_(ICEMODE_FULL), |
98 ice_role_(ICEROLE_UNKNOWN), | 105 ice_role_(ICEROLE_UNKNOWN), |
99 tiebreaker_(0), | 106 tiebreaker_(0), |
100 gathering_state_(kIceGatheringNew), | 107 gathering_state_(kIceGatheringNew), |
101 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), | 108 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), |
102 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, | 109 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, |
103 0 /* backup_connection_ping_interval */, | 110 0 /* backup_connection_ping_interval */, |
104 false /* gather_continually */, | 111 GATHER_ONCE /* continual_gathering_policy */, |
105 false /* prioritize_most_likely_candidate_pairs */, | 112 false /* prioritize_most_likely_candidate_pairs */, |
106 STABLE_WRITABLE_CONNECTION_PING_INTERVAL, | 113 STABLE_WRITABLE_CONNECTION_PING_INTERVAL, |
107 true /* presume_writable_when_fully_relayed */) { | 114 true /* presume_writable_when_fully_relayed */, |
| 115 DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL) { |
108 uint32_t weak_ping_interval = ::strtoul( | 116 uint32_t weak_ping_interval = ::strtoul( |
109 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), | 117 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), |
110 nullptr, 10); | 118 nullptr, 10); |
111 if (weak_ping_interval) { | 119 if (weak_ping_interval) { |
112 weak_ping_interval_ = static_cast<int>(weak_ping_interval); | 120 weak_ping_interval_ = static_cast<int>(weak_ping_interval); |
113 } | 121 } |
114 } | 122 } |
115 | 123 |
116 P2PTransportChannel::~P2PTransportChannel() { | 124 P2PTransportChannel::~P2PTransportChannel() { |
117 ASSERT(worker_thread_ == rtc::Thread::Current()); | 125 ASSERT(worker_thread_ == rtc::Thread::Current()); |
118 } | 126 } |
119 | 127 |
120 // Add the allocator session to our list so that we know which sessions | 128 // Add the allocator session to our list so that we know which sessions |
121 // are still active. | 129 // are still active. |
122 void P2PTransportChannel::AddAllocatorSession( | 130 void P2PTransportChannel::AddAllocatorSession( |
123 std::unique_ptr<PortAllocatorSession> session) { | 131 std::unique_ptr<PortAllocatorSession> session) { |
124 ASSERT(worker_thread_ == rtc::Thread::Current()); | 132 ASSERT(worker_thread_ == rtc::Thread::Current()); |
125 | 133 |
126 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); | 134 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); |
127 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); | 135 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); |
| 136 session->SignalPortsRemoved.connect(this, |
| 137 &P2PTransportChannel::OnPortsRemoved); |
128 session->SignalPortPruned.connect(this, &P2PTransportChannel::OnPortPruned); | 138 session->SignalPortPruned.connect(this, &P2PTransportChannel::OnPortPruned); |
129 session->SignalCandidatesReady.connect( | 139 session->SignalCandidatesReady.connect( |
130 this, &P2PTransportChannel::OnCandidatesReady); | 140 this, &P2PTransportChannel::OnCandidatesReady); |
| 141 session->SignalCandidatesRemoved.connect( |
| 142 this, &P2PTransportChannel::OnCandidatesRemoved); |
131 session->SignalCandidatesAllocationDone.connect( | 143 session->SignalCandidatesAllocationDone.connect( |
132 this, &P2PTransportChannel::OnCandidatesAllocationDone); | 144 this, &P2PTransportChannel::OnCandidatesAllocationDone); |
133 | 145 |
134 // We now only want to apply new candidates that we receive to the ports | 146 // We now only want to apply new candidates that we receive to the ports |
135 // created by this new session because these are replacing those of the | 147 // created by this new session because these are replacing those of the |
136 // previous sessions. | 148 // previous sessions. |
137 removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end()); | 149 removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end()); |
138 ports_.clear(); | 150 ports_.clear(); |
139 | 151 |
140 allocator_sessions_.push_back(std::move(session)); | 152 allocator_sessions_.push_back(std::move(session)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 301 } |
290 // Updating the remote ICE candidate generation could change the sort order. | 302 // Updating the remote ICE candidate generation could change the sort order. |
291 RequestSortAndStateUpdate(); | 303 RequestSortAndStateUpdate(); |
292 } | 304 } |
293 | 305 |
294 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { | 306 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { |
295 remote_ice_mode_ = mode; | 307 remote_ice_mode_ = mode; |
296 } | 308 } |
297 | 309 |
298 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { | 310 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { |
299 config_.gather_continually = config.gather_continually; | 311 if (config_.continual_gathering_policy != config.continual_gathering_policy) { |
300 LOG(LS_INFO) << "Set gather_continually to " << config_.gather_continually; | 312 LOG(LS_INFO) << "Set continual_gathering_policy to " |
| 313 << config_.continual_gathering_policy; |
| 314 config_.continual_gathering_policy = config.continual_gathering_policy; |
| 315 } |
301 | 316 |
302 if (config.backup_connection_ping_interval >= 0 && | 317 if (config.backup_connection_ping_interval >= 0 && |
303 config_.backup_connection_ping_interval != | 318 config_.backup_connection_ping_interval != |
304 config.backup_connection_ping_interval) { | 319 config.backup_connection_ping_interval) { |
305 config_.backup_connection_ping_interval = | 320 config_.backup_connection_ping_interval = |
306 config.backup_connection_ping_interval; | 321 config.backup_connection_ping_interval; |
307 LOG(LS_INFO) << "Set backup connection ping interval to " | 322 LOG(LS_INFO) << "Set backup connection ping interval to " |
308 << config_.backup_connection_ping_interval << " milliseconds."; | 323 << config_.backup_connection_ping_interval << " milliseconds."; |
309 } | 324 } |
310 | 325 |
(...skipping 29 matching lines...) Expand all Loading... |
340 if (!connections_.empty()) { | 355 if (!connections_.empty()) { |
341 LOG(LS_ERROR) << "Trying to change 'presume writable' " | 356 LOG(LS_ERROR) << "Trying to change 'presume writable' " |
342 << "while connections already exist!"; | 357 << "while connections already exist!"; |
343 } else { | 358 } else { |
344 config_.presume_writable_when_fully_relayed = | 359 config_.presume_writable_when_fully_relayed = |
345 config.presume_writable_when_fully_relayed; | 360 config.presume_writable_when_fully_relayed; |
346 LOG(LS_INFO) << "Set presume writable when fully relayed to " | 361 LOG(LS_INFO) << "Set presume writable when fully relayed to " |
347 << config_.presume_writable_when_fully_relayed; | 362 << config_.presume_writable_when_fully_relayed; |
348 } | 363 } |
349 } | 364 } |
| 365 |
| 366 if (config.regather_on_failed_networks_interval) { |
| 367 config_.regather_on_failed_networks_interval = |
| 368 config.regather_on_failed_networks_interval; |
| 369 LOG(LS_INFO) << "Set regather_on_failed_networks_interval to " |
| 370 << *config_.regather_on_failed_networks_interval; |
| 371 } |
350 } | 372 } |
351 | 373 |
352 const IceConfig& P2PTransportChannel::config() const { | 374 const IceConfig& P2PTransportChannel::config() const { |
353 return config_; | 375 return config_; |
354 } | 376 } |
355 | 377 |
356 void P2PTransportChannel::MaybeStartGathering() { | 378 void P2PTransportChannel::MaybeStartGathering() { |
357 if (ice_ufrag_.empty() || ice_pwd_.empty()) { | 379 if (ice_ufrag_.empty() || ice_pwd_.empty()) { |
358 return; | 380 return; |
359 } | 381 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 // Remember the ports and candidates, and signal that candidates are ready. | 433 // Remember the ports and candidates, and signal that candidates are ready. |
412 // The session will handle this, and send an initiate/accept/modify message | 434 // The session will handle this, and send an initiate/accept/modify message |
413 // if one is pending. | 435 // if one is pending. |
414 | 436 |
415 port->SetIceRole(ice_role_); | 437 port->SetIceRole(ice_role_); |
416 port->SetIceTiebreaker(tiebreaker_); | 438 port->SetIceTiebreaker(tiebreaker_); |
417 ports_.push_back(port); | 439 ports_.push_back(port); |
418 port->SignalUnknownAddress.connect( | 440 port->SignalUnknownAddress.connect( |
419 this, &P2PTransportChannel::OnUnknownAddress); | 441 this, &P2PTransportChannel::OnUnknownAddress); |
420 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); | 442 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); |
421 port->SignalNetworkInactive.connect( | 443 |
422 this, &P2PTransportChannel::OnPortNetworkInactive); | |
423 port->SignalRoleConflict.connect( | 444 port->SignalRoleConflict.connect( |
424 this, &P2PTransportChannel::OnRoleConflict); | 445 this, &P2PTransportChannel::OnRoleConflict); |
425 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); | 446 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); |
426 | 447 |
427 // Attempt to create a connection from this new port to all of the remote | 448 // Attempt to create a connection from this new port to all of the remote |
428 // candidates that we were given so far. | 449 // candidates that we were given so far. |
429 | 450 |
430 std::vector<RemoteCandidate>::iterator iter; | 451 std::vector<RemoteCandidate>::iterator iter; |
431 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); | 452 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); |
432 ++iter) { | 453 ++iter) { |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 return; | 971 return; |
951 } | 972 } |
952 | 973 |
953 int64_t now = rtc::TimeMillis(); | 974 int64_t now = rtc::TimeMillis(); |
954 if (std::any_of( | 975 if (std::any_of( |
955 connections_.begin(), connections_.end(), | 976 connections_.begin(), connections_.end(), |
956 [this, now](const Connection* c) { return IsPingable(c, now); })) { | 977 [this, now](const Connection* c) { return IsPingable(c, now); })) { |
957 LOG_J(LS_INFO, this) << "Have a pingable connection for the first time; " | 978 LOG_J(LS_INFO, this) << "Have a pingable connection for the first time; " |
958 << "starting to ping."; | 979 << "starting to ping."; |
959 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING); | 980 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING); |
| 981 thread()->PostDelayed(RTC_FROM_HERE, |
| 982 *config_.regather_on_failed_networks_interval, this, |
| 983 MSG_REGATHER_ON_FAILED_NETWORKS); |
960 started_pinging_ = true; | 984 started_pinging_ = true; |
961 } | 985 } |
962 } | 986 } |
963 | 987 |
964 // Compare two connections based on their writing, receiving, and connected | 988 // Compare two connections based on their writing, receiving, and connected |
965 // states. | 989 // states. |
966 int P2PTransportChannel::CompareConnectionStates(const Connection* a, | 990 int P2PTransportChannel::CompareConnectionStates(const Connection* a, |
967 const Connection* b) const { | 991 const Connection* b) const { |
968 // First, prefer a connection that's writable or presumed writable over | 992 // First, prefer a connection that's writable or presumed writable over |
969 // one that's not writable. | 993 // one that's not writable. |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 } | 1330 } |
1307 set_receiving(receiving); | 1331 set_receiving(receiving); |
1308 } | 1332 } |
1309 | 1333 |
1310 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { | 1334 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { |
1311 if (!IsGettingPorts()) { | 1335 if (!IsGettingPorts()) { |
1312 return; | 1336 return; |
1313 } | 1337 } |
1314 | 1338 |
1315 for (const auto& session : allocator_sessions_) { | 1339 for (const auto& session : allocator_sessions_) { |
1316 if (!session->IsGettingPorts()) { | 1340 if (session->IsStopped()) { |
1317 continue; | 1341 continue; |
1318 } | 1342 } |
1319 // If gathering continually, keep the last session running so that it | 1343 // If gathering continually, keep the last session running so that |
1320 // will gather candidates if the networks change. | 1344 // it can gather candidates if the networks change. |
1321 if (config_.gather_continually && session == allocator_sessions_.back()) { | 1345 if (config_.gather_continually() && session == allocator_sessions_.back()) { |
1322 session->ClearGettingPorts(); | 1346 session->ClearGettingPorts(); |
1323 break; | 1347 } else { |
| 1348 session->StopGettingPorts(); |
1324 } | 1349 } |
1325 session->StopGettingPorts(); | |
1326 } | 1350 } |
1327 } | 1351 } |
1328 | 1352 |
1329 // If all connections timed out, delete them all. | 1353 // If all connections timed out, delete them all. |
1330 void P2PTransportChannel::HandleAllTimedOut() { | 1354 void P2PTransportChannel::HandleAllTimedOut() { |
1331 for (Connection* connection : connections_) { | 1355 for (Connection* connection : connections_) { |
1332 connection->Destroy(); | 1356 connection->Destroy(); |
1333 } | 1357 } |
1334 } | 1358 } |
1335 | 1359 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 | 1394 |
1371 // Handle any queued up requests | 1395 // Handle any queued up requests |
1372 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) { | 1396 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) { |
1373 switch (pmsg->message_id) { | 1397 switch (pmsg->message_id) { |
1374 case MSG_SORT_AND_UPDATE_STATE: | 1398 case MSG_SORT_AND_UPDATE_STATE: |
1375 SortConnectionsAndUpdateState(); | 1399 SortConnectionsAndUpdateState(); |
1376 break; | 1400 break; |
1377 case MSG_CHECK_AND_PING: | 1401 case MSG_CHECK_AND_PING: |
1378 OnCheckAndPing(); | 1402 OnCheckAndPing(); |
1379 break; | 1403 break; |
| 1404 case MSG_REGATHER_ON_FAILED_NETWORKS: |
| 1405 OnRegatherOnFailedNetworks(); |
| 1406 break; |
1380 default: | 1407 default: |
1381 ASSERT(false); | 1408 ASSERT(false); |
1382 break; | 1409 break; |
1383 } | 1410 } |
1384 } | 1411 } |
1385 | 1412 |
1386 // Handle queued up check-and-ping request | 1413 // Handle queued up check-and-ping request |
1387 void P2PTransportChannel::OnCheckAndPing() { | 1414 void P2PTransportChannel::OnCheckAndPing() { |
1388 // Make sure the states of the connections are up-to-date (since this affects | 1415 // Make sure the states of the connections are up-to-date (since this affects |
1389 // which ones are pingable). | 1416 // which ones are pingable). |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 SwitchSelectedConnection(nullptr); | 1626 SwitchSelectedConnection(nullptr); |
1600 RequestSortAndStateUpdate(); | 1627 RequestSortAndStateUpdate(); |
1601 } else { | 1628 } else { |
1602 // If a non-selected connection was destroyed, we don't need to re-sort but | 1629 // If a non-selected connection was destroyed, we don't need to re-sort but |
1603 // we do need to update state, because we could be switching to "failed" or | 1630 // we do need to update state, because we could be switching to "failed" or |
1604 // "completed". | 1631 // "completed". |
1605 UpdateState(); | 1632 UpdateState(); |
1606 } | 1633 } |
1607 } | 1634 } |
1608 | 1635 |
1609 // When a port is destroyed remove it from our list of ports to use for | 1636 // When a port is destroyed, remove it from our list of ports to use for |
1610 // connection attempts. | 1637 // connection attempts. |
1611 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { | 1638 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { |
1612 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1639 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1613 | 1640 |
1614 // Remove this port from the lists (if we didn't drop it already). | |
1615 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); | 1641 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); |
1616 removed_ports_.erase( | 1642 removed_ports_.erase( |
1617 std::remove(removed_ports_.begin(), removed_ports_.end(), port), | 1643 std::remove(removed_ports_.begin(), removed_ports_.end(), port), |
1618 removed_ports_.end()); | 1644 removed_ports_.end()); |
1619 | 1645 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size() |
1620 LOG(INFO) << "Removed port because it is destroyed: " | 1646 << " remaining"; |
1621 << static_cast<int>(ports_.size()) << " remaining"; | |
1622 } | 1647 } |
1623 | 1648 |
1624 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { | 1649 void P2PTransportChannel::OnPortsRemoved( |
1625 // If it does not gather continually, the port will be removed from the list | 1650 PortAllocatorSession* session, |
1626 // when ICE restarts. | 1651 const std::vector<PortInterface*>& ports) { |
1627 if (!config_.gather_continually) { | 1652 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 1653 LOG(LS_INFO) << "Remove " << ports.size() << " ports"; |
| 1654 for (PortInterface* port : ports) { |
| 1655 if (RemovePort(port)) { |
| 1656 LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size() |
| 1657 << " remaining"; |
| 1658 } |
| 1659 } |
| 1660 } |
| 1661 |
| 1662 void P2PTransportChannel::OnCandidatesRemoved( |
| 1663 PortAllocatorSession* session, |
| 1664 const std::vector<Candidate>& candidates) { |
| 1665 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 1666 // Do not signal candidate removals if continual gathering is not enabled, or |
| 1667 // if this is not the last session because an ICE restart would have signaled |
| 1668 // the remote side to remove all candidates in previous sessions. |
| 1669 if (!config_.gather_continually() || session != allocator_session()) { |
1628 return; | 1670 return; |
1629 } | 1671 } |
1630 if (!RemovePort(port)) { | 1672 |
1631 return; | 1673 std::vector<Candidate> candidates_to_remove; |
| 1674 for (Candidate candidate : candidates) { |
| 1675 candidate.set_transport_name(transport_name()); |
| 1676 candidates_to_remove.push_back(candidate); |
1632 } | 1677 } |
1633 LOG(INFO) << "Removed port because its network is inactive : " | 1678 SignalCandidatesRemoved(this, candidates_to_remove); |
1634 << port->ToString() << " " << ports_.size() << " remaining"; | 1679 } |
1635 std::vector<Candidate> candidates = port->Candidates(); | 1680 |
1636 for (Candidate& candidate : candidates) { | 1681 void P2PTransportChannel::OnRegatherOnFailedNetworks() { |
1637 candidate.set_transport_name(transport_name()); | 1682 // Only re-gather when the current session is in the CLEARED state (i.e., not |
| 1683 // running or stopped). It is only possible to enter this state when we gather |
| 1684 // continually, so there is an implicit check on continual gathering here. |
| 1685 if (!allocator_sessions_.empty() && allocator_session()->IsCleared()) { |
| 1686 allocator_session()->RegatherOnFailedNetworks(); |
1638 } | 1687 } |
1639 SignalCandidatesRemoved(this, candidates); | 1688 |
| 1689 thread()->PostDelayed(RTC_FROM_HERE, |
| 1690 *config_.regather_on_failed_networks_interval, this, |
| 1691 MSG_REGATHER_ON_FAILED_NETWORKS); |
1640 } | 1692 } |
1641 | 1693 |
1642 void P2PTransportChannel::OnPortPruned(PortAllocatorSession* session, | 1694 void P2PTransportChannel::OnPortPruned(PortAllocatorSession* session, |
1643 PortInterface* port) { | 1695 PortInterface* port) { |
1644 if (RemovePort(port)) { | 1696 if (RemovePort(port)) { |
1645 LOG(INFO) << "Removed port because it is pruned: " << port->ToString() | 1697 LOG(INFO) << "Removed port because it is pruned: " << port->ToString() |
1646 << " " << ports_.size() << " remaining"; | 1698 << " " << ports_.size() << " remaining"; |
1647 } | 1699 } |
1648 } | 1700 } |
1649 | 1701 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 | 1857 |
1806 // During the initial state when nothing has been pinged yet, return the first | 1858 // During the initial state when nothing has been pinged yet, return the first |
1807 // one in the ordered |connections_|. | 1859 // one in the ordered |connections_|. |
1808 return *(std::find_if(connections_.begin(), connections_.end(), | 1860 return *(std::find_if(connections_.begin(), connections_.end(), |
1809 [conn1, conn2](Connection* conn) { | 1861 [conn1, conn2](Connection* conn) { |
1810 return conn == conn1 || conn == conn2; | 1862 return conn == conn1 || conn == conn2; |
1811 })); | 1863 })); |
1812 } | 1864 } |
1813 | 1865 |
1814 } // namespace cricket | 1866 } // namespace cricket |
OLD | NEW |