Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel.cc

Issue 2025573002: Use continual gathering to restore backup connections (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address comments and revised tests Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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) {
362 config_.regather_on_failed_networks_interval =
363 config.regather_on_failed_networks_interval;
364 LOG(LS_INFO) << "Set regather_on_failed_networks_interval to "
365 << *config_.regather_on_failed_networks_interval;
366 }
349 } 367 }
350 368
351 const IceConfig& P2PTransportChannel::config() const { 369 const IceConfig& P2PTransportChannel::config() const {
352 return config_; 370 return config_;
353 } 371 }
354 372
355 // Go into the state of processing candidates, and running in general 373 // Go into the state of processing candidates, and running in general
356 void P2PTransportChannel::Connect() { 374 void P2PTransportChannel::Connect() {
357 ASSERT(worker_thread_ == rtc::Thread::Current()); 375 ASSERT(worker_thread_ == rtc::Thread::Current());
358 if (ice_ufrag_.empty() || ice_pwd_.empty()) { 376 if (ice_ufrag_.empty() || ice_pwd_.empty()) {
359 ASSERT(false); 377 ASSERT(false);
360 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the " 378 LOG(LS_ERROR) << "P2PTransportChannel::Connect: The ice_ufrag_ and the "
361 << "ice_pwd_ are not set."; 379 << "ice_pwd_ are not set.";
362 return; 380 return;
363 } 381 }
364 382
365 // Start checking and pinging as the ports come in. 383 // Start checking and pinging as the ports come in.
366 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING); 384 thread()->Post(RTC_FROM_HERE, this, MSG_CHECK_AND_PING);
385 thread()->PostDelayed(RTC_FROM_HERE,
386 *config_.regather_on_failed_networks_interval, this,
387 MSG_REGATHER_ON_FAILED_NETWORKS);
367 } 388 }
368 389
369 void P2PTransportChannel::MaybeStartGathering() { 390 void P2PTransportChannel::MaybeStartGathering() {
370 // Start gathering if we never started before, or if an ICE restart occurred. 391 // Start gathering if we never started before, or if an ICE restart occurred.
371 if (allocator_sessions_.empty() || 392 if (allocator_sessions_.empty() ||
372 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), 393 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(),
373 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, 394 allocator_sessions_.back()->ice_pwd(), ice_ufrag_,
374 ice_pwd_)) { 395 ice_pwd_)) {
375 if (gathering_state_ != kIceGatheringGathering) { 396 if (gathering_state_ != kIceGatheringGathering) {
376 gathering_state_ = kIceGatheringGathering; 397 gathering_state_ = kIceGatheringGathering;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // Remember the ports and candidates, and signal that candidates are ready. 442 // Remember the ports and candidates, and signal that candidates are ready.
422 // The session will handle this, and send an initiate/accept/modify message 443 // The session will handle this, and send an initiate/accept/modify message
423 // if one is pending. 444 // if one is pending.
424 445
425 port->SetIceRole(ice_role_); 446 port->SetIceRole(ice_role_);
426 port->SetIceTiebreaker(tiebreaker_); 447 port->SetIceTiebreaker(tiebreaker_);
427 ports_.push_back(port); 448 ports_.push_back(port);
428 port->SignalUnknownAddress.connect( 449 port->SignalUnknownAddress.connect(
429 this, &P2PTransportChannel::OnUnknownAddress); 450 this, &P2PTransportChannel::OnUnknownAddress);
430 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); 451 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed);
431 port->SignalNetworkInactive.connect( 452
432 this, &P2PTransportChannel::OnPortNetworkInactive);
433 port->SignalRoleConflict.connect( 453 port->SignalRoleConflict.connect(
434 this, &P2PTransportChannel::OnRoleConflict); 454 this, &P2PTransportChannel::OnRoleConflict);
435 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); 455 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket);
436 456
437 // Attempt to create a connection from this new port to all of the remote 457 // Attempt to create a connection from this new port to all of the remote
438 // candidates that we were given so far. 458 // candidates that we were given so far.
439 459
440 std::vector<RemoteCandidate>::iterator iter; 460 std::vector<RemoteCandidate>::iterator iter;
441 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); 461 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end();
442 ++iter) { 462 ++iter) {
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 1316
1297 void P2PTransportChannel::MaybeStopPortAllocatorSessions() { 1317 void P2PTransportChannel::MaybeStopPortAllocatorSessions() {
1298 if (!IsGettingPorts()) { 1318 if (!IsGettingPorts()) {
1299 return; 1319 return;
1300 } 1320 }
1301 1321
1302 for (const auto& session : allocator_sessions_) { 1322 for (const auto& session : allocator_sessions_) {
1303 if (!session->IsGettingPorts()) { 1323 if (!session->IsGettingPorts()) {
1304 continue; 1324 continue;
1305 } 1325 }
1306 // If gathering continually, keep the last session running so that it 1326 // If gathering continually, keep the last session running so that
1307 // will gather candidates if the networks change. 1327 // it can gather candidates if the networks change.
1308 if (config_.gather_continually && session == allocator_sessions_.back()) { 1328 if (config_.gather_continually() && session == allocator_sessions_.back()) {
1309 session->ClearGettingPorts(); 1329 session->ClearGettingPorts();
1310 break; 1330 } else {
1331 session->StopGettingPorts();
1311 } 1332 }
1312 session->StopGettingPorts();
1313 } 1333 }
1314 } 1334 }
1315 1335
1316 // If all connections timed out, delete them all. 1336 // If all connections timed out, delete them all.
1317 void P2PTransportChannel::HandleAllTimedOut() { 1337 void P2PTransportChannel::HandleAllTimedOut() {
1318 for (Connection* connection : connections_) { 1338 for (Connection* connection : connections_) {
1319 connection->Destroy(); 1339 connection->Destroy();
1320 } 1340 }
1321 } 1341 }
1322 1342
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 1377
1358 // Handle any queued up requests 1378 // Handle any queued up requests
1359 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) { 1379 void P2PTransportChannel::OnMessage(rtc::Message *pmsg) {
1360 switch (pmsg->message_id) { 1380 switch (pmsg->message_id) {
1361 case MSG_SORT: 1381 case MSG_SORT:
1362 OnSort(); 1382 OnSort();
1363 break; 1383 break;
1364 case MSG_CHECK_AND_PING: 1384 case MSG_CHECK_AND_PING:
1365 OnCheckAndPing(); 1385 OnCheckAndPing();
1366 break; 1386 break;
1387 case MSG_REGATHER_ON_FAILED_NETWORKS:
1388 OnRegatherOnFailedNetworks();
1389 break;
1367 default: 1390 default:
1368 ASSERT(false); 1391 ASSERT(false);
1369 break; 1392 break;
1370 } 1393 }
1371 } 1394 }
1372 1395
1373 // Handle queued up sort request 1396 // Handle queued up sort request
1374 void P2PTransportChannel::OnSort() { 1397 void P2PTransportChannel::OnSort() {
1375 // Resort the connections based on the new statistics. 1398 // Resort the connections based on the new statistics.
1376 SortConnections(); 1399 SortConnections();
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 // selected connection. 1610 // selected connection.
1588 if (selected_connection_ == connection) { 1611 if (selected_connection_ == connection) {
1589 LOG(LS_INFO) << "selected connection destroyed. Will choose a new one."; 1612 LOG(LS_INFO) << "selected connection destroyed. Will choose a new one.";
1590 SwitchSelectedConnection(nullptr); 1613 SwitchSelectedConnection(nullptr);
1591 RequestSort(); 1614 RequestSort();
1592 } 1615 }
1593 1616
1594 UpdateState(); 1617 UpdateState();
1595 } 1618 }
1596 1619
1597 // When a port is destroyed remove it from our list of ports to use for 1620 // When a port is destroyed, remove it from our list of ports to use for
1598 // connection attempts. 1621 // connection attempts.
1599 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { 1622 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) {
1600 ASSERT(worker_thread_ == rtc::Thread::Current()); 1623 ASSERT(worker_thread_ == rtc::Thread::Current());
1601 1624
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()); 1625 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end());
1604 removed_ports_.erase( 1626 removed_ports_.erase(
1605 std::remove(removed_ports_.begin(), removed_ports_.end(), port), 1627 std::remove(removed_ports_.begin(), removed_ports_.end(), port),
1606 removed_ports_.end()); 1628 removed_ports_.end());
1607 1629 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size()
1608 LOG(INFO) << "Removed port from p2p socket: " 1630 << " remaining";
1609 << static_cast<int>(ports_.size()) << " remaining";
1610 } 1631 }
1611 1632
1612 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { 1633 void P2PTransportChannel::OnPortsRemoved(
1613 // If it does not gather continually, the port will be removed from the list 1634 PortAllocatorSession* session,
1614 // when ICE restarts. 1635 const std::vector<PortInterface*>& ports) {
1615 if (!config_.gather_continually) { 1636 ASSERT(worker_thread_ == rtc::Thread::Current());
1637 LOG(LS_INFO) << "Remove " << ports.size() << " ports";
1638 for (PortInterface* port : ports) {
1639 if (RemovePort(port)) {
1640 LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size()
1641 << " remaining";
1642 }
1643 }
1644 }
1645
1646 bool P2PTransportChannel::RemovePort(PortInterface* port) {
1647 // Move this port from |ports_| to |removed_ports_| (if we haven't done it
1648 // already).
1649 auto new_end = std::remove(ports_.begin(), ports_.end(), port);
1650 if (new_end != ports_.end()) {
1651 ports_.erase(new_end, ports_.end());
1652 removed_ports_.push_back(port);
1653 return true;
1654 }
1655 return false;
1656 }
1657
1658 void P2PTransportChannel::OnCandidatesRemoved(
1659 PortAllocatorSession* session,
1660 const std::vector<Candidate>& candidates) {
1661 ASSERT(worker_thread_ == rtc::Thread::Current());
1662 // Do not signal candidate removals if continual gathering is not enabled, or
1663 // if this is not the last session because an ICE restart would have signaled
1664 // the remote side to remove all candidates in previous sessions.
1665 if (!config_.gather_continually() || session != allocator_session()) {
1616 return; 1666 return;
1617 } 1667 }
1618 auto it = std::find(ports_.begin(), ports_.end(), port); 1668
1619 // Don't need to do anything if the port has been deleted from the port list. 1669 std::vector<Candidate> candidates_to_remove;
1620 if (it == ports_.end()) { 1670 for (Candidate candidate : candidates) {
1621 return; 1671 candidate.set_transport_name(transport_name());
1672 candidates_to_remove.push_back(candidate);
1622 } 1673 }
1623 removed_ports_.push_back(*it); 1674 SignalCandidatesRemoved(this, candidates_to_remove);
1624 ports_.erase(it); 1675 }
1625 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() 1676
1626 << " remaining"; 1677 void P2PTransportChannel::OnRegatherOnFailedNetworks() {
1627 std::vector<Candidate> candidates = port->Candidates(); 1678 if (config_.gather_continually() && !allocator_sessions_.empty()) {
1628 for (Candidate& candidate : candidates) { 1679 allocator_session()->RegatherOnFailedNetworks();
1629 candidate.set_transport_name(transport_name());
1630 } 1680 }
1631 SignalCandidatesRemoved(this, candidates); 1681
1682 thread()->PostDelayed(RTC_FROM_HERE,
1683 *config_.regather_on_failed_networks_interval, this,
1684 MSG_REGATHER_ON_FAILED_NETWORKS);
1632 } 1685 }
1633 1686
1634 // We data is available, let listeners know 1687 // We data is available, let listeners know
1635 void P2PTransportChannel::OnReadPacket(Connection* connection, 1688 void P2PTransportChannel::OnReadPacket(Connection* connection,
1636 const char* data, 1689 const char* data,
1637 size_t len, 1690 size_t len,
1638 const rtc::PacketTime& packet_time) { 1691 const rtc::PacketTime& packet_time) {
1639 ASSERT(worker_thread_ == rtc::Thread::Current()); 1692 ASSERT(worker_thread_ == rtc::Thread::Current());
1640 1693
1641 // Do not deliver, if packet doesn't belong to the correct transport channel. 1694 // 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
1778 1831
1779 // During the initial state when nothing has been pinged yet, return the first 1832 // During the initial state when nothing has been pinged yet, return the first
1780 // one in the ordered |connections_|. 1833 // one in the ordered |connections_|.
1781 return *(std::find_if(connections_.begin(), connections_.end(), 1834 return *(std::find_if(connections_.begin(), connections_.end(),
1782 [conn1, conn2](Connection* conn) { 1835 [conn1, conn2](Connection* conn) {
1783 return conn == conn1 || conn == conn2; 1836 return conn == conn1 || conn == conn2;
1784 })); 1837 }));
1785 } 1838 }
1786 1839
1787 } // namespace cricket 1840 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698