| 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 |
| 11 #include "webrtc/p2p/base/p2ptransportchannel.h" | 11 #include "webrtc/p2p/base/p2ptransportchannel.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <set> | 14 #include <set> |
| 15 #include "webrtc/p2p/base/common.h" | 15 |
| 16 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE. | |
| 17 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE. | |
| 18 #include "webrtc/base/common.h" | 16 #include "webrtc/base/common.h" |
| 19 #include "webrtc/base/crc32.h" | 17 #include "webrtc/base/crc32.h" |
| 20 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/stringencode.h" | 19 #include "webrtc/base/stringencode.h" |
| 20 #include "webrtc/p2p/base/candidate.h" |
| 21 #include "webrtc/p2p/base/common.h" |
| 22 #include "webrtc/p2p/base/relayport.h" // For RELAY_PORT_TYPE. |
| 23 #include "webrtc/p2p/base/stunport.h" // For STUN_PORT_TYPE. |
| 22 #include "webrtc/system_wrappers/include/field_trial.h" | 24 #include "webrtc/system_wrappers/include/field_trial.h" |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // messages for queuing up work for ourselves | 28 // messages for queuing up work for ourselves |
| 27 enum { MSG_SORT = 1, MSG_CHECK_AND_PING }; | 29 enum { MSG_SORT = 1, MSG_CHECK_AND_PING }; |
| 28 | 30 |
| 29 // The minimum improvement in RTT that justifies a switch. | 31 // The minimum improvement in RTT that justifies a switch. |
| 30 static const double kMinImprovement = 10; | 32 static const double kMinImprovement = 10; |
| 31 | 33 |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 // Remember the ports and candidates, and signal that candidates are ready. | 448 // Remember the ports and candidates, and signal that candidates are ready. |
| 447 // The session will handle this, and send an initiate/accept/modify message | 449 // The session will handle this, and send an initiate/accept/modify message |
| 448 // if one is pending. | 450 // if one is pending. |
| 449 | 451 |
| 450 port->SetIceRole(ice_role_); | 452 port->SetIceRole(ice_role_); |
| 451 port->SetIceTiebreaker(tiebreaker_); | 453 port->SetIceTiebreaker(tiebreaker_); |
| 452 ports_.push_back(port); | 454 ports_.push_back(port); |
| 453 port->SignalUnknownAddress.connect( | 455 port->SignalUnknownAddress.connect( |
| 454 this, &P2PTransportChannel::OnUnknownAddress); | 456 this, &P2PTransportChannel::OnUnknownAddress); |
| 455 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); | 457 port->SignalDestroyed.connect(this, &P2PTransportChannel::OnPortDestroyed); |
| 458 port->SignalStopped.connect(this, &P2PTransportChannel::OnPortStopped); |
| 456 port->SignalRoleConflict.connect( | 459 port->SignalRoleConflict.connect( |
| 457 this, &P2PTransportChannel::OnRoleConflict); | 460 this, &P2PTransportChannel::OnRoleConflict); |
| 458 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); | 461 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); |
| 459 | 462 |
| 460 // Attempt to create a connection from this new port to all of the remote | 463 // Attempt to create a connection from this new port to all of the remote |
| 461 // candidates that we were given so far. | 464 // candidates that we were given so far. |
| 462 | 465 |
| 463 std::vector<RemoteCandidate>::iterator iter; | 466 std::vector<RemoteCandidate>::iterator iter; |
| 464 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); | 467 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); |
| 465 ++iter) { | 468 ++iter) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 } | 707 } |
| 705 } | 708 } |
| 706 | 709 |
| 707 // Create connections to this remote candidate. | 710 // Create connections to this remote candidate. |
| 708 CreateConnections(new_remote_candidate, NULL); | 711 CreateConnections(new_remote_candidate, NULL); |
| 709 | 712 |
| 710 // Resort the connections list, which may have new elements. | 713 // Resort the connections list, which may have new elements. |
| 711 SortConnections(); | 714 SortConnections(); |
| 712 } | 715 } |
| 713 | 716 |
| 717 void P2PTransportChannel::RemoveRemoteCandidate(const Candidate& target) { |
| 718 auto iter = |
| 719 std::remove_if(remote_candidates_.begin(), remote_candidates_.end(), |
| 720 [target](const Candidate& candidate) { |
| 721 return target.IsWeaklyEquivalent(candidate); |
| 722 }); |
| 723 if (iter != remote_candidates_.end()) { |
| 724 LOG(LS_VERBOSE) << "Removed remote candidate " << target.ToString(); |
| 725 remote_candidates_.erase(iter, remote_candidates_.end()); |
| 726 } |
| 727 } |
| 728 |
| 714 // Creates connections from all of the ports that we care about to the given | 729 // Creates connections from all of the ports that we care about to the given |
| 715 // remote candidate. The return value is true if we created a connection from | 730 // remote candidate. The return value is true if we created a connection from |
| 716 // the origin port. | 731 // the origin port. |
| 717 bool P2PTransportChannel::CreateConnections(const Candidate& remote_candidate, | 732 bool P2PTransportChannel::CreateConnections(const Candidate& remote_candidate, |
| 718 PortInterface* origin_port) { | 733 PortInterface* origin_port) { |
| 719 ASSERT(worker_thread_ == rtc::Thread::Current()); | 734 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 720 | 735 |
| 721 // If we've already seen the new remote candidate (in the current candidate | 736 // If we've already seen the new remote candidate (in the current candidate |
| 722 // generation), then we shouldn't try creating connections for it. | 737 // generation), then we shouldn't try creating connections for it. |
| 723 // We either already have a connection for it, or we previously created one | 738 // We either already have a connection for it, or we previously created one |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 // Remove this port from the list (if we didn't drop it already). | 1410 // Remove this port from the list (if we didn't drop it already). |
| 1396 std::vector<PortInterface*>::iterator iter = | 1411 std::vector<PortInterface*>::iterator iter = |
| 1397 std::find(ports_.begin(), ports_.end(), port); | 1412 std::find(ports_.begin(), ports_.end(), port); |
| 1398 if (iter != ports_.end()) | 1413 if (iter != ports_.end()) |
| 1399 ports_.erase(iter); | 1414 ports_.erase(iter); |
| 1400 | 1415 |
| 1401 LOG(INFO) << "Removed port from p2p socket: " | 1416 LOG(INFO) << "Removed port from p2p socket: " |
| 1402 << static_cast<int>(ports_.size()) << " remaining"; | 1417 << static_cast<int>(ports_.size()) << " remaining"; |
| 1403 } | 1418 } |
| 1404 | 1419 |
| 1420 void P2PTransportChannel::OnPortStopped(PortInterface* port) { |
| 1421 // If it does not gather continually, the port will be removed from the list |
| 1422 // when ICE restarts. |
| 1423 if (!gather_continually_) { |
| 1424 return; |
| 1425 } |
| 1426 auto it = std::find(ports_.begin(), ports_.end(), port); |
| 1427 // Don't need to do anything if the port has been deleted from the port list. |
| 1428 if (it == ports_.end()) { |
| 1429 return; |
| 1430 } |
| 1431 ports_.erase(it); |
| 1432 LOG(INFO) << "Removed port that has stopped: " << ports_.size() |
| 1433 << " remaining"; |
| 1434 // Make a copy of the candidates and change the priority on the copies. |
| 1435 std::vector<Candidate> candidates = port->Candidates(); |
| 1436 for (Candidate& candidate : candidates) { |
| 1437 candidate.set_priority(0); |
| 1438 } |
| 1439 SignalCandidatesRemoved(this, candidates); |
| 1440 } |
| 1441 |
| 1405 // We data is available, let listeners know | 1442 // We data is available, let listeners know |
| 1406 void P2PTransportChannel::OnReadPacket(Connection* connection, | 1443 void P2PTransportChannel::OnReadPacket(Connection* connection, |
| 1407 const char* data, | 1444 const char* data, |
| 1408 size_t len, | 1445 size_t len, |
| 1409 const rtc::PacketTime& packet_time) { | 1446 const rtc::PacketTime& packet_time) { |
| 1410 ASSERT(worker_thread_ == rtc::Thread::Current()); | 1447 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 1411 | 1448 |
| 1412 // Do not deliver, if packet doesn't belong to the correct transport channel. | 1449 // Do not deliver, if packet doesn't belong to the correct transport channel. |
| 1413 if (!FindConnection(connection)) | 1450 if (!FindConnection(connection)) |
| 1414 return; | 1451 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1430 SignalSentPacket(this, sent_packet); | 1467 SignalSentPacket(this, sent_packet); |
| 1431 } | 1468 } |
| 1432 | 1469 |
| 1433 void P2PTransportChannel::OnReadyToSend(Connection* connection) { | 1470 void P2PTransportChannel::OnReadyToSend(Connection* connection) { |
| 1434 if (connection == best_connection_ && writable()) { | 1471 if (connection == best_connection_ && writable()) { |
| 1435 SignalReadyToSend(this); | 1472 SignalReadyToSend(this); |
| 1436 } | 1473 } |
| 1437 } | 1474 } |
| 1438 | 1475 |
| 1439 } // namespace cricket | 1476 } // namespace cricket |
| OLD | NEW |