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

Unified Diff: webrtc/p2p/base/p2ptransportchannel.cc

Issue 2395243005: Prune connections based on network name. (Closed)
Patch Set: . Created 4 years, 2 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 6bcf0d7d2bfb09e9548501dccfde4e2ba249a5bd..0458baf3ef46a0b9d9894ae87cbc6d395ffc2f98 100644
--- a/webrtc/p2p/base/p2ptransportchannel.cc
+++ b/webrtc/p2p/base/p2ptransportchannel.cc
@@ -1306,34 +1306,35 @@ void P2PTransportChannel::SortConnectionsAndUpdateState() {
}
void P2PTransportChannel::PruneConnections() {
- // We can prune any connection for which there is a connected, writable
- // connection on the same network with better or equal priority. We leave
- // those with better priority just in case they become writable later (at
- // which point, we would prune out the current selected connection). We leave
- // connections on other networks because they may not be using the same
- // resources and they may represent very distinct paths over which we can
- // switch. If the |premier| connection is not connected, we may be
- // reconnecting a TCP connection and temporarily do not prune connections in
- // this network. See the big comment in CompareConnectionStates.
-
- // Get a list of the networks that we are using.
- std::set<rtc::Network*> networks;
- for (const Connection* conn : connections_) {
- networks.insert(conn->port()->Network());
- }
- for (rtc::Network* network : networks) {
- Connection* premier = GetBestConnectionOnNetwork(network);
- // Do not prune connections if the current selected connection is weak on
- // this network. Otherwise, it may delete connections prematurely.
- if (!premier || premier->weak()) {
- continue;
- }
-
- for (Connection* conn : connections_) {
- if ((conn != premier) && (conn->port()->Network() == network) &&
- (CompareConnectionCandidates(premier, conn) >= 0)) {
- conn->Prune();
- }
+ // We can prune any connection for which there is a connected, writable,
+ // and receiving connection with the same network name with better or equal
+ // priority. We leave those with better priority just in case they become
+ // writable later (at which point, we would prune out the current selected
+ // connection). We leave connections on other networks because they may not
+ // be using the same resources and they may represent very distinct paths
+ // over which we can switch. If the |premier| connection is not connected,
+ // we may be reconnecting a TCP connection and temporarily do not prune
+ // connections in this network. See the big comment in
+ // CompareConnectionStates.
+
+ std::map<std::string, Connection*> premier_connection_by_network_name;
+ if (selected_connection_) {
+ // |selected_connection_| is always a premier connection.
+ const std::string& network_name =
+ selected_connection_->port()->Network()->name();
+ premier_connection_by_network_name[network_name] = selected_connection_;
+ }
+ for (Connection* conn : connections_) {
+ const std::string& network_name = conn->port()->Network()->name();
+ Connection* premier = premier_connection_by_network_name[network_name];
+ // Since the connections are sorted, the first one with a given network name
+ // is the premier connection for the network name.
+ // |premier| might be equal to |conn| if this is the selected connection.
+ if (premier == nullptr) {
+ premier_connection_by_network_name[network_name] = conn;
+ } else if (premier != conn && !premier->weak() &&
+ CompareConnectionCandidates(premier, conn) >= 0) {
+ conn->Prune();
}
}
}
@@ -1471,26 +1472,6 @@ bool P2PTransportChannel::ReadyToSend(Connection* connection) const {
PresumedWritable(connection));
}
-// If we have a selected connection, return it, otherwise return top one in the
-// list (later we will mark it best).
-Connection* P2PTransportChannel::GetBestConnectionOnNetwork(
- rtc::Network* network) const {
- // If the selected connection is on this network, then it wins.
- if (selected_connection_ &&
- (selected_connection_->port()->Network() == network)) {
- return selected_connection_;
- }
-
- // Otherwise, we return the top-most in sorted order.
- for (size_t i = 0; i < connections_.size(); ++i) {
- if (connections_[i]->port()->Network() == network) {
- return connections_[i];
- }
- }
-
- return NULL;
-}
-
// Handle any queued up requests
void P2PTransportChannel::OnMessage(rtc::Message *pmsg) {
switch (pmsg->message_id) {

Powered by Google App Engine
This is Rietveld 408576698