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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel.cc

Issue 2053043003: Update ICE role on all ports, not just ones used for new connections. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing issue with call to `erase`. Adding test for port destruction. Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); 272 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size()));
273 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); 273 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady);
274 session->SignalCandidatesReady.connect( 274 session->SignalCandidatesReady.connect(
275 this, &P2PTransportChannel::OnCandidatesReady); 275 this, &P2PTransportChannel::OnCandidatesReady);
276 session->SignalCandidatesAllocationDone.connect( 276 session->SignalCandidatesAllocationDone.connect(
277 this, &P2PTransportChannel::OnCandidatesAllocationDone); 277 this, &P2PTransportChannel::OnCandidatesAllocationDone);
278 278
279 // We now only want to apply new candidates that we receive to the ports 279 // We now only want to apply new candidates that we receive to the ports
280 // created by this new session because these are replacing those of the 280 // created by this new session because these are replacing those of the
281 // previous sessions. 281 // previous sessions.
282 removed_ports_.insert(removed_ports_.end(), ports_.begin(), ports_.end());
282 ports_.clear(); 283 ports_.clear();
283 284
284 allocator_sessions_.push_back(std::move(session)); 285 allocator_sessions_.push_back(std::move(session));
285 } 286 }
286 287
287 void P2PTransportChannel::AddConnection(Connection* connection) { 288 void P2PTransportChannel::AddConnection(Connection* connection) {
288 connections_.push_back(connection); 289 connections_.push_back(connection);
289 unpinged_connections_.insert(connection); 290 unpinged_connections_.insert(connection);
290 connection->set_remote_ice_mode(remote_ice_mode_); 291 connection->set_remote_ice_mode(remote_ice_mode_);
291 connection->set_receiving_timeout(config_.receiving_timeout); 292 connection->set_receiving_timeout(config_.receiving_timeout);
292 connection->SignalReadPacket.connect( 293 connection->SignalReadPacket.connect(
293 this, &P2PTransportChannel::OnReadPacket); 294 this, &P2PTransportChannel::OnReadPacket);
294 connection->SignalReadyToSend.connect( 295 connection->SignalReadyToSend.connect(
295 this, &P2PTransportChannel::OnReadyToSend); 296 this, &P2PTransportChannel::OnReadyToSend);
296 connection->SignalStateChange.connect( 297 connection->SignalStateChange.connect(
297 this, &P2PTransportChannel::OnConnectionStateChange); 298 this, &P2PTransportChannel::OnConnectionStateChange);
298 connection->SignalDestroyed.connect( 299 connection->SignalDestroyed.connect(
299 this, &P2PTransportChannel::OnConnectionDestroyed); 300 this, &P2PTransportChannel::OnConnectionDestroyed);
300 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated); 301 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated);
301 had_connection_ = true; 302 had_connection_ = true;
302 } 303 }
303 304
304 void P2PTransportChannel::SetIceRole(IceRole ice_role) { 305 void P2PTransportChannel::SetIceRole(IceRole ice_role) {
305 ASSERT(worker_thread_ == rtc::Thread::Current()); 306 ASSERT(worker_thread_ == rtc::Thread::Current());
306 if (ice_role_ != ice_role) { 307 if (ice_role_ != ice_role) {
307 ice_role_ = ice_role; 308 ice_role_ = ice_role;
308 for (std::vector<PortInterface *>::iterator it = ports_.begin(); 309 for (PortInterface* port : ports_) {
309 it != ports_.end(); ++it) { 310 port->SetIceRole(ice_role);
310 (*it)->SetIceRole(ice_role); 311 }
312 // Update role on removed ports as well, because they may still have
313 // connections alive that should be using the correct role.
314 for (PortInterface* port : removed_ports_) {
315 port->SetIceRole(ice_role);
311 } 316 }
312 } 317 }
313 } 318 }
314 319
315 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { 320 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) {
316 ASSERT(worker_thread_ == rtc::Thread::Current()); 321 ASSERT(worker_thread_ == rtc::Thread::Current());
317 if (!ports_.empty()) { 322 if (!ports_.empty() || !removed_ports_.empty()) {
318 LOG(LS_ERROR) 323 LOG(LS_ERROR)
319 << "Attempt to change tiebreaker after Port has been allocated."; 324 << "Attempt to change tiebreaker after Port has been allocated.";
320 return; 325 return;
321 } 326 }
322 327
323 tiebreaker_ = tiebreaker; 328 tiebreaker_ = tiebreaker;
324 } 329 }
325 330
326 TransportChannelState P2PTransportChannel::GetState() const { 331 TransportChannelState P2PTransportChannel::GetState() const {
327 return state_; 332 return state_;
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 ASSERT(worker_thread_ == rtc::Thread::Current()); 965 ASSERT(worker_thread_ == rtc::Thread::Current());
961 OptionMap::iterator it = options_.find(opt); 966 OptionMap::iterator it = options_.find(opt);
962 if (it == options_.end()) { 967 if (it == options_.end()) {
963 options_.insert(std::make_pair(opt, value)); 968 options_.insert(std::make_pair(opt, value));
964 } else if (it->second == value) { 969 } else if (it->second == value) {
965 return 0; 970 return 0;
966 } else { 971 } else {
967 it->second = value; 972 it->second = value;
968 } 973 }
969 974
970 for (size_t i = 0; i < ports_.size(); ++i) { 975 for (PortInterface* port : ports_) {
971 int val = ports_[i]->SetOption(opt, value); 976 int val = port->SetOption(opt, value);
972 if (val < 0) { 977 if (val < 0) {
973 // Because this also occurs deferred, probably no point in reporting an 978 // Because this also occurs deferred, probably no point in reporting an
974 // error 979 // error
975 LOG(WARNING) << "SetOption(" << opt << ", " << value << ") failed: " 980 LOG(WARNING) << "SetOption(" << opt << ", " << value
976 << ports_[i]->GetError(); 981 << ") failed: " << port->GetError();
977 } 982 }
978 } 983 }
979 return 0; 984 return 0;
980 } 985 }
981 986
982 bool P2PTransportChannel::GetOption(rtc::Socket::Option opt, int* value) { 987 bool P2PTransportChannel::GetOption(rtc::Socket::Option opt, int* value) {
983 ASSERT(worker_thread_ == rtc::Thread::Current()); 988 ASSERT(worker_thread_ == rtc::Thread::Current());
984 989
985 const auto& found = options_.find(opt); 990 const auto& found = options_.find(opt);
986 if (found == options_.end()) { 991 if (found == options_.end()) {
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 } 1510 }
1506 1511
1507 UpdateState(); 1512 UpdateState();
1508 } 1513 }
1509 1514
1510 // When a port is destroyed remove it from our list of ports to use for 1515 // When a port is destroyed remove it from our list of ports to use for
1511 // connection attempts. 1516 // connection attempts.
1512 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { 1517 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) {
1513 ASSERT(worker_thread_ == rtc::Thread::Current()); 1518 ASSERT(worker_thread_ == rtc::Thread::Current());
1514 1519
1515 // Remove this port from the list (if we didn't drop it already). 1520 // Remove this port from the lists (if we didn't drop it already).
1516 std::vector<PortInterface*>::iterator iter = 1521 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end());
1517 std::find(ports_.begin(), ports_.end(), port); 1522 removed_ports_.erase(
1518 if (iter != ports_.end()) 1523 std::remove(removed_ports_.begin(), removed_ports_.end(), port),
1519 ports_.erase(iter); 1524 removed_ports_.end());
1520 1525
1521 LOG(INFO) << "Removed port from p2p socket: " 1526 LOG(INFO) << "Removed port from p2p socket: "
1522 << static_cast<int>(ports_.size()) << " remaining"; 1527 << static_cast<int>(ports_.size()) << " remaining";
1523 } 1528 }
1524 1529
1525 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { 1530 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) {
1526 // If it does not gather continually, the port will be removed from the list 1531 // If it does not gather continually, the port will be removed from the list
1527 // when ICE restarts. 1532 // when ICE restarts.
1528 if (!config_.gather_continually) { 1533 if (!config_.gather_continually) {
1529 return; 1534 return;
1530 } 1535 }
1531 auto it = std::find(ports_.begin(), ports_.end(), port); 1536 auto it = std::find(ports_.begin(), ports_.end(), port);
1532 // Don't need to do anything if the port has been deleted from the port list. 1537 // Don't need to do anything if the port has been deleted from the port list.
1533 if (it == ports_.end()) { 1538 if (it == ports_.end()) {
1534 return; 1539 return;
1535 } 1540 }
1541 removed_ports_.push_back(*it);
1536 ports_.erase(it); 1542 ports_.erase(it);
1537 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() 1543 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size()
1538 << " remaining"; 1544 << " remaining";
1539 std::vector<Candidate> candidates = port->Candidates(); 1545 std::vector<Candidate> candidates = port->Candidates();
1540 for (Candidate& candidate : candidates) { 1546 for (Candidate& candidate : candidates) {
1541 candidate.set_transport_name(transport_name()); 1547 candidate.set_transport_name(transport_name());
1542 } 1548 }
1543 SignalCandidatesRemoved(this, candidates); 1549 SignalCandidatesRemoved(this, candidates);
1544 } 1550 }
1545 1551
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 1694
1689 // During the initial state when nothing has been pinged yet, return the first 1695 // During the initial state when nothing has been pinged yet, return the first
1690 // one in the ordered |connections_|. 1696 // one in the ordered |connections_|.
1691 return *(std::find_if(connections_.begin(), connections_.end(), 1697 return *(std::find_if(connections_.begin(), connections_.end(),
1692 [conn1, conn2](Connection* conn) { 1698 [conn1, conn2](Connection* conn) {
1693 return conn == conn1 || conn == conn2; 1699 return conn == conn1 || conn == conn2;
1694 })); 1700 }));
1695 } 1701 }
1696 1702
1697 } // namespace cricket 1703 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698