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

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: 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 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::CreateConnection(PortInterface* port,
852 const Candidate& remote_candidate, 852 const Candidate& remote_candidate,
853 PortInterface* origin_port) { 853 PortInterface* origin_port) {
854 if (!port->SupportsProtocol(remote_candidate.protocol())) { 854 if (!port->SupportsProtocol(remote_candidate.protocol())) {
855 return false; 855 return false;
856 } 856 }
857 // Look for an existing connection with this remote address. If one is not 857 // 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. 858 // found or it is found but the existing remote candidate has an older
859 // generation, then we can create a new connection for this address.
859 Connection* connection = port->GetConnection(remote_candidate.address()); 860 Connection* connection = port->GetConnection(remote_candidate.address());
860 if (connection != NULL) { 861 if (connection == nullptr ||
861 connection->MaybeUpdatePeerReflexiveCandidate(remote_candidate); 862 connection->remote_candidate().generation() <
862 863 remote_candidate.generation()) {
863 // It is not legal to try to change any of the parameters of an existing 864 // Don't create a connection if this is a candidate we received in a
864 // connection; however, the other side can send a duplicate candidate. 865 // message and we are not allowed to make outgoing connections.
865 if (!remote_candidate.IsEquivalent(connection->remote_candidate())) { 866 PortInterface::CandidateOrigin origin = GetOrigin(port, origin_port);
866 LOG(INFO) << "Attempt to change a remote candidate." 867 if (origin == PortInterface::ORIGIN_MESSAGE && incoming_only_) {
867 << " Existing remote candidate: "
868 << connection->remote_candidate().ToString()
869 << "New remote candidate: "
870 << remote_candidate.ToString();
871 return false; 868 return false;
872 } 869 }
873 } else { 870 Connection* connection = port->CreateConnection(remote_candidate, origin);
874 PortInterface::CandidateOrigin origin = GetOrigin(port, origin_port); 871 if (!connection) {
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; 872 return false;
880 873 }
881 connection = port->CreateConnection(remote_candidate, origin);
882 if (!connection)
883 return false;
884
885 AddConnection(connection); 874 AddConnection(connection);
886
887 LOG_J(LS_INFO, this) << "Created connection with origin=" << origin << ", (" 875 LOG_J(LS_INFO, this) << "Created connection with origin=" << origin << ", ("
888 << connections_.size() << " total)"; 876 << connections_.size() << " total)";
877 return true;
889 } 878 }
890 879
891 return true; 880 // No new connection was created.
881 // Check if this is a peer reflexive candidate.
882 connection->MaybeUpdatePeerReflexiveCandidate(remote_candidate);
883
884 // It is not legal to try to change any of the parameters of an existing
885 // connection; however, the other side can send a duplicate candidate.
886 if (!remote_candidate.IsEquivalent(connection->remote_candidate())) {
887 LOG(INFO) << "Attempt to change a remote candidate."
888 << " Existing remote candidate: "
889 << connection->remote_candidate().ToString()
890 << "New remote candidate: " << remote_candidate.ToString();
891 }
892 return false;
892 } 893 }
893 894
894 bool P2PTransportChannel::FindConnection(Connection* connection) const { 895 bool P2PTransportChannel::FindConnection(Connection* connection) const {
895 std::vector<Connection*>::const_iterator citer = 896 std::vector<Connection*>::const_iterator citer =
896 std::find(connections_.begin(), connections_.end(), connection); 897 std::find(connections_.begin(), connections_.end(), connection);
897 return citer != connections_.end(); 898 return citer != connections_.end();
898 } 899 }
899 900
900 uint32_t P2PTransportChannel::GetRemoteCandidateGeneration( 901 uint32_t P2PTransportChannel::GetRemoteCandidateGeneration(
901 const Candidate& candidate) { 902 const Candidate& candidate) {
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 1696
1696 // During the initial state when nothing has been pinged yet, return the first 1697 // During the initial state when nothing has been pinged yet, return the first
1697 // one in the ordered |connections_|. 1698 // one in the ordered |connections_|.
1698 return *(std::find_if(connections_.begin(), connections_.end(), 1699 return *(std::find_if(connections_.begin(), connections_.end(),
1699 [conn1, conn2](Connection* conn) { 1700 [conn1, conn2](Connection* conn) {
1700 return conn == conn1 || conn == conn2; 1701 return conn == conn1 || conn == conn2;
1701 })); 1702 }));
1702 } 1703 }
1703 1704
1704 } // namespace cricket 1705 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698