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

Side by Side Diff: webrtc/p2p/base/port_unittest.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: address comments 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
« no previous file with comments | « webrtc/p2p/base/port.cc ('k') | webrtc/p2p/base/relayport.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 const std::string& type, 162 const std::string& type,
163 int type_preference, 163 int type_preference,
164 bool final) { 164 bool final) {
165 AddAddress(addr, base_address, rtc::SocketAddress(), "udp", "", "", type, 165 AddAddress(addr, base_address, rtc::SocketAddress(), "udp", "", "", type,
166 type_preference, 0, final); 166 type_preference, 0, final);
167 } 167 }
168 168
169 virtual Connection* CreateConnection(const Candidate& remote_candidate, 169 virtual Connection* CreateConnection(const Candidate& remote_candidate,
170 CandidateOrigin origin) { 170 CandidateOrigin origin) {
171 Connection* conn = new ProxyConnection(this, 0, remote_candidate); 171 Connection* conn = new ProxyConnection(this, 0, remote_candidate);
172 AddConnection(conn); 172 AddOrReplaceConnection(conn);
173 // Set use-candidate attribute flag as this will add USE-CANDIDATE attribute 173 // Set use-candidate attribute flag as this will add USE-CANDIDATE attribute
174 // in STUN binding requests. 174 // in STUN binding requests.
175 conn->set_use_candidate_attr(true); 175 conn->set_use_candidate_attr(true);
176 return conn; 176 return conn;
177 } 177 }
178 virtual int SendTo( 178 virtual int SendTo(
179 const void* data, size_t size, const rtc::SocketAddress& addr, 179 const void* data, size_t size, const rtc::SocketAddress& addr,
180 const rtc::PacketOptions& options, bool payload) { 180 const rtc::PacketOptions& options, bool payload) {
181 if (!payload) { 181 if (!payload) {
182 IceMessage* msg = new IceMessage; 182 IceMessage* msg = new IceMessage;
(...skipping 2475 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 EXPECT_EQ(1UL, port->Candidates().size()); 2658 EXPECT_EQ(1UL, port->Candidates().size());
2659 port->SetIceParameters(1, "ufrag2", "password2"); 2659 port->SetIceParameters(1, "ufrag2", "password2");
2660 EXPECT_EQ(1, port->component()); 2660 EXPECT_EQ(1, port->component());
2661 EXPECT_EQ("ufrag2", port->username_fragment()); 2661 EXPECT_EQ("ufrag2", port->username_fragment());
2662 EXPECT_EQ("password2", port->password()); 2662 EXPECT_EQ("password2", port->password());
2663 const Candidate& candidate = port->Candidates()[0]; 2663 const Candidate& candidate = port->Candidates()[0];
2664 EXPECT_EQ(1, candidate.component()); 2664 EXPECT_EQ(1, candidate.component());
2665 EXPECT_EQ("ufrag2", candidate.username()); 2665 EXPECT_EQ("ufrag2", candidate.username());
2666 EXPECT_EQ("password2", candidate.password()); 2666 EXPECT_EQ("password2", candidate.password());
2667 } 2667 }
2668
2669 TEST_F(PortTest, TestAddConnectionWithSameAddress) {
2670 std::unique_ptr<TestPort> port(
2671 CreateTestPort(kLocalAddr1, "ufrag1", "password1"));
2672 port->PrepareAddress();
2673 EXPECT_EQ(1u, port->Candidates().size());
2674 rtc::SocketAddress address("1.1.1.1", 5000);
2675 cricket::Candidate candidate(1, "udp", address, 0, "", "", "relay", 0, "");
2676 cricket::Connection* conn1 =
2677 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE);
2678 cricket::Connection* conn_in_use = port->GetConnection(address);
2679 EXPECT_EQ(conn1, conn_in_use);
2680 EXPECT_EQ(0u, conn_in_use->remote_candidate().generation());
2681
2682 // Creating with a candidate with the same address again will get us a
2683 // different connection with the new candidate.
2684 candidate.set_generation(2);
2685 cricket::Connection* conn2 =
2686 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE);
2687 EXPECT_NE(conn1, conn2);
2688 conn_in_use = port->GetConnection(address);
2689 EXPECT_EQ(conn2, conn_in_use);
2690 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation());
2691
2692 // Make sure the new connection was not deleted.
2693 rtc::Thread::Current()->ProcessMessages(300);
2694 EXPECT_TRUE(port->GetConnection(address) != nullptr);
2695 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.cc ('k') | webrtc/p2p/base/relayport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698