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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
148 | 146 |
149 // We now only want to apply new candidates that we receive to the ports | 147 // 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 | 148 // created by this new session because these are replacing those of the |
151 // previous sessions. | 149 // previous sessions. |
152 removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end()); | 150 pruned_ports_.insert(pruned_ports_.end(), ports_.begin(), ports_.end()); |
153 ports_.clear(); | 151 ports_.clear(); |
154 | 152 |
155 allocator_sessions_.push_back(std::move(session)); | 153 allocator_sessions_.push_back(std::move(session)); |
156 } | 154 } |
157 | 155 |
158 void P2PTransportChannel::AddConnection(Connection* connection) { | 156 void P2PTransportChannel::AddConnection(Connection* connection) { |
159 connections_.push_back(connection); | 157 connections_.push_back(connection); |
160 unpinged_connections_.insert(connection); | 158 unpinged_connections_.insert(connection); |
161 connection->set_remote_ice_mode(remote_ice_mode_); | 159 connection->set_remote_ice_mode(remote_ice_mode_); |
162 connection->set_receiving_timeout(config_.receiving_timeout); | 160 connection->set_receiving_timeout(config_.receiving_timeout); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 233 |
236 void P2PTransportChannel::SetIceRole(IceRole ice_role) { | 234 void P2PTransportChannel::SetIceRole(IceRole ice_role) { |
237 ASSERT(worker_thread_ == rtc::Thread::Current()); | 235 ASSERT(worker_thread_ == rtc::Thread::Current()); |
238 if (ice_role_ != ice_role) { | 236 if (ice_role_ != ice_role) { |
239 ice_role_ = ice_role; | 237 ice_role_ = ice_role; |
240 for (PortInterface* port : ports_) { | 238 for (PortInterface* port : ports_) { |
241 port->SetIceRole(ice_role); | 239 port->SetIceRole(ice_role); |
242 } | 240 } |
243 // Update role on removed ports as well, because they may still have | 241 // Update role on removed ports as well, because they may still have |
244 // connections alive that should be using the correct role. | 242 // connections alive that should be using the correct role. |
245 for (PortInterface* port : removed_ports_) { | 243 for (PortInterface* port : pruned_ports_) { |
246 port->SetIceRole(ice_role); | 244 port->SetIceRole(ice_role); |
247 } | 245 } |
248 } | 246 } |
249 } | 247 } |
250 | 248 |
251 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { | 249 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { |
252 ASSERT(worker_thread_ == rtc::Thread::Current()); | 250 ASSERT(worker_thread_ == rtc::Thread::Current()); |
253 if (!ports_.empty() || !removed_ports_.empty()) { | 251 if (!ports_.empty() || !pruned_ports_.empty()) { |
254 LOG(LS_ERROR) | 252 LOG(LS_ERROR) |
255 << "Attempt to change tiebreaker after Port has been allocated."; | 253 << "Attempt to change tiebreaker after Port has been allocated."; |
256 return; | 254 return; |
257 } | 255 } |
258 | 256 |
259 tiebreaker_ = tiebreaker; | 257 tiebreaker_ = tiebreaker; |
260 } | 258 } |
261 | 259 |
262 TransportChannelState P2PTransportChannel::GetState() const { | 260 TransportChannelState P2PTransportChannel::GetState() const { |
263 return state_; | 261 return state_; |
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 UpdateState(); | 1669 UpdateState(); |
1672 } | 1670 } |
1673 } | 1671 } |
1674 | 1672 |
1675 // When a port is destroyed, remove it from our list of ports to use for | 1673 // When a port is destroyed, remove it from our list of ports to use for |
1676 // connection attempts. | 1674 // connection attempts. |
1677 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { | 1675 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { |
1678 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1676 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1679 | 1677 |
1680 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); | 1678 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end()); |
1681 removed_ports_.erase( | 1679 pruned_ports_.erase( |
1682 std::remove(removed_ports_.begin(), removed_ports_.end(), port), | 1680 std::remove(pruned_ports_.begin(), pruned_ports_.end(), port), |
1683 removed_ports_.end()); | 1681 pruned_ports_.end()); |
1684 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size() | 1682 LOG(INFO) << "Removed port because it is destroyed: " << ports_.size() |
1685 << " remaining"; | 1683 << " remaining"; |
1686 } | 1684 } |
1687 | 1685 |
1688 void P2PTransportChannel::OnPortsRemoved( | 1686 void P2PTransportChannel::OnPortsPruned( |
1689 PortAllocatorSession* session, | 1687 PortAllocatorSession* session, |
1690 const std::vector<PortInterface*>& ports) { | 1688 const std::vector<PortInterface*>& ports) { |
1691 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1689 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1692 LOG(LS_INFO) << "Remove " << ports.size() << " ports"; | |
1693 for (PortInterface* port : ports) { | 1690 for (PortInterface* port : ports) { |
1694 if (RemovePort(port)) { | 1691 if (OnPortPruned(port)) { |
1695 LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size() | 1692 LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size() |
1696 << " remaining"; | 1693 << " remaining"; |
1697 } | 1694 } |
1698 } | 1695 } |
1699 } | 1696 } |
1700 | 1697 |
1701 void P2PTransportChannel::OnCandidatesRemoved( | 1698 void P2PTransportChannel::OnCandidatesRemoved( |
1702 PortAllocatorSession* session, | 1699 PortAllocatorSession* session, |
1703 const std::vector<Candidate>& candidates) { | 1700 const std::vector<Candidate>& candidates) { |
1704 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1701 ASSERT(worker_thread_ == rtc::Thread::Current()); |
(...skipping 18 matching lines...) Expand all Loading... |
1723 // continually, so there is an implicit check on continual gathering here. | 1720 // continually, so there is an implicit check on continual gathering here. |
1724 if (!allocator_sessions_.empty() && allocator_session()->IsCleared()) { | 1721 if (!allocator_sessions_.empty() && allocator_session()->IsCleared()) { |
1725 allocator_session()->RegatherOnFailedNetworks(); | 1722 allocator_session()->RegatherOnFailedNetworks(); |
1726 } | 1723 } |
1727 | 1724 |
1728 thread()->PostDelayed(RTC_FROM_HERE, | 1725 thread()->PostDelayed(RTC_FROM_HERE, |
1729 *config_.regather_on_failed_networks_interval, this, | 1726 *config_.regather_on_failed_networks_interval, this, |
1730 MSG_REGATHER_ON_FAILED_NETWORKS); | 1727 MSG_REGATHER_ON_FAILED_NETWORKS); |
1731 } | 1728 } |
1732 | 1729 |
1733 void P2PTransportChannel::OnPortPruned(PortAllocatorSession* session, | 1730 bool P2PTransportChannel::OnPortPruned(PortInterface* port) { |
1734 PortInterface* port) { | |
1735 if (RemovePort(port)) { | |
1736 LOG(INFO) << "Removed port because it is pruned: " << port->ToString() | |
1737 << " " << ports_.size() << " remaining"; | |
1738 } | |
1739 } | |
1740 | |
1741 bool P2PTransportChannel::RemovePort(PortInterface* port) { | |
1742 auto it = std::find(ports_.begin(), ports_.end(), port); | 1731 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. | 1732 // Don't need to do anything if the port has been deleted from the port list. |
1744 if (it == ports_.end()) { | 1733 if (it == ports_.end()) { |
1745 return false; | 1734 return false; |
1746 } | 1735 } |
1747 ports_.erase(it); | 1736 ports_.erase(it); |
1748 removed_ports_.push_back(port); | 1737 pruned_ports_.push_back(port); |
1749 return true; | 1738 return true; |
1750 } | 1739 } |
1751 | 1740 |
1752 // We data is available, let listeners know | 1741 // We data is available, let listeners know |
1753 void P2PTransportChannel::OnReadPacket(Connection* connection, | 1742 void P2PTransportChannel::OnReadPacket(Connection* connection, |
1754 const char* data, | 1743 const char* data, |
1755 size_t len, | 1744 size_t len, |
1756 const rtc::PacketTime& packet_time) { | 1745 const rtc::PacketTime& packet_time) { |
1757 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1746 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1758 | 1747 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1893 | 1882 |
1894 // During the initial state when nothing has been pinged yet, return the first | 1883 // During the initial state when nothing has been pinged yet, return the first |
1895 // one in the ordered |connections_|. | 1884 // one in the ordered |connections_|. |
1896 return *(std::find_if(connections_.begin(), connections_.end(), | 1885 return *(std::find_if(connections_.begin(), connections_.end(), |
1897 [conn1, conn2](Connection* conn) { | 1886 [conn1, conn2](Connection* conn) { |
1898 return conn == conn1 || conn == conn2; | 1887 return conn == conn1 || conn == conn2; |
1899 })); | 1888 })); |
1900 } | 1889 } |
1901 | 1890 |
1902 } // namespace cricket | 1891 } // namespace cricket |
OLD | NEW |