OLD | NEW |
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 26 matching lines...) Expand all Loading... |
37 using cricket::kDefaultStepDelay; | 37 using cricket::kDefaultStepDelay; |
38 using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET; | 38 using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET; |
39 using cricket::ServerAddresses; | 39 using cricket::ServerAddresses; |
40 using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL; | 40 using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL; |
41 using rtc::SocketAddress; | 41 using rtc::SocketAddress; |
42 | 42 |
43 static const int kDefaultTimeout = 1000; | 43 static const int kDefaultTimeout = 1000; |
44 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | | 44 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | |
45 cricket::PORTALLOCATOR_DISABLE_RELAY | | 45 cricket::PORTALLOCATOR_DISABLE_RELAY | |
46 cricket::PORTALLOCATOR_DISABLE_TCP; | 46 cricket::PORTALLOCATOR_DISABLE_TCP; |
| 47 static const int LOW_RTT = 20; |
47 // Addresses on the public internet. | 48 // Addresses on the public internet. |
48 static const SocketAddress kPublicAddrs[2] = | 49 static const SocketAddress kPublicAddrs[2] = |
49 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; | 50 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; |
50 // IPv6 Addresses on the public internet. | 51 // IPv6 Addresses on the public internet. |
51 static const SocketAddress kIPv6PublicAddrs[2] = { | 52 static const SocketAddress kIPv6PublicAddrs[2] = { |
52 SocketAddress("2400:4030:1:2c00:be30:abcd:efab:cdef", 0), | 53 SocketAddress("2400:4030:1:2c00:be30:abcd:efab:cdef", 0), |
53 SocketAddress("2620:0:1000:1b03:2e41:38ff:fea6:f2a4", 0) | 54 SocketAddress("2620:0:1000:1b03:2e41:38ff:fea6:f2a4", 0) |
54 }; | 55 }; |
55 // For configuring multihomed clients. | 56 // For configuring multihomed clients. |
56 static const SocketAddress kAlternateAddrs[2] = | 57 static const SocketAddress kAlternateAddrs[2] = |
(...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2070 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2071 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2071 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 2072 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
2072 | 2073 |
2073 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2074 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2074 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2075 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2075 ASSERT_TRUE(conn1 != nullptr); | 2076 ASSERT_TRUE(conn1 != nullptr); |
2076 ASSERT_TRUE(conn2 != nullptr); | 2077 ASSERT_TRUE(conn2 != nullptr); |
2077 | 2078 |
2078 // Low-priority connection becomes writable so that the other connection | 2079 // Low-priority connection becomes writable so that the other connection |
2079 // is not pruned. | 2080 // is not pruned. |
2080 conn1->ReceivedPingResponse(); | 2081 conn1->ReceivedPingResponse(LOW_RTT); |
2081 EXPECT_TRUE_WAIT( | 2082 EXPECT_TRUE_WAIT( |
2082 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && | 2083 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && |
2083 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, | 2084 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, |
2084 kDefaultTimeout); | 2085 kDefaultTimeout); |
2085 } | 2086 } |
2086 | 2087 |
| 2088 // Verify that the connections are pinged at the right time. |
| 2089 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { |
| 2090 rtc::ScopedFakeClock clock; |
| 2091 int RTT_RATIO = 4; |
| 2092 int SCHEDULING_RANGE = 200; |
| 2093 int RTT_RANGE = 10; |
| 2094 |
| 2095 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2096 cricket::P2PTransportChannel ch("TestChannel", 1, &pa); |
| 2097 PrepareChannel(&ch); |
| 2098 ch.Connect(); |
| 2099 ch.MaybeStartGathering(); |
| 2100 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
| 2101 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2102 |
| 2103 ASSERT_TRUE(conn != nullptr); |
| 2104 SIMULATED_WAIT(conn->num_pings_sent() == 1, kDefaultTimeout, clock); |
| 2105 |
| 2106 // Initializing. |
| 2107 |
| 2108 int64_t start = clock.TimeNanos(); |
| 2109 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, |
| 2110 kDefaultTimeout, clock); |
| 2111 int64_t ping_interval_ms = (clock.TimeNanos() - start) / |
| 2112 rtc::kNumNanosecsPerMillisec / |
| 2113 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); |
| 2114 EXPECT_EQ(ping_interval_ms, cricket::WEAK_PING_INTERVAL); |
| 2115 |
| 2116 // Stabilizing. |
| 2117 |
| 2118 conn->ReceivedPingResponse(LOW_RTT); |
| 2119 int ping_sent_before = conn->num_pings_sent(); |
| 2120 start = clock.TimeNanos(); |
| 2121 // The connection becomes strong but not stable because we haven't been able |
| 2122 // to converge the RTT. |
| 2123 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
| 2124 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
| 2125 EXPECT_GE(ping_interval_ms, |
| 2126 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); |
| 2127 EXPECT_LE(ping_interval_ms, |
| 2128 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + |
| 2129 SCHEDULING_RANGE); |
| 2130 |
| 2131 // Stabilized. |
| 2132 |
| 2133 // The connection becomes stable after receiving more than RTT_RATIO rtt |
| 2134 // samples. |
| 2135 for (int i = 0; i < RTT_RATIO; i++) { |
| 2136 conn->ReceivedPingResponse(LOW_RTT); |
| 2137 } |
| 2138 ping_sent_before = conn->num_pings_sent(); |
| 2139 start = clock.TimeNanos(); |
| 2140 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
| 2141 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
| 2142 EXPECT_GE(ping_interval_ms, |
| 2143 cricket::STABLE_WRITABLE_CONNECTION_PING_INTERVAL); |
| 2144 EXPECT_LE( |
| 2145 ping_interval_ms, |
| 2146 cricket::STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); |
| 2147 |
| 2148 // Destabilized. |
| 2149 |
| 2150 conn->ReceivedPingResponse(LOW_RTT); |
| 2151 // Create a in-flight ping. |
| 2152 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); |
| 2153 start = clock.TimeNanos(); |
| 2154 // In-flight ping timeout and the connection will be unstable. |
| 2155 SIMULATED_WAIT( |
| 2156 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, |
| 2157 clock); |
| 2158 int64_t duration_ms = |
| 2159 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
| 2160 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); |
| 2161 EXPECT_LE(duration_ms, 2 * conn->rtt() + RTT_RANGE); |
| 2162 // The connection become unstable due to not receiving ping responses. |
| 2163 ping_sent_before = conn->num_pings_sent(); |
| 2164 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
| 2165 // The interval is expected to be |
| 2166 // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL. |
| 2167 start = clock.TimeNanos(); |
| 2168 ping_sent_before = conn->num_pings_sent(); |
| 2169 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
| 2170 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
| 2171 EXPECT_GE(ping_interval_ms, |
| 2172 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); |
| 2173 EXPECT_LE(ping_interval_ms, |
| 2174 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + |
| 2175 SCHEDULING_RANGE); |
| 2176 } |
| 2177 |
2087 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { | 2178 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { |
2088 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2179 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2089 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 2180 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
2090 PrepareChannel(&ch); | 2181 PrepareChannel(&ch); |
2091 ch.Connect(); | 2182 ch.Connect(); |
2092 ch.MaybeStartGathering(); | 2183 ch.MaybeStartGathering(); |
2093 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2184 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2094 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 2185 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
2095 | 2186 |
2096 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2187 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2097 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2188 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2098 ASSERT_TRUE(conn1 != nullptr); | 2189 ASSERT_TRUE(conn1 != nullptr); |
2099 ASSERT_TRUE(conn2 != nullptr); | 2190 ASSERT_TRUE(conn2 != nullptr); |
2100 | 2191 |
2101 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 2192 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
2102 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); | 2193 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); |
2103 conn1->ReceivedPingResponse(); | 2194 conn1->ReceivedPingResponse(LOW_RTT); |
2104 ASSERT_TRUE(conn1->writable()); | 2195 ASSERT_TRUE(conn1->writable()); |
2105 conn1->ReceivedPing(); | 2196 conn1->ReceivedPing(); |
2106 | 2197 |
2107 // Ping received, but the connection is already writable, so no | 2198 // Ping received, but the connection is already writable, so no |
2108 // "triggered check" and conn2 is pinged before conn1 because it has | 2199 // "triggered check" and conn2 is pinged before conn1 because it has |
2109 // a higher priority. | 2200 // a higher priority. |
2110 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 2201 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
2111 } | 2202 } |
2112 | 2203 |
2113 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { | 2204 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2284 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2194 ASSERT_TRUE(conn1 != nullptr); | 2285 ASSERT_TRUE(conn1 != nullptr); |
2195 uint32_t remote_priority = conn1->remote_candidate().priority(); | 2286 uint32_t remote_priority = conn1->remote_candidate().priority(); |
2196 | 2287 |
2197 // Create a higher priority candidate and make the connection | 2288 // Create a higher priority candidate and make the connection |
2198 // receiving/writable. This will prune conn1. | 2289 // receiving/writable. This will prune conn1. |
2199 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 2290 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
2200 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2291 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2201 ASSERT_TRUE(conn2 != nullptr); | 2292 ASSERT_TRUE(conn2 != nullptr); |
2202 conn2->ReceivedPing(); | 2293 conn2->ReceivedPing(); |
2203 conn2->ReceivedPingResponse(); | 2294 conn2->ReceivedPingResponse(LOW_RTT); |
2204 | 2295 |
2205 // Wait for conn1 to be pruned. | 2296 // Wait for conn1 to be pruned. |
2206 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 2297 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
2207 // Destroy the connection to test SignalUnknownAddress. | 2298 // Destroy the connection to test SignalUnknownAddress. |
2208 conn1->Destroy(); | 2299 conn1->Destroy(); |
2209 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); | 2300 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); |
2210 | 2301 |
2211 // Create a minimal STUN message with prflx priority. | 2302 // Create a minimal STUN message with prflx priority. |
2212 cricket::IceMessage request; | 2303 cricket::IceMessage request; |
2213 request.SetType(cricket::STUN_BINDING_REQUEST); | 2304 request.SetType(cricket::STUN_BINDING_REQUEST); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 | 2387 |
2297 // If a stun request with use-candidate attribute arrives, the receiving | 2388 // If a stun request with use-candidate attribute arrives, the receiving |
2298 // connection will be set as the best connection, even though | 2389 // connection will be set as the best connection, even though |
2299 // its priority is lower. | 2390 // its priority is lower. |
2300 SendData(ch, data, len, ++last_packet_id); | 2391 SendData(ch, data, len, ++last_packet_id); |
2301 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); | 2392 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); |
2302 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2393 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2303 ASSERT_TRUE(conn3 != nullptr); | 2394 ASSERT_TRUE(conn3 != nullptr); |
2304 // Because it has a lower priority, the best connection is still conn2. | 2395 // Because it has a lower priority, the best connection is still conn2. |
2305 EXPECT_EQ(conn2, ch.best_connection()); | 2396 EXPECT_EQ(conn2, ch.best_connection()); |
2306 conn3->ReceivedPingResponse(); // Become writable. | 2397 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. |
2307 // But if it is nominated via use_candidate, it is chosen as the best | 2398 // But if it is nominated via use_candidate, it is chosen as the best |
2308 // connection. | 2399 // connection. |
2309 conn3->set_nominated(true); | 2400 conn3->set_nominated(true); |
2310 conn3->SignalNominated(conn3); | 2401 conn3->SignalNominated(conn3); |
2311 EXPECT_EQ(conn3, ch.best_connection()); | 2402 EXPECT_EQ(conn3, ch.best_connection()); |
2312 EXPECT_EQ(conn3, last_selected_candidate_pair()); | 2403 EXPECT_EQ(conn3, last_selected_candidate_pair()); |
2313 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2404 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2314 EXPECT_TRUE(channel_ready_to_send()); | 2405 EXPECT_TRUE(channel_ready_to_send()); |
2315 | 2406 |
2316 // Even if another higher priority candidate arrives, | 2407 // Even if another higher priority candidate arrives, |
2317 // it will not be set as the best connection because the best connection | 2408 // it will not be set as the best connection because the best connection |
2318 // is nominated by the controlling side. | 2409 // is nominated by the controlling side. |
2319 SendData(ch, data, len, ++last_packet_id); | 2410 SendData(ch, data, len, ++last_packet_id); |
2320 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); | 2411 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); |
2321 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2412 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
2322 ASSERT_TRUE(conn4 != nullptr); | 2413 ASSERT_TRUE(conn4 != nullptr); |
2323 EXPECT_EQ(conn3, ch.best_connection()); | 2414 EXPECT_EQ(conn3, ch.best_connection()); |
2324 // But if it is nominated via use_candidate and writable, it will be set as | 2415 // But if it is nominated via use_candidate and writable, it will be set as |
2325 // the best connection. | 2416 // the best connection. |
2326 conn4->set_nominated(true); | 2417 conn4->set_nominated(true); |
2327 conn4->SignalNominated(conn4); | 2418 conn4->SignalNominated(conn4); |
2328 // Not switched yet because conn4 is not writable. | 2419 // Not switched yet because conn4 is not writable. |
2329 EXPECT_EQ(conn3, ch.best_connection()); | 2420 EXPECT_EQ(conn3, ch.best_connection()); |
2330 reset_channel_ready_to_send(); | 2421 reset_channel_ready_to_send(); |
2331 // The best connection switches after conn4 becomes writable. | 2422 // The best connection switches after conn4 becomes writable. |
2332 conn4->ReceivedPingResponse(); | 2423 conn4->ReceivedPingResponse(LOW_RTT); |
2333 EXPECT_EQ(conn4, ch.best_connection()); | 2424 EXPECT_EQ(conn4, ch.best_connection()); |
2334 EXPECT_EQ(conn4, last_selected_candidate_pair()); | 2425 EXPECT_EQ(conn4, last_selected_candidate_pair()); |
2335 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2426 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2336 // SignalReadyToSend is fired again because conn4 is writable. | 2427 // SignalReadyToSend is fired again because conn4 is writable. |
2337 EXPECT_TRUE(channel_ready_to_send()); | 2428 EXPECT_TRUE(channel_ready_to_send()); |
2338 } | 2429 } |
2339 | 2430 |
2340 // The controlled side will select a connection as the "best connection" based | 2431 // The controlled side will select a connection as the "best connection" based |
2341 // on requests from an unknown address before the controlling side nominates | 2432 // on requests from an unknown address before the controlling side nominates |
2342 // a connection, and will nominate a connection from an unknown address if the | 2433 // a connection, and will nominate a connection from an unknown address if the |
(...skipping 14 matching lines...) Expand all Loading... |
2357 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2448 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
2358 request.AddAttribute(new cricket::StunUInt32Attribute( | 2449 request.AddAttribute(new cricket::StunUInt32Attribute( |
2359 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 2450 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
2360 cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch)); | 2451 cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch)); |
2361 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 2452 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), |
2362 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2453 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2363 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2454 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2364 ASSERT_TRUE(conn1 != nullptr); | 2455 ASSERT_TRUE(conn1 != nullptr); |
2365 EXPECT_TRUE(port->sent_binding_response()); | 2456 EXPECT_TRUE(port->sent_binding_response()); |
2366 EXPECT_EQ(conn1, ch.best_connection()); | 2457 EXPECT_EQ(conn1, ch.best_connection()); |
2367 conn1->ReceivedPingResponse(); | 2458 conn1->ReceivedPingResponse(LOW_RTT); |
2368 EXPECT_EQ(conn1, ch.best_connection()); | 2459 EXPECT_EQ(conn1, ch.best_connection()); |
2369 port->set_sent_binding_response(false); | 2460 port->set_sent_binding_response(false); |
2370 | 2461 |
2371 // Another connection is nominated via use_candidate. | 2462 // Another connection is nominated via use_candidate. |
2372 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2463 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2373 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2464 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2374 ASSERT_TRUE(conn2 != nullptr); | 2465 ASSERT_TRUE(conn2 != nullptr); |
2375 // Because it has a lower priority, the best connection is still conn1. | 2466 // Because it has a lower priority, the best connection is still conn1. |
2376 EXPECT_EQ(conn1, ch.best_connection()); | 2467 EXPECT_EQ(conn1, ch.best_connection()); |
2377 // When it is nominated via use_candidate and writable, it is chosen as the | 2468 // When it is nominated via use_candidate and writable, it is chosen as the |
2378 // best connection. | 2469 // best connection. |
2379 conn2->ReceivedPingResponse(); // Become writable. | 2470 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. |
2380 conn2->set_nominated(true); | 2471 conn2->set_nominated(true); |
2381 conn2->SignalNominated(conn2); | 2472 conn2->SignalNominated(conn2); |
2382 EXPECT_EQ(conn2, ch.best_connection()); | 2473 EXPECT_EQ(conn2, ch.best_connection()); |
2383 | 2474 |
2384 // Another request with unknown address, it will not be set as the best | 2475 // Another request with unknown address, it will not be set as the best |
2385 // connection because the best connection was nominated by the controlling | 2476 // connection because the best connection was nominated by the controlling |
2386 // side. | 2477 // side. |
2387 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), | 2478 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), |
2388 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2479 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2389 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2480 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2390 ASSERT_TRUE(conn3 != nullptr); | 2481 ASSERT_TRUE(conn3 != nullptr); |
2391 EXPECT_TRUE(port->sent_binding_response()); | 2482 EXPECT_TRUE(port->sent_binding_response()); |
2392 conn3->ReceivedPingResponse(); // Become writable. | 2483 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. |
2393 EXPECT_EQ(conn2, ch.best_connection()); | 2484 EXPECT_EQ(conn2, ch.best_connection()); |
2394 port->set_sent_binding_response(false); | 2485 port->set_sent_binding_response(false); |
2395 | 2486 |
2396 // However if the request contains use_candidate attribute, it will be | 2487 // However if the request contains use_candidate attribute, it will be |
2397 // selected as the best connection. | 2488 // selected as the best connection. |
2398 request.AddAttribute( | 2489 request.AddAttribute( |
2399 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); | 2490 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); |
2400 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), | 2491 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), |
2401 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2492 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2402 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2493 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
2403 ASSERT_TRUE(conn4 != nullptr); | 2494 ASSERT_TRUE(conn4 != nullptr); |
2404 EXPECT_TRUE(port->sent_binding_response()); | 2495 EXPECT_TRUE(port->sent_binding_response()); |
2405 // conn4 is not the best connection yet because it is not writable. | 2496 // conn4 is not the best connection yet because it is not writable. |
2406 EXPECT_EQ(conn2, ch.best_connection()); | 2497 EXPECT_EQ(conn2, ch.best_connection()); |
2407 conn4->ReceivedPingResponse(); // Become writable. | 2498 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. |
2408 EXPECT_EQ(conn4, ch.best_connection()); | 2499 EXPECT_EQ(conn4, ch.best_connection()); |
2409 | 2500 |
2410 // Test that the request from an unknown address contains a ufrag from an old | 2501 // Test that the request from an unknown address contains a ufrag from an old |
2411 // generation. | 2502 // generation. |
2412 port->set_sent_binding_response(false); | 2503 port->set_sent_binding_response(false); |
2413 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 2504 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
2414 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 2505 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
2415 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), | 2506 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), |
2416 cricket::PROTO_UDP, &request, kIceUfrag[2], false); | 2507 cricket::PROTO_UDP, &request, kIceUfrag[2], false); |
2417 cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); | 2508 cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); |
(...skipping 22 matching lines...) Expand all Loading... |
2440 // switch to conn2 because the controlled side must mirror the media path | 2531 // switch to conn2 because the controlled side must mirror the media path |
2441 // chosen by the controlling side. | 2532 // chosen by the controlling side. |
2442 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2533 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2443 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2534 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2444 ASSERT_TRUE(conn2 != nullptr); | 2535 ASSERT_TRUE(conn2 != nullptr); |
2445 conn2->ReceivedPing(); // Start receiving. | 2536 conn2->ReceivedPing(); // Start receiving. |
2446 // Do not switch because it is not writable. | 2537 // Do not switch because it is not writable. |
2447 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2538 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2448 EXPECT_EQ(conn1, ch.best_connection()); | 2539 EXPECT_EQ(conn1, ch.best_connection()); |
2449 | 2540 |
2450 conn2->ReceivedPingResponse(); // Become writable. | 2541 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. |
2451 // Switch because it is writable. | 2542 // Switch because it is writable. |
2452 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); | 2543 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); |
2453 EXPECT_EQ(conn2, ch.best_connection()); | 2544 EXPECT_EQ(conn2, ch.best_connection()); |
2454 | 2545 |
2455 // Now another STUN message with an unknown address and use_candidate will | 2546 // Now another STUN message with an unknown address and use_candidate will |
2456 // nominate the best connection. | 2547 // nominate the best connection. |
2457 cricket::IceMessage request; | 2548 cricket::IceMessage request; |
2458 request.SetType(cricket::STUN_BINDING_REQUEST); | 2549 request.SetType(cricket::STUN_BINDING_REQUEST); |
2459 request.AddAttribute(new cricket::StunByteStringAttribute( | 2550 request.AddAttribute(new cricket::StunByteStringAttribute( |
2460 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 2551 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
2461 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2552 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
2462 request.AddAttribute(new cricket::StunUInt32Attribute( | 2553 request.AddAttribute(new cricket::StunUInt32Attribute( |
2463 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 2554 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
2464 request.AddAttribute( | 2555 request.AddAttribute( |
2465 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); | 2556 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); |
2466 cricket::Port* port = GetPort(&ch); | 2557 cricket::Port* port = GetPort(&ch); |
2467 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), | 2558 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), |
2468 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2559 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2469 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2560 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2470 ASSERT_TRUE(conn3 != nullptr); | 2561 ASSERT_TRUE(conn3 != nullptr); |
2471 EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet. | 2562 EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet. |
2472 conn3->ReceivedPingResponse(); // Become writable. | 2563 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. |
2473 EXPECT_EQ(conn3, ch.best_connection()); | 2564 EXPECT_EQ(conn3, ch.best_connection()); |
2474 | 2565 |
2475 // Now another data packet will not switch the best connection because the | 2566 // Now another data packet will not switch the best connection because the |
2476 // best connection was nominated by the controlling side. | 2567 // best connection was nominated by the controlling side. |
2477 conn2->ReceivedPing(); | 2568 conn2->ReceivedPing(); |
2478 conn2->ReceivedPingResponse(); | 2569 conn2->ReceivedPingResponse(LOW_RTT); |
2479 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 2570 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
2480 EXPECT_EQ(conn3, ch.best_connection()); | 2571 EXPECT_EQ(conn3, ch.best_connection()); |
2481 } | 2572 } |
2482 | 2573 |
2483 // Test that if a new remote candidate has the same address and port with | 2574 // Test that if a new remote candidate has the same address and port with |
2484 // an old one, it will be used to create a new connection. | 2575 // an old one, it will be used to create a new connection. |
2485 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { | 2576 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { |
2486 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2577 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2487 cricket::P2PTransportChannel ch("candidate reuse", 1, &pa); | 2578 cricket::P2PTransportChannel ch("candidate reuse", 1, &pa); |
2488 PrepareChannel(&ch); | 2579 PrepareChannel(&ch); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2525 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2616 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2526 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2617 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2527 PrepareChannel(&ch); | 2618 PrepareChannel(&ch); |
2528 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2619 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2529 ch.Connect(); | 2620 ch.Connect(); |
2530 ch.MaybeStartGathering(); | 2621 ch.MaybeStartGathering(); |
2531 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2622 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2532 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2623 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2533 ASSERT_TRUE(conn1 != nullptr); | 2624 ASSERT_TRUE(conn1 != nullptr); |
2534 EXPECT_EQ(conn1, ch.best_connection()); | 2625 EXPECT_EQ(conn1, ch.best_connection()); |
2535 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2626 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2536 | 2627 |
2537 // When a higher-priority, nominated candidate comes in, the connections with | 2628 // When a higher-priority, nominated candidate comes in, the connections with |
2538 // lower-priority are pruned. | 2629 // lower-priority are pruned. |
2539 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); | 2630 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); |
2540 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2631 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2541 ASSERT_TRUE(conn2 != nullptr); | 2632 ASSERT_TRUE(conn2 != nullptr); |
2542 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2633 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2543 conn2->set_nominated(true); | 2634 conn2->set_nominated(true); |
2544 conn2->SignalNominated(conn2); | 2635 conn2->SignalNominated(conn2); |
2545 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 2636 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
2546 | 2637 |
2547 ch.SetIceConfig(CreateIceConfig(500, false)); | 2638 ch.SetIceConfig(CreateIceConfig(500, false)); |
2548 // Wait until conn2 becomes not receiving. | 2639 // Wait until conn2 becomes not receiving. |
2549 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | 2640 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); |
2550 | 2641 |
2551 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); | 2642 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); |
2552 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2643 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
(...skipping 15 matching lines...) Expand all Loading... |
2568 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); | 2659 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); |
2569 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2660 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
2570 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2661 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2571 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2662 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2572 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2663 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2573 ASSERT_TRUE(conn1 != nullptr); | 2664 ASSERT_TRUE(conn1 != nullptr); |
2574 ASSERT_TRUE(conn2 != nullptr); | 2665 ASSERT_TRUE(conn2 != nullptr); |
2575 // Now there are two connections, so the transport channel is connecting. | 2666 // Now there are two connections, so the transport channel is connecting. |
2576 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2667 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); |
2577 // |conn1| becomes writable and receiving; it then should prune |conn2|. | 2668 // |conn1| becomes writable and receiving; it then should prune |conn2|. |
2578 conn1->ReceivedPingResponse(); | 2669 conn1->ReceivedPingResponse(LOW_RTT); |
2579 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | 2670 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); |
2580 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2671 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2581 conn1->Prune(); // All connections are pruned. | 2672 conn1->Prune(); // All connections are pruned. |
2582 // Need to wait until the channel state is updated. | 2673 // Need to wait until the channel state is updated. |
2583 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), | 2674 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), |
2584 1000); | 2675 1000); |
2585 } | 2676 } |
2586 | 2677 |
2587 // Test that when a low-priority connection is pruned, it is not deleted | 2678 // Test that when a low-priority connection is pruned, it is not deleted |
2588 // right away, and it can become active and be pruned again. | 2679 // right away, and it can become active and be pruned again. |
2589 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 2680 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
2590 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2681 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2591 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2682 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2592 PrepareChannel(&ch); | 2683 PrepareChannel(&ch); |
2593 ch.SetIceConfig(CreateIceConfig(1000, false)); | 2684 ch.SetIceConfig(CreateIceConfig(1000, false)); |
2594 ch.Connect(); | 2685 ch.Connect(); |
2595 ch.MaybeStartGathering(); | 2686 ch.MaybeStartGathering(); |
2596 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2687 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
2597 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2688 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2598 ASSERT_TRUE(conn1 != nullptr); | 2689 ASSERT_TRUE(conn1 != nullptr); |
2599 EXPECT_EQ(conn1, ch.best_connection()); | 2690 EXPECT_EQ(conn1, ch.best_connection()); |
2600 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2691 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2601 | 2692 |
2602 // Add a low-priority connection |conn2|, which will be pruned, but it will | 2693 // Add a low-priority connection |conn2|, which will be pruned, but it will |
2603 // not be deleted right away. Once the current best connection becomes not | 2694 // not be deleted right away. Once the current best connection becomes not |
2604 // receiving, |conn2| will start to ping and upon receiving the ping response, | 2695 // receiving, |conn2| will start to ping and upon receiving the ping response, |
2605 // it will become the best connection. | 2696 // it will become the best connection. |
2606 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2697 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2607 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2698 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2608 ASSERT_TRUE(conn2 != nullptr); | 2699 ASSERT_TRUE(conn2 != nullptr); |
2609 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2700 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
2610 // |conn2| should not send a ping yet. | 2701 // |conn2| should not send a ping yet. |
2611 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state()); | 2702 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state()); |
2612 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2703 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2613 // Wait for |conn1| becoming not receiving. | 2704 // Wait for |conn1| becoming not receiving. |
2614 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); | 2705 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); |
2615 // Make sure conn2 is not deleted. | 2706 // Make sure conn2 is not deleted. |
2616 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2707 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2617 ASSERT_TRUE(conn2 != nullptr); | 2708 ASSERT_TRUE(conn2 != nullptr); |
2618 EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000); | 2709 EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000); |
2619 conn2->ReceivedPingResponse(); | 2710 conn2->ReceivedPingResponse(LOW_RTT); |
2620 EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000); | 2711 EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000); |
2621 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2712 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); |
2622 | 2713 |
2623 // When |conn1| comes back again, |conn2| will be pruned again. | 2714 // When |conn1| comes back again, |conn2| will be pruned again. |
2624 conn1->ReceivedPingResponse(); | 2715 conn1->ReceivedPingResponse(LOW_RTT); |
2625 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); | 2716 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); |
2626 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2717 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
2627 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2718 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2628 } | 2719 } |
2629 | 2720 |
2630 // Test that if all connections in a channel has timed out on writing, they | 2721 // Test that if all connections in a channel has timed out on writing, they |
2631 // will all be deleted. We use Prune to simulate write_time_out. | 2722 // will all be deleted. We use Prune to simulate write_time_out. |
2632 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 2723 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
2633 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2724 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2634 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2725 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
(...skipping 30 matching lines...) Expand all Loading... |
2665 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { | 2756 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
2666 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2757 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2667 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2758 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2668 PrepareChannel(&ch); | 2759 PrepareChannel(&ch); |
2669 ch.SetIceConfig(CreateIceConfig(2000, false)); | 2760 ch.SetIceConfig(CreateIceConfig(2000, false)); |
2670 ch.Connect(); | 2761 ch.Connect(); |
2671 ch.MaybeStartGathering(); | 2762 ch.MaybeStartGathering(); |
2672 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2763 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
2673 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2764 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2674 ASSERT_TRUE(conn1 != nullptr); | 2765 ASSERT_TRUE(conn1 != nullptr); |
2675 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2766 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2676 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2767 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2677 | 2768 |
2678 // Start a new session. Even though conn1, which belongs to an older | 2769 // Start a new session. Even though conn1, which belongs to an older |
2679 // session, becomes unwritable and writable again, it should not stop the | 2770 // session, becomes unwritable and writable again, it should not stop the |
2680 // current session. | 2771 // current session. |
2681 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2772 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
2682 ch.MaybeStartGathering(); | 2773 ch.MaybeStartGathering(); |
2683 conn1->Prune(); | 2774 conn1->Prune(); |
2684 conn1->ReceivedPingResponse(); | 2775 conn1->ReceivedPingResponse(LOW_RTT); |
2685 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); | 2776 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); |
2686 | 2777 |
2687 // But if a new connection created from the new session becomes writable, | 2778 // But if a new connection created from the new session becomes writable, |
2688 // it will stop the current session. | 2779 // it will stop the current session. |
2689 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 100)); | 2780 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 100)); |
2690 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2781 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2691 ASSERT_TRUE(conn2 != nullptr); | 2782 ASSERT_TRUE(conn2 != nullptr); |
2692 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2783 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
2693 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2784 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2694 } | 2785 } |
2695 | 2786 |
2696 class P2PTransportChannelMostLikelyToWorkFirstTest | 2787 class P2PTransportChannelMostLikelyToWorkFirstTest |
2697 : public P2PTransportChannelPingTest { | 2788 : public P2PTransportChannelPingTest { |
2698 public: | 2789 public: |
2699 P2PTransportChannelMostLikelyToWorkFirstTest() | 2790 P2PTransportChannelMostLikelyToWorkFirstTest() |
2700 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { | 2791 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { |
2701 network_manager_.AddInterface(kPublicAddrs[0]); | 2792 network_manager_.AddInterface(kPublicAddrs[0]); |
2702 allocator_.reset(new cricket::BasicPortAllocator( | 2793 allocator_.reset(new cricket::BasicPortAllocator( |
2703 &network_manager_, ServerAddresses(), rtc::SocketAddress(), | 2794 &network_manager_, ServerAddresses(), rtc::SocketAddress(), |
2704 rtc::SocketAddress(), rtc::SocketAddress())); | 2795 rtc::SocketAddress(), rtc::SocketAddress())); |
2705 allocator_->set_flags(allocator_->flags() | | 2796 allocator_->set_flags(allocator_->flags() | |
2706 cricket::PORTALLOCATOR_DISABLE_STUN | | 2797 cricket::PORTALLOCATOR_DISABLE_STUN | |
2707 cricket::PORTALLOCATOR_DISABLE_TCP); | 2798 cricket::PORTALLOCATOR_DISABLE_TCP); |
2708 cricket::RelayServerConfig config(cricket::RELAY_TURN); | 2799 cricket::RelayServerConfig config(cricket::RELAY_TURN); |
2709 config.credentials = kRelayCredentials; | 2800 config.credentials = kRelayCredentials; |
2710 config.ports.push_back( | 2801 config.ports.push_back( |
2711 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); | 2802 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
2712 allocator_->AddTurnServer(config); | 2803 allocator_->AddTurnServer(config); |
2713 allocator_->set_step_delay(kMinimumStepDelay); | 2804 allocator_->set_step_delay(kMinimumStepDelay); |
2714 } | 2805 } |
2715 | 2806 |
2716 cricket::P2PTransportChannel& StartTransportChannel( | 2807 cricket::P2PTransportChannel& StartTransportChannel( |
2717 bool prioritize_most_likely_to_work, | 2808 bool prioritize_most_likely_to_work, |
2718 int max_strong_interval) { | 2809 int stable_writable_connection_ping_interval) { |
2719 channel_.reset( | 2810 channel_.reset( |
2720 new cricket::P2PTransportChannel("checks", 1, nullptr, allocator())); | 2811 new cricket::P2PTransportChannel("checks", 1, nullptr, allocator())); |
2721 cricket::IceConfig config = channel_->config(); | 2812 cricket::IceConfig config = channel_->config(); |
2722 config.prioritize_most_likely_candidate_pairs = | 2813 config.prioritize_most_likely_candidate_pairs = |
2723 prioritize_most_likely_to_work; | 2814 prioritize_most_likely_to_work; |
2724 config.max_strong_interval = max_strong_interval; | 2815 config.stable_writable_connection_ping_interval = |
| 2816 stable_writable_connection_ping_interval; |
2725 channel_->SetIceConfig(config); | 2817 channel_->SetIceConfig(config); |
2726 PrepareChannel(channel_.get()); | 2818 PrepareChannel(channel_.get()); |
2727 channel_->Connect(); | 2819 channel_->Connect(); |
2728 channel_->MaybeStartGathering(); | 2820 channel_->MaybeStartGathering(); |
2729 return *channel_.get(); | 2821 return *channel_.get(); |
2730 } | 2822 } |
2731 | 2823 |
2732 cricket::BasicPortAllocator* allocator() { return allocator_.get(); } | 2824 cricket::BasicPortAllocator* allocator() { return allocator_.get(); } |
2733 cricket::TestTurnServer* turn_server() { return &turn_server_; } | 2825 cricket::TestTurnServer* turn_server() { return &turn_server_; } |
2734 | 2826 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2790 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2882 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2791 EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE); | 2883 EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE); |
2792 EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE); | 2884 EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE); |
2793 conn2->ReceivedPing(); | 2885 conn2->ReceivedPing(); |
2794 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 2886 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
2795 | 2887 |
2796 // Make conn3 the best connection. | 2888 // Make conn3 the best connection. |
2797 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2889 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2798 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); | 2890 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); |
2799 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); | 2891 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); |
2800 conn3->ReceivedPingResponse(); | 2892 conn3->ReceivedPingResponse(LOW_RTT); |
2801 ASSERT_TRUE(conn3->writable()); | 2893 ASSERT_TRUE(conn3->writable()); |
2802 conn3->ReceivedPing(); | 2894 conn3->ReceivedPing(); |
2803 | 2895 |
2804 /* | 2896 /* |
2805 | 2897 |
2806 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix | 2898 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix |
2807 the flakiness. The following test becomes flaky because we now ping the | 2899 the flakiness. The following test becomes flaky because we now ping the |
2808 connections with fast rates until every connection is pinged at least three | 2900 connections with fast rates until every connection is pinged at least three |
2809 times. The best connection may have been pinged before |max_strong_interval|, | 2901 times. The best connection may have been pinged before |max_strong_interval|, |
2810 so it may not be the next connection to be pinged as expected in the test. | 2902 so it may not be the next connection to be pinged as expected in the test. |
2811 | 2903 |
2812 // Verify that conn3 will be the "best connection" since it is readable and | 2904 // Verify that conn3 will be the "best connection" since it is readable and |
2813 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next | 2905 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next |
2814 // pingable connection. | 2906 // pingable connection. |
2815 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); | 2907 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); |
2816 WAIT(false, max_strong_interval + 100); | 2908 WAIT(false, max_strong_interval + 100); |
2817 conn3->ReceivedPingResponse(); | 2909 conn3->ReceivedPingResponse(LOW_RTT); |
2818 ASSERT_TRUE(conn3->writable()); | 2910 ASSERT_TRUE(conn3->writable()); |
2819 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); | 2911 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); |
2820 | 2912 |
2821 */ | 2913 */ |
2822 } | 2914 } |
2823 | 2915 |
2824 // Test that Relay/Relay connections will be pinged first when everything has | 2916 // Test that Relay/Relay connections will be pinged first when everything has |
2825 // been pinged even if the Relay/Relay connection wasn't the first to be pinged | 2917 // been pinged even if the Relay/Relay connection wasn't the first to be pinged |
2826 // in the first round. | 2918 // in the first round. |
2827 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, | 2919 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2923 | 3015 |
2924 // TCP Relay/Relay is the next. | 3016 // TCP Relay/Relay is the next. |
2925 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3017 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
2926 cricket::RELAY_PORT_TYPE, | 3018 cricket::RELAY_PORT_TYPE, |
2927 cricket::TCP_PROTOCOL_NAME); | 3019 cricket::TCP_PROTOCOL_NAME); |
2928 | 3020 |
2929 // Finally, Local/Relay will be pinged. | 3021 // Finally, Local/Relay will be pinged. |
2930 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 3022 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
2931 cricket::RELAY_PORT_TYPE); | 3023 cricket::RELAY_PORT_TYPE); |
2932 } | 3024 } |
OLD | NEW |