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

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

Issue 2018693002: Create a new connection if a candidate reuses an address (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Sync with head 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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 port->SignalRoleConflict.connect( 525 port->SignalRoleConflict.connect(
526 this, &P2PTransportChannel::OnRoleConflict); 526 this, &P2PTransportChannel::OnRoleConflict);
527 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket); 527 port->SignalSentPacket.connect(this, &P2PTransportChannel::OnSentPacket);
528 528
529 // Attempt to create a connection from this new port to all of the remote 529 // Attempt to create a connection from this new port to all of the remote
530 // candidates that we were given so far. 530 // candidates that we were given so far.
531 531
532 std::vector<RemoteCandidate>::iterator iter; 532 std::vector<RemoteCandidate>::iterator iter;
533 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end(); 533 for (iter = remote_candidates_.begin(); iter != remote_candidates_.end();
534 ++iter) { 534 ++iter) {
535 CreateConnection(port, *iter, iter->origin_port()); 535 MaybeCreateConnection(port, *iter, iter->origin_port());
536 } 536 }
537 537
538 SortConnections(); 538 SortConnections();
539 } 539 }
540 540
541 // A new candidate is available, let listeners know 541 // A new candidate is available, let listeners know
542 void P2PTransportChannel::OnCandidatesReady( 542 void P2PTransportChannel::OnCandidatesReady(
543 PortAllocatorSession* session, 543 PortAllocatorSession* session,
544 const std::vector<Candidate>& candidates) { 544 const std::vector<Candidate>& candidates) {
545 ASSERT(worker_thread_ == rtc::Thread::Current()); 545 ASSERT(worker_thread_ == rtc::Thread::Current());
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 } 821 }
822 822
823 // Add a new connection for this candidate to every port that allows such a 823 // 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 824 // 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 825 // 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, 826 // 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. 827 // since that may be the only port that can create this connection.
828 bool created = false; 828 bool created = false;
829 std::vector<PortInterface *>::reverse_iterator it; 829 std::vector<PortInterface *>::reverse_iterator it;
830 for (it = ports_.rbegin(); it != ports_.rend(); ++it) { 830 for (it = ports_.rbegin(); it != ports_.rend(); ++it) {
831 if (CreateConnection(*it, remote_candidate, origin_port)) { 831 if (MaybeCreateConnection(*it, remote_candidate, origin_port)) {
832 if (*it == origin_port) 832 if (*it == origin_port)
833 created = true; 833 created = true;
834 } 834 }
835 } 835 }
836 836
837 if ((origin_port != NULL) && 837 if ((origin_port != NULL) &&
838 std::find(ports_.begin(), ports_.end(), origin_port) == ports_.end()) { 838 std::find(ports_.begin(), ports_.end(), origin_port) == ports_.end()) {
839 if (CreateConnection(origin_port, remote_candidate, origin_port)) 839 if (MaybeCreateConnection(origin_port, remote_candidate, origin_port))
840 created = true; 840 created = true;
841 } 841 }
842 842
843 // Remember this remote candidate so that we can add it to future ports. 843 // Remember this remote candidate so that we can add it to future ports.
844 RememberRemoteCandidate(remote_candidate, origin_port); 844 RememberRemoteCandidate(remote_candidate, origin_port);
845 845
846 return created; 846 return created;
847 } 847 }
848 848
849 // Setup a connection object for the local and remote candidate combination. 849 // Setup a connection object for the local and remote candidate combination.
850 // And then listen to connection object for changes. 850 // And then listen to connection object for changes.
851 bool P2PTransportChannel::CreateConnection(PortInterface* port, 851 bool P2PTransportChannel::MaybeCreateConnection(
852 const Candidate& remote_candidate, 852 PortInterface* port,
853 PortInterface* origin_port) { 853 const Candidate& remote_candidate,
854 PortInterface* origin_port) {
854 if (!port->SupportsProtocol(remote_candidate.protocol())) { 855 if (!port->SupportsProtocol(remote_candidate.protocol())) {
855 return false; 856 return false;
856 } 857 }
857 // Look for an existing connection with this remote address. If one is not 858 // Look for an existing connection with this remote address. If one is not
858 // found, then we can create a new connection for this address. 859 // found or it is found but the existing remote candidate has an older
860 // generation, then we can create a new connection for this address.
859 Connection* connection = port->GetConnection(remote_candidate.address()); 861 Connection* connection = port->GetConnection(remote_candidate.address());
860 if (connection != NULL) { 862 if (connection == nullptr ||
861 connection->MaybeUpdatePeerReflexiveCandidate(remote_candidate); 863 connection->remote_candidate().generation() <
862 864 remote_candidate.generation()) {
863 // It is not legal to try to change any of the parameters of an existing 865 return CreateConnection(port, remote_candidate, origin_port);
864 // connection; however, the other side can send a duplicate candidate.
865 if (!remote_candidate.IsEquivalent(connection->remote_candidate())) {
866 LOG(INFO) << "Attempt to change a remote candidate."
867 << " Existing remote candidate: "
868 << connection->remote_candidate().ToString()
869 << "New remote candidate: "
870 << remote_candidate.ToString();
871 return false;
872 }
873 } else {
874 PortInterface::CandidateOrigin origin = GetOrigin(port, origin_port);
875
876 // Don't create connection if this is a candidate we received in a
877 // message and we are not allowed to make outgoing connections.
878 if (origin == PortInterface::ORIGIN_MESSAGE && incoming_only_)
879 return false;
880
881 connection = port->CreateConnection(remote_candidate, origin);
882 if (!connection)
883 return false;
884
885 AddConnection(connection);
886
887 LOG_J(LS_INFO, this) << "Created connection with origin=" << origin << ", ("
888 << connections_.size() << " total)";
889 } 866 }
890 867
868 // Check if this is a peer reflexive candidate.
869 connection->MaybeUpdatePeerReflexiveCandidate(remote_candidate);
870
871 // It is not legal to try to change any of the parameters of an existing
872 // connection; however, the other side can send a duplicate candidate.
873 if (!remote_candidate.IsEquivalent(connection->remote_candidate())) {
874 LOG(INFO) << "Attempt to change a remote candidate."
875 << " Existing remote candidate: "
876 << connection->remote_candidate().ToString()
877 << "New remote candidate: " << remote_candidate.ToString();
878 }
879 // No new connection was created at this point.
880 return false;
881 }
882
883 bool P2PTransportChannel::CreateConnection(PortInterface* port,
884 const Candidate& remote_candidate,
885 PortInterface* origin_port) {
pthatcher1 2016/05/27 18:42:54 I don't quite understand why you split these metho
honghaiz3 2016/05/31 18:57:31 I thought it may improve readability. Since it cau
886 PortInterface::CandidateOrigin origin = GetOrigin(port, origin_port);
887
888 // Don't create connection if this is a candidate we received in a
pthatcher1 2016/05/27 18:42:54 create connection => create a caonnection
honghaiz3 2016/05/31 18:57:31 Done.
889 // message and we are not allowed to make outgoing connections.
890 if (origin == PortInterface::ORIGIN_MESSAGE && incoming_only_)
pthatcher1 2016/05/27 18:42:54 {}s please
honghaiz3 2016/05/31 18:57:31 Done.
891 return false;
892
893 Connection* connection = port->CreateConnection(remote_candidate, origin);
894 if (!connection) {
895 return false;
896 }
897
898 AddConnection(connection);
899 LOG_J(LS_INFO, this) << "Created connection with origin=" << origin << ", ("
900 << connections_.size() << " total)";
891 return true; 901 return true;
892 } 902 }
893 903
894 bool P2PTransportChannel::FindConnection(Connection* connection) const { 904 bool P2PTransportChannel::FindConnection(Connection* connection) const {
895 std::vector<Connection*>::const_iterator citer = 905 std::vector<Connection*>::const_iterator citer =
896 std::find(connections_.begin(), connections_.end(), connection); 906 std::find(connections_.begin(), connections_.end(), connection);
897 return citer != connections_.end(); 907 return citer != connections_.end();
898 } 908 }
899 909
900 uint32_t P2PTransportChannel::GetRemoteCandidateGeneration( 910 uint32_t P2PTransportChannel::GetRemoteCandidateGeneration(
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 1705
1696 // During the initial state when nothing has been pinged yet, return the first 1706 // During the initial state when nothing has been pinged yet, return the first
1697 // one in the ordered |connections_|. 1707 // one in the ordered |connections_|.
1698 return *(std::find_if(connections_.begin(), connections_.end(), 1708 return *(std::find_if(connections_.begin(), connections_.end(),
1699 [conn1, conn2](Connection* conn) { 1709 [conn1, conn2](Connection* conn) {
1700 return conn == conn1 || conn == conn2; 1710 return conn == conn1 || conn == conn2;
1701 })); 1711 }));
1702 } 1712 }
1703 1713
1704 } // namespace cricket 1714 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698