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

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: Renaming variables, adding tests. 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 for (PortInterface* port : removed_ports_) {
313 port->SetIceRole(ice_role);
pthatcher1 2016/06/16 22:36:23 Maybe add a comment of why we set the ICE role of
311 } 314 }
312 } 315 }
313 } 316 }
314 317
315 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { 318 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) {
316 ASSERT(worker_thread_ == rtc::Thread::Current()); 319 ASSERT(worker_thread_ == rtc::Thread::Current());
317 if (!ports_.empty()) { 320 if (!ports_.empty() || !removed_ports_.empty()) {
318 LOG(LS_ERROR) 321 LOG(LS_ERROR)
319 << "Attempt to change tiebreaker after Port has been allocated."; 322 << "Attempt to change tiebreaker after Port has been allocated.";
320 return; 323 return;
321 } 324 }
322 325
323 tiebreaker_ = tiebreaker; 326 tiebreaker_ = tiebreaker;
324 } 327 }
325 328
326 TransportChannelState P2PTransportChannel::GetState() const { 329 TransportChannelState P2PTransportChannel::GetState() const {
327 return state_; 330 return state_;
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 ASSERT(worker_thread_ == rtc::Thread::Current()); 963 ASSERT(worker_thread_ == rtc::Thread::Current());
961 OptionMap::iterator it = options_.find(opt); 964 OptionMap::iterator it = options_.find(opt);
962 if (it == options_.end()) { 965 if (it == options_.end()) {
963 options_.insert(std::make_pair(opt, value)); 966 options_.insert(std::make_pair(opt, value));
964 } else if (it->second == value) { 967 } else if (it->second == value) {
965 return 0; 968 return 0;
966 } else { 969 } else {
967 it->second = value; 970 it->second = value;
968 } 971 }
969 972
970 for (size_t i = 0; i < ports_.size(); ++i) { 973 for (PortInterface* port : ports_) {
971 int val = ports_[i]->SetOption(opt, value); 974 int val = port->SetOption(opt, value);
972 if (val < 0) { 975 if (val < 0) {
973 // Because this also occurs deferred, probably no point in reporting an 976 // Because this also occurs deferred, probably no point in reporting an
974 // error 977 // error
975 LOG(WARNING) << "SetOption(" << opt << ", " << value << ") failed: " 978 LOG(WARNING) << "SetOption(" << opt << ", " << value
976 << ports_[i]->GetError(); 979 << ") failed: " << port->GetError();
977 } 980 }
978 } 981 }
979 return 0; 982 return 0;
980 } 983 }
981 984
982 bool P2PTransportChannel::GetOption(rtc::Socket::Option opt, int* value) { 985 bool P2PTransportChannel::GetOption(rtc::Socket::Option opt, int* value) {
983 ASSERT(worker_thread_ == rtc::Thread::Current()); 986 ASSERT(worker_thread_ == rtc::Thread::Current());
984 987
985 const auto& found = options_.find(opt); 988 const auto& found = options_.find(opt);
986 if (found == options_.end()) { 989 if (found == options_.end()) {
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 1509
1507 UpdateState(); 1510 UpdateState();
1508 } 1511 }
1509 1512
1510 // When a port is destroyed remove it from our list of ports to use for 1513 // When a port is destroyed remove it from our list of ports to use for
1511 // connection attempts. 1514 // connection attempts.
1512 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { 1515 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) {
1513 ASSERT(worker_thread_ == rtc::Thread::Current()); 1516 ASSERT(worker_thread_ == rtc::Thread::Current());
1514 1517
1515 // Remove this port from the list (if we didn't drop it already). 1518 // Remove this port from the list (if we didn't drop it already).
1516 std::vector<PortInterface*>::iterator iter = 1519 ports_.erase(std::remove(ports_.begin(), ports_.end(), port));
1517 std::find(ports_.begin(), ports_.end(), port); 1520 removed_ports_.erase(
1518 if (iter != ports_.end()) 1521 std::remove(removed_ports_.begin(), removed_ports_.end(), port));
1519 ports_.erase(iter);
1520 1522
1521 LOG(INFO) << "Removed port from p2p socket: " 1523 LOG(INFO) << "Removed port from p2p socket: "
1522 << static_cast<int>(ports_.size()) << " remaining"; 1524 << static_cast<int>(ports_.size()) << " remaining";
1523 } 1525 }
1524 1526
1525 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { 1527 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) {
1526 // If it does not gather continually, the port will be removed from the list 1528 // If it does not gather continually, the port will be removed from the list
1527 // when ICE restarts. 1529 // when ICE restarts.
1528 if (!config_.gather_continually) { 1530 if (!config_.gather_continually) {
1529 return; 1531 return;
1530 } 1532 }
1531 auto it = std::find(ports_.begin(), ports_.end(), port); 1533 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. 1534 // Don't need to do anything if the port has been deleted from the port list.
1533 if (it == ports_.end()) { 1535 if (it == ports_.end()) {
1534 return; 1536 return;
1535 } 1537 }
1538 removed_ports_.push_back(*it);
1536 ports_.erase(it); 1539 ports_.erase(it);
1537 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() 1540 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size()
1538 << " remaining"; 1541 << " remaining";
1539 std::vector<Candidate> candidates = port->Candidates(); 1542 std::vector<Candidate> candidates = port->Candidates();
1540 for (Candidate& candidate : candidates) { 1543 for (Candidate& candidate : candidates) {
1541 candidate.set_transport_name(transport_name()); 1544 candidate.set_transport_name(transport_name());
1542 } 1545 }
1543 SignalCandidatesRemoved(this, candidates); 1546 SignalCandidatesRemoved(this, candidates);
1544 } 1547 }
1545 1548
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 1691
1689 // During the initial state when nothing has been pinged yet, return the first 1692 // During the initial state when nothing has been pinged yet, return the first
1690 // one in the ordered |connections_|. 1693 // one in the ordered |connections_|.
1691 return *(std::find_if(connections_.begin(), connections_.end(), 1694 return *(std::find_if(connections_.begin(), connections_.end(),
1692 [conn1, conn2](Connection* conn) { 1695 [conn1, conn2](Connection* conn) {
1693 return conn == conn1 || conn == conn2; 1696 return conn == conn1 || conn == conn2;
1694 })); 1697 }));
1695 } 1698 }
1696 1699
1697 } // namespace cricket 1700 } // 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