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

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

Issue 2093623004: Add config to prune TURN ports (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: . 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
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 118 }
119 119
120 // Add the allocator session to our list so that we know which sessions 120 // Add the allocator session to our list so that we know which sessions
121 // are still active. 121 // are still active.
122 void P2PTransportChannel::AddAllocatorSession( 122 void P2PTransportChannel::AddAllocatorSession(
123 std::unique_ptr<PortAllocatorSession> session) { 123 std::unique_ptr<PortAllocatorSession> session) {
124 ASSERT(worker_thread_ == rtc::Thread::Current()); 124 ASSERT(worker_thread_ == rtc::Thread::Current());
125 125
126 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); 126 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size()));
127 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); 127 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady);
128 session->SignalPortPruned.connect(this, &P2PTransportChannel::OnPortPruned);
128 session->SignalCandidatesReady.connect( 129 session->SignalCandidatesReady.connect(
129 this, &P2PTransportChannel::OnCandidatesReady); 130 this, &P2PTransportChannel::OnCandidatesReady);
130 session->SignalCandidatesAllocationDone.connect( 131 session->SignalCandidatesAllocationDone.connect(
131 this, &P2PTransportChannel::OnCandidatesAllocationDone); 132 this, &P2PTransportChannel::OnCandidatesAllocationDone);
132 133
133 // We now only want to apply new candidates that we receive to the ports 134 // 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 135 // created by this new session because these are replacing those of the
135 // previous sessions. 136 // previous sessions.
136 removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end()); 137 removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end());
137 ports_.clear(); 138 ports_.clear();
(...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 // connection attempts. 1599 // connection attempts.
1599 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { 1600 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) {
1600 ASSERT(worker_thread_ == rtc::Thread::Current()); 1601 ASSERT(worker_thread_ == rtc::Thread::Current());
1601 1602
1602 // Remove this port from the lists (if we didn't drop it already). 1603 // 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()); 1604 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end());
1604 removed_ports_.erase( 1605 removed_ports_.erase(
1605 std::remove(removed_ports_.begin(), removed_ports_.end(), port), 1606 std::remove(removed_ports_.begin(), removed_ports_.end(), port),
1606 removed_ports_.end()); 1607 removed_ports_.end());
1607 1608
1608 LOG(INFO) << "Removed port from p2p socket: " 1609 LOG(INFO) << "Removed port because it is destroyed: "
1609 << static_cast<int>(ports_.size()) << " remaining"; 1610 << static_cast<int>(ports_.size()) << " remaining";
1610 } 1611 }
1611 1612
1612 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { 1613 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) {
1613 // If it does not gather continually, the port will be removed from the list 1614 // If it does not gather continually, the port will be removed from the list
1614 // when ICE restarts. 1615 // when ICE restarts.
1615 if (!config_.gather_continually) { 1616 if (!config_.gather_continually) {
1616 return; 1617 return;
1617 } 1618 }
1618 auto it = std::find(ports_.begin(), ports_.end(), port); 1619 if (!RemovePort(port)) {
1619 // Don't need to do anything if the port has been deleted from the port list.
1620 if (it == ports_.end()) {
1621 return; 1620 return;
1622 } 1621 }
1623 removed_ports_.push_back(*it); 1622 LOG(INFO) << "Removed port because its network is inactive : "
1624 ports_.erase(it); 1623 << port->ToString() << " " << ports_.size() << " remaining";
1625 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size()
1626 << " remaining";
1627 std::vector<Candidate> candidates = port->Candidates(); 1624 std::vector<Candidate> candidates = port->Candidates();
1628 for (Candidate& candidate : candidates) { 1625 for (Candidate& candidate : candidates) {
1629 candidate.set_transport_name(transport_name()); 1626 candidate.set_transport_name(transport_name());
1630 } 1627 }
1631 SignalCandidatesRemoved(this, candidates); 1628 SignalCandidatesRemoved(this, candidates);
1632 } 1629 }
1633 1630
1631 void P2PTransportChannel::OnPortPruned(PortAllocatorSession* session,
1632 PortInterface* port) {
1633 if (RemovePort(port)) {
Taylor Brandstetter 2016/06/29 20:57:35 If a port is pruned and it doesn't have any connec
honghaiz3 2016/06/29 22:53:29 Since the candidates of the port may have been sen
1634 LOG(INFO) << "Removed port because it is pruned: " << port->ToString()
1635 << " " << ports_.size() << " remaining";
1636 }
1637 }
1638
1639 bool P2PTransportChannel::RemovePort(PortInterface* port) {
1640 auto it = std::find(ports_.begin(), ports_.end(), port);
1641 // Don't need to do anything if the port has been deleted from the port list.
1642 if (it == ports_.end()) {
1643 return false;
1644 }
1645 ports_.erase(it);
1646 removed_ports_.push_back(port);
1647 return true;
1648 }
1649
1634 // We data is available, let listeners know 1650 // We data is available, let listeners know
1635 void P2PTransportChannel::OnReadPacket(Connection* connection, 1651 void P2PTransportChannel::OnReadPacket(Connection* connection,
1636 const char* data, 1652 const char* data,
1637 size_t len, 1653 size_t len,
1638 const rtc::PacketTime& packet_time) { 1654 const rtc::PacketTime& packet_time) {
1639 ASSERT(worker_thread_ == rtc::Thread::Current()); 1655 ASSERT(worker_thread_ == rtc::Thread::Current());
1640 1656
1641 // Do not deliver, if packet doesn't belong to the correct transport channel. 1657 // Do not deliver, if packet doesn't belong to the correct transport channel.
1642 if (!FindConnection(connection)) 1658 if (!FindConnection(connection))
1643 return; 1659 return;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 1794
1779 // During the initial state when nothing has been pinged yet, return the first 1795 // During the initial state when nothing has been pinged yet, return the first
1780 // one in the ordered |connections_|. 1796 // one in the ordered |connections_|.
1781 return *(std::find_if(connections_.begin(), connections_.end(), 1797 return *(std::find_if(connections_.begin(), connections_.end(),
1782 [conn1, conn2](Connection* conn) { 1798 [conn1, conn2](Connection* conn) {
1783 return conn == conn1 || conn == conn2; 1799 return conn == conn1 || conn == conn2;
1784 })); 1800 }));
1785 } 1801 }
1786 1802
1787 } // namespace cricket 1803 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698