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

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

Issue 2099563004: Start ICE connectivity checks as soon as the first pair is pingable. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Updating unit test failures. We ping too fast for our own good. Created 4 years, 5 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 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 channel->SignalReadPacket.connect( 348 channel->SignalReadPacket.connect(
349 this, &P2PTransportChannelTestBase::OnReadPacket); 349 this, &P2PTransportChannelTestBase::OnReadPacket);
350 channel->SignalRoleConflict.connect( 350 channel->SignalRoleConflict.connect(
351 this, &P2PTransportChannelTestBase::OnRoleConflict); 351 this, &P2PTransportChannelTestBase::OnRoleConflict);
352 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); 352 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd);
353 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) { 353 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) {
354 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); 354 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd);
355 } 355 }
356 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); 356 channel->SetIceRole(GetEndpoint(endpoint)->ice_role());
357 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); 357 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker());
358 channel->Connect();
359 return channel; 358 return channel;
360 } 359 }
361 void DestroyChannels() { 360 void DestroyChannels() {
362 ep1_.cd1_.ch_.reset(); 361 ep1_.cd1_.ch_.reset();
363 ep2_.cd1_.ch_.reset(); 362 ep2_.cd1_.ch_.reset();
364 ep1_.cd2_.ch_.reset(); 363 ep1_.cd2_.ch_.reset();
365 ep2_.cd2_.ch_.reset(); 364 ep2_.cd2_.ch_.reset();
366 } 365 }
367 P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); } 366 P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); }
368 P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); } 367 P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); }
369 P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); } 368 P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); }
370 P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); } 369 P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); }
371 370
372 TestTurnServer* test_turn_server() { return &turn_server_; } 371 TestTurnServer* test_turn_server() { return &turn_server_; }
372 rtc::VirtualSocketServer* virtual_socket_server() { return vss_.get(); }
373 373
374 // Common results. 374 // Common results.
375 static const Result kLocalUdpToLocalUdp; 375 static const Result kLocalUdpToLocalUdp;
376 static const Result kLocalUdpToStunUdp; 376 static const Result kLocalUdpToStunUdp;
377 static const Result kLocalUdpToPrflxUdp; 377 static const Result kLocalUdpToPrflxUdp;
378 static const Result kPrflxUdpToLocalUdp; 378 static const Result kPrflxUdpToLocalUdp;
379 static const Result kStunUdpToLocalUdp; 379 static const Result kStunUdpToLocalUdp;
380 static const Result kStunUdpToStunUdp; 380 static const Result kStunUdpToStunUdp;
381 static const Result kPrflxUdpToStunUdp; 381 static const Result kPrflxUdpToStunUdp;
382 static const Result kLocalUdpToRelayUdp; 382 static const Result kLocalUdpToRelayUdp;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 EXPECT_EQ(expected.local_type, local_type); 480 EXPECT_EQ(expected.local_type, local_type);
481 EXPECT_EQ(expected.remote_type, remote_type); 481 EXPECT_EQ(expected.remote_type, remote_type);
482 EXPECT_EQ(expected.local_proto, local_proto); 482 EXPECT_EQ(expected.local_proto, local_proto);
483 EXPECT_EQ(expected.remote_proto, remote_proto); 483 EXPECT_EQ(expected.remote_proto, remote_proto);
484 } 484 }
485 485
486 // Return true if the approprite parts of the expected Result, based 486 // Return true if the approprite parts of the expected Result, based
487 // on the local and remote candidate of ep2_ch1, match. This can be 487 // on the local and remote candidate of ep2_ch1, match. This can be
488 // used in an EXPECT_TRUE_WAIT. 488 // used in an EXPECT_TRUE_WAIT.
489 bool CheckCandidate2(const Result& expected) { 489 bool CheckCandidate2(const Result& expected) {
490 const std::string& local_type = LocalCandidate(ep2_ch1())->type();
491 // const std::string& remote_type = RemoteCandidate(ep2_ch1())->type();
492 const std::string& local_proto = LocalCandidate(ep2_ch1())->protocol(); 490 const std::string& local_proto = LocalCandidate(ep2_ch1())->protocol();
493 const std::string& remote_proto = RemoteCandidate(ep2_ch1())->protocol(); 491 const std::string& remote_proto = RemoteCandidate(ep2_ch1())->protocol();
494 // Removed remote_type comparision aginst selected connection remote 492 // Removed remote_type comparision aginst selected connection remote
495 // candidate. This is done to handle remote type discrepancy from 493 // candidate. This is done to handle remote type discrepancy from
496 // local to stun based on the test type. 494 // local to stun based on the test type.
497 // For example in case of Open -> NAT, ep2 channels will have LULU 495 // For example in case of Open -> NAT, ep2 channels will have LULU
498 // and in other cases like NAT -> NAT it will be LUSU. To avoid these 496 // and in other cases like NAT -> NAT it will be LUSU. To avoid these
499 // mismatches and we are doing comparision in different way. 497 // mismatches and we are doing comparision in different way.
500 // i.e. when don't match its remote type is either local or stun. 498 // i.e. when don't match its remote type is either local or stun.
499 //
500 // Update(deadbeef): Also had to remove local type comparison. There
501 // is currently an issue where the local type is not updated to stun.
502 // So one side may see local<->relay while the other sees relay<->stun.
503 // This mean the other side may prioritize prflx<->relay, and won't have
504 // a local type of relay no matter how long we wait.
505 // TODO(deadbeef): Fix this!! It's causing us to have very sparse test
506 // coverage and is a very real bug.
507 //
pthatcher1 2016/06/25 00:02:36 Who is going to fix this, and how soon?
Taylor Brandstetter 2016/06/27 22:19:34 Me, and this week if possible. I also plan to re-e
501 // TODO(ronghuawu): Refine the test criteria. 508 // TODO(ronghuawu): Refine the test criteria.
502 // https://code.google.com/p/webrtc/issues/detail?id=1953 509 // https://code.google.com/p/webrtc/issues/detail?id=1953
503 return ((local_proto == expected.local_proto2 && 510 return ((local_proto == expected.local_proto2 &&
504 remote_proto == expected.remote_proto2) && 511 remote_proto == expected.remote_proto2));
505 (local_type == expected.local_type2 ||
506 // Sometimes we expect local -> prflx or prflx -> local
507 // and instead get prflx -> local or local -> prflx, and
508 // that's OK.
509 (IsLocalToPrflxOrTheReverse(expected) &&
510 local_type == expected.remote_type2)));
511 } 512 }
512 513
513 // EXPECT_EQ on the approprite parts of the expected Result, based 514 // EXPECT_EQ on the approprite parts of the expected Result, based
514 // on the local and remote candidate of ep2_ch1. This is like 515 // on the local and remote candidate of ep2_ch1. This is like
515 // CheckCandidate2, except that it will provide more detail about 516 // CheckCandidate2, except that it will provide more detail about
516 // what didn't match. 517 // what didn't match.
517 void ExpectCandidate2(const Result& expected) { 518 void ExpectCandidate2(const Result& expected) {
518 if (CheckCandidate2(expected)) { 519 if (CheckCandidate2(expected)) {
519 return; 520 return;
520 } 521 }
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 FLAKY_P2P_TEST(x, NAT_PORT_RESTRICTED) \ 1056 FLAKY_P2P_TEST(x, NAT_PORT_RESTRICTED) \
1056 P2P_TEST(x, NAT_SYMMETRIC) \ 1057 P2P_TEST(x, NAT_SYMMETRIC) \
1057 FLAKY_P2P_TEST(x, NAT_DOUBLE_CONE) \ 1058 FLAKY_P2P_TEST(x, NAT_DOUBLE_CONE) \
1058 P2P_TEST(x, NAT_SYMMETRIC_THEN_CONE) \ 1059 P2P_TEST(x, NAT_SYMMETRIC_THEN_CONE) \
1059 P2P_TEST(x, BLOCK_UDP) \ 1060 P2P_TEST(x, BLOCK_UDP) \
1060 P2P_TEST(x, BLOCK_UDP_AND_INCOMING_TCP) \ 1061 P2P_TEST(x, BLOCK_UDP_AND_INCOMING_TCP) \
1061 P2P_TEST(x, BLOCK_ALL_BUT_OUTGOING_HTTP) \ 1062 P2P_TEST(x, BLOCK_ALL_BUT_OUTGOING_HTTP) \
1062 P2P_TEST(x, PROXY_HTTPS) \ 1063 P2P_TEST(x, PROXY_HTTPS) \
1063 P2P_TEST(x, PROXY_SOCKS) 1064 P2P_TEST(x, PROXY_SOCKS)
1064 1065
1065 #define FLAKY_P2P_TEST_SET(x) \
1066 P2P_TEST(x, OPEN) \
1067 P2P_TEST(x, NAT_FULL_CONE) \
1068 P2P_TEST(x, NAT_ADDR_RESTRICTED) \
1069 P2P_TEST(x, NAT_PORT_RESTRICTED) \
1070 P2P_TEST(x, NAT_SYMMETRIC) \
1071 P2P_TEST(x, NAT_DOUBLE_CONE) \
1072 P2P_TEST(x, NAT_SYMMETRIC_THEN_CONE) \
1073 P2P_TEST(x, BLOCK_UDP) \
1074 P2P_TEST(x, BLOCK_UDP_AND_INCOMING_TCP) \
1075 P2P_TEST(x, BLOCK_ALL_BUT_OUTGOING_HTTP) \
1076 P2P_TEST(x, PROXY_HTTPS) \
1077 P2P_TEST(x, PROXY_SOCKS)
1078
1079 P2P_TEST_SET(OPEN) 1066 P2P_TEST_SET(OPEN)
1080 P2P_TEST_SET(NAT_FULL_CONE) 1067 P2P_TEST_SET(NAT_FULL_CONE)
1081 P2P_TEST_SET(NAT_ADDR_RESTRICTED) 1068 P2P_TEST_SET(NAT_ADDR_RESTRICTED)
1082 P2P_TEST_SET(NAT_PORT_RESTRICTED) 1069 P2P_TEST_SET(NAT_PORT_RESTRICTED)
1083 P2P_TEST_SET(NAT_SYMMETRIC) 1070 P2P_TEST_SET(NAT_SYMMETRIC)
1084 P2P_TEST_SET(NAT_DOUBLE_CONE) 1071 P2P_TEST_SET(NAT_DOUBLE_CONE)
1085 P2P_TEST_SET(NAT_SYMMETRIC_THEN_CONE) 1072 P2P_TEST_SET(NAT_SYMMETRIC_THEN_CONE)
1086 P2P_TEST_SET(BLOCK_UDP) 1073 P2P_TEST_SET(BLOCK_UDP)
1087 P2P_TEST_SET(BLOCK_UDP_AND_INCOMING_TCP) 1074 P2P_TEST_SET(BLOCK_UDP_AND_INCOMING_TCP)
1088 P2P_TEST_SET(BLOCK_ALL_BUT_OUTGOING_HTTP) 1075 P2P_TEST_SET(BLOCK_ALL_BUT_OUTGOING_HTTP)
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole()); 1430 EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole());
1444 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); 1431 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker());
1445 } 1432 }
1446 1433
1447 ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED); 1434 ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED);
1448 ep1_ch1()->SetIceTiebreaker(kTiebreaker2); 1435 ep1_ch1()->SetIceTiebreaker(kTiebreaker2);
1449 1436
1450 const std::vector<PortInterface*> ports_after = ep1_ch1()->ports(); 1437 const std::vector<PortInterface*> ports_after = ep1_ch1()->ports();
1451 for (size_t i = 0; i < ports_after.size(); ++i) { 1438 for (size_t i = 0; i < ports_after.size(); ++i) {
1452 EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); 1439 EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole());
1453 // SetIceTiebreaker after Connect() has been called will fail. So expect the 1440 // SetIceTiebreaker after ports have been created will fail. So expect the
1454 // original value. 1441 // original value.
1455 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); 1442 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker());
1456 } 1443 }
1457 1444
1458 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && 1445 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() &&
1459 ep1_ch1()->writable() && 1446 ep1_ch1()->writable() &&
1460 ep2_ch1()->receiving() && 1447 ep2_ch1()->receiving() &&
1461 ep2_ch1()->writable(), 1448 ep2_ch1()->writable(),
1462 1000); 1449 1000);
1463 1450
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 // Also expect that the channel instantly indicates that it's writable since 1684 // Also expect that the channel instantly indicates that it's writable since
1698 // it has a TURN-TURN pair. 1685 // it has a TURN-TURN pair.
1699 EXPECT_TRUE(ep1_ch1()->writable()); 1686 EXPECT_TRUE(ep1_ch1()->writable());
1700 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_); 1687 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_);
1701 } 1688 }
1702 1689
1703 // Test that a TURN/peer reflexive candidate pair is also presumed writable. 1690 // Test that a TURN/peer reflexive candidate pair is also presumed writable.
1704 TEST_F(P2PTransportChannelTest, TurnToPrflxPresumedWritable) { 1691 TEST_F(P2PTransportChannelTest, TurnToPrflxPresumedWritable) {
1705 rtc::ScopedFakeClock fake_clock; 1692 rtc::ScopedFakeClock fake_clock;
1706 1693
1694 // We need to add artificial network delay to verify that the connection
1695 // is presumed writable before it's actually writable. Without this delay
1696 // it would become writable instantly.
1697 virtual_socket_server()->set_delay_mean(50);
1698 virtual_socket_server()->UpdateDelayDistribution();
1699
1707 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1700 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1708 kDefaultPortAllocatorFlags); 1701 kDefaultPortAllocatorFlags);
1709 // We want the remote TURN candidate to show up as prflx. To do this we need 1702 // We want the remote TURN candidate to show up as prflx. To do this we need
1710 // to configure the server to accept packets from an address we haven't 1703 // to configure the server to accept packets from an address we haven't
1711 // explicitly installed permission for. 1704 // explicitly installed permission for.
1712 test_turn_server()->set_enable_permission_checks(false); 1705 test_turn_server()->set_enable_permission_checks(false);
1713 IceConfig config; 1706 IceConfig config;
1714 config.presume_writable_when_fully_relayed = true; 1707 config.presume_writable_when_fully_relayed = true;
1715 GetEndpoint(0)->cd1_.ch_.reset( 1708 GetEndpoint(0)->cd1_.ch_.reset(
1716 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], 1709 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0],
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
2284 int selected_candidate_pair_switches_ = 0; 2277 int selected_candidate_pair_switches_ = 0;
2285 int last_sent_packet_id_ = -1; 2278 int last_sent_packet_id_ = -1;
2286 bool channel_ready_to_send_ = false; 2279 bool channel_ready_to_send_ = false;
2287 TransportChannelState channel_state_ = STATE_INIT; 2280 TransportChannelState channel_state_ = STATE_INIT;
2288 }; 2281 };
2289 2282
2290 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { 2283 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
2291 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2284 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2292 P2PTransportChannel ch("trigger checks", 1, &pa); 2285 P2PTransportChannel ch("trigger checks", 1, &pa);
2293 PrepareChannel(&ch); 2286 PrepareChannel(&ch);
2294 ch.Connect();
2295 ch.MaybeStartGathering(); 2287 ch.MaybeStartGathering();
2296 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2288 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2297 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2289 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2298 2290
2299 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2291 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2300 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2292 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2301 ASSERT_TRUE(conn1 != nullptr); 2293 ASSERT_TRUE(conn1 != nullptr);
2302 ASSERT_TRUE(conn2 != nullptr); 2294 ASSERT_TRUE(conn2 != nullptr);
2303 2295
2304 // Before a triggered check, the first connection to ping is the 2296 // Before a triggered check, the first connection to ping is the
2305 // highest priority one. 2297 // highest priority one.
2306 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2298 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2307 2299
2308 // Receiving a ping causes a triggered check which should make conn1 2300 // Receiving a ping causes a triggered check which should make conn1
2309 // be pinged first instead of conn2, even though conn2 has a higher 2301 // be pinged first instead of conn2, even though conn2 has a higher
2310 // priority. 2302 // priority.
2311 conn1->ReceivedPing(); 2303 conn1->ReceivedPing();
2312 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2304 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2313 } 2305 }
2314 2306
2315 TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) { 2307 TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
2316 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2308 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2317 P2PTransportChannel ch("ping sufficiently", 1, &pa); 2309 P2PTransportChannel ch("ping sufficiently", 1, &pa);
2318 PrepareChannel(&ch); 2310 PrepareChannel(&ch);
2319 ch.Connect();
2320 ch.MaybeStartGathering(); 2311 ch.MaybeStartGathering();
2321 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2312 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2322 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2313 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2323 2314
2324 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2315 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2325 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2316 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2326 ASSERT_TRUE(conn1 != nullptr); 2317 ASSERT_TRUE(conn1 != nullptr);
2327 ASSERT_TRUE(conn2 != nullptr); 2318 ASSERT_TRUE(conn2 != nullptr);
2328 2319
2329 // Low-priority connection becomes writable so that the other connection 2320 // Low-priority connection becomes writable so that the other connection
2330 // is not pruned. 2321 // is not pruned.
2331 conn1->ReceivedPingResponse(LOW_RTT); 2322 conn1->ReceivedPingResponse(LOW_RTT);
2332 EXPECT_TRUE_WAIT( 2323 EXPECT_TRUE_WAIT(
2333 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && 2324 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL &&
2334 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2325 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2335 kDefaultTimeout); 2326 kDefaultTimeout);
2336 } 2327 }
2337 2328
2338 // Verify that the connections are pinged at the right time. 2329 // Verify that the connections are pinged at the right time.
2339 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { 2330 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
2340 rtc::ScopedFakeClock clock; 2331 rtc::ScopedFakeClock clock;
2341 int RTT_RATIO = 4; 2332 int RTT_RATIO = 4;
2342 int SCHEDULING_RANGE = 200; 2333 int SCHEDULING_RANGE = 200;
2343 int RTT_RANGE = 10; 2334 int RTT_RANGE = 10;
2344 2335
2345 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2336 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2346 P2PTransportChannel ch("TestChannel", 1, &pa); 2337 P2PTransportChannel ch("TestChannel", 1, &pa);
2347 PrepareChannel(&ch); 2338 PrepareChannel(&ch);
2348 ch.Connect();
2349 ch.MaybeStartGathering(); 2339 ch.MaybeStartGathering();
2350 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2340 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2351 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2341 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2352 2342
2353 ASSERT_TRUE(conn != nullptr); 2343 ASSERT_TRUE(conn != nullptr);
2354 SIMULATED_WAIT(conn->num_pings_sent() == 1, kDefaultTimeout, clock); 2344 SIMULATED_WAIT(conn->num_pings_sent() == 1, kDefaultTimeout, clock);
2355 2345
2356 // Initializing. 2346 // Initializing.
2357 2347
2358 int64_t start = clock.TimeNanos(); 2348 int64_t start = clock.TimeNanos();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2416 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2406 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2417 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 2407 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
2418 EXPECT_LE(ping_interval_ms, 2408 EXPECT_LE(ping_interval_ms,
2419 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2409 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2420 } 2410 }
2421 2411
2422 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { 2412 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
2423 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2413 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2424 P2PTransportChannel ch("trigger checks", 1, &pa); 2414 P2PTransportChannel ch("trigger checks", 1, &pa);
2425 PrepareChannel(&ch); 2415 PrepareChannel(&ch);
2426 ch.Connect();
2427 ch.MaybeStartGathering(); 2416 ch.MaybeStartGathering();
2428 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2417 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2429 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2418 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2430 2419
2431 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2420 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2432 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2421 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2433 ASSERT_TRUE(conn1 != nullptr); 2422 ASSERT_TRUE(conn1 != nullptr);
2434 ASSERT_TRUE(conn2 != nullptr); 2423 ASSERT_TRUE(conn2 != nullptr);
2435 2424
2436 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2425 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2437 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2426 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2438 conn1->ReceivedPingResponse(LOW_RTT); 2427 conn1->ReceivedPingResponse(LOW_RTT);
2439 ASSERT_TRUE(conn1->writable()); 2428 ASSERT_TRUE(conn1->writable());
2440 conn1->ReceivedPing(); 2429 conn1->ReceivedPing();
2441 2430
2442 // Ping received, but the connection is already writable, so no 2431 // Ping received, but the connection is already writable, so no
2443 // "triggered check" and conn2 is pinged before conn1 because it has 2432 // "triggered check" and conn2 is pinged before conn1 because it has
2444 // a higher priority. 2433 // a higher priority.
2445 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2434 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2446 } 2435 }
2447 2436
2448 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) { 2437 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) {
2449 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2438 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2450 P2PTransportChannel ch("Do not ping failed connections", 1, &pa); 2439 P2PTransportChannel ch("Do not ping failed connections", 1, &pa);
2451 PrepareChannel(&ch); 2440 PrepareChannel(&ch);
2452 ch.Connect();
2453 ch.MaybeStartGathering(); 2441 ch.MaybeStartGathering();
2454 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2442 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2455 2443
2456 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2444 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2457 ASSERT_TRUE(conn1 != nullptr); 2445 ASSERT_TRUE(conn1 != nullptr);
2458 2446
2459 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); 2447 EXPECT_EQ(conn1, ch.FindNextPingableConnection());
2460 conn1->Prune(); // A pruned connection may still be pingable. 2448 conn1->Prune(); // A pruned connection may still be pingable.
2461 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); 2449 EXPECT_EQ(conn1, ch.FindNextPingableConnection());
2462 conn1->FailAndPrune(); 2450 conn1->FailAndPrune();
2463 EXPECT_TRUE(nullptr == ch.FindNextPingableConnection()); 2451 EXPECT_TRUE(nullptr == ch.FindNextPingableConnection());
2464 } 2452 }
2465 2453
2466 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { 2454 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) {
2467 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2455 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2468 P2PTransportChannel ch("state change", 1, &pa); 2456 P2PTransportChannel ch("state change", 1, &pa);
2469 PrepareChannel(&ch); 2457 PrepareChannel(&ch);
2470 ch.Connect();
2471 ch.MaybeStartGathering(); 2458 ch.MaybeStartGathering();
2472 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2459 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2473 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2460 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2474 ASSERT_TRUE(conn1 != nullptr); 2461 ASSERT_TRUE(conn1 != nullptr);
2475 // Pruning the connection reduces the set of active connections and changes 2462 // Pruning the connection reduces the set of active connections and changes
2476 // the channel state. 2463 // the channel state.
2477 conn1->Prune(); 2464 conn1->Prune();
2478 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); 2465 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout);
2479 } 2466 }
2480 2467
2481 // Test adding remote candidates with different ufrags. If a remote candidate 2468 // Test adding remote candidates with different ufrags. If a remote candidate
2482 // is added with an old ufrag, it will be discarded. If it is added with a 2469 // is added with an old ufrag, it will be discarded. If it is added with a
2483 // ufrag that was not seen before, it will be used to create connections 2470 // ufrag that was not seen before, it will be used to create connections
2484 // although the ICE pwd in the remote candidate will be set when the ICE 2471 // although the ICE pwd in the remote candidate will be set when the ICE
2485 // credentials arrive. If a remote candidate is added with the current ICE 2472 // credentials arrive. If a remote candidate is added with the current ICE
2486 // ufrag, its pwd and generation will be set properly. 2473 // ufrag, its pwd and generation will be set properly.
2487 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { 2474 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
2488 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2475 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2489 P2PTransportChannel ch("add candidate", 1, &pa); 2476 P2PTransportChannel ch("add candidate", 1, &pa);
2490 PrepareChannel(&ch); 2477 PrepareChannel(&ch);
2491 ch.Connect();
2492 ch.MaybeStartGathering(); 2478 ch.MaybeStartGathering();
2493 // Add a candidate with a future ufrag. 2479 // Add a candidate with a future ufrag.
2494 ch.AddRemoteCandidate( 2480 ch.AddRemoteCandidate(
2495 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2])); 2481 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2]));
2496 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2482 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2497 ASSERT_TRUE(conn1 != nullptr); 2483 ASSERT_TRUE(conn1 != nullptr);
2498 const Candidate& candidate = conn1->remote_candidate(); 2484 const Candidate& candidate = conn1->remote_candidate();
2499 EXPECT_EQ(kIceUfrag[2], candidate.username()); 2485 EXPECT_EQ(kIceUfrag[2], candidate.username());
2500 EXPECT_TRUE(candidate.password().empty()); 2486 EXPECT_TRUE(candidate.password().empty());
2501 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); 2487 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 } else if (candidate.username() == kIceUfrag[2]) { 2520 } else if (candidate.username() == kIceUfrag[2]) {
2535 EXPECT_EQ(kIcePwd[2], candidate.password()); 2521 EXPECT_EQ(kIcePwd[2], candidate.password());
2536 } 2522 }
2537 } 2523 }
2538 } 2524 }
2539 2525
2540 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { 2526 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
2541 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2527 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2542 P2PTransportChannel ch("connection resurrection", 1, &pa); 2528 P2PTransportChannel ch("connection resurrection", 1, &pa);
2543 PrepareChannel(&ch); 2529 PrepareChannel(&ch);
2544 ch.Connect();
2545 ch.MaybeStartGathering(); 2530 ch.MaybeStartGathering();
2546 2531
2547 // Create conn1 and keep track of original candidate priority. 2532 // Create conn1 and keep track of original candidate priority.
2548 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2533 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2549 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2534 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2550 ASSERT_TRUE(conn1 != nullptr); 2535 ASSERT_TRUE(conn1 != nullptr);
2551 uint32_t remote_priority = conn1->remote_candidate().priority(); 2536 uint32_t remote_priority = conn1->remote_candidate().priority();
2552 2537
2553 // Create a higher priority candidate and make the connection 2538 // Create a higher priority candidate and make the connection
2554 // receiving/writable. This will prune conn1. 2539 // receiving/writable. This will prune conn1.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2594 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2579 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2595 P2PTransportChannel ch("receiving state change", 1, &pa); 2580 P2PTransportChannel ch("receiving state change", 1, &pa);
2596 PrepareChannel(&ch); 2581 PrepareChannel(&ch);
2597 // Default receiving timeout and checking receiving interval should not be too 2582 // Default receiving timeout and checking receiving interval should not be too
2598 // small. 2583 // small.
2599 EXPECT_LE(1000, ch.receiving_timeout()); 2584 EXPECT_LE(1000, ch.receiving_timeout());
2600 EXPECT_LE(200, ch.check_receiving_interval()); 2585 EXPECT_LE(200, ch.check_receiving_interval());
2601 ch.SetIceConfig(CreateIceConfig(500, false)); 2586 ch.SetIceConfig(CreateIceConfig(500, false));
2602 EXPECT_EQ(500, ch.receiving_timeout()); 2587 EXPECT_EQ(500, ch.receiving_timeout());
2603 EXPECT_EQ(50, ch.check_receiving_interval()); 2588 EXPECT_EQ(50, ch.check_receiving_interval());
2604 ch.Connect();
2605 ch.MaybeStartGathering(); 2589 ch.MaybeStartGathering();
2606 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2590 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2607 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2591 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2608 ASSERT_TRUE(conn1 != nullptr); 2592 ASSERT_TRUE(conn1 != nullptr);
2609 2593
2610 conn1->ReceivedPing(); 2594 conn1->ReceivedPing();
2611 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 2595 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
2612 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000); 2596 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000);
2613 EXPECT_TRUE_WAIT(ch.receiving(), 1000); 2597 EXPECT_TRUE_WAIT(ch.receiving(), 1000);
2614 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); 2598 EXPECT_TRUE_WAIT(!ch.receiving(), 1000);
2615 } 2599 }
2616 2600
2617 // The controlled side will select a connection as the "selected connection" 2601 // The controlled side will select a connection as the "selected connection"
2618 // based on priority until the controlling side nominates a connection, at which 2602 // based on priority until the controlling side nominates a connection, at which
2619 // point the controlled side will select that connection as the 2603 // point the controlled side will select that connection as the
2620 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the 2604 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the
2621 // selected connection changes and SignalReadyToSend will be fired if the new 2605 // selected connection changes and SignalReadyToSend will be fired if the new
2622 // selected connection is writable. 2606 // selected connection is writable.
2623 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { 2607 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
2624 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2608 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2625 P2PTransportChannel ch("receiving state change", 1, &pa); 2609 P2PTransportChannel ch("receiving state change", 1, &pa);
2626 PrepareChannel(&ch); 2610 PrepareChannel(&ch);
2627 ch.SetIceRole(ICEROLE_CONTROLLED); 2611 ch.SetIceRole(ICEROLE_CONTROLLED);
2628 ch.Connect();
2629 ch.MaybeStartGathering(); 2612 ch.MaybeStartGathering();
2630 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2613 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2631 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2614 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2632 ASSERT_TRUE(conn1 != nullptr); 2615 ASSERT_TRUE(conn1 != nullptr);
2633 EXPECT_EQ(conn1, ch.selected_connection()); 2616 EXPECT_EQ(conn1, ch.selected_connection());
2634 EXPECT_EQ(conn1, last_selected_candidate_pair()); 2617 EXPECT_EQ(conn1, last_selected_candidate_pair());
2635 EXPECT_EQ(-1, last_sent_packet_id()); 2618 EXPECT_EQ(-1, last_sent_packet_id());
2636 // Channel is not ready to send because it is not writable. 2619 // Channel is not ready to send because it is not writable.
2637 EXPECT_FALSE(channel_ready_to_send()); 2620 EXPECT_FALSE(channel_ready_to_send());
2638 2621
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2697 // based on requests from an unknown address before the controlling side 2680 // based on requests from an unknown address before the controlling side
2698 // nominates a connection, and will nominate a connection from an unknown 2681 // nominates a connection, and will nominate a connection from an unknown
2699 // address if the request contains the use_candidate attribute. Plus, it will 2682 // address if the request contains the use_candidate attribute. Plus, it will
2700 // also sends back a ping response and set the ICE pwd in the remote candidate 2683 // also sends back a ping response and set the ICE pwd in the remote candidate
2701 // appropriately. 2684 // appropriately.
2702 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { 2685 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
2703 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2686 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2704 P2PTransportChannel ch("receiving state change", 1, &pa); 2687 P2PTransportChannel ch("receiving state change", 1, &pa);
2705 PrepareChannel(&ch); 2688 PrepareChannel(&ch);
2706 ch.SetIceRole(ICEROLE_CONTROLLED); 2689 ch.SetIceRole(ICEROLE_CONTROLLED);
2707 ch.Connect();
2708 ch.MaybeStartGathering(); 2690 ch.MaybeStartGathering();
2709 // A minimal STUN message with prflx priority. 2691 // A minimal STUN message with prflx priority.
2710 IceMessage request; 2692 IceMessage request;
2711 request.SetType(STUN_BINDING_REQUEST); 2693 request.SetType(STUN_BINDING_REQUEST);
2712 request.AddAttribute( 2694 request.AddAttribute(
2713 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 2695 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
2714 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 2696 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
2715 request.AddAttribute( 2697 request.AddAttribute(
2716 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 2698 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
2717 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); 2699 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2778 2760
2779 // The controlled side will select a connection as the "selected connection" 2761 // The controlled side will select a connection as the "selected connection"
2780 // based on media received until the controlling side nominates a connection, 2762 // based on media received until the controlling side nominates a connection,
2781 // at which point the controlled side will select that connection as 2763 // at which point the controlled side will select that connection as
2782 // the "selected connection". 2764 // the "selected connection".
2783 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { 2765 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
2784 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2766 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2785 P2PTransportChannel ch("receiving state change", 1, &pa); 2767 P2PTransportChannel ch("receiving state change", 1, &pa);
2786 PrepareChannel(&ch); 2768 PrepareChannel(&ch);
2787 ch.SetIceRole(ICEROLE_CONTROLLED); 2769 ch.SetIceRole(ICEROLE_CONTROLLED);
2788 ch.Connect();
2789 ch.MaybeStartGathering(); 2770 ch.MaybeStartGathering();
2790 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10)); 2771 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10));
2791 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2772 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2792 ASSERT_TRUE(conn1 != nullptr); 2773 ASSERT_TRUE(conn1 != nullptr);
2793 EXPECT_EQ(conn1, ch.selected_connection()); 2774 EXPECT_EQ(conn1, ch.selected_connection());
2794 2775
2795 // If a data packet is received on conn2, the selected connection should 2776 // If a data packet is received on conn2, the selected connection should
2796 // switch to conn2 because the controlled side must mirror the media path 2777 // switch to conn2 because the controlled side must mirror the media path
2797 // chosen by the controlling side. 2778 // chosen by the controlling side.
2798 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 2779 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2831 } 2812 }
2832 2813
2833 TEST_F(P2PTransportChannelPingTest, 2814 TEST_F(P2PTransportChannelPingTest,
2834 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) { 2815 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) {
2835 rtc::ScopedFakeClock clock; 2816 rtc::ScopedFakeClock clock;
2836 2817
2837 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2818 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2838 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 2819 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
2839 PrepareChannel(&ch); 2820 PrepareChannel(&ch);
2840 ch.SetIceRole(ICEROLE_CONTROLLED); 2821 ch.SetIceRole(ICEROLE_CONTROLLED);
2841 ch.Connect();
2842 ch.MaybeStartGathering(); 2822 ch.MaybeStartGathering();
2843 // The connections have decreasing priority. 2823 // The connections have decreasing priority.
2844 Connection* conn1 = 2824 Connection* conn1 =
2845 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); 2825 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true);
2846 ASSERT_TRUE(conn1 != nullptr); 2826 ASSERT_TRUE(conn1 != nullptr);
2847 Connection* conn2 = 2827 Connection* conn2 =
2848 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true); 2828 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true);
2849 ASSERT_TRUE(conn2 != nullptr); 2829 ASSERT_TRUE(conn2 != nullptr);
2850 2830
2851 // Initially, connections are selected based on priority. 2831 // Initially, connections are selected based on priority.
(...skipping 19 matching lines...) Expand all
2871 } 2851 }
2872 2852
2873 TEST_F(P2PTransportChannelPingTest, 2853 TEST_F(P2PTransportChannelPingTest,
2874 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) { 2854 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) {
2875 rtc::ScopedFakeClock clock; 2855 rtc::ScopedFakeClock clock;
2876 2856
2877 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2857 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2878 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 2858 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
2879 PrepareChannel(&ch); 2859 PrepareChannel(&ch);
2880 ch.SetIceRole(ICEROLE_CONTROLLED); 2860 ch.SetIceRole(ICEROLE_CONTROLLED);
2881 ch.Connect();
2882 ch.MaybeStartGathering(); 2861 ch.MaybeStartGathering();
2883 // The connections have decreasing priority. 2862 // The connections have decreasing priority.
2884 Connection* conn1 = 2863 Connection* conn1 =
2885 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 2864 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
2886 ASSERT_TRUE(conn1 != nullptr); 2865 ASSERT_TRUE(conn1 != nullptr);
2887 Connection* conn2 = 2866 Connection* conn2 =
2888 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 2867 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
2889 ASSERT_TRUE(conn2 != nullptr); 2868 ASSERT_TRUE(conn2 != nullptr);
2890 2869
2891 // conn1 received data; it is the selected connection. 2870 // conn1 received data; it is the selected connection.
(...skipping 25 matching lines...) Expand all
2917 } 2896 }
2918 2897
2919 TEST_F(P2PTransportChannelPingTest, 2898 TEST_F(P2PTransportChannelPingTest,
2920 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) { 2899 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) {
2921 rtc::ScopedFakeClock clock; 2900 rtc::ScopedFakeClock clock;
2922 2901
2923 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2902 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2924 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 2903 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
2925 PrepareChannel(&ch); 2904 PrepareChannel(&ch);
2926 ch.SetIceRole(ICEROLE_CONTROLLED); 2905 ch.SetIceRole(ICEROLE_CONTROLLED);
2927 ch.Connect();
2928 ch.MaybeStartGathering(); 2906 ch.MaybeStartGathering();
2929 // The connections have decreasing priority. 2907 // The connections have decreasing priority.
2930 Connection* conn1 = 2908 Connection* conn1 =
2931 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 2909 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
2932 ASSERT_TRUE(conn1 != nullptr); 2910 ASSERT_TRUE(conn1 != nullptr);
2933 Connection* conn2 = 2911 Connection* conn2 =
2934 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 2912 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
2935 ASSERT_TRUE(conn2 != nullptr); 2913 ASSERT_TRUE(conn2 != nullptr);
2936 2914
2937 NominateConnection(conn1); 2915 NominateConnection(conn1);
(...skipping 18 matching lines...) Expand all
2956 SIMULATED_WAIT(false, 10, clock); 2934 SIMULATED_WAIT(false, 10, clock);
2957 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); 2935 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches());
2958 } 2936 }
2959 2937
2960 // Test that if a new remote candidate has the same address and port with 2938 // Test that if a new remote candidate has the same address and port with
2961 // an old one, it will be used to create a new connection. 2939 // an old one, it will be used to create a new connection.
2962 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { 2940 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
2963 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2941 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2964 P2PTransportChannel ch("candidate reuse", 1, &pa); 2942 P2PTransportChannel ch("candidate reuse", 1, &pa);
2965 PrepareChannel(&ch); 2943 PrepareChannel(&ch);
2966 ch.Connect();
2967 ch.MaybeStartGathering(); 2944 ch.MaybeStartGathering();
2968 const std::string host_address = "1.1.1.1"; 2945 const std::string host_address = "1.1.1.1";
2969 const int port_num = 1; 2946 const int port_num = 1;
2970 2947
2971 // kIceUfrag[1] is the current generation ufrag. 2948 // kIceUfrag[1] is the current generation ufrag.
2972 Candidate candidate = CreateUdpCandidate(LOCAL_PORT_TYPE, host_address, 2949 Candidate candidate = CreateUdpCandidate(LOCAL_PORT_TYPE, host_address,
2973 port_num, 1, kIceUfrag[1]); 2950 port_num, 1, kIceUfrag[1]);
2974 ch.AddRemoteCandidate(candidate); 2951 ch.AddRemoteCandidate(candidate);
2975 Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num); 2952 Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num);
2976 ASSERT_TRUE(conn1 != nullptr); 2953 ASSERT_TRUE(conn1 != nullptr);
(...skipping 19 matching lines...) Expand all
2996 EXPECT_TRUE(conn2->last_ping_received() > 0); 2973 EXPECT_TRUE(conn2->last_ping_received() > 0);
2997 } 2974 }
2998 2975
2999 // When the current selected connection is strong, lower-priority connections 2976 // When the current selected connection is strong, lower-priority connections
3000 // will be pruned. Otherwise, lower-priority connections are kept. 2977 // will be pruned. Otherwise, lower-priority connections are kept.
3001 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { 2978 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
3002 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2979 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3003 P2PTransportChannel ch("test channel", 1, &pa); 2980 P2PTransportChannel ch("test channel", 1, &pa);
3004 PrepareChannel(&ch); 2981 PrepareChannel(&ch);
3005 ch.SetIceRole(ICEROLE_CONTROLLED); 2982 ch.SetIceRole(ICEROLE_CONTROLLED);
3006 ch.Connect();
3007 ch.MaybeStartGathering(); 2983 ch.MaybeStartGathering();
3008 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2984 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3009 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2985 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3010 ASSERT_TRUE(conn1 != nullptr); 2986 ASSERT_TRUE(conn1 != nullptr);
3011 EXPECT_EQ(conn1, ch.selected_connection()); 2987 EXPECT_EQ(conn1, ch.selected_connection());
3012 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 2988 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3013 2989
3014 // When a higher-priority, nominated candidate comes in, the connections with 2990 // When a higher-priority, nominated candidate comes in, the connections with
3015 // lower-priority are pruned. 2991 // lower-priority are pruned.
3016 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 2992 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
(...skipping 17 matching lines...) Expand all
3034 WAIT(conn3->pruned(), 1000); 3010 WAIT(conn3->pruned(), 1000);
3035 EXPECT_FALSE(conn3->pruned()); 3011 EXPECT_FALSE(conn3->pruned());
3036 } 3012 }
3037 3013
3038 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) { 3014 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) {
3039 rtc::ScopedFakeClock clock; 3015 rtc::ScopedFakeClock clock;
3040 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3016 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3041 P2PTransportChannel ch("test channel", 1, &pa); 3017 P2PTransportChannel ch("test channel", 1, &pa);
3042 PrepareChannel(&ch); 3018 PrepareChannel(&ch);
3043 ch.SetIceRole(ICEROLE_CONTROLLED); 3019 ch.SetIceRole(ICEROLE_CONTROLLED);
3044 ch.Connect();
3045 ch.MaybeStartGathering(); 3020 ch.MaybeStartGathering();
3046 Connection* conn1 = 3021 Connection* conn1 =
3047 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 100, true); 3022 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 100, true);
3048 ASSERT_TRUE(conn1 != nullptr); 3023 ASSERT_TRUE(conn1 != nullptr);
3049 Connection* conn2 = 3024 Connection* conn2 =
3050 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 200, false); 3025 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 200, false);
3051 ASSERT_TRUE(conn2 != nullptr); 3026 ASSERT_TRUE(conn2 != nullptr);
3052 // Even if conn1 is writable, nominated, receiving data, it should not prune 3027 // Even if conn1 is writable, nominated, receiving data, it should not prune
3053 // conn2. 3028 // conn2.
3054 NominateConnection(conn1); 3029 NominateConnection(conn1);
3055 SIMULATED_WAIT(false, 1, clock); 3030 SIMULATED_WAIT(false, 1, clock);
3056 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3031 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3057 SIMULATED_WAIT(conn2->pruned(), 100, clock); 3032 SIMULATED_WAIT(conn2->pruned(), 100, clock);
3058 EXPECT_FALSE(conn2->pruned()); 3033 EXPECT_FALSE(conn2->pruned());
3059 } 3034 }
3060 3035
3061 // Test that GetState returns the state correctly. 3036 // Test that GetState returns the state correctly.
3062 TEST_F(P2PTransportChannelPingTest, TestGetState) { 3037 TEST_F(P2PTransportChannelPingTest, TestGetState) {
3063 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3038 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3064 P2PTransportChannel ch("test channel", 1, &pa); 3039 P2PTransportChannel ch("test channel", 1, &pa);
3065 PrepareChannel(&ch); 3040 PrepareChannel(&ch);
3066 ch.Connect();
3067 ch.MaybeStartGathering(); 3041 ch.MaybeStartGathering();
3068 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); 3042 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState());
3069 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3043 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3070 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3044 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3071 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3045 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3072 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3046 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3073 ASSERT_TRUE(conn1 != nullptr); 3047 ASSERT_TRUE(conn1 != nullptr);
3074 ASSERT_TRUE(conn2 != nullptr); 3048 ASSERT_TRUE(conn2 != nullptr);
3075 // Now there are two connections, so the transport channel is connecting. 3049 // Now there are two connections, so the transport channel is connecting.
3076 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3050 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3077 // |conn1| becomes writable and receiving; it then should prune |conn2|. 3051 // |conn1| becomes writable and receiving; it then should prune |conn2|.
3078 conn1->ReceivedPingResponse(LOW_RTT); 3052 conn1->ReceivedPingResponse(LOW_RTT);
3079 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); 3053 EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
3080 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3054 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3081 conn1->Prune(); // All connections are pruned. 3055 conn1->Prune(); // All connections are pruned.
3082 // Need to wait until the channel state is updated. 3056 // Need to wait until the channel state is updated.
3083 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); 3057 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000);
3084 } 3058 }
3085 3059
3086 // Test that when a low-priority connection is pruned, it is not deleted 3060 // Test that when a low-priority connection is pruned, it is not deleted
3087 // right away, and it can become active and be pruned again. 3061 // right away, and it can become active and be pruned again.
3088 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { 3062 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
3089 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3063 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3090 P2PTransportChannel ch("test channel", 1, &pa); 3064 P2PTransportChannel ch("test channel", 1, &pa);
3091 PrepareChannel(&ch); 3065 PrepareChannel(&ch);
3092 ch.SetIceConfig(CreateIceConfig(1000, false)); 3066 ch.SetIceConfig(CreateIceConfig(1000, false));
3093 ch.Connect();
3094 ch.MaybeStartGathering(); 3067 ch.MaybeStartGathering();
3095 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3068 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3096 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3069 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3097 ASSERT_TRUE(conn1 != nullptr); 3070 ASSERT_TRUE(conn1 != nullptr);
3098 EXPECT_EQ(conn1, ch.selected_connection()); 3071 EXPECT_EQ(conn1, ch.selected_connection());
3099 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3072 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3100 3073
3101 // Add a low-priority connection |conn2|, which will be pruned, but it will 3074 // Add a low-priority connection |conn2|, which will be pruned, but it will
3102 // not be deleted right away. Once the current selected connection becomes not 3075 // not be deleted right away. Once the current selected connection becomes not
3103 // receiving, |conn2| will start to ping and upon receiving the ping response, 3076 // receiving, |conn2| will start to ping and upon receiving the ping response,
(...skipping 21 matching lines...) Expand all
3125 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 3098 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
3126 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3099 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3127 } 3100 }
3128 3101
3129 // Test that if all connections in a channel has timed out on writing, they 3102 // Test that if all connections in a channel has timed out on writing, they
3130 // will all be deleted. We use Prune to simulate write_time_out. 3103 // will all be deleted. We use Prune to simulate write_time_out.
3131 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 3104 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
3132 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3105 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3133 P2PTransportChannel ch("test channel", 1, &pa); 3106 P2PTransportChannel ch("test channel", 1, &pa);
3134 PrepareChannel(&ch); 3107 PrepareChannel(&ch);
3135 ch.Connect();
3136 ch.MaybeStartGathering(); 3108 ch.MaybeStartGathering();
3137 // Have one connection only but later becomes write-time-out. 3109 // Have one connection only but later becomes write-time-out.
3138 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3110 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3139 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3111 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3140 ASSERT_TRUE(conn1 != nullptr); 3112 ASSERT_TRUE(conn1 != nullptr);
3141 conn1->ReceivedPing(); // Becomes receiving 3113 conn1->ReceivedPing(); // Becomes receiving
3142 conn1->Prune(); 3114 conn1->Prune();
3143 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); 3115 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000);
3144 3116
3145 // Have two connections but both become write-time-out later. 3117 // Have two connections but both become write-time-out later.
(...skipping 13 matching lines...) Expand all
3159 3131
3160 // Tests that after a port allocator session is started, it will be stopped 3132 // Tests that after a port allocator session is started, it will be stopped
3161 // when a new connection becomes writable and receiving. Also tests that if a 3133 // when a new connection becomes writable and receiving. Also tests that if a
3162 // connection belonging to an old session becomes writable, it won't stop 3134 // connection belonging to an old session becomes writable, it won't stop
3163 // the current port allocator session. 3135 // the current port allocator session.
3164 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { 3136 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
3165 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3137 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3166 P2PTransportChannel ch("test channel", 1, &pa); 3138 P2PTransportChannel ch("test channel", 1, &pa);
3167 PrepareChannel(&ch); 3139 PrepareChannel(&ch);
3168 ch.SetIceConfig(CreateIceConfig(2000, false)); 3140 ch.SetIceConfig(CreateIceConfig(2000, false));
3169 ch.Connect();
3170 ch.MaybeStartGathering(); 3141 ch.MaybeStartGathering();
3171 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3142 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3172 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3143 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3173 ASSERT_TRUE(conn1 != nullptr); 3144 ASSERT_TRUE(conn1 != nullptr);
3174 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3145 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3175 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3146 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3176 3147
3177 // Start a new session. Even though conn1, which belongs to an older 3148 // Start a new session. Even though conn1, which belongs to an older
3178 // session, becomes unwritable and writable again, it should not stop the 3149 // session, becomes unwritable and writable again, it should not stop the
3179 // current session. 3150 // current session.
(...skipping 17 matching lines...) Expand all
3197 // a correct role, in case the network becomes active before the connection is 3168 // a correct role, in case the network becomes active before the connection is
3198 // destroyed. 3169 // destroyed.
3199 TEST_F(P2PTransportChannelPingTest, 3170 TEST_F(P2PTransportChannelPingTest,
3200 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) { 3171 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) {
3201 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3172 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3202 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3173 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3203 // Starts with ICEROLE_CONTROLLING. 3174 // Starts with ICEROLE_CONTROLLING.
3204 PrepareChannel(&ch); 3175 PrepareChannel(&ch);
3205 IceConfig config = CreateIceConfig(1000, true); 3176 IceConfig config = CreateIceConfig(1000, true);
3206 ch.SetIceConfig(config); 3177 ch.SetIceConfig(config);
3207 ch.Connect();
3208 ch.MaybeStartGathering(); 3178 ch.MaybeStartGathering();
3209 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3179 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3210 3180
3211 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3181 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3212 ASSERT_TRUE(conn != nullptr); 3182 ASSERT_TRUE(conn != nullptr);
3213 3183
3214 // Make the fake port signal that its network is inactive, then change the 3184 // Make the fake port signal that its network is inactive, then change the
3215 // ICE role and expect it to be updated. 3185 // ICE role and expect it to be updated.
3216 conn->port()->SignalNetworkInactive(conn->port()); 3186 conn->port()->SignalNetworkInactive(conn->port());
3217 ch.SetIceRole(ICEROLE_CONTROLLED); 3187 ch.SetIceRole(ICEROLE_CONTROLLED);
3218 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 3188 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
3219 } 3189 }
3220 3190
3221 // Test that the ICE role is updated even on ports with inactive networks. 3191 // Test that the ICE role is updated even on ports with inactive networks.
3222 // These ports may still have connections that need a correct role, for the 3192 // These ports may still have connections that need a correct role, for the
3223 // pings sent by those connections until they're replaced by newer-generation 3193 // pings sent by those connections until they're replaced by newer-generation
3224 // connections. 3194 // connections.
3225 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { 3195 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
3226 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3196 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3227 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3197 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3228 // Starts with ICEROLE_CONTROLLING. 3198 // Starts with ICEROLE_CONTROLLING.
3229 PrepareChannel(&ch); 3199 PrepareChannel(&ch);
3230 ch.Connect();
3231 ch.MaybeStartGathering(); 3200 ch.MaybeStartGathering();
3232 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3201 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3233 3202
3234 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3203 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3235 ASSERT_TRUE(conn != nullptr); 3204 ASSERT_TRUE(conn != nullptr);
3236 3205
3237 // Do an ICE restart, change the role, and expect the old port to have its 3206 // Do an ICE restart, change the role, and expect the old port to have its
3238 // role updated. 3207 // role updated.
3239 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3208 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
3240 ch.MaybeStartGathering(); 3209 ch.MaybeStartGathering();
3241 ch.SetIceRole(ICEROLE_CONTROLLED); 3210 ch.SetIceRole(ICEROLE_CONTROLLED);
3242 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 3211 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
3243 } 3212 }
3244 3213
3245 // Test that after some amount of time without receiving data, the connection 3214 // Test that after some amount of time without receiving data, the connection
3246 // and port are destroyed. 3215 // and port are destroyed.
3247 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) { 3216 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) {
3248 rtc::ScopedFakeClock fake_clock; 3217 rtc::ScopedFakeClock fake_clock;
3249 3218
3250 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3219 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3251 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3220 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3252 PrepareChannel(&ch); 3221 PrepareChannel(&ch);
3253 // Only a controlled channel should expect its ports to be destroyed. 3222 // Only a controlled channel should expect its ports to be destroyed.
3254 ch.SetIceRole(ICEROLE_CONTROLLED); 3223 ch.SetIceRole(ICEROLE_CONTROLLED);
3255 ch.Connect();
3256 ch.MaybeStartGathering(); 3224 ch.MaybeStartGathering();
3257 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3225 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3258 3226
3259 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3227 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3260 ASSERT_TRUE(conn != nullptr); 3228 ASSERT_TRUE(conn != nullptr);
3261 3229
3262 // Simulate 2 minutes going by. This should be enough time for the port to 3230 // Simulate 2 minutes going by. This should be enough time for the port to
3263 // time out. 3231 // time out.
3264 for (int second = 0; second < 120; ++second) { 3232 for (int second = 0; second < 120; ++second) {
3265 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); 3233 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
(...skipping 24 matching lines...) Expand all
3290 bool prioritize_most_likely_to_work, 3258 bool prioritize_most_likely_to_work,
3291 int stable_writable_connection_ping_interval) { 3259 int stable_writable_connection_ping_interval) {
3292 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator())); 3260 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator()));
3293 IceConfig config = channel_->config(); 3261 IceConfig config = channel_->config();
3294 config.prioritize_most_likely_candidate_pairs = 3262 config.prioritize_most_likely_candidate_pairs =
3295 prioritize_most_likely_to_work; 3263 prioritize_most_likely_to_work;
3296 config.stable_writable_connection_ping_interval = 3264 config.stable_writable_connection_ping_interval =
3297 stable_writable_connection_ping_interval; 3265 stable_writable_connection_ping_interval;
3298 channel_->SetIceConfig(config); 3266 channel_->SetIceConfig(config);
3299 PrepareChannel(channel_.get()); 3267 PrepareChannel(channel_.get());
3300 channel_->Connect();
3301 channel_->MaybeStartGathering(); 3268 channel_->MaybeStartGathering();
3302 return *channel_.get(); 3269 return *channel_.get();
3303 } 3270 }
3304 3271
3305 BasicPortAllocator* allocator() { return allocator_.get(); } 3272 BasicPortAllocator* allocator() { return allocator_.get(); }
3306 TestTurnServer* turn_server() { return &turn_server_; } 3273 TestTurnServer* turn_server() { return &turn_server_; }
3307 3274
3308 // This verifies the next pingable connection has the expected candidates' 3275 // This verifies the next pingable connection has the expected candidates'
3309 // types and, for relay local candidate, the expected relay protocol and ping 3276 // types and, for relay local candidate, the expected relay protocol and ping
3310 // it. 3277 // it.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
3474 3441
3475 // TCP Relay/Relay is the next. 3442 // TCP Relay/Relay is the next.
3476 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3443 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3477 TCP_PROTOCOL_NAME); 3444 TCP_PROTOCOL_NAME);
3478 3445
3479 // Finally, Local/Relay will be pinged. 3446 // Finally, Local/Relay will be pinged.
3480 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3447 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3481 } 3448 }
3482 3449
3483 } // namespace cricket { 3450 } // namespace cricket {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698