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 { MSG_SORT = 1, MSG_CHECK_AND_PING, MSG_REGATHER_ON_FAILED_NETWORKS }; |
31 | 31 |
32 // The minimum improvement in RTT that justifies a switch. | 32 // The minimum improvement in RTT that justifies a switch. |
33 static const double kMinImprovement = 10; | 33 const int kMinImprovement = 10; |
34 | 34 |
35 bool IsRelayRelay(const cricket::Connection* conn) { | 35 bool IsRelayRelay(const cricket::Connection* conn) { |
36 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE && | 36 return conn->local_candidate().type() == cricket::RELAY_PORT_TYPE && |
37 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE; | 37 conn->remote_candidate().type() == cricket::RELAY_PORT_TYPE; |
38 } | 38 } |
39 | 39 |
40 bool IsUdp(cricket::Connection* conn) { | 40 bool IsUdp(cricket::Connection* conn) { |
41 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME; | 41 return conn->local_candidate().relay_protocol() == cricket::UDP_PROTOCOL_NAME; |
42 } | 42 } |
43 | 43 |
(...skipping 25 matching lines...) Expand all Loading... | |
69 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; | 69 const int WEAK_PING_INTERVAL = 1000 * PING_PACKET_SIZE / 10000; |
70 | 70 |
71 // Writable connections are pinged at a faster rate while stabilizing. | 71 // Writable connections are pinged at a faster rate while stabilizing. |
72 const int STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900; // ms | 72 const int STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900; // ms |
73 | 73 |
74 // Writable connections are pinged at a slower rate once stabilized. | 74 // Writable connections are pinged at a slower rate once stabilized. |
75 const int STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms | 75 const int STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500; // ms |
76 | 76 |
77 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms | 77 static const int MIN_CHECK_RECEIVING_INTERVAL = 50; // ms |
78 | 78 |
79 // We periodically check if any existing networks do not have any connection | |
80 // and regather on those networks. | |
81 static const int DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000; | |
79 static constexpr int a_is_better = 1; | 82 static constexpr int a_is_better = 1; |
80 static constexpr int b_is_better = -1; | 83 static constexpr int b_is_better = -1; |
81 | 84 |
82 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 85 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
83 int component, | 86 int component, |
84 P2PTransport* transport, | 87 P2PTransport* transport, |
85 PortAllocator* allocator) | 88 PortAllocator* allocator) |
86 : P2PTransportChannel(transport_name, component, allocator) {} | 89 : P2PTransportChannel(transport_name, component, allocator) {} |
87 | 90 |
88 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 91 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
89 int component, | 92 int component, |
90 PortAllocator* allocator) | 93 PortAllocator* allocator) |
91 : TransportChannelImpl(transport_name, component), | 94 : TransportChannelImpl(transport_name, component), |
92 allocator_(allocator), | 95 allocator_(allocator), |
93 worker_thread_(rtc::Thread::Current()), | 96 worker_thread_(rtc::Thread::Current()), |
94 incoming_only_(false), | 97 incoming_only_(false), |
95 error_(0), | 98 error_(0), |
96 sort_dirty_(false), | 99 sort_dirty_(false), |
97 remote_ice_mode_(ICEMODE_FULL), | 100 remote_ice_mode_(ICEMODE_FULL), |
98 ice_role_(ICEROLE_UNKNOWN), | 101 ice_role_(ICEROLE_UNKNOWN), |
99 tiebreaker_(0), | 102 tiebreaker_(0), |
100 gathering_state_(kIceGatheringNew), | 103 gathering_state_(kIceGatheringNew), |
101 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), | 104 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), |
102 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, | 105 config_(MIN_CHECK_RECEIVING_INTERVAL * 50 /* receiving_timeout */, |
103 0 /* backup_connection_ping_interval */, | 106 0 /* backup_connection_ping_interval */, |
104 false /* gather_continually */, | 107 GATHER_ONCE /* continual_gathering_policy */, |
105 false /* prioritize_most_likely_candidate_pairs */, | 108 false /* prioritize_most_likely_candidate_pairs */, |
106 STABLE_WRITABLE_CONNECTION_PING_INTERVAL, | 109 STABLE_WRITABLE_CONNECTION_PING_INTERVAL, |
107 true /* presume_writable_when_fully_relayed */) { | 110 true /* presume_writable_when_fully_relayed */, |
111 DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL) { | |
108 uint32_t weak_ping_interval = ::strtoul( | 112 uint32_t weak_ping_interval = ::strtoul( |
109 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), | 113 webrtc::field_trial::FindFullName("WebRTC-StunInterPacketDelay").c_str(), |
110 nullptr, 10); | 114 nullptr, 10); |
111 if (weak_ping_interval) { | 115 if (weak_ping_interval) { |
112 weak_ping_interval_ = static_cast<int>(weak_ping_interval); | 116 weak_ping_interval_ = static_cast<int>(weak_ping_interval); |
113 } | 117 } |
114 } | 118 } |
115 | 119 |
116 P2PTransportChannel::~P2PTransportChannel() { | 120 P2PTransportChannel::~P2PTransportChannel() { |
117 ASSERT(worker_thread_ == rtc::Thread::Current()); | 121 ASSERT(worker_thread_ == rtc::Thread::Current()); |
118 } | 122 } |
119 | 123 |
120 // Add the allocator session to our list so that we know which sessions | 124 // Add the allocator session to our list so that we know which sessions |
121 // are still active. | 125 // are still active. |
122 void P2PTransportChannel::AddAllocatorSession( | 126 void P2PTransportChannel::AddAllocatorSession( |
123 std::unique_ptr<PortAllocatorSession> session) { | 127 std::unique_ptr<PortAllocatorSession> session) { |
124 ASSERT(worker_thread_ == rtc::Thread::Current()); | 128 ASSERT(worker_thread_ == rtc::Thread::Current()); |
125 | 129 |
126 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); | 130 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); |
127 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); | 131 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); |
132 session->SignalPortsRemoved.connect(this, | |
133 &P2PTransportChannel::OnPortsRemoved); | |
128 session->SignalCandidatesReady.connect( | 134 session->SignalCandidatesReady.connect( |
129 this, &P2PTransportChannel::OnCandidatesReady); | 135 this, &P2PTransportChannel::OnCandidatesReady); |
136 session->SignalCandidatesRemoved.connect( | |
137 this, &P2PTransportChannel::OnCandidatesRemoved); | |
130 session->SignalCandidatesAllocationDone.connect( | 138 session->SignalCandidatesAllocationDone.connect( |
131 this, &P2PTransportChannel::OnCandidatesAllocationDone); | 139 this, &P2PTransportChannel::OnCandidatesAllocationDone); |
132 | 140 |
133 // We now only want to apply new candidates that we receive to the ports | 141 // We now only want to apply new candidates that we receive to the ports |
134 // created by this new session because these are replacing those of the | 142 // created by this new session because these are replacing those of the |
135 // previous sessions. | 143 // previous sessions. |
136 removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end()); | 144 removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end()); |
137 ports_.clear(); | 145 ports_.clear(); |
138 | 146 |
139 allocator_sessions_.push_back(std::move(session)); | 147 allocator_sessions_.push_back(std::move(session)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 } | 296 } |
289 // Updating the remote ICE candidate generation could change the sort order. | 297 // Updating the remote ICE candidate generation could change the sort order. |
290 RequestSort(); | 298 RequestSort(); |
291 } | 299 } |
292 | 300 |
293 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { | 301 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { |
294 remote_ice_mode_ = mode; | 302 remote_ice_mode_ = mode; |
295 } | 303 } |
296 | 304 |
297 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { | 305 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { |
298 config_.gather_continually = config.gather_continually; | 306 if (config_.continual_gathering_policy != config.continual_gathering_policy) { |
299 LOG(LS_INFO) << "Set gather_continually to " << config_.gather_continually; | 307 LOG(LS_INFO) << "Set continual_gathering_policy to " |
308 << config_.continual_gathering_policy; | |
309 config_.continual_gathering_policy = config.continual_gathering_policy; | |
310 } | |
300 | 311 |
301 if (config.backup_connection_ping_interval >= 0 && | 312 if (config.backup_connection_ping_interval >= 0 && |
302 config_.backup_connection_ping_interval != | 313 config_.backup_connection_ping_interval != |
303 config.backup_connection_ping_interval) { | 314 config.backup_connection_ping_interval) { |
304 config_.backup_connection_ping_interval = | 315 config_.backup_connection_ping_interval = |
305 config.backup_connection_ping_interval; | 316 config.backup_connection_ping_interval; |
306 LOG(LS_INFO) << "Set backup connection ping interval to " | 317 LOG(LS_INFO) << "Set backup connection ping interval to " |
307 << config_.backup_connection_ping_interval << " milliseconds."; | 318 << config_.backup_connection_ping_interval << " milliseconds."; |
308 } | 319 } |
309 | 320 |
(...skipping 29 matching lines...) Expand all Loading... | |
339 if (!connections_.empty()) { | 350 if (!connections_.empty()) { |
340 LOG(LS_ERROR) << "Trying to change 'presume writable' " | 351 LOG(LS_ERROR) << "Trying to change 'presume writable' " |
341 << "while connections already exist!"; | 352 << "while connections already exist!"; |
342 } else { | 353 } else { |
343 config_.presume_writable_when_fully_relayed = | 354 config_.presume_writable_when_fully_relayed = |
344 config.presume_writable_when_fully_relayed; | 355 config.presume_writable_when_fully_relayed; |
345 LOG(LS_INFO) << "Set presume writable when fully relayed to " | 356 LOG(LS_INFO) << "Set presume writable when fully relayed to " |
346 << config_.presume_writable_when_fully_relayed; | 357 << config_.presume_writable_when_fully_relayed; |
347 } | 358 } |
348 } | 359 } |
360 | |
361 if (config.regather_on_failed_networks_interval >= 0 && | |
362 config.regather_on_failed_networks_interval != | |
pthatcher1
2016/06/29 18:53:27
Can we use an rtc::optional in config rather than
honghaiz3
2016/06/29 20:19:22
Done.
| |
363 config_.regather_on_failed_networks_interval) { | |
364 config_.regather_on_failed_networks_interval = | |
365 config.regather_on_failed_networks_interval; | |
366 LOG(LS_INFO) << "Set regather_on_failed_networks_interval to " | |
367 << config_.regather_on_failed_networks_interval; | |
368 } | |
349 } | 369 } |
350 | 370 |
351 const IceConfig& P2PTransportChannel::config() const { | 371 const IceConfig& P2PTransportChannel::config() const { |
352 return config_; | 372 return config_; |
353 } | 373 } |
354 | 374 |
355 // Go into the state of processing candidates, and running in general | 375 // Go into the state of processing candidates, and running in general |
356 void P2PTransportChannel::Connect() { | 376 void P2PTransportChannel::Connect() { |
357 ASSERT(worker_thread_ == rtc::Thread::Current()); | 377 ASSERT(worker_thread_ == rtc::Thread::Current()); |
358 if (ice_ufrag_.empty() || ice_pwd_.empty()) { | 378 if (ice_ufrag_.empty() || ice_pwd_.empty()) { |
359 ASSERT(false); | 379 ASSERT(false); |
360 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the " | 380 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the " |
361 << "ice_pwd_ are not set."; | 381 << "ice_pwd_ are not set."; |
362 return; | 382 return; |
363 } | 383 } |
364 | 384 |
365 // Start checking and pinging as the ports come in. | 385 // Start checking and pinging as the ports come in. |
366 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING); | 386 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING); |
387 thread()->PostDelayed(RTC_FROM_HERE, | |
388 config_.regather_on_failed_networks_interval, this, | |
389 MSG_REGATHER_ON_FAILED_NETWORKS); | |
pthatcher1
2016/06/29 18:53:27
Taylor just refactored this :)
honghaiz3
2016/06/29 20:19:22
Will merge when his CL is in.
| |
367 } | 390 } |
368 | 391 |
369 void P2PTransportChannel::MaybeStartGathering() { | 392 void P2PTransportChannel::MaybeStartGathering() { |
370 // Start gathering if we never started before, or if an ICE restart occurred. | 393 // Start gathering if we never started before, or if an ICE restart occurred. |
371 if (allocator_sessions_.empty() || | 394 if (allocator_sessions_.empty() || |
372 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), | 395 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), |
373 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, | 396 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, |
374 ice_pwd_)) { | 397 ice_pwd_)) { |
375 if (gathering_state_ != kIceGatheringGathering) { | 398 if (gathering_state_ != kIceGatheringGathering) { |
376 gathering_state_ = kIceGatheringGathering; | 399 gathering_state_ = kIceGatheringGathering; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 // Remember the ports and candidates, and signal that candidates are ready. | 444 // Remember the ports and candidates, and signal that candidates are ready. |
422 // The session will handle this, and send an initiate/accept/modify message | 445 // The session will handle this, and send an initiate/accept/modify message |
423 // if one is pending. | 446 // if one is pending. |
424 | 447 |
425 port->SetIceRole(ice_role_); | 448 port->SetIceRole(ice_role_); |
426 port->SetIceTiebreaker(tiebreaker_); | 449 port->SetIceTiebreaker(tiebreaker_); |
427 ports_.push_back(port); | 450 ports_.push_back(port); |
428 port->SignalUnknownAddress.connect( | 451 port->SignalUnknownAddress.connect( |
429 this, &P2PTransportChannel::OnUnknownAddress); | 452 this, &P2PTransportChannel::OnUnknownAddress); |
430 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); | 453 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); |
431 port->SignalNetworkInactive.connect( | 454 |
432 this, &P2PTransportChannel::OnPortNetworkInactive); | |
433 port->SignalRoleConflict.connect( | 455 port->SignalRoleConflict.connect( |
434 this, &P2PTransportChannel::OnRoleConflict); | 456 this, &P2PTransportChannel::OnRoleConflict); |
435 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); | 457 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); |
436 | 458 |
437 // Attempt to create a connection from this new port to all of the remote | 459 // Attempt to create a connection from this new port to all of the remote |
438 // candidates that we were given so far. | 460 // candidates that we were given so far. |
439 | 461 |
440 std::vector<RemoteCandidate>::iterator iter; | 462 std::vector<RemoteCandidate>::iterator iter; |
441 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); | 463 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); |
442 ++iter) { | 464 ++iter) { |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1296 | 1318 |
1297 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { | 1319 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { |
1298 if (!IsGettingPorts()) { | 1320 if (!IsGettingPorts()) { |
1299 return; | 1321 return; |
1300 } | 1322 } |
1301 | 1323 |
1302 for (const auto& session : allocator_sessions_) { | 1324 for (const auto& session : allocator_sessions_) { |
1303 if (!session->IsGettingPorts()) { | 1325 if (!session->IsGettingPorts()) { |
1304 continue; | 1326 continue; |
1305 } | 1327 } |
1306 // If gathering continually, keep the last session running so that it | 1328 // If gathering continually, keep the last session running so that |
1307 // will gather candidates if the networks change. | 1329 // it can gather candidates if the networks change. |
1308 if (config_.gather_continually && session == allocator_sessions_.back()) { | 1330 if (config_.gather_continually() && session == allocator_sessions_.back()) { |
1309 session->ClearGettingPorts(); | 1331 session->ClearGettingPorts(); |
1310 break; | 1332 } else { |
1333 session->StopGettingPorts(); | |
1311 } | 1334 } |
1312 session->StopGettingPorts(); | |
1313 } | 1335 } |
1314 } | 1336 } |
1315 | 1337 |
1316 // If all connections timed out, delete them all. | 1338 // If all connections timed out, delete them all. |
1317 void P2PTransportChannel::HandleAllTimedOut() { | 1339 void P2PTransportChannel::HandleAllTimedOut() { |
1318 for (Connection* connection : connections_) { | 1340 for (Connection* connection : connections_) { |
1319 connection->Destroy(); | 1341 connection->Destroy(); |
1320 } | 1342 } |
1321 } | 1343 } |
1322 | 1344 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 | 1379 |
1358 // Handle any queued up requests | 1380 // Handle any queued up requests |
1359 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) { | 1381 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) { |
1360 switch (pmsg->message_id) { | 1382 switch (pmsg->message_id) { |
1361 case MSG_SORT: | 1383 case MSG_SORT: |
1362 OnSort(); | 1384 OnSort(); |
1363 break; | 1385 break; |
1364 case MSG_CHECK_AND_PING: | 1386 case MSG_CHECK_AND_PING: |
1365 OnCheckAndPing(); | 1387 OnCheckAndPing(); |
1366 break; | 1388 break; |
1389 case MSG_REGATHER_ON_FAILED_NETWORKS: | |
1390 OnRegatherOnFailedNetworks(); | |
1391 break; | |
1367 default: | 1392 default: |
1368 ASSERT(false); | 1393 ASSERT(false); |
1369 break; | 1394 break; |
1370 } | 1395 } |
1371 } | 1396 } |
1372 | 1397 |
1373 // Handle queued up sort request | 1398 // Handle queued up sort request |
1374 void P2PTransportChannel::OnSort() { | 1399 void P2PTransportChannel::OnSort() { |
1375 // Resort the connections based on the new statistics. | 1400 // Resort the connections based on the new statistics. |
1376 SortConnections(); | 1401 SortConnections(); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1587 // selected connection. | 1612 // selected connection. |
1588 if (selected_connection_ == connection) { | 1613 if (selected_connection_ == connection) { |
1589 LOG(LS_INFO) << "selected connection destroyed. Will choose a new one."; | 1614 LOG(LS_INFO) << "selected connection destroyed. Will choose a new one."; |
1590 SwitchSelectedConnection(nullptr); | 1615 SwitchSelectedConnection(nullptr); |
1591 RequestSort(); | 1616 RequestSort(); |
1592 } | 1617 } |
1593 | 1618 |
1594 UpdateState(); | 1619 UpdateState(); |
1595 } | 1620 } |
1596 | 1621 |
1597 // When a port is destroyed remove it from our list of ports to use for | 1622 // When a port is destroyed, remove it from our list of ports to use for |
1598 // connection attempts. | 1623 // connection attempts. |
1599 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { | 1624 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { |
1600 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1625 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1601 | 1626 |
1602 // Remove this port from the lists (if we didn't drop it already). | |
1603 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); | 1627 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); |
1604 removed_ports_.erase( | 1628 removed_ports_.erase( |
1605 std::remove(removed_ports_.begin(), removed_ports_.end(), port), | 1629 std::remove(removed_ports_.begin(), removed_ports_.end(), port), |
1606 removed_ports_.end()); | 1630 removed_ports_.end()); |
1607 | 1631 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size() |
1608 LOG(INFO) << "Removed port from p2p socket: " | 1632 << " remaining"; |
1609 << static_cast<int>(ports_.size()) << " remaining"; | |
1610 } | 1633 } |
1611 | 1634 |
1612 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { | 1635 void P2PTransportChannel::OnPortsRemoved( |
1613 // If it does not gather continually, the port will be removed from the list | 1636 PortAllocatorSession* session, |
1614 // when ICE restarts. | 1637 const std::vector<PortInterface*>& ports) { |
1615 if (!config_.gather_continually) { | 1638 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1639 LOG(LS_INFO) << "Remove " << ports.size() << " ports"; | |
1640 for (PortInterface* port : ports) { | |
1641 if (RemovePort(port)) { | |
1642 LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size() | |
1643 << " remaining"; | |
1644 } | |
1645 } | |
1646 } | |
1647 | |
1648 bool P2PTransportChannel::RemovePort(PortInterface* port) { | |
1649 // Move this port from |ports_| to |removed_ports_| (if we haven't done it | |
1650 // already). | |
1651 auto new_end = std::remove(ports_.begin(), ports_.end(), port); | |
1652 if (new_end != ports_.end()) { | |
1653 ports_.erase(new_end, ports_.end()); | |
1654 removed_ports_.push_back(port); | |
1655 return true; | |
1656 } | |
1657 return false; | |
1658 } | |
1659 | |
1660 void P2PTransportChannel::OnCandidatesRemoved( | |
1661 PortAllocatorSession* session, | |
1662 const std::vector<Candidate>& candidates) { | |
1663 ASSERT(worker_thread_ == rtc::Thread::Current()); | |
1664 // Do not signal candidate removals if continual gathering is not enabled, or | |
1665 // if this is not the last session because an ICE restart would have signaled | |
1666 // the remote side to remove all candidates in previous sessions. | |
1667 if (!config_.gather_continually() || session != allocator_session()) { | |
1616 return; | 1668 return; |
1617 } | 1669 } |
1618 auto it = std::find(ports_.begin(), ports_.end(), port); | 1670 |
1619 // Don't need to do anything if the port has been deleted from the port list. | 1671 std::vector<Candidate> candidates_to_remove; |
1620 if (it == ports_.end()) { | 1672 for (Candidate candidate : candidates) { |
1673 candidate.set_transport_name(transport_name()); | |
1674 candidates_to_remove.push_back(candidate); | |
1675 } | |
1676 SignalCandidatesRemoved(this, candidates_to_remove); | |
1677 } | |
1678 | |
1679 void P2PTransportChannel::OnRegatherOnFailedNetworks() { | |
1680 if (!config_.gather_continually() || allocator_sessions_.empty()) { | |
1621 return; | 1681 return; |
1622 } | 1682 } |
1623 removed_ports_.push_back(*it); | 1683 allocator_session()->RegatherOnFailedNetworks(); |
1624 ports_.erase(it); | 1684 |
1625 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() | 1685 thread()->PostDelayed(RTC_FROM_HERE, |
1626 << " remaining"; | 1686 config_.regather_on_failed_networks_interval, this, |
1627 std::vector<Candidate> candidates = port->Candidates(); | 1687 MSG_REGATHER_ON_FAILED_NETWORKS); |
1628 for (Candidate& candidate : candidates) { | |
1629 candidate.set_transport_name(transport_name()); | |
1630 } | |
1631 SignalCandidatesRemoved(this, candidates); | |
1632 } | 1688 } |
1633 | 1689 |
1634 // We data is available, let listeners know | 1690 // We data is available, let listeners know |
1635 void P2PTransportChannel::OnReadPacket(Connection* connection, | 1691 void P2PTransportChannel::OnReadPacket(Connection* connection, |
1636 const char* data, | 1692 const char* data, |
1637 size_t len, | 1693 size_t len, |
1638 const rtc::PacketTime& packet_time) { | 1694 const rtc::PacketTime& packet_time) { |
1639 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1695 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1640 | 1696 |
1641 // Do not deliver, if packet doesn't belong to the correct transport channel. | 1697 // Do not deliver, if packet doesn't belong to the correct transport channel. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1778 | 1834 |
1779 // During the initial state when nothing has been pinged yet, return the first | 1835 // During the initial state when nothing has been pinged yet, return the first |
1780 // one in the ordered |connections_|. | 1836 // one in the ordered |connections_|. |
1781 return *(std::find_if(connections_.begin(), connections_.end(), | 1837 return *(std::find_if(connections_.begin(), connections_.end(), |
1782 [conn1, conn2](Connection* conn) { | 1838 [conn1, conn2](Connection* conn) { |
1783 return conn == conn1 || conn == conn2; | 1839 return conn == conn1 || conn == conn2; |
1784 })); | 1840 })); |
1785 } | 1841 } |
1786 | 1842 |
1787 } // namespace cricket | 1843 } // namespace cricket |
OLD | NEW |