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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 // connection attempts. | 1610 // connection attempts. |
1610 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { | 1611 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { |
1611 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1612 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1612 | 1613 |
1613 // Remove this port from the lists (if we didn't drop it already). | 1614 // Remove this port from the lists (if we didn't drop it already). |
1614 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); | 1615 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); |
1615 removed_ports_.erase( | 1616 removed_ports_.erase( |
1616 std::remove(removed_ports_.begin(), removed_ports_.end(), port), | 1617 std::remove(removed_ports_.begin(), removed_ports_.end(), port), |
1617 removed_ports_.end()); | 1618 removed_ports_.end()); |
1618 | 1619 |
1619 LOG(INFO) << "Removed port from p2p socket: " | 1620 LOG(INFO) << "Removed port because it is destroyed: " |
1620 << static_cast<int>(ports_.size()) << " remaining"; | 1621 << static_cast<int>(ports_.size()) << " remaining"; |
1621 } | 1622 } |
1622 | 1623 |
1623 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { | 1624 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { |
1624 // If it does not gather continually, the port will be removed from the list | 1625 // If it does not gather continually, the port will be removed from the list |
1625 // when ICE restarts. | 1626 // when ICE restarts. |
1626 if (!config_.gather_continually) { | 1627 if (!config_.gather_continually) { |
1627 return; | 1628 return; |
1628 } | 1629 } |
1629 auto it = std::find(ports_.begin(), ports_.end(), port); | 1630 if (!RemovePort(port)) { |
1630 // Don't need to do anything if the port has been deleted from the port list. | |
1631 if (it == ports_.end()) { | |
1632 return; | 1631 return; |
1633 } | 1632 } |
1634 removed_ports_.push_back(*it); | 1633 LOG(INFO) << "Removed port because its network is inactive : " |
1635 ports_.erase(it); | 1634 << port->ToString() << " " << ports_.size() << " remaining"; |
1636 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() | |
1637 << " remaining"; | |
1638 std::vector<Candidate> candidates = port->Candidates(); | 1635 std::vector<Candidate> candidates = port->Candidates(); |
1639 for (Candidate& candidate : candidates) { | 1636 for (Candidate& candidate : candidates) { |
1640 candidate.set_transport_name(transport_name()); | 1637 candidate.set_transport_name(transport_name()); |
1641 } | 1638 } |
1642 SignalCandidatesRemoved(this, candidates); | 1639 SignalCandidatesRemoved(this, candidates); |
1643 } | 1640 } |
1644 | 1641 |
| 1642 void P2PTransportChannel::OnPortPruned(PortAllocatorSession* session, |
| 1643 PortInterface* port) { |
| 1644 if (RemovePort(port)) { |
| 1645 LOG(INFO) << "Removed port because it is pruned: " << port->ToString() |
| 1646 << " " << ports_.size() << " remaining"; |
| 1647 } |
| 1648 } |
| 1649 |
| 1650 bool P2PTransportChannel::RemovePort(PortInterface* port) { |
| 1651 auto it = std::find(ports_.begin(), ports_.end(), port); |
| 1652 // Don't need to do anything if the port has been deleted from the port list. |
| 1653 if (it == ports_.end()) { |
| 1654 return false; |
| 1655 } |
| 1656 ports_.erase(it); |
| 1657 removed_ports_.push_back(port); |
| 1658 return true; |
| 1659 } |
| 1660 |
1645 // We data is available, let listeners know | 1661 // We data is available, let listeners know |
1646 void P2PTransportChannel::OnReadPacket(Connection* connection, | 1662 void P2PTransportChannel::OnReadPacket(Connection* connection, |
1647 const char* data, | 1663 const char* data, |
1648 size_t len, | 1664 size_t len, |
1649 const rtc::PacketTime& packet_time) { | 1665 const rtc::PacketTime& packet_time) { |
1650 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1666 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1651 | 1667 |
1652 // Do not deliver, if packet doesn't belong to the correct transport channel. | 1668 // Do not deliver, if packet doesn't belong to the correct transport channel. |
1653 if (!FindConnection(connection)) | 1669 if (!FindConnection(connection)) |
1654 return; | 1670 return; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 | 1805 |
1790 // During the initial state when nothing has been pinged yet, return the first | 1806 // During the initial state when nothing has been pinged yet, return the first |
1791 // one in the ordered |connections_|. | 1807 // one in the ordered |connections_|. |
1792 return *(std::find_if(connections_.begin(), connections_.end(), | 1808 return *(std::find_if(connections_.begin(), connections_.end(), |
1793 [conn1, conn2](Connection* conn) { | 1809 [conn1, conn2](Connection* conn) { |
1794 return conn == conn1 || conn == conn2; | 1810 return conn == conn1 || conn == conn2; |
1795 })); | 1811 })); |
1796 } | 1812 } |
1797 | 1813 |
1798 } // namespace cricket | 1814 } // namespace cricket |
OLD | NEW |