| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); | 137 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); |
| 138 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); | 138 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); |
| 139 session->SignalPortsPruned.connect(this, &P2PTransportChannel::OnPortsPruned); | 139 session->SignalPortsPruned.connect(this, &P2PTransportChannel::OnPortsPruned); |
| 140 session->SignalCandidatesReady.connect( | 140 session->SignalCandidatesReady.connect( |
| 141 this, &P2PTransportChannel::OnCandidatesReady); | 141 this, &P2PTransportChannel::OnCandidatesReady); |
| 142 session->SignalCandidatesRemoved.connect( | 142 session->SignalCandidatesRemoved.connect( |
| 143 this, &P2PTransportChannel::OnCandidatesRemoved); | 143 this, &P2PTransportChannel::OnCandidatesRemoved); |
| 144 session->SignalCandidatesAllocationDone.connect( | 144 session->SignalCandidatesAllocationDone.connect( |
| 145 this, &P2PTransportChannel::OnCandidatesAllocationDone); | 145 this, &P2PTransportChannel::OnCandidatesAllocationDone); |
| 146 if (!allocator_sessions_.empty()) { |
| 147 allocator_session()->PruneAllPorts(); |
| 148 } |
| 149 allocator_sessions_.push_back(std::move(session)); |
| 146 | 150 |
| 147 // We now only want to apply new candidates that we receive to the ports | 151 // We now only want to apply new candidates that we receive to the ports |
| 148 // created by this new session because these are replacing those of the | 152 // created by this new session because these are replacing those of the |
| 149 // previous sessions. | 153 // previous sessions. |
| 150 pruned_ports_.insert(pruned_ports_.end(), ports_.begin(), ports_.end()); | 154 PruneAllPorts(); |
| 151 ports_.clear(); | |
| 152 | |
| 153 allocator_sessions_.push_back(std::move(session)); | |
| 154 } | 155 } |
| 155 | 156 |
| 156 void P2PTransportChannel::AddConnection(Connection* connection) { | 157 void P2PTransportChannel::AddConnection(Connection* connection) { |
| 157 connections_.push_back(connection); | 158 connections_.push_back(connection); |
| 158 unpinged_connections_.insert(connection); | 159 unpinged_connections_.insert(connection); |
| 159 connection->set_remote_ice_mode(remote_ice_mode_); | 160 connection->set_remote_ice_mode(remote_ice_mode_); |
| 160 connection->set_receiving_timeout(config_.receiving_timeout); | 161 connection->set_receiving_timeout(config_.receiving_timeout); |
| 161 connection->SignalReadPacket.connect( | 162 connection->SignalReadPacket.connect( |
| 162 this, &P2PTransportChannel::OnReadPacket); | 163 this, &P2PTransportChannel::OnReadPacket); |
| 163 connection->SignalReadyToSend.connect( | 164 connection->SignalReadyToSend.connect( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 return false; | 232 return false; |
| 232 } | 233 } |
| 233 | 234 |
| 234 void P2PTransportChannel::SetIceRole(IceRole ice_role) { | 235 void P2PTransportChannel::SetIceRole(IceRole ice_role) { |
| 235 ASSERT(worker_thread_ == rtc::Thread::Current()); | 236 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 236 if (ice_role_ != ice_role) { | 237 if (ice_role_ != ice_role) { |
| 237 ice_role_ = ice_role; | 238 ice_role_ = ice_role; |
| 238 for (PortInterface* port : ports_) { | 239 for (PortInterface* port : ports_) { |
| 239 port->SetIceRole(ice_role); | 240 port->SetIceRole(ice_role); |
| 240 } | 241 } |
| 241 // Update role on removed ports as well, because they may still have | 242 // Update role on pruned ports as well, because they may still have |
| 242 // connections alive that should be using the correct role. | 243 // connections alive that should be using the correct role. |
| 243 for (PortInterface* port : pruned_ports_) { | 244 for (PortInterface* port : pruned_ports_) { |
| 244 port->SetIceRole(ice_role); | 245 port->SetIceRole(ice_role); |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 } | 248 } |
| 248 | 249 |
| 249 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { | 250 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { |
| 250 ASSERT(worker_thread_ == rtc::Thread::Current()); | 251 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 251 if (!ports_.empty() || !pruned_ports_.empty()) { | 252 if (!ports_.empty() || !pruned_ports_.empty()) { |
| (...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 pruned_ports_.end()); | 1682 pruned_ports_.end()); |
| 1682 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size() | 1683 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size() |
| 1683 << " remaining"; | 1684 << " remaining"; |
| 1684 } | 1685 } |
| 1685 | 1686 |
| 1686 void P2PTransportChannel::OnPortsPruned( | 1687 void P2PTransportChannel::OnPortsPruned( |
| 1687 PortAllocatorSession* session, | 1688 PortAllocatorSession* session, |
| 1688 const std::vector<PortInterface*>& ports) { | 1689 const std::vector<PortInterface*>& ports) { |
| 1689 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1690 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 1690 for (PortInterface* port : ports) { | 1691 for (PortInterface* port : ports) { |
| 1691 if (OnPortPruned(port)) { | 1692 if (PrunePort(port)) { |
| 1692 LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size() | 1693 LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size() |
| 1693 << " remaining"; | 1694 << " remaining"; |
| 1694 } | 1695 } |
| 1695 } | 1696 } |
| 1696 } | 1697 } |
| 1697 | 1698 |
| 1698 void P2PTransportChannel::OnCandidatesRemoved( | 1699 void P2PTransportChannel::OnCandidatesRemoved( |
| 1699 PortAllocatorSession* session, | 1700 PortAllocatorSession* session, |
| 1700 const std::vector<Candidate>& candidates) { | 1701 const std::vector<Candidate>& candidates) { |
| 1701 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1702 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1720 // continually, so there is an implicit check on continual gathering here. | 1721 // continually, so there is an implicit check on continual gathering here. |
| 1721 if (!allocator_sessions_.empty() && allocator_session()->IsCleared()) { | 1722 if (!allocator_sessions_.empty() && allocator_session()->IsCleared()) { |
| 1722 allocator_session()->RegatherOnFailedNetworks(); | 1723 allocator_session()->RegatherOnFailedNetworks(); |
| 1723 } | 1724 } |
| 1724 | 1725 |
| 1725 thread()->PostDelayed(RTC_FROM_HERE, | 1726 thread()->PostDelayed(RTC_FROM_HERE, |
| 1726 *config_.regather_on_failed_networks_interval, this, | 1727 *config_.regather_on_failed_networks_interval, this, |
| 1727 MSG_REGATHER_ON_FAILED_NETWORKS); | 1728 MSG_REGATHER_ON_FAILED_NETWORKS); |
| 1728 } | 1729 } |
| 1729 | 1730 |
| 1730 bool P2PTransportChannel::OnPortPruned(PortInterface* port) { | 1731 void P2PTransportChannel::PruneAllPorts() { |
| 1732 pruned_ports_.insert(pruned_ports_.end(), ports_.begin(), ports_.end()); |
| 1733 ports_.clear(); |
| 1734 } |
| 1735 |
| 1736 bool P2PTransportChannel::PrunePort(PortInterface* port) { |
| 1731 auto it = std::find(ports_.begin(), ports_.end(), port); | 1737 auto it = std::find(ports_.begin(), ports_.end(), port); |
| 1732 // Don't need to do anything if the port has been deleted from the port list. | 1738 // Don't need to do anything if the port has been deleted from the port list. |
| 1733 if (it == ports_.end()) { | 1739 if (it == ports_.end()) { |
| 1734 return false; | 1740 return false; |
| 1735 } | 1741 } |
| 1736 ports_.erase(it); | 1742 ports_.erase(it); |
| 1737 pruned_ports_.push_back(port); | 1743 pruned_ports_.push_back(port); |
| 1738 return true; | 1744 return true; |
| 1739 } | 1745 } |
| 1740 | 1746 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1882 | 1888 |
| 1883 // During the initial state when nothing has been pinged yet, return the first | 1889 // During the initial state when nothing has been pinged yet, return the first |
| 1884 // one in the ordered |connections_|. | 1890 // one in the ordered |connections_|. |
| 1885 return *(std::find_if(connections_.begin(), connections_.end(), | 1891 return *(std::find_if(connections_.begin(), connections_.end(), |
| 1886 [conn1, conn2](Connection* conn) { | 1892 [conn1, conn2](Connection* conn) { |
| 1887 return conn == conn1 || conn == conn2; | 1893 return conn == conn1 || conn == conn2; |
| 1888 })); | 1894 })); |
| 1889 } | 1895 } |
| 1890 | 1896 |
| 1891 } // namespace cricket | 1897 } // namespace cricket |
| OLD | NEW |