OLD | NEW |
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 Loading... |
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()); | |
283 ports_.clear(); | 282 ports_.clear(); |
284 | 283 |
285 allocator_sessions_.push_back(std::move(session)); | 284 allocator_sessions_.push_back(std::move(session)); |
286 } | 285 } |
287 | 286 |
288 void P2PTransportChannel::AddConnection(Connection* connection) { | 287 void P2PTransportChannel::AddConnection(Connection* connection) { |
289 connections_.push_back(connection); | 288 connections_.push_back(connection); |
290 unpinged_connections_.insert(connection); | 289 unpinged_connections_.insert(connection); |
291 connection->set_remote_ice_mode(remote_ice_mode_); | 290 connection->set_remote_ice_mode(remote_ice_mode_); |
292 connection->set_receiving_timeout(config_.receiving_timeout); | 291 connection->set_receiving_timeout(config_.receiving_timeout); |
293 connection->SignalReadPacket.connect( | 292 connection->SignalReadPacket.connect( |
294 this, &P2PTransportChannel::OnReadPacket); | 293 this, &P2PTransportChannel::OnReadPacket); |
295 connection->SignalReadyToSend.connect( | 294 connection->SignalReadyToSend.connect( |
296 this, &P2PTransportChannel::OnReadyToSend); | 295 this, &P2PTransportChannel::OnReadyToSend); |
297 connection->SignalStateChange.connect( | 296 connection->SignalStateChange.connect( |
298 this, &P2PTransportChannel::OnConnectionStateChange); | 297 this, &P2PTransportChannel::OnConnectionStateChange); |
299 connection->SignalDestroyed.connect( | 298 connection->SignalDestroyed.connect( |
300 this, &P2PTransportChannel::OnConnectionDestroyed); | 299 this, &P2PTransportChannel::OnConnectionDestroyed); |
301 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated); | 300 connection->SignalNominated.connect(this, &P2PTransportChannel::OnNominated); |
302 had_connection_ = true; | 301 had_connection_ = true; |
303 } | 302 } |
304 | 303 |
305 void P2PTransportChannel::SetIceRole(IceRole ice_role) { | 304 void P2PTransportChannel::SetIceRole(IceRole ice_role) { |
306 ASSERT(worker_thread_ == rtc::Thread::Current()); | 305 ASSERT(worker_thread_ == rtc::Thread::Current()); |
307 if (ice_role_ != ice_role) { | 306 if (ice_role_ != ice_role) { |
308 ice_role_ = ice_role; | 307 ice_role_ = ice_role; |
309 for (PortInterface* port : ports_) { | 308 for (std::vector<PortInterface *>::iterator it = ports_.begin(); |
310 port->SetIceRole(ice_role); | 309 it != ports_.end(); ++it) { |
311 } | 310 (*it)->SetIceRole(ice_role); |
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); | |
316 } | 311 } |
317 } | 312 } |
318 } | 313 } |
319 | 314 |
320 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { | 315 void P2PTransportChannel::SetIceTiebreaker(uint64_t tiebreaker) { |
321 ASSERT(worker_thread_ == rtc::Thread::Current()); | 316 ASSERT(worker_thread_ == rtc::Thread::Current()); |
322 if (!ports_.empty() || !removed_ports_.empty()) { | 317 if (!ports_.empty()) { |
323 LOG(LS_ERROR) | 318 LOG(LS_ERROR) |
324 << "Attempt to change tiebreaker after Port has been allocated."; | 319 << "Attempt to change tiebreaker after Port has been allocated."; |
325 return; | 320 return; |
326 } | 321 } |
327 | 322 |
328 tiebreaker_ = tiebreaker; | 323 tiebreaker_ = tiebreaker; |
329 } | 324 } |
330 | 325 |
331 TransportChannelState P2PTransportChannel::GetState() const { | 326 TransportChannelState P2PTransportChannel::GetState() const { |
332 return state_; | 327 return state_; |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 ASSERT(worker_thread_ == rtc::Thread::Current()); | 960 ASSERT(worker_thread_ == rtc::Thread::Current()); |
966 OptionMap::iterator it = options_.find(opt); | 961 OptionMap::iterator it = options_.find(opt); |
967 if (it == options_.end()) { | 962 if (it == options_.end()) { |
968 options_.insert(std::make_pair(opt, value)); | 963 options_.insert(std::make_pair(opt, value)); |
969 } else if (it->second == value) { | 964 } else if (it->second == value) { |
970 return 0; | 965 return 0; |
971 } else { | 966 } else { |
972 it->second = value; | 967 it->second = value; |
973 } | 968 } |
974 | 969 |
975 for (PortInterface* port : ports_) { | 970 for (size_t i = 0; i < ports_.size(); ++i) { |
976 int val = port->SetOption(opt, value); | 971 int val = ports_[i]->SetOption(opt, value); |
977 if (val < 0) { | 972 if (val < 0) { |
978 // Because this also occurs deferred, probably no point in reporting an | 973 // Because this also occurs deferred, probably no point in reporting an |
979 // error | 974 // error |
980 LOG(WARNING) << "SetOption(" << opt << ", " << value | 975 LOG(WARNING) << "SetOption(" << opt << ", " << value << ") failed: " |
981 << ") failed: " << port->GetError(); | 976 << ports_[i]->GetError(); |
982 } | 977 } |
983 } | 978 } |
984 return 0; | 979 return 0; |
985 } | 980 } |
986 | 981 |
987 bool P2PTransportChannel::GetOption(rtc::Socket::Option opt, int* value) { | 982 bool P2PTransportChannel::GetOption(rtc::Socket::Option opt, int* value) { |
988 ASSERT(worker_thread_ == rtc::Thread::Current()); | 983 ASSERT(worker_thread_ == rtc::Thread::Current()); |
989 | 984 |
990 const auto& found = options_.find(opt); | 985 const auto& found = options_.find(opt); |
991 if (found == options_.end()) { | 986 if (found == options_.end()) { |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 | 1506 |
1512 UpdateState(); | 1507 UpdateState(); |
1513 } | 1508 } |
1514 | 1509 |
1515 // When a port is destroyed remove it from our list of ports to use for | 1510 // When a port is destroyed remove it from our list of ports to use for |
1516 // connection attempts. | 1511 // connection attempts. |
1517 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { | 1512 void P2PTransportChannel::OnPortDestroyed(PortInterface* port) { |
1518 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1513 ASSERT(worker_thread_ == rtc::Thread::Current()); |
1519 | 1514 |
1520 // Remove this port from the list (if we didn't drop it already). | 1515 // Remove this port from the list (if we didn't drop it already). |
1521 ports_.erase(std::remove(ports_.begin(), ports_.end(), port)); | 1516 std::vector<PortInterface*>::iterator iter = |
1522 removed_ports_.erase( | 1517 std::find(ports_.begin(), ports_.end(), port); |
1523 std::remove(removed_ports_.begin(), removed_ports_.end(), port)); | 1518 if (iter != ports_.end()) |
| 1519 ports_.erase(iter); |
1524 | 1520 |
1525 LOG(INFO) << "Removed port from p2p socket: " | 1521 LOG(INFO) << "Removed port from p2p socket: " |
1526 << static_cast<int>(ports_.size()) << " remaining"; | 1522 << static_cast<int>(ports_.size()) << " remaining"; |
1527 } | 1523 } |
1528 | 1524 |
1529 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { | 1525 void P2PTransportChannel::OnPortNetworkInactive(PortInterface* port) { |
1530 // If it does not gather continually, the port will be removed from the list | 1526 // If it does not gather continually, the port will be removed from the list |
1531 // when ICE restarts. | 1527 // when ICE restarts. |
1532 if (!config_.gather_continually) { | 1528 if (!config_.gather_continually) { |
1533 return; | 1529 return; |
1534 } | 1530 } |
1535 auto it = std::find(ports_.begin(), ports_.end(), port); | 1531 auto it = std::find(ports_.begin(), ports_.end(), port); |
1536 // Don't need to do anything if the port has been deleted from the port list. | 1532 // Don't need to do anything if the port has been deleted from the port list. |
1537 if (it == ports_.end()) { | 1533 if (it == ports_.end()) { |
1538 return; | 1534 return; |
1539 } | 1535 } |
1540 removed_ports_.push_back(*it); | |
1541 ports_.erase(it); | 1536 ports_.erase(it); |
1542 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() | 1537 LOG(INFO) << "Removed port due to inactive networks: " << ports_.size() |
1543 << " remaining"; | 1538 << " remaining"; |
1544 std::vector<Candidate> candidates = port->Candidates(); | 1539 std::vector<Candidate> candidates = port->Candidates(); |
1545 for (Candidate& candidate : candidates) { | 1540 for (Candidate& candidate : candidates) { |
1546 candidate.set_transport_name(transport_name()); | 1541 candidate.set_transport_name(transport_name()); |
1547 } | 1542 } |
1548 SignalCandidatesRemoved(this, candidates); | 1543 SignalCandidatesRemoved(this, candidates); |
1549 } | 1544 } |
1550 | 1545 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 | 1688 |
1694 // During the initial state when nothing has been pinged yet, return the first | 1689 // During the initial state when nothing has been pinged yet, return the first |
1695 // one in the ordered |connections_|. | 1690 // one in the ordered |connections_|. |
1696 return *(std::find_if(connections_.begin(), connections_.end(), | 1691 return *(std::find_if(connections_.begin(), connections_.end(), |
1697 [conn1, conn2](Connection* conn) { | 1692 [conn1, conn2](Connection* conn) { |
1698 return conn == conn1 || conn == conn2; | 1693 return conn == conn1 || conn == conn2; |
1699 })); | 1694 })); |
1700 } | 1695 } |
1701 | 1696 |
1702 } // namespace cricket | 1697 } // namespace cricket |
OLD | NEW |