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

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: Code style fixes, renaming some methods, calling MaybeStartPinging in a different place. 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 //
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL. 2402 // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL.
2413 start = clock.TimeNanos(); 2403 start = clock.TimeNanos();
2414 ping_sent_before = conn->num_pings_sent(); 2404 ping_sent_before = conn->num_pings_sent();
2415 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2405 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
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
2412 // Test that we start pinging as soon as we have a connection and remote ICE
2413 // credentials.
2414 TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) {
2415 rtc::ScopedFakeClock clock;
2416
2417 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2418 P2PTransportChannel ch("TestChannel", 1, &pa);
2419 ch.SetIceRole(ICEROLE_CONTROLLING);
2420 ch.SetIceCredentials(kIceUfrag[0], kIcePwd[0]);
2421 ch.MaybeStartGathering();
2422 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(),
2423 kDefaultTimeout);
2424
2425 // Simulate a binding request being received, creating a peer reflexive
2426 // candidate pair while we still don't have remote ICE credentials.
2427 IceMessage request;
2428 request.SetType(STUN_BINDING_REQUEST);
2429 request.AddAttribute(
2430 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
2431 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
2432 request.AddAttribute(
2433 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
2434 Port* port = GetPort(&ch);
2435 ASSERT_NE(nullptr, port);
2436 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
2437 &request, kIceUfrag[1], false);
2438 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1);
2439 ASSERT_NE(nullptr, conn);
2440
2441 // Simulate waiting for a second (and change) and verify that no pings were
2442 // sent, since we don't yet have remote ICE credentials.
2443 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock);
2444 EXPECT_EQ(0, conn->num_pings_sent());
2445
2446 // Set remote ICE credentials. Now we should be able to ping. Ensure that
2447 // the first ping is sent as soon as possible, within one simulated clock
2448 // tick.
2449 ch.SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
2450 EXPECT_TRUE_SIMULATED_WAIT(conn->num_pings_sent() > 0, 1, clock);
2451 }
2452
2422 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { 2453 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
2423 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2454 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2424 P2PTransportChannel ch("trigger checks", 1, &pa); 2455 P2PTransportChannel ch("trigger checks", 1, &pa);
2425 PrepareChannel(&ch); 2456 PrepareChannel(&ch);
2426 ch.Connect();
2427 ch.MaybeStartGathering(); 2457 ch.MaybeStartGathering();
2428 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2458 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)); 2459 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
2430 2460
2431 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2461 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2432 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2462 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2433 ASSERT_TRUE(conn1 != nullptr); 2463 ASSERT_TRUE(conn1 != nullptr);
2434 ASSERT_TRUE(conn2 != nullptr); 2464 ASSERT_TRUE(conn2 != nullptr);
2435 2465
2436 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2466 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2437 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2467 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2438 conn1->ReceivedPingResponse(LOW_RTT); 2468 conn1->ReceivedPingResponse(LOW_RTT);
2439 ASSERT_TRUE(conn1->writable()); 2469 ASSERT_TRUE(conn1->writable());
2440 conn1->ReceivedPing(); 2470 conn1->ReceivedPing();
2441 2471
2442 // Ping received, but the connection is already writable, so no 2472 // Ping received, but the connection is already writable, so no
2443 // "triggered check" and conn2 is pinged before conn1 because it has 2473 // "triggered check" and conn2 is pinged before conn1 because it has
2444 // a higher priority. 2474 // a higher priority.
2445 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2475 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2446 } 2476 }
2447 2477
2448 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) { 2478 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) {
2449 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2479 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2450 P2PTransportChannel ch("Do not ping failed connections", 1, &pa); 2480 P2PTransportChannel ch("Do not ping failed connections", 1, &pa);
2451 PrepareChannel(&ch); 2481 PrepareChannel(&ch);
2452 ch.Connect();
2453 ch.MaybeStartGathering(); 2482 ch.MaybeStartGathering();
2454 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2483 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2455 2484
2456 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2485 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2457 ASSERT_TRUE(conn1 != nullptr); 2486 ASSERT_TRUE(conn1 != nullptr);
2458 2487
2459 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); 2488 EXPECT_EQ(conn1, ch.FindNextPingableConnection());
2460 conn1->Prune(); // A pruned connection may still be pingable. 2489 conn1->Prune(); // A pruned connection may still be pingable.
2461 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); 2490 EXPECT_EQ(conn1, ch.FindNextPingableConnection());
2462 conn1->FailAndPrune(); 2491 conn1->FailAndPrune();
2463 EXPECT_TRUE(nullptr == ch.FindNextPingableConnection()); 2492 EXPECT_TRUE(nullptr == ch.FindNextPingableConnection());
2464 } 2493 }
2465 2494
2466 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { 2495 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) {
2467 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2496 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2468 P2PTransportChannel ch("state change", 1, &pa); 2497 P2PTransportChannel ch("state change", 1, &pa);
2469 PrepareChannel(&ch); 2498 PrepareChannel(&ch);
2470 ch.Connect();
2471 ch.MaybeStartGathering(); 2499 ch.MaybeStartGathering();
2472 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2500 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2473 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2501 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2474 ASSERT_TRUE(conn1 != nullptr); 2502 ASSERT_TRUE(conn1 != nullptr);
2475 // Pruning the connection reduces the set of active connections and changes 2503 // Pruning the connection reduces the set of active connections and changes
2476 // the channel state. 2504 // the channel state.
2477 conn1->Prune(); 2505 conn1->Prune();
2478 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); 2506 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout);
2479 } 2507 }
2480 2508
2481 // Test adding remote candidates with different ufrags. If a remote candidate 2509 // 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 2510 // 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 2511 // 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 2512 // 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 2513 // credentials arrive. If a remote candidate is added with the current ICE
2486 // ufrag, its pwd and generation will be set properly. 2514 // ufrag, its pwd and generation will be set properly.
2487 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { 2515 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
2488 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2516 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2489 P2PTransportChannel ch("add candidate", 1, &pa); 2517 P2PTransportChannel ch("add candidate", 1, &pa);
2490 PrepareChannel(&ch); 2518 PrepareChannel(&ch);
2491 ch.Connect();
2492 ch.MaybeStartGathering(); 2519 ch.MaybeStartGathering();
2493 // Add a candidate with a future ufrag. 2520 // Add a candidate with a future ufrag.
2494 ch.AddRemoteCandidate( 2521 ch.AddRemoteCandidate(
2495 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2])); 2522 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2]));
2496 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2523 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2497 ASSERT_TRUE(conn1 != nullptr); 2524 ASSERT_TRUE(conn1 != nullptr);
2498 const Candidate& candidate = conn1->remote_candidate(); 2525 const Candidate& candidate = conn1->remote_candidate();
2499 EXPECT_EQ(kIceUfrag[2], candidate.username()); 2526 EXPECT_EQ(kIceUfrag[2], candidate.username());
2500 EXPECT_TRUE(candidate.password().empty()); 2527 EXPECT_TRUE(candidate.password().empty());
2501 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); 2528 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 } else if (candidate.username() == kIceUfrag[2]) { 2561 } else if (candidate.username() == kIceUfrag[2]) {
2535 EXPECT_EQ(kIcePwd[2], candidate.password()); 2562 EXPECT_EQ(kIcePwd[2], candidate.password());
2536 } 2563 }
2537 } 2564 }
2538 } 2565 }
2539 2566
2540 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { 2567 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
2541 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2568 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2542 P2PTransportChannel ch("connection resurrection", 1, &pa); 2569 P2PTransportChannel ch("connection resurrection", 1, &pa);
2543 PrepareChannel(&ch); 2570 PrepareChannel(&ch);
2544 ch.Connect();
2545 ch.MaybeStartGathering(); 2571 ch.MaybeStartGathering();
2546 2572
2547 // Create conn1 and keep track of original candidate priority. 2573 // Create conn1 and keep track of original candidate priority.
2548 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2574 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2549 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2575 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2550 ASSERT_TRUE(conn1 != nullptr); 2576 ASSERT_TRUE(conn1 != nullptr);
2551 uint32_t remote_priority = conn1->remote_candidate().priority(); 2577 uint32_t remote_priority = conn1->remote_candidate().priority();
2552 2578
2553 // Create a higher priority candidate and make the connection 2579 // Create a higher priority candidate and make the connection
2554 // receiving/writable. This will prune conn1. 2580 // 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); 2620 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2595 P2PTransportChannel ch("receiving state change", 1, &pa); 2621 P2PTransportChannel ch("receiving state change", 1, &pa);
2596 PrepareChannel(&ch); 2622 PrepareChannel(&ch);
2597 // Default receiving timeout and checking receiving interval should not be too 2623 // Default receiving timeout and checking receiving interval should not be too
2598 // small. 2624 // small.
2599 EXPECT_LE(1000, ch.receiving_timeout()); 2625 EXPECT_LE(1000, ch.receiving_timeout());
2600 EXPECT_LE(200, ch.check_receiving_interval()); 2626 EXPECT_LE(200, ch.check_receiving_interval());
2601 ch.SetIceConfig(CreateIceConfig(500, false)); 2627 ch.SetIceConfig(CreateIceConfig(500, false));
2602 EXPECT_EQ(500, ch.receiving_timeout()); 2628 EXPECT_EQ(500, ch.receiving_timeout());
2603 EXPECT_EQ(50, ch.check_receiving_interval()); 2629 EXPECT_EQ(50, ch.check_receiving_interval());
2604 ch.Connect();
2605 ch.MaybeStartGathering(); 2630 ch.MaybeStartGathering();
2606 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2631 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2607 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2632 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2608 ASSERT_TRUE(conn1 != nullptr); 2633 ASSERT_TRUE(conn1 != nullptr);
2609 2634
2610 conn1->ReceivedPing(); 2635 conn1->ReceivedPing();
2611 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 2636 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
2612 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000); 2637 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000);
2613 EXPECT_TRUE_WAIT(ch.receiving(), 1000); 2638 EXPECT_TRUE_WAIT(ch.receiving(), 1000);
2614 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); 2639 EXPECT_TRUE_WAIT(!ch.receiving(), 1000);
2615 } 2640 }
2616 2641
2617 // The controlled side will select a connection as the "selected connection" 2642 // The controlled side will select a connection as the "selected connection"
2618 // based on priority until the controlling side nominates a connection, at which 2643 // based on priority until the controlling side nominates a connection, at which
2619 // point the controlled side will select that connection as the 2644 // point the controlled side will select that connection as the
2620 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the 2645 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the
2621 // selected connection changes and SignalReadyToSend will be fired if the new 2646 // selected connection changes and SignalReadyToSend will be fired if the new
2622 // selected connection is writable. 2647 // selected connection is writable.
2623 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { 2648 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
2624 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2649 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2625 P2PTransportChannel ch("receiving state change", 1, &pa); 2650 P2PTransportChannel ch("receiving state change", 1, &pa);
2626 PrepareChannel(&ch); 2651 PrepareChannel(&ch);
2627 ch.SetIceRole(ICEROLE_CONTROLLED); 2652 ch.SetIceRole(ICEROLE_CONTROLLED);
2628 ch.Connect();
2629 ch.MaybeStartGathering(); 2653 ch.MaybeStartGathering();
2630 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2654 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2631 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2655 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2632 ASSERT_TRUE(conn1 != nullptr); 2656 ASSERT_TRUE(conn1 != nullptr);
2633 EXPECT_EQ(conn1, ch.selected_connection()); 2657 EXPECT_EQ(conn1, ch.selected_connection());
2634 EXPECT_EQ(conn1, last_selected_candidate_pair()); 2658 EXPECT_EQ(conn1, last_selected_candidate_pair());
2635 EXPECT_EQ(-1, last_sent_packet_id()); 2659 EXPECT_EQ(-1, last_sent_packet_id());
2636 // Channel is not ready to send because it is not writable. 2660 // Channel is not ready to send because it is not writable.
2637 EXPECT_FALSE(channel_ready_to_send()); 2661 EXPECT_FALSE(channel_ready_to_send());
2638 2662
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2697 // based on requests from an unknown address before the controlling side 2721 // based on requests from an unknown address before the controlling side
2698 // nominates a connection, and will nominate a connection from an unknown 2722 // nominates a connection, and will nominate a connection from an unknown
2699 // address if the request contains the use_candidate attribute. Plus, it will 2723 // 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 2724 // also sends back a ping response and set the ICE pwd in the remote candidate
2701 // appropriately. 2725 // appropriately.
2702 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { 2726 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
2703 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2727 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2704 P2PTransportChannel ch("receiving state change", 1, &pa); 2728 P2PTransportChannel ch("receiving state change", 1, &pa);
2705 PrepareChannel(&ch); 2729 PrepareChannel(&ch);
2706 ch.SetIceRole(ICEROLE_CONTROLLED); 2730 ch.SetIceRole(ICEROLE_CONTROLLED);
2707 ch.Connect();
2708 ch.MaybeStartGathering(); 2731 ch.MaybeStartGathering();
2709 // A minimal STUN message with prflx priority. 2732 // A minimal STUN message with prflx priority.
2710 IceMessage request; 2733 IceMessage request;
2711 request.SetType(STUN_BINDING_REQUEST); 2734 request.SetType(STUN_BINDING_REQUEST);
2712 request.AddAttribute( 2735 request.AddAttribute(
2713 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 2736 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
2714 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 2737 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
2715 request.AddAttribute( 2738 request.AddAttribute(
2716 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 2739 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
2717 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); 2740 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2778 2801
2779 // The controlled side will select a connection as the "selected connection" 2802 // The controlled side will select a connection as the "selected connection"
2780 // based on media received until the controlling side nominates a connection, 2803 // based on media received until the controlling side nominates a connection,
2781 // at which point the controlled side will select that connection as 2804 // at which point the controlled side will select that connection as
2782 // the "selected connection". 2805 // the "selected connection".
2783 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { 2806 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
2784 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2807 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2785 P2PTransportChannel ch("receiving state change", 1, &pa); 2808 P2PTransportChannel ch("receiving state change", 1, &pa);
2786 PrepareChannel(&ch); 2809 PrepareChannel(&ch);
2787 ch.SetIceRole(ICEROLE_CONTROLLED); 2810 ch.SetIceRole(ICEROLE_CONTROLLED);
2788 ch.Connect();
2789 ch.MaybeStartGathering(); 2811 ch.MaybeStartGathering();
2790 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10)); 2812 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10));
2791 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2813 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2792 ASSERT_TRUE(conn1 != nullptr); 2814 ASSERT_TRUE(conn1 != nullptr);
2793 EXPECT_EQ(conn1, ch.selected_connection()); 2815 EXPECT_EQ(conn1, ch.selected_connection());
2794 2816
2795 // If a data packet is received on conn2, the selected connection should 2817 // 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 2818 // switch to conn2 because the controlled side must mirror the media path
2797 // chosen by the controlling side. 2819 // chosen by the controlling side.
2798 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 2820 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 } 2853 }
2832 2854
2833 TEST_F(P2PTransportChannelPingTest, 2855 TEST_F(P2PTransportChannelPingTest,
2834 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) { 2856 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) {
2835 rtc::ScopedFakeClock clock; 2857 rtc::ScopedFakeClock clock;
2836 2858
2837 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2859 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2838 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 2860 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
2839 PrepareChannel(&ch); 2861 PrepareChannel(&ch);
2840 ch.SetIceRole(ICEROLE_CONTROLLED); 2862 ch.SetIceRole(ICEROLE_CONTROLLED);
2841 ch.Connect();
2842 ch.MaybeStartGathering(); 2863 ch.MaybeStartGathering();
2843 // The connections have decreasing priority. 2864 // The connections have decreasing priority.
2844 Connection* conn1 = 2865 Connection* conn1 =
2845 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); 2866 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true);
2846 ASSERT_TRUE(conn1 != nullptr); 2867 ASSERT_TRUE(conn1 != nullptr);
2847 Connection* conn2 = 2868 Connection* conn2 =
2848 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true); 2869 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true);
2849 ASSERT_TRUE(conn2 != nullptr); 2870 ASSERT_TRUE(conn2 != nullptr);
2850 2871
2851 // Initially, connections are selected based on priority. 2872 // Initially, connections are selected based on priority.
(...skipping 19 matching lines...) Expand all
2871 } 2892 }
2872 2893
2873 TEST_F(P2PTransportChannelPingTest, 2894 TEST_F(P2PTransportChannelPingTest,
2874 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) { 2895 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) {
2875 rtc::ScopedFakeClock clock; 2896 rtc::ScopedFakeClock clock;
2876 2897
2877 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2898 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2878 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 2899 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
2879 PrepareChannel(&ch); 2900 PrepareChannel(&ch);
2880 ch.SetIceRole(ICEROLE_CONTROLLED); 2901 ch.SetIceRole(ICEROLE_CONTROLLED);
2881 ch.Connect();
2882 ch.MaybeStartGathering(); 2902 ch.MaybeStartGathering();
2883 // The connections have decreasing priority. 2903 // The connections have decreasing priority.
2884 Connection* conn1 = 2904 Connection* conn1 =
2885 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 2905 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
2886 ASSERT_TRUE(conn1 != nullptr); 2906 ASSERT_TRUE(conn1 != nullptr);
2887 Connection* conn2 = 2907 Connection* conn2 =
2888 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 2908 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
2889 ASSERT_TRUE(conn2 != nullptr); 2909 ASSERT_TRUE(conn2 != nullptr);
2890 2910
2891 // conn1 received data; it is the selected connection. 2911 // conn1 received data; it is the selected connection.
(...skipping 25 matching lines...) Expand all
2917 } 2937 }
2918 2938
2919 TEST_F(P2PTransportChannelPingTest, 2939 TEST_F(P2PTransportChannelPingTest,
2920 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) { 2940 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) {
2921 rtc::ScopedFakeClock clock; 2941 rtc::ScopedFakeClock clock;
2922 2942
2923 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2943 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2924 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 2944 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
2925 PrepareChannel(&ch); 2945 PrepareChannel(&ch);
2926 ch.SetIceRole(ICEROLE_CONTROLLED); 2946 ch.SetIceRole(ICEROLE_CONTROLLED);
2927 ch.Connect();
2928 ch.MaybeStartGathering(); 2947 ch.MaybeStartGathering();
2929 // The connections have decreasing priority. 2948 // The connections have decreasing priority.
2930 Connection* conn1 = 2949 Connection* conn1 =
2931 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 2950 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
2932 ASSERT_TRUE(conn1 != nullptr); 2951 ASSERT_TRUE(conn1 != nullptr);
2933 Connection* conn2 = 2952 Connection* conn2 =
2934 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 2953 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
2935 ASSERT_TRUE(conn2 != nullptr); 2954 ASSERT_TRUE(conn2 != nullptr);
2936 2955
2937 NominateConnection(conn1); 2956 NominateConnection(conn1);
(...skipping 18 matching lines...) Expand all
2956 SIMULATED_WAIT(false, 10, clock); 2975 SIMULATED_WAIT(false, 10, clock);
2957 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); 2976 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches());
2958 } 2977 }
2959 2978
2960 // Test that if a new remote candidate has the same address and port with 2979 // 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. 2980 // an old one, it will be used to create a new connection.
2962 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { 2981 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
2963 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2982 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2964 P2PTransportChannel ch("candidate reuse", 1, &pa); 2983 P2PTransportChannel ch("candidate reuse", 1, &pa);
2965 PrepareChannel(&ch); 2984 PrepareChannel(&ch);
2966 ch.Connect();
2967 ch.MaybeStartGathering(); 2985 ch.MaybeStartGathering();
2968 const std::string host_address = "1.1.1.1"; 2986 const std::string host_address = "1.1.1.1";
2969 const int port_num = 1; 2987 const int port_num = 1;
2970 2988
2971 // kIceUfrag[1] is the current generation ufrag. 2989 // kIceUfrag[1] is the current generation ufrag.
2972 Candidate candidate = CreateUdpCandidate(LOCAL_PORT_TYPE, host_address, 2990 Candidate candidate = CreateUdpCandidate(LOCAL_PORT_TYPE, host_address,
2973 port_num, 1, kIceUfrag[1]); 2991 port_num, 1, kIceUfrag[1]);
2974 ch.AddRemoteCandidate(candidate); 2992 ch.AddRemoteCandidate(candidate);
2975 Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num); 2993 Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num);
2976 ASSERT_TRUE(conn1 != nullptr); 2994 ASSERT_TRUE(conn1 != nullptr);
(...skipping 19 matching lines...) Expand all
2996 EXPECT_TRUE(conn2->last_ping_received() > 0); 3014 EXPECT_TRUE(conn2->last_ping_received() > 0);
2997 } 3015 }
2998 3016
2999 // When the current selected connection is strong, lower-priority connections 3017 // When the current selected connection is strong, lower-priority connections
3000 // will be pruned. Otherwise, lower-priority connections are kept. 3018 // will be pruned. Otherwise, lower-priority connections are kept.
3001 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { 3019 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
3002 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3020 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3003 P2PTransportChannel ch("test channel", 1, &pa); 3021 P2PTransportChannel ch("test channel", 1, &pa);
3004 PrepareChannel(&ch); 3022 PrepareChannel(&ch);
3005 ch.SetIceRole(ICEROLE_CONTROLLED); 3023 ch.SetIceRole(ICEROLE_CONTROLLED);
3006 ch.Connect();
3007 ch.MaybeStartGathering(); 3024 ch.MaybeStartGathering();
3008 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3025 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3009 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3026 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3010 ASSERT_TRUE(conn1 != nullptr); 3027 ASSERT_TRUE(conn1 != nullptr);
3011 EXPECT_EQ(conn1, ch.selected_connection()); 3028 EXPECT_EQ(conn1, ch.selected_connection());
3012 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3029 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3013 3030
3014 // When a higher-priority, nominated candidate comes in, the connections with 3031 // When a higher-priority, nominated candidate comes in, the connections with
3015 // lower-priority are pruned. 3032 // lower-priority are pruned.
3016 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 3033 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
(...skipping 17 matching lines...) Expand all
3034 WAIT(conn3->pruned(), 1000); 3051 WAIT(conn3->pruned(), 1000);
3035 EXPECT_FALSE(conn3->pruned()); 3052 EXPECT_FALSE(conn3->pruned());
3036 } 3053 }
3037 3054
3038 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) { 3055 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) {
3039 rtc::ScopedFakeClock clock; 3056 rtc::ScopedFakeClock clock;
3040 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3057 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3041 P2PTransportChannel ch("test channel", 1, &pa); 3058 P2PTransportChannel ch("test channel", 1, &pa);
3042 PrepareChannel(&ch); 3059 PrepareChannel(&ch);
3043 ch.SetIceRole(ICEROLE_CONTROLLED); 3060 ch.SetIceRole(ICEROLE_CONTROLLED);
3044 ch.Connect();
3045 ch.MaybeStartGathering(); 3061 ch.MaybeStartGathering();
3046 Connection* conn1 = 3062 Connection* conn1 =
3047 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 100, true); 3063 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 100, true);
3048 ASSERT_TRUE(conn1 != nullptr); 3064 ASSERT_TRUE(conn1 != nullptr);
3049 Connection* conn2 = 3065 Connection* conn2 =
3050 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 200, false); 3066 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 200, false);
3051 ASSERT_TRUE(conn2 != nullptr); 3067 ASSERT_TRUE(conn2 != nullptr);
3052 // Even if conn1 is writable, nominated, receiving data, it should not prune 3068 // Even if conn1 is writable, nominated, receiving data, it should not prune
3053 // conn2. 3069 // conn2.
3054 NominateConnection(conn1); 3070 NominateConnection(conn1);
3055 SIMULATED_WAIT(false, 1, clock); 3071 SIMULATED_WAIT(false, 1, clock);
3056 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3072 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3057 SIMULATED_WAIT(conn2->pruned(), 100, clock); 3073 SIMULATED_WAIT(conn2->pruned(), 100, clock);
3058 EXPECT_FALSE(conn2->pruned()); 3074 EXPECT_FALSE(conn2->pruned());
3059 } 3075 }
3060 3076
3061 // Test that GetState returns the state correctly. 3077 // Test that GetState returns the state correctly.
3062 TEST_F(P2PTransportChannelPingTest, TestGetState) { 3078 TEST_F(P2PTransportChannelPingTest, TestGetState) {
3063 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3079 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3064 P2PTransportChannel ch("test channel", 1, &pa); 3080 P2PTransportChannel ch("test channel", 1, &pa);
3065 PrepareChannel(&ch); 3081 PrepareChannel(&ch);
3066 ch.Connect();
3067 ch.MaybeStartGathering(); 3082 ch.MaybeStartGathering();
3068 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); 3083 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState());
3069 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3084 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)); 3085 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3071 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3086 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3072 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3087 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3073 ASSERT_TRUE(conn1 != nullptr); 3088 ASSERT_TRUE(conn1 != nullptr);
3074 ASSERT_TRUE(conn2 != nullptr); 3089 ASSERT_TRUE(conn2 != nullptr);
3075 // Now there are two connections, so the transport channel is connecting. 3090 // Now there are two connections, so the transport channel is connecting.
3076 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3091 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3077 // |conn1| becomes writable and receiving; it then should prune |conn2|. 3092 // |conn1| becomes writable and receiving; it then should prune |conn2|.
3078 conn1->ReceivedPingResponse(LOW_RTT); 3093 conn1->ReceivedPingResponse(LOW_RTT);
3079 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); 3094 EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
3080 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3095 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3081 conn1->Prune(); // All connections are pruned. 3096 conn1->Prune(); // All connections are pruned.
3082 // Need to wait until the channel state is updated. 3097 // Need to wait until the channel state is updated.
3083 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); 3098 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000);
3084 } 3099 }
3085 3100
3086 // Test that when a low-priority connection is pruned, it is not deleted 3101 // 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. 3102 // right away, and it can become active and be pruned again.
3088 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { 3103 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
3089 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3104 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3090 P2PTransportChannel ch("test channel", 1, &pa); 3105 P2PTransportChannel ch("test channel", 1, &pa);
3091 PrepareChannel(&ch); 3106 PrepareChannel(&ch);
3092 ch.SetIceConfig(CreateIceConfig(1000, false)); 3107 ch.SetIceConfig(CreateIceConfig(1000, false));
3093 ch.Connect();
3094 ch.MaybeStartGathering(); 3108 ch.MaybeStartGathering();
3095 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3109 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3096 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3110 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3097 ASSERT_TRUE(conn1 != nullptr); 3111 ASSERT_TRUE(conn1 != nullptr);
3098 EXPECT_EQ(conn1, ch.selected_connection()); 3112 EXPECT_EQ(conn1, ch.selected_connection());
3099 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3113 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3100 3114
3101 // Add a low-priority connection |conn2|, which will be pruned, but it will 3115 // 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 3116 // 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, 3117 // 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); 3139 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
3126 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3140 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3127 } 3141 }
3128 3142
3129 // Test that if all connections in a channel has timed out on writing, they 3143 // 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. 3144 // will all be deleted. We use Prune to simulate write_time_out.
3131 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 3145 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
3132 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3146 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3133 P2PTransportChannel ch("test channel", 1, &pa); 3147 P2PTransportChannel ch("test channel", 1, &pa);
3134 PrepareChannel(&ch); 3148 PrepareChannel(&ch);
3135 ch.Connect();
3136 ch.MaybeStartGathering(); 3149 ch.MaybeStartGathering();
3137 // Have one connection only but later becomes write-time-out. 3150 // Have one connection only but later becomes write-time-out.
3138 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3151 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3139 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3152 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3140 ASSERT_TRUE(conn1 != nullptr); 3153 ASSERT_TRUE(conn1 != nullptr);
3141 conn1->ReceivedPing(); // Becomes receiving 3154 conn1->ReceivedPing(); // Becomes receiving
3142 conn1->Prune(); 3155 conn1->Prune();
3143 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); 3156 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000);
3144 3157
3145 // Have two connections but both become write-time-out later. 3158 // Have two connections but both become write-time-out later.
(...skipping 13 matching lines...) Expand all
3159 3172
3160 // Tests that after a port allocator session is started, it will be stopped 3173 // 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 3174 // 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 3175 // connection belonging to an old session becomes writable, it won't stop
3163 // the current port allocator session. 3176 // the current port allocator session.
3164 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { 3177 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
3165 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3178 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3166 P2PTransportChannel ch("test channel", 1, &pa); 3179 P2PTransportChannel ch("test channel", 1, &pa);
3167 PrepareChannel(&ch); 3180 PrepareChannel(&ch);
3168 ch.SetIceConfig(CreateIceConfig(2000, false)); 3181 ch.SetIceConfig(CreateIceConfig(2000, false));
3169 ch.Connect();
3170 ch.MaybeStartGathering(); 3182 ch.MaybeStartGathering();
3171 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3183 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3172 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3184 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3173 ASSERT_TRUE(conn1 != nullptr); 3185 ASSERT_TRUE(conn1 != nullptr);
3174 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3186 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3175 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3187 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3176 3188
3177 // Start a new session. Even though conn1, which belongs to an older 3189 // Start a new session. Even though conn1, which belongs to an older
3178 // session, becomes unwritable and writable again, it should not stop the 3190 // session, becomes unwritable and writable again, it should not stop the
3179 // current session. 3191 // current session.
(...skipping 17 matching lines...) Expand all
3197 // a correct role, in case the network becomes active before the connection is 3209 // a correct role, in case the network becomes active before the connection is
3198 // destroyed. 3210 // destroyed.
3199 TEST_F(P2PTransportChannelPingTest, 3211 TEST_F(P2PTransportChannelPingTest,
3200 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) { 3212 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) {
3201 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3213 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3202 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3214 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3203 // Starts with ICEROLE_CONTROLLING. 3215 // Starts with ICEROLE_CONTROLLING.
3204 PrepareChannel(&ch); 3216 PrepareChannel(&ch);
3205 IceConfig config = CreateIceConfig(1000, true); 3217 IceConfig config = CreateIceConfig(1000, true);
3206 ch.SetIceConfig(config); 3218 ch.SetIceConfig(config);
3207 ch.Connect();
3208 ch.MaybeStartGathering(); 3219 ch.MaybeStartGathering();
3209 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3220 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3210 3221
3211 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3222 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3212 ASSERT_TRUE(conn != nullptr); 3223 ASSERT_TRUE(conn != nullptr);
3213 3224
3214 // Make the fake port signal that its network is inactive, then change the 3225 // Make the fake port signal that its network is inactive, then change the
3215 // ICE role and expect it to be updated. 3226 // ICE role and expect it to be updated.
3216 conn->port()->SignalNetworkInactive(conn->port()); 3227 conn->port()->SignalNetworkInactive(conn->port());
3217 ch.SetIceRole(ICEROLE_CONTROLLED); 3228 ch.SetIceRole(ICEROLE_CONTROLLED);
3218 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 3229 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
3219 } 3230 }
3220 3231
3221 // Test that the ICE role is updated even on ports with inactive networks. 3232 // 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 3233 // 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 3234 // pings sent by those connections until they're replaced by newer-generation
3224 // connections. 3235 // connections.
3225 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { 3236 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
3226 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3237 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3227 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3238 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3228 // Starts with ICEROLE_CONTROLLING. 3239 // Starts with ICEROLE_CONTROLLING.
3229 PrepareChannel(&ch); 3240 PrepareChannel(&ch);
3230 ch.Connect();
3231 ch.MaybeStartGathering(); 3241 ch.MaybeStartGathering();
3232 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3242 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3233 3243
3234 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3244 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3235 ASSERT_TRUE(conn != nullptr); 3245 ASSERT_TRUE(conn != nullptr);
3236 3246
3237 // Do an ICE restart, change the role, and expect the old port to have its 3247 // Do an ICE restart, change the role, and expect the old port to have its
3238 // role updated. 3248 // role updated.
3239 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3249 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
3240 ch.MaybeStartGathering(); 3250 ch.MaybeStartGathering();
3241 ch.SetIceRole(ICEROLE_CONTROLLED); 3251 ch.SetIceRole(ICEROLE_CONTROLLED);
3242 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 3252 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
3243 } 3253 }
3244 3254
3245 // Test that after some amount of time without receiving data, the connection 3255 // Test that after some amount of time without receiving data, the connection
3246 // and port are destroyed. 3256 // and port are destroyed.
3247 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) { 3257 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) {
3248 rtc::ScopedFakeClock fake_clock; 3258 rtc::ScopedFakeClock fake_clock;
3249 3259
3250 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3260 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3251 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3261 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3252 PrepareChannel(&ch); 3262 PrepareChannel(&ch);
3253 // Only a controlled channel should expect its ports to be destroyed. 3263 // Only a controlled channel should expect its ports to be destroyed.
3254 ch.SetIceRole(ICEROLE_CONTROLLED); 3264 ch.SetIceRole(ICEROLE_CONTROLLED);
3255 ch.Connect();
3256 ch.MaybeStartGathering(); 3265 ch.MaybeStartGathering();
3257 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3266 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3258 3267
3259 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3268 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3260 ASSERT_TRUE(conn != nullptr); 3269 ASSERT_TRUE(conn != nullptr);
3261 3270
3262 // Simulate 2 minutes going by. This should be enough time for the port to 3271 // Simulate 2 minutes going by. This should be enough time for the port to
3263 // time out. 3272 // time out.
3264 for (int second = 0; second < 120; ++second) { 3273 for (int second = 0; second < 120; ++second) {
3265 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); 3274 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
(...skipping 24 matching lines...) Expand all
3290 bool prioritize_most_likely_to_work, 3299 bool prioritize_most_likely_to_work,
3291 int stable_writable_connection_ping_interval) { 3300 int stable_writable_connection_ping_interval) {
3292 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator())); 3301 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator()));
3293 IceConfig config = channel_->config(); 3302 IceConfig config = channel_->config();
3294 config.prioritize_most_likely_candidate_pairs = 3303 config.prioritize_most_likely_candidate_pairs =
3295 prioritize_most_likely_to_work; 3304 prioritize_most_likely_to_work;
3296 config.stable_writable_connection_ping_interval = 3305 config.stable_writable_connection_ping_interval =
3297 stable_writable_connection_ping_interval; 3306 stable_writable_connection_ping_interval;
3298 channel_->SetIceConfig(config); 3307 channel_->SetIceConfig(config);
3299 PrepareChannel(channel_.get()); 3308 PrepareChannel(channel_.get());
3300 channel_->Connect();
3301 channel_->MaybeStartGathering(); 3309 channel_->MaybeStartGathering();
3302 return *channel_.get(); 3310 return *channel_.get();
3303 } 3311 }
3304 3312
3305 BasicPortAllocator* allocator() { return allocator_.get(); } 3313 BasicPortAllocator* allocator() { return allocator_.get(); }
3306 TestTurnServer* turn_server() { return &turn_server_; } 3314 TestTurnServer* turn_server() { return &turn_server_; }
3307 3315
3308 // This verifies the next pingable connection has the expected candidates' 3316 // This verifies the next pingable connection has the expected candidates'
3309 // types and, for relay local candidate, the expected relay protocol and ping 3317 // types and, for relay local candidate, the expected relay protocol and ping
3310 // it. 3318 // it.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
3474 3482
3475 // TCP Relay/Relay is the next. 3483 // TCP Relay/Relay is the next.
3476 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3484 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3477 TCP_PROTOCOL_NAME); 3485 TCP_PROTOCOL_NAME);
3478 3486
3479 // Finally, Local/Relay will be pinged. 3487 // Finally, Local/Relay will be pinged.
3480 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3488 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3481 } 3489 }
3482 3490
3483 } // namespace cricket { 3491 } // namespace cricket {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698