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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/p2ptransportchannel.cc
diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc
index 5238da83ca9302954e00b4a5204fc5121eda6851..32a996c5d5758690390d90d8e495efaf4789deef 100644
--- a/webrtc/p2p/base/p2ptransportchannel.cc
+++ b/webrtc/p2p/base/p2ptransportchannel.cc
@@ -136,23 +136,22 @@ void P2PTransportChannel::AddAllocatorSession(
session->set_generation(static_cast<uint32_t>(allocator_sessions_.size()));
session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady);
- session->SignalPortsRemoved.connect(this,
- &P2PTransportChannel::OnPortsRemoved);
- session->SignalPortPruned.connect(this, &P2PTransportChannel::OnPortPruned);
+ session->SignalPortsPruned.connect(this, &P2PTransportChannel::OnPortsPruned);
session->SignalCandidatesReady.connect(
this, &P2PTransportChannel::OnCandidatesReady);
session->SignalCandidatesRemoved.connect(
this, &P2PTransportChannel::OnCandidatesRemoved);
session->SignalCandidatesAllocationDone.connect(
this, &P2PTransportChannel::OnCandidatesAllocationDone);
+ if (!allocator_sessions_.empty()) {
+ allocator_session()->PruneAllPorts();
+ }
+ allocator_sessions_.push_back(std::move(session));
// We now only want to apply new candidates that we receive to the ports
// created by this new session because these are replacing those of the
// previous sessions.
- removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end());
- ports_.clear();
-
- allocator_sessions_.push_back(std::move(session));
+ PruneAllPorts();
}
void P2PTransportChannel::AddConnection(Connection* connection) {
@@ -240,9 +239,9 @@ void P2PTransportChannel::SetIceRole(IceRole ice_role) {
for (PortInterface* port : ports_) {
port->SetIceRole(ice_role);
}
- // Update role on removed ports as well, because they may still have
+ // Update role on pruned ports as well, because they may still have
// connections alive that should be using the correct role.
- for (PortInterface* port : removed_ports_) {
+ for (PortInterface* port : pruned_ports_) {
port->SetIceRole(ice_role);
}
}
@@ -250,7 +249,7 @@ void P2PTransportChannel::SetIceRole(IceRole ice_role) {
void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) {
ASSERT(worker_thread_ == rtc::Thread::Current());
- if (!ports_.empty() || !removed_ports_.empty()) {
+ if (!ports_.empty() || !pruned_ports_.empty()) {
LOG(LS_ERROR)
<< "Attempt to change tiebreaker after Port has been allocated.";
return;
@@ -1678,20 +1677,19 @@ void P2PTransportChannel::OnPortDestroyed(PortInterface* port) {
ASSERT(worker_thread_ == rtc::Thread::Current());
ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end());
- removed_ports_.erase(
- std::remove(removed_ports_.begin(), removed_ports_.end(), port),
- removed_ports_.end());
+ pruned_ports_.erase(
+ std::remove(pruned_ports_.begin(), pruned_ports_.end(), port),
+ pruned_ports_.end());
LOG(INFO) << "Removed port because it is destroyed: " << ports_.size()
<< " remaining";
}
-void P2PTransportChannel::OnPortsRemoved(
+void P2PTransportChannel::OnPortsPruned(
PortAllocatorSession* session,
const std::vector<PortInterface*>& ports) {
ASSERT(worker_thread_ == rtc::Thread::Current());
- LOG(LS_INFO) << "Remove " << ports.size() << " ports";
for (PortInterface* port : ports) {
- if (RemovePort(port)) {
+ if (PrunePort(port)) {
LOG(INFO) << "Removed port: " << port->ToString() << " " << ports_.size()
<< " remaining";
}
@@ -1730,22 +1728,19 @@ void P2PTransportChannel::OnRegatherOnFailedNetworks() {
MSG_REGATHER_ON_FAILED_NETWORKS);
}
-void P2PTransportChannel::OnPortPruned(PortAllocatorSession* session,
- PortInterface* port) {
- if (RemovePort(port)) {
- LOG(INFO) << "Removed port because it is pruned: " << port->ToString()
- << " " << ports_.size() << " remaining";
- }
+void P2PTransportChannel::PruneAllPorts() {
+ pruned_ports_.insert(pruned_ports_.end(), ports_.begin(), ports_.end());
+ ports_.clear();
}
-bool P2PTransportChannel::RemovePort(PortInterface* port) {
+bool P2PTransportChannel::PrunePort(PortInterface* port) {
auto it = std::find(ports_.begin(), ports_.end(), port);
// Don't need to do anything if the port has been deleted from the port list.
if (it == ports_.end()) {
return false;
}
ports_.erase(it);
- removed_ports_.push_back(port);
+ pruned_ports_.push_back(port);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698