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

Unified Diff: webrtc/p2p/client/basicportallocator.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/client/basicportallocator.cc
diff --git a/webrtc/p2p/client/basicportallocator.cc b/webrtc/p2p/client/basicportallocator.cc
index 5e4930c1cb39a29ec4ff15b9dfae84d10e3ccb3a..c2a1ec9cc031ec83a9d18fbb684b81180ad1d9d0 100644
--- a/webrtc/p2p/client/basicportallocator.cc
+++ b/webrtc/p2p/client/basicportallocator.cc
@@ -695,17 +695,18 @@ void BasicPortAllocatorSession::OnCandidateReady(
// Note: We should check whether any candidates may become ready after this
// because there we will check whether the candidate is generated by the ready
// ports, which may include this port.
- bool pruned_port = false;
+ bool pruned = false;
if (CandidatePairable(c, port) && !data->has_pairable_candidate()) {
data->set_has_pairable_candidate(true);
if (prune_turn_ports_ && port->Type() == RELAY_PORT_TYPE) {
- pruned_port = PruneTurnPorts(port);
+ pruned = PruneTurnPorts(port);
}
// If the current port is not pruned yet, SignalPortReady.
if (!data->pruned()) {
LOG_J(LS_INFO, port) << "Port ready.";
SignalPortReady(this, port);
+ port->BecomeReady();
}
}
@@ -726,7 +727,7 @@ void BasicPortAllocatorSession::OnCandidateReady(
}
// If we have pruned any port, maybe need to signal port allocation done.
- if (pruned_port) {
+ if (pruned) {
MaybeSignalCandidatesAllocationDone();
}
}
@@ -745,7 +746,6 @@ Port* BasicPortAllocatorSession::GetBestTurnPortForNetwork(
}
bool BasicPortAllocatorSession::PruneTurnPorts(Port* newly_pairable_turn_port) {
- bool pruned_port = false;
// Note: We determine the same network based only on their network names. So
// if an IPv4 address and an IPv6 address have the same network name, they
// are considered the same network here.
@@ -754,18 +754,31 @@ bool BasicPortAllocatorSession::PruneTurnPorts(Port* newly_pairable_turn_port) {
// |port| is already in the list of ports, so the best port cannot be nullptr.
RTC_CHECK(best_turn_port != nullptr);
+ bool pruned = false;
+ std::vector<PortInterface*> pruned_ports;
for (PortData& data : ports_) {
if (data.port()->Network()->name() == network_name &&
data.port()->Type() == RELAY_PORT_TYPE && !data.pruned() &&
ComparePort(data.port(), best_turn_port) < 0) {
data.set_pruned();
- pruned_port = true;
+ pruned = true;
+ data.port()->Prune();
if (data.port() != newly_pairable_turn_port) {
- SignalPortPruned(this, data.port());
+ pruned_ports.push_back(data.port());
}
}
}
- return pruned_port;
+ if (!pruned_ports.empty()) {
+ LOG(LS_INFO) << "Pruned " << pruned_ports.size() << " ports";
+ SignalPortsPruned(this, pruned_ports);
+ }
+ return pruned;
+}
+
+void BasicPortAllocatorSession::PruneAllPorts() {
+ for (PortData& data : ports_) {
+ data.port()->Prune();
+ }
}
void BasicPortAllocatorSession::OnPortComplete(Port* port) {
@@ -937,6 +950,8 @@ void BasicPortAllocatorSession::RemovePortsAndCandidates(
data.sequence()->network()) == networks.end()) {
continue;
}
+ // Prune the port so that it may be destroyed.
+ data.port()->Prune();
ports_to_remove.push_back(data.port());
if (data.has_pairable_candidate()) {
GetCandidatesFromPort(data, &candidates_to_remove);
@@ -946,7 +961,8 @@ void BasicPortAllocatorSession::RemovePortsAndCandidates(
}
}
if (!ports_to_remove.empty()) {
- SignalPortsRemoved(this, ports_to_remove);
+ LOG(LS_INFO) << "Removed " << ports_to_remove.size() << " ports";
+ SignalPortsPruned(this, ports_to_remove);
}
if (!candidates_to_remove.empty()) {
SignalCandidatesRemoved(this, candidates_to_remove);

Powered by Google App Engine
This is Rietveld 408576698