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

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

Issue 2171183002: Remove ports that are not used by any channel after timeout (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 4 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
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 129 }
130 130
131 // Add the allocator session to our list so that we know which sessions 131 // Add the allocator session to our list so that we know which sessions
132 // are still active. 132 // are still active.
133 void P2PTransportChannel::AddAllocatorSession( 133 void P2PTransportChannel::AddAllocatorSession(
134 std::unique_ptr<PortAllocatorSession> session) { 134 std::unique_ptr<PortAllocatorSession> session) {
135 ASSERT(worker_thread_ == rtc::Thread::Current()); 135 ASSERT(worker_thread_ == rtc::Thread::Current());
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->SignalPortsRemoved.connect(this, 139 session->SignalPortsPruned.connect(this, &P2PTransportChannel::OnPortsPruned);
140 &P2PTransportChannel::OnPortsRemoved);
141 session->SignalPortPruned.connect(this, &P2PTransportChannel::OnPortPruned);
142 session->SignalCandidatesReady.connect( 140 session->SignalCandidatesReady.connect(
143 this, &P2PTransportChannel::OnCandidatesReady); 141 this, &P2PTransportChannel::OnCandidatesReady);
144 session->SignalCandidatesRemoved.connect( 142 session->SignalCandidatesRemoved.connect(
145 this, &P2PTransportChannel::OnCandidatesRemoved); 143 this, &P2PTransportChannel::OnCandidatesRemoved);
146 session->SignalCandidatesAllocationDone.connect( 144 session->SignalCandidatesAllocationDone.connect(
147 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));
148 150
149 // 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
150 // 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
151 // previous sessions. 153 // previous sessions.
152 removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end()); 154 PruneAllPorts();
153 ports_.clear();
154
155 allocator_sessions_.push_back(std::move(session));
156 } 155 }
157 156
158 void P2PTransportChannel::AddConnection(Connection* connection) { 157 void P2PTransportChannel::AddConnection(Connection* connection) {
159 connections_.push_back(connection); 158 connections_.push_back(connection);
160 unpinged_connections_.insert(connection); 159 unpinged_connections_.insert(connection);
161 connection->set_remote_ice_mode(remote_ice_mode_); 160 connection->set_remote_ice_mode(remote_ice_mode_);
162 connection->set_receiving_timeout(config_.receiving_timeout); 161 connection->set_receiving_timeout(config_.receiving_timeout);
163 connection->SignalReadPacket.connect( 162 connection->SignalReadPacket.connect(
164 this, &P2PTransportChannel::OnReadPacket); 163 this, &P2PTransportChannel::OnReadPacket);
165 connection->SignalReadyToSend.connect( 164 connection->SignalReadyToSend.connect(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 return false; 232 return false;
234 } 233 }
235 234
236 void P2PTransportChannel::SetIceRole(IceRole ice_role) { 235 void P2PTransportChannel::SetIceRole(IceRole ice_role) {
237 ASSERT(worker_thread_ == rtc::Thread::Current()); 236 ASSERT(worker_thread_ == rtc::Thread::Current());
238 if (ice_role_ != ice_role) { 237 if (ice_role_ != ice_role) {
239 ice_role_ = ice_role; 238 ice_role_ = ice_role;
240 for (PortInterface* port : ports_) { 239 for (PortInterface* port : ports_) {
241 port->SetIceRole(ice_role); 240 port->SetIceRole(ice_role);
242 } 241 }
243 // 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
244 // connections alive that should be using the correct role. 243 // connections alive that should be using the correct role.
245 for (PortInterface* port : removed_ports_) { 244 for (PortInterface* port : pruned_ports_) {
246 port->SetIceRole(ice_role); 245 port->SetIceRole(ice_role);
247 } 246 }
248 } 247 }
249 } 248 }
250 249
251 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { 250 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) {
252 ASSERT(worker_thread_ == rtc::Thread::Current()); 251 ASSERT(worker_thread_ == rtc::Thread::Current());
253 if (!ports_.empty() || !removed_ports_.empty()) { 252 if (!ports_.empty() || !pruned_ports_.empty()) {
254 LOG(LS_ERROR) 253 LOG(LS_ERROR)
255 << "Attempt to change tiebreaker after Port has been allocated."; 254 << "Attempt to change tiebreaker after Port has been allocated.";
256 return; 255 return;
257 } 256 }
258 257
259 tiebreaker_ = tiebreaker; 258 tiebreaker_ = tiebreaker;
260 } 259 }
261 260
262 TransportChannelState P2PTransportChannel::GetState() const { 261 TransportChannelState P2PTransportChannel::GetState() const {
263 return state_; 262 return state_;
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 UpdateState(); 1670 UpdateState();
1672 } 1671 }
1673 } 1672 }
1674 1673
1675 // When a port is destroyed, remove it from our list of ports to use for 1674 // When a port is destroyed, remove it from our list of ports to use for
1676 // connection attempts. 1675 // connection attempts.
1677 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { 1676 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) {
1678 ASSERT(worker_thread_ == rtc::Thread::Current()); 1677 ASSERT(worker_thread_ == rtc::Thread::Current());
1679 1678
1680 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); 1679 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end());
1681 removed_ports_.erase( 1680 pruned_ports_.erase(
1682 std::remove(removed_ports_.begin(), removed_ports_.end(), port), 1681 std::remove(pruned_ports_.begin(), pruned_ports_.end(), port),
1683 removed_ports_.end()); 1682 pruned_ports_.end());
1684 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size() 1683 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size()
1685 << " remaining"; 1684 << " remaining";
1686 } 1685 }
1687 1686
1688 void P2PTransportChannel::OnPortsRemoved( 1687 void P2PTransportChannel::OnPortsPruned(
1689 PortAllocatorSession* session, 1688 PortAllocatorSession* session,
1690 const std::vector<PortInterface*>& ports) { 1689 const std::vector<PortInterface*>& ports) {
1691 ASSERT(worker_thread_ == rtc::Thread::Current()); 1690 ASSERT(worker_thread_ == rtc::Thread::Current());
1692 LOG(LS_INFO) << "Remove " << ports.size() << " ports";
1693 for (PortInterface* port : ports) { 1691 for (PortInterface* port : ports) {
1694 if (RemovePort(port)) { 1692 if (PrunePort(port)) {
1695 LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size() 1693 LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size()
1696 << " remaining"; 1694 << " remaining";
1697 } 1695 }
1698 } 1696 }
1699 } 1697 }
1700 1698
1701 void P2PTransportChannel::OnCandidatesRemoved( 1699 void P2PTransportChannel::OnCandidatesRemoved(
1702 PortAllocatorSession* session, 1700 PortAllocatorSession* session,
1703 const std::vector<Candidate>& candidates) { 1701 const std::vector<Candidate>& candidates) {
1704 ASSERT(worker_thread_ == rtc::Thread::Current()); 1702 ASSERT(worker_thread_ == rtc::Thread::Current());
(...skipping 18 matching lines...) Expand all
1723 // continually, so there is an implicit check on continual gathering here. 1721 // continually, so there is an implicit check on continual gathering here.
1724 if (!allocator_sessions_.empty() && allocator_session()->IsCleared()) { 1722 if (!allocator_sessions_.empty() && allocator_session()->IsCleared()) {
1725 allocator_session()->RegatherOnFailedNetworks(); 1723 allocator_session()->RegatherOnFailedNetworks();
1726 } 1724 }
1727 1725
1728 thread()->PostDelayed(RTC_FROM_HERE, 1726 thread()->PostDelayed(RTC_FROM_HERE,
1729 *config_.regather_on_failed_networks_interval, this, 1727 *config_.regather_on_failed_networks_interval, this,
1730 MSG_REGATHER_ON_FAILED_NETWORKS); 1728 MSG_REGATHER_ON_FAILED_NETWORKS);
1731 } 1729 }
1732 1730
1733 void P2PTransportChannel::OnPortPruned(PortAllocatorSession* session, 1731 void P2PTransportChannel::PruneAllPorts() {
1734 PortInterface* port) { 1732 pruned_ports_.insert(pruned_ports_.end(), ports_.begin(), ports_.end());
1735 if (RemovePort(port)) { 1733 ports_.clear();
1736 LOG(INFO) << "Removed port because it is pruned: " << port->ToString()
1737 << " " << ports_.size() << " remaining";
1738 }
1739 } 1734 }
1740 1735
1741 bool P2PTransportChannel::RemovePort(PortInterface* port) { 1736 bool P2PTransportChannel::PrunePort(PortInterface* port) {
1742 auto it = std::find(ports_.begin(), ports_.end(), port); 1737 auto it = std::find(ports_.begin(), ports_.end(), port);
1743 // 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.
1744 if (it == ports_.end()) { 1739 if (it == ports_.end()) {
1745 return false; 1740 return false;
1746 } 1741 }
1747 ports_.erase(it); 1742 ports_.erase(it);
1748 removed_ports_.push_back(port); 1743 pruned_ports_.push_back(port);
1749 return true; 1744 return true;
1750 } 1745 }
1751 1746
1752 // We data is available, let listeners know 1747 // We data is available, let listeners know
1753 void P2PTransportChannel::OnReadPacket(Connection* connection, 1748 void P2PTransportChannel::OnReadPacket(Connection* connection,
1754 const char* data, 1749 const char* data,
1755 size_t len, 1750 size_t len,
1756 const rtc::PacketTime& packet_time) { 1751 const rtc::PacketTime& packet_time) {
1757 ASSERT(worker_thread_ == rtc::Thread::Current()); 1752 ASSERT(worker_thread_ == rtc::Thread::Current());
1758 1753
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 1888
1894 // 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
1895 // one in the ordered |connections_|. 1890 // one in the ordered |connections_|.
1896 return *(std::find_if(connections_.begin(), connections_.end(), 1891 return *(std::find_if(connections_.begin(), connections_.end(),
1897 [conn1, conn2](Connection* conn) { 1892 [conn1, conn2](Connection* conn) {
1898 return conn == conn1 || conn == conn2; 1893 return conn == conn1 || conn == conn2;
1899 })); 1894 }));
1900 } 1895 }
1901 1896
1902 } // namespace cricket 1897 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698