Index: webrtc/p2p/base/p2ptransportchannel.cc |
diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc |
index fc1f0a4e6769ee96ce28f851d0f7cbc368fbf69c..f0e440c19300ede7e6754270b1d8b95c0dbff7ee 100644 |
--- a/webrtc/p2p/base/p2ptransportchannel.cc |
+++ b/webrtc/p2p/base/p2ptransportchannel.cc |
@@ -279,7 +279,9 @@ void P2PTransportChannel::AddAllocatorSession( |
// 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. |
- ports_.clear(); |
+ inactive_ports_.insert(inactive_ports_.end(), active_ports_.begin(), |
+ active_ports_.end()); |
+ active_ports_.clear(); |
allocator_sessions_.push_back(std::move(session)); |
} |
@@ -305,16 +307,18 @@ void P2PTransportChannel::SetIceRole(IceRole ice_role) { |
ASSERT(worker_thread_ == rtc::Thread::Current()); |
if (ice_role_ != ice_role) { |
ice_role_ = ice_role; |
- for (std::vector<PortInterface *>::iterator it = ports_.begin(); |
- it != ports_.end(); ++it) { |
- (*it)->SetIceRole(ice_role); |
+ for (PortInterface* port : active_ports_) { |
+ port->SetIceRole(ice_role); |
+ } |
+ for (PortInterface* port : inactive_ports_) { |
+ port->SetIceRole(ice_role); |
} |
} |
} |
void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { |
ASSERT(worker_thread_ == rtc::Thread::Current()); |
- if (!ports_.empty()) { |
+ if (!active_ports_.empty() || !inactive_ports_.empty()) { |
LOG(LS_ERROR) |
<< "Attempt to change tiebreaker after Port has been allocated."; |
return; |
@@ -516,7 +520,7 @@ void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, |
port->SetIceRole(ice_role_); |
port->SetIceTiebreaker(tiebreaker_); |
- ports_.push_back(port); |
+ active_ports_.push_back(port); |
port->SignalUnknownAddress.connect( |
this, &P2PTransportChannel::OnUnknownAddress); |
port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); |
@@ -827,7 +831,7 @@ bool P2PTransportChannel::CreateConnections(const Candidate& remote_candidate, |
// since that may be the only port that can create this connection. |
bool created = false; |
std::vector<PortInterface *>::reverse_iterator it; |
- for (it = ports_.rbegin(); it != ports_.rend(); ++it) { |
+ for (it = active_ports_.rbegin(); it != active_ports_.rend(); ++it) { |
if (CreateConnection(*it, remote_candidate, origin_port)) { |
if (*it == origin_port) |
created = true; |
@@ -835,7 +839,8 @@ bool P2PTransportChannel::CreateConnections(const Candidate& remote_candidate, |
} |
if ((origin_port != NULL) && |
- std::find(ports_.begin(), ports_.end(), origin_port) == ports_.end()) { |
+ std::find(active_ports_.begin(), active_ports_.end(), origin_port) == |
+ active_ports_.end()) { |
if (CreateConnection(origin_port, remote_candidate, origin_port)) |
created = true; |
} |
@@ -967,13 +972,13 @@ int P2PTransportChannel::SetOption(rtc::Socket::Option opt, int value) { |
it->second = value; |
} |
- for (size_t i = 0; i < ports_.size(); ++i) { |
- int val = ports_[i]->SetOption(opt, value); |
+ for (PortInterface* port : active_ports_) { |
+ int val = port->SetOption(opt, value); |
if (val < 0) { |
// Because this also occurs deferred, probably no point in reporting an |
// error |
- LOG(WARNING) << "SetOption(" << opt << ", " << value << ") failed: " |
- << ports_[i]->GetError(); |
+ LOG(WARNING) << "SetOption(" << opt << ", " << value |
+ << ") failed: " << port->GetError(); |
} |
} |
return 0; |
@@ -1513,13 +1518,13 @@ void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { |
ASSERT(worker_thread_ == rtc::Thread::Current()); |
// Remove this port from the list (if we didn't drop it already). |
- std::vector<PortInterface*>::iterator iter = |
- std::find(ports_.begin(), ports_.end(), port); |
- if (iter != ports_.end()) |
- ports_.erase(iter); |
+ active_ports_.erase( |
+ std::remove(active_ports_.begin(), active_ports_.end(), port)); |
+ inactive_ports_.erase( |
+ std::remove(inactive_ports_.begin(), inactive_ports_.end(), port)); |
LOG(INFO) << "Removed port from p2p socket: " |
- << static_cast<int>(ports_.size()) << " remaining"; |
+ << static_cast<int>(active_ports_.size()) << " remaining"; |
} |
void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { |
@@ -1528,13 +1533,14 @@ void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { |
if (!config_.gather_continually) { |
return; |
} |
- auto it = std::find(ports_.begin(), ports_.end(), port); |
+ auto it = std::find(active_ports_.begin(), active_ports_.end(), port); |
// Don't need to do anything if the port has been deleted from the port list. |
- if (it == ports_.end()) { |
+ if (it == active_ports_.end()) { |
return; |
} |
- ports_.erase(it); |
- LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() |
+ inactive_ports_.push_back(*it); |
+ active_ports_.erase(it); |
+ LOG(INFO) << "Removed port due to inactive networks: " << active_ports_.size() |
<< " remaining"; |
std::vector<Candidate> candidates = port->Candidates(); |
for (Candidate& candidate : candidates) { |