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

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: 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
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 ports_.clear(); 282 inactive_ports_.insert(inactive_ports_.end(), active_ports_.begin(),
283 active_ports_.end());
284 active_ports_.clear();
283 285
284 allocator_sessions_.push_back(std::move(session)); 286 allocator_sessions_.push_back(std::move(session));
285 } 287 }
286 288
287 void P2PTransportChannel::AddConnection(Connection* connection) { 289 void P2PTransportChannel::AddConnection(Connection* connection) {
288 connections_.push_back(connection); 290 connections_.push_back(connection);
289 unpinged_connections_.insert(connection); 291 unpinged_connections_.insert(connection);
290 connection->set_remote_ice_mode(remote_ice_mode_); 292 connection->set_remote_ice_mode(remote_ice_mode_);
291 connection->set_receiving_timeout(config_.receiving_timeout); 293 connection->set_receiving_timeout(config_.receiving_timeout);
292 connection->SignalReadPacket.connect( 294 connection->SignalReadPacket.connect(
293 this, &P2PTransportChannel::OnReadPacket); 295 this, &P2PTransportChannel::OnReadPacket);
294 connection->SignalReadyToSend.connect( 296 connection->SignalReadyToSend.connect(
295 this, &P2PTransportChannel::OnReadyToSend); 297 this, &P2PTransportChannel::OnReadyToSend);
296 connection->SignalStateChange.connect( 298 connection->SignalStateChange.connect(
297 this, &P2PTransportChannel::OnConnectionStateChange); 299 this, &P2PTransportChannel::OnConnectionStateChange);
298 connection->SignalDestroyed.connect( 300 connection->SignalDestroyed.connect(
299 this, &P2PTransportChannel::OnConnectionDestroyed); 301 this, &P2PTransportChannel::OnConnectionDestroyed);
300 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated); 302 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated);
301 had_connection_ = true; 303 had_connection_ = true;
302 } 304 }
303 305
304 void P2PTransportChannel::SetIceRole(IceRole ice_role) { 306 void P2PTransportChannel::SetIceRole(IceRole ice_role) {
305 ASSERT(worker_thread_ == rtc::Thread::Current()); 307 ASSERT(worker_thread_ == rtc::Thread::Current());
306 if (ice_role_ != ice_role) { 308 if (ice_role_ != ice_role) {
307 ice_role_ = ice_role; 309 ice_role_ = ice_role;
308 for (std::vector<PortInterface *>::iterator it = ports_.begin(); 310 for (PortInterface* port : active_ports_) {
309 it != ports_.end(); ++it) { 311 port->SetIceRole(ice_role);
310 (*it)->SetIceRole(ice_role); 312 }
313 for (PortInterface* port : inactive_ports_) {
314 port->SetIceRole(ice_role);
311 } 315 }
312 } 316 }
313 } 317 }
314 318
315 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { 319 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) {
316 ASSERT(worker_thread_ == rtc::Thread::Current()); 320 ASSERT(worker_thread_ == rtc::Thread::Current());
317 if (!ports_.empty()) { 321 if (!active_ports_.empty() || !inactive_ports_.empty()) {
318 LOG(LS_ERROR) 322 LOG(LS_ERROR)
319 << "Attempt to change tiebreaker after Port has been allocated."; 323 << "Attempt to change tiebreaker after Port has been allocated.";
320 return; 324 return;
321 } 325 }
322 326
323 tiebreaker_ = tiebreaker; 327 tiebreaker_ = tiebreaker;
324 } 328 }
325 329
326 TransportChannelState P2PTransportChannel::GetState() const { 330 TransportChannelState P2PTransportChannel::GetState() const {
327 return state_; 331 return state_;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 << ") failed: " << port->GetError(); 513 << ") failed: " << port->GetError();
510 } 514 }
511 } 515 }
512 516
513 // Remember the ports and candidates, and signal that candidates are ready. 517 // Remember the ports and candidates, and signal that candidates are ready.
514 // The session will handle this, and send an initiate/accept/modify message 518 // The session will handle this, and send an initiate/accept/modify message
515 // if one is pending. 519 // if one is pending.
516 520
517 port->SetIceRole(ice_role_); 521 port->SetIceRole(ice_role_);
518 port->SetIceTiebreaker(tiebreaker_); 522 port->SetIceTiebreaker(tiebreaker_);
519 ports_.push_back(port); 523 active_ports_.push_back(port);
520 port->SignalUnknownAddress.connect( 524 port->SignalUnknownAddress.connect(
521 this, &P2PTransportChannel::OnUnknownAddress); 525 this, &P2PTransportChannel::OnUnknownAddress);
522 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); 526 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed);
523 port->SignalNetworkInactive.connect( 527 port->SignalNetworkInactive.connect(
524 this, &P2PTransportChannel::OnPortNetworkInactive); 528 this, &P2PTransportChannel::OnPortNetworkInactive);
525 port->SignalRoleConflict.connect( 529 port->SignalRoleConflict.connect(
526 this, &P2PTransportChannel::OnRoleConflict); 530 this, &P2PTransportChannel::OnRoleConflict);
527 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); 531 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket);
528 532
529 // Attempt to create a connection from this new port to all of the remote 533 // Attempt to create a connection from this new port to all of the remote
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 return true; 824 return true;
821 } 825 }
822 826
823 // Add a new connection for this candidate to every port that allows such a 827 // Add a new connection for this candidate to every port that allows such a
824 // connection (i.e., if they have compatible protocols) and that does not 828 // connection (i.e., if they have compatible protocols) and that does not
825 // already have a connection to an equivalent candidate. We must be careful 829 // already have a connection to an equivalent candidate. We must be careful
826 // to make sure that the origin port is included, even if it was pruned, 830 // to make sure that the origin port is included, even if it was pruned,
827 // since that may be the only port that can create this connection. 831 // since that may be the only port that can create this connection.
828 bool created = false; 832 bool created = false;
829 std::vector<PortInterface *>::reverse_iterator it; 833 std::vector<PortInterface *>::reverse_iterator it;
830 for (it = ports_.rbegin(); it != ports_.rend(); ++it) { 834 for (it = active_ports_.rbegin(); it != active_ports_.rend(); ++it) {
831 if (CreateConnection(*it, remote_candidate, origin_port)) { 835 if (CreateConnection(*it, remote_candidate, origin_port)) {
832 if (*it == origin_port) 836 if (*it == origin_port)
833 created = true; 837 created = true;
834 } 838 }
835 } 839 }
836 840
837 if ((origin_port != NULL) && 841 if ((origin_port != NULL) &&
838 std::find(ports_.begin(), ports_.end(), origin_port) == ports_.end()) { 842 std::find(active_ports_.begin(), active_ports_.end(), origin_port) ==
843 active_ports_.end()) {
839 if (CreateConnection(origin_port, remote_candidate, origin_port)) 844 if (CreateConnection(origin_port, remote_candidate, origin_port))
840 created = true; 845 created = true;
841 } 846 }
842 847
843 // Remember this remote candidate so that we can add it to future ports. 848 // Remember this remote candidate so that we can add it to future ports.
844 RememberRemoteCandidate(remote_candidate, origin_port); 849 RememberRemoteCandidate(remote_candidate, origin_port);
845 850
846 return created; 851 return created;
847 } 852 }
848 853
(...skipping 111 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 : active_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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 list (if we didn't drop it already).
1516 std::vector<PortInterface*>::iterator iter = 1521 active_ports_.erase(
1517 std::find(ports_.begin(), ports_.end(), port); 1522 std::remove(active_ports_.begin(), active_ports_.end(), port));
1518 if (iter != ports_.end()) 1523 inactive_ports_.erase(
1519 ports_.erase(iter); 1524 std::remove(inactive_ports_.begin(), inactive_ports_.end(), port));
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>(active_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(active_ports_.begin(), active_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 == active_ports_.end()) {
1534 return; 1539 return;
1535 } 1540 }
1536 ports_.erase(it); 1541 inactive_ports_.push_back(*it);
1537 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() 1542 active_ports_.erase(it);
1543 LOG(INFO) << "Removed port due to inactive networks: " << active_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
1546 // We data is available, let listeners know 1552 // We data is available, let listeners know
1547 void P2PTransportChannel::OnReadPacket(Connection* connection, 1553 void P2PTransportChannel::OnReadPacket(Connection* connection,
(...skipping 140 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
« webrtc/p2p/base/p2ptransportchannel.h ('K') | « webrtc/p2p/base/p2ptransportchannel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698