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 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 // Emulate no remote credentials coming in. | 1189 // Emulate no remote credentials coming in. |
1190 set_remote_ice_credential_source(FROM_CANDIDATE); | 1190 set_remote_ice_credential_source(FROM_CANDIDATE); |
1191 CreateChannels(1); | 1191 CreateChannels(1); |
1192 // Only have remote credentials come in for ep2, not ep1. | 1192 // Only have remote credentials come in for ep2, not ep1. |
1193 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1193 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
1194 | 1194 |
1195 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1195 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
1196 // candidate. | 1196 // candidate. |
1197 PauseCandidates(1); | 1197 PauseCandidates(1); |
1198 | 1198 |
1199 // The caller should have the selected connection connected to the peer | 1199 // Wait until the callee becomes writable to make sure that a ping request is |
1200 // reflexive candidate. | 1200 // received by the caller before his remote ICE credentials are set. |
1201 const Connection* selected_connection = NULL; | 1201 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000); |
1202 WAIT((selected_connection = ep1_ch1()->selected_connection()) != NULL, 2000); | |
1203 EXPECT_EQ("prflx", | |
1204 ep1_ch1()->selected_connection()->remote_candidate().type()); | |
1205 | |
1206 // Because we don't have a remote pwd, we don't ping yet. | |
1207 EXPECT_EQ(kIceUfrag[1], | |
1208 ep1_ch1()->selected_connection()->remote_candidate().username()); | |
1209 EXPECT_EQ("", | |
1210 ep1_ch1()->selected_connection()->remote_candidate().password()); | |
1211 // Because we don't have ICE credentials yet, we don't know the generation. | |
1212 EXPECT_EQ(0u, | |
1213 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
1214 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); | |
1215 | |
1216 // Add two sets of remote ICE credentials, so that the ones used by the | 1202 // Add two sets of remote ICE credentials, so that the ones used by the |
1217 // candidate will be generation 1 instead of 0. | 1203 // candidate will be generation 1 instead of 0. |
1218 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1204 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
1219 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1205 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
1220 // After setting the remote ICE credentials, the password and generation | 1206 // The caller should have the selected connection connected to the peer |
1221 // of the peer reflexive candidate should be updated. | 1207 // reflexive candidate. |
1222 EXPECT_EQ(kIcePwd[1], | 1208 const Connection* selected_connection = nullptr; |
1223 ep1_ch1()->selected_connection()->remote_candidate().password()); | 1209 ASSERT_TRUE_WAIT( |
1224 EXPECT_EQ(1u, | 1210 (selected_connection = ep1_ch1()->selected_connection()) != nullptr, |
1225 ep1_ch1()->selected_connection()->remote_candidate().generation()); | 1211 2000); |
1226 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection()); | 1212 EXPECT_EQ("prflx", selected_connection->remote_candidate().type()); |
| 1213 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); |
| 1214 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); |
| 1215 EXPECT_EQ(1u, selected_connection->remote_candidate().generation()); |
1227 | 1216 |
1228 ResumeCandidates(1); | 1217 ResumeCandidates(1); |
1229 | |
1230 WAIT(ep2_ch1()->selected_connection() != NULL, 2000); | |
1231 // Verify ep1's selected connection is updated to use the 'local' candidate. | 1218 // Verify ep1's selected connection is updated to use the 'local' candidate. |
1232 EXPECT_EQ_WAIT("local", | 1219 EXPECT_EQ_WAIT("local", |
1233 ep1_ch1()->selected_connection()->remote_candidate().type(), | 1220 ep1_ch1()->selected_connection()->remote_candidate().type(), |
1234 2000); | 1221 2000); |
1235 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); | 1222 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); |
1236 DestroyChannels(); | 1223 DestroyChannels(); |
1237 } | 1224 } |
1238 | 1225 |
1239 // Test that we properly create a connection on a STUN ping from unknown address | 1226 // Test that we properly create a connection on a STUN ping from unknown address |
1240 // when the signaling is slow and the end points are behind NAT. | 1227 // when the signaling is slow and the end points are behind NAT. |
1241 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { | 1228 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { |
1242 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, | 1229 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
1243 kDefaultPortAllocatorFlags); | 1230 kDefaultPortAllocatorFlags); |
1244 // Emulate no remote credentials coming in. | 1231 // Emulate no remote credentials coming in. |
1245 set_remote_ice_credential_source(FROM_CANDIDATE); | 1232 set_remote_ice_credential_source(FROM_CANDIDATE); |
1246 CreateChannels(1); | 1233 CreateChannels(1); |
1247 // Only have remote credentials come in for ep2, not ep1. | 1234 // Only have remote credentials come in for ep2, not ep1. |
1248 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1235 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
1249 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1236 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
1250 // candidate. | 1237 // candidate. |
1251 PauseCandidates(1); | 1238 PauseCandidates(1); |
1252 | 1239 |
1253 // The caller should have the selected connection connected to the peer | 1240 // Wait until the callee becomes writable to make sure that a ping request is |
1254 // reflexive candidate. | 1241 // received by the caller before his remote ICE credentials are set. |
1255 WAIT(ep1_ch1()->selected_connection() != NULL, 2000); | 1242 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000); |
1256 EXPECT_EQ("prflx", | |
1257 ep1_ch1()->selected_connection()->remote_candidate().type()); | |
1258 | |
1259 // Because we don't have a remote pwd, we don't ping yet. | |
1260 EXPECT_EQ(kIceUfrag[1], | |
1261 ep1_ch1()->selected_connection()->remote_candidate().username()); | |
1262 EXPECT_EQ("", | |
1263 ep1_ch1()->selected_connection()->remote_candidate().password()); | |
1264 // Because we don't have ICE credentials yet, we don't know the generation. | |
1265 EXPECT_EQ(0u, | |
1266 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
1267 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); | |
1268 | |
1269 // Add two sets of remote ICE credentials, so that the ones used by the | 1243 // Add two sets of remote ICE credentials, so that the ones used by the |
1270 // candidate will be generation 1 instead of 0. | 1244 // candidate will be generation 1 instead of 0. |
1271 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1245 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
1272 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1246 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
1273 // After setting the remote ICE credentials, the password and generation | 1247 |
1274 // of the peer reflexive candidate should be updated. | 1248 // The caller's selected connection should be connected to the peer reflexive |
1275 EXPECT_EQ(kIcePwd[1], | 1249 // candidate. |
1276 ep1_ch1()->selected_connection()->remote_candidate().password()); | 1250 const Connection* selected_connection = nullptr; |
1277 EXPECT_EQ(1u, | 1251 ASSERT_TRUE_WAIT( |
1278 ep1_ch1()->selected_connection()->remote_candidate().generation()); | 1252 (selected_connection = ep1_ch1()->selected_connection()) != nullptr, |
| 1253 2000); |
| 1254 EXPECT_EQ("prflx", selected_connection->remote_candidate().type()); |
| 1255 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); |
| 1256 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); |
| 1257 EXPECT_EQ(1u, selected_connection->remote_candidate().generation()); |
1279 | 1258 |
1280 ResumeCandidates(1); | 1259 ResumeCandidates(1); |
1281 | 1260 |
1282 const Connection* selected_connection = NULL; | 1261 EXPECT_EQ_WAIT("prflx", |
1283 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 2000); | 1262 ep1_ch1()->selected_connection()->remote_candidate().type(), |
1284 | 1263 2000); |
1285 // Wait to verify the connection is not culled. | 1264 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); |
1286 WAIT(ep1_ch1()->writable(), 2000); | |
1287 EXPECT_EQ(ep2_ch1()->selected_connection(), selected_connection); | |
1288 EXPECT_EQ("prflx", | |
1289 ep1_ch1()->selected_connection()->remote_candidate().type()); | |
1290 DestroyChannels(); | 1265 DestroyChannels(); |
1291 } | 1266 } |
1292 | 1267 |
1293 // Test that we properly create a connection on a STUN ping from unknown address | 1268 // Test that we properly create a connection on a STUN ping from unknown address |
1294 // when the signaling is slow, even if the new candidate is created due to the | 1269 // when the signaling is slow, even if the new candidate is created due to the |
1295 // remote peer doing an ICE restart, pairing this candidate across generations. | 1270 // remote peer doing an ICE restart, pairing this candidate across generations. |
1296 // | 1271 // |
1297 // Previously this wasn't working due to a bug where the peer reflexive | 1272 // Previously this wasn't working due to a bug where the peer reflexive |
1298 // candidate was only updated for the newest generation candidate pairs, and | 1273 // candidate was only updated for the newest generation candidate pairs, and |
1299 // not older-generation candidate pairs created by pairing candidates across | 1274 // not older-generation candidate pairs created by pairing candidates across |
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2574 ch->SignalSelectedCandidatePairChanged.connect( | 2549 ch->SignalSelectedCandidatePairChanged.connect( |
2575 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); | 2550 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); |
2576 ch->SignalReadyToSend.connect(this, | 2551 ch->SignalReadyToSend.connect(this, |
2577 &P2PTransportChannelPingTest::OnReadyToSend); | 2552 &P2PTransportChannelPingTest::OnReadyToSend); |
2578 ch->SignalStateChanged.connect( | 2553 ch->SignalStateChanged.connect( |
2579 this, &P2PTransportChannelPingTest::OnChannelStateChanged); | 2554 this, &P2PTransportChannelPingTest::OnChannelStateChanged); |
2580 } | 2555 } |
2581 | 2556 |
2582 Connection* WaitForConnectionTo(P2PTransportChannel* ch, | 2557 Connection* WaitForConnectionTo(P2PTransportChannel* ch, |
2583 const std::string& ip, | 2558 const std::string& ip, |
2584 int port_num) { | 2559 int port_num, |
2585 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); | 2560 rtc::FakeClock* clock = nullptr) { |
| 2561 if (clock == nullptr) { |
| 2562 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); |
| 2563 } else { |
| 2564 EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, |
| 2565 3000, *clock); |
| 2566 } |
2586 return GetConnectionTo(ch, ip, port_num); | 2567 return GetConnectionTo(ch, ip, port_num); |
2587 } | 2568 } |
2588 | 2569 |
2589 Port* GetPort(P2PTransportChannel* ch) { | 2570 Port* GetPort(P2PTransportChannel* ch) { |
2590 if (ch->ports().empty()) { | 2571 if (ch->ports().empty()) { |
2591 return nullptr; | 2572 return nullptr; |
2592 } | 2573 } |
2593 return static_cast<Port*>(ch->ports()[0]); | 2574 return static_cast<Port*>(ch->ports()[0]); |
2594 } | 2575 } |
2595 | 2576 |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3060 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); | 3041 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); |
3061 EXPECT_EQ(500, ch.receiving_timeout()); | 3042 EXPECT_EQ(500, ch.receiving_timeout()); |
3062 EXPECT_EQ(50, ch.check_receiving_interval()); | 3043 EXPECT_EQ(50, ch.check_receiving_interval()); |
3063 ch.MaybeStartGathering(); | 3044 ch.MaybeStartGathering(); |
3064 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3045 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
3065 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3046 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3066 ASSERT_TRUE(conn1 != nullptr); | 3047 ASSERT_TRUE(conn1 != nullptr); |
3067 | 3048 |
3068 conn1->ReceivedPing(); | 3049 conn1->ReceivedPing(); |
3069 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 3050 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
3070 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000); | |
3071 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 3051 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
3072 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 3052 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
3073 } | 3053 } |
3074 | 3054 |
3075 // The controlled side will select a connection as the "selected connection" | 3055 // The controlled side will select a connection as the "selected connection" |
3076 // based on priority until the controlling side nominates a connection, at which | 3056 // based on priority until the controlling side nominates a connection, at which |
3077 // point the controlled side will select that connection as the | 3057 // point the controlled side will select that connection as the |
3078 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the | 3058 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the |
3079 // selected connection changes and SignalReadyToSend will be fired if the new | 3059 // selected connection changes and SignalReadyToSend will be fired if the new |
3080 // selected connection is writable. | 3060 // selected connection is writable. |
3081 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 3061 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
3082 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3062 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3083 P2PTransportChannel ch("receiving state change", 1, &pa); | 3063 P2PTransportChannel ch("receiving state change", 1, &pa); |
3084 PrepareChannel(&ch); | 3064 PrepareChannel(&ch); |
3085 ch.SetIceRole(ICEROLE_CONTROLLED); | 3065 ch.SetIceRole(ICEROLE_CONTROLLED); |
3086 ch.MaybeStartGathering(); | 3066 ch.MaybeStartGathering(); |
3087 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3067 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
3088 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3068 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3089 ASSERT_TRUE(conn1 != nullptr); | 3069 ASSERT_TRUE(conn1 != nullptr); |
3090 EXPECT_EQ(conn1, ch.selected_connection()); | |
3091 EXPECT_EQ(conn1, last_selected_candidate_pair()); | |
3092 EXPECT_EQ(-1, last_sent_packet_id()); | |
3093 // Channel is not ready to send because it is not writable. | 3070 // Channel is not ready to send because it is not writable. |
3094 EXPECT_FALSE(channel_ready_to_send()); | 3071 EXPECT_FALSE(channel_ready_to_send()); |
3095 | |
3096 int last_packet_id = 0; | 3072 int last_packet_id = 0; |
3097 const char* data = "ABCDEFGH"; | 3073 const char* data = "ABCDEFGH"; |
3098 int len = static_cast<int>(strlen(data)); | 3074 int len = static_cast<int>(strlen(data)); |
3099 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); | 3075 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); |
| 3076 EXPECT_EQ(-1, last_sent_packet_id()); |
| 3077 |
| 3078 // A connection needs to be writable before it is selected for transmission. |
| 3079 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
| 3080 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); |
| 3081 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
| 3082 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); |
| 3083 |
3100 // When a higher priority candidate comes in, the new connection is chosen | 3084 // When a higher priority candidate comes in, the new connection is chosen |
3101 // as the selected connection. | 3085 // as the selected connection. |
3102 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); | 3086 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); |
3103 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3087 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3104 ASSERT_TRUE(conn2 != nullptr); | 3088 ASSERT_TRUE(conn2 != nullptr); |
3105 EXPECT_EQ(conn2, ch.selected_connection()); | 3089 conn2->ReceivedPingResponse(LOW_RTT, "id"); |
| 3090 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), kDefaultTimeout); |
3106 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 3091 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
3107 EXPECT_EQ(-1, last_sent_packet_id()); | 3092 EXPECT_TRUE(channel_ready_to_send()); |
3108 EXPECT_FALSE(channel_ready_to_send()); | 3093 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
3109 | 3094 |
3110 // If a stun request with use-candidate attribute arrives, the receiving | 3095 // If a stun request with use-candidate attribute arrives, the receiving |
3111 // connection will be set as the selected connection, even though | 3096 // connection will be set as the selected connection, even though |
3112 // its priority is lower. | 3097 // its priority is lower. |
3113 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); | 3098 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); |
3114 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); | 3099 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); |
3115 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 3100 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
3116 ASSERT_TRUE(conn3 != nullptr); | 3101 ASSERT_TRUE(conn3 != nullptr); |
3117 // Because it has a lower priority, the selected connection is still conn2. | 3102 // Because it has a lower priority, the selected connection is still conn2. |
3118 EXPECT_EQ(conn2, ch.selected_connection()); | 3103 EXPECT_EQ(conn2, ch.selected_connection()); |
3119 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. | 3104 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. |
3120 // But if it is nominated via use_candidate, it is chosen as the selected | 3105 // But if it is nominated via use_candidate, it is chosen as the selected |
3121 // connection. | 3106 // connection. |
3122 NominateConnection(conn3); | 3107 NominateConnection(conn3); |
3123 EXPECT_EQ(conn3, ch.selected_connection()); | 3108 EXPECT_EQ(conn3, ch.selected_connection()); |
3124 EXPECT_EQ(conn3, last_selected_candidate_pair()); | 3109 EXPECT_EQ(conn3, last_selected_candidate_pair()); |
3125 EXPECT_EQ(-1, last_sent_packet_id()); | 3110 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
3126 EXPECT_TRUE(channel_ready_to_send()); | 3111 EXPECT_TRUE(channel_ready_to_send()); |
3127 | 3112 |
3128 // Even if another higher priority candidate arrives, it will not be set as | 3113 // Even if another higher priority candidate arrives, it will not be set as |
3129 // the selected connection because the selected connection is nominated by | 3114 // the selected connection because the selected connection is nominated by |
3130 // the controlling side. | 3115 // the controlling side. |
3131 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); | 3116 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); |
3132 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); | 3117 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); |
3133 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 3118 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
3134 ASSERT_TRUE(conn4 != nullptr); | 3119 ASSERT_TRUE(conn4 != nullptr); |
3135 EXPECT_EQ(conn3, ch.selected_connection()); | 3120 EXPECT_EQ(conn3, ch.selected_connection()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3167 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); | 3152 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); |
3168 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; | 3153 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; |
3169 request.AddAttribute( | 3154 request.AddAttribute( |
3170 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); | 3155 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); |
3171 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); | 3156 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); |
3172 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, | 3157 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, |
3173 &request, kIceUfrag[1], false); | 3158 &request, kIceUfrag[1], false); |
3174 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3159 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3175 ASSERT_TRUE(conn1 != nullptr); | 3160 ASSERT_TRUE(conn1 != nullptr); |
3176 EXPECT_TRUE(port->sent_binding_response()); | 3161 EXPECT_TRUE(port->sent_binding_response()); |
3177 EXPECT_EQ(conn1, ch.selected_connection()); | 3162 EXPECT_NE(conn1, ch.selected_connection()); |
3178 conn1->ReceivedPingResponse(LOW_RTT, "id"); | 3163 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
3179 EXPECT_EQ(conn1, ch.selected_connection()); | 3164 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); |
3180 port->set_sent_binding_response(false); | 3165 port->set_sent_binding_response(false); |
3181 | 3166 |
3182 // Another connection is nominated via use_candidate. | 3167 // Another connection is nominated via use_candidate. |
3183 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); | 3168 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
3184 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3169 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3185 ASSERT_TRUE(conn2 != nullptr); | 3170 ASSERT_TRUE(conn2 != nullptr); |
3186 // Because it has a lower priority, the selected connection is still conn1. | 3171 // Because it has a lower priority, the selected connection is still conn1. |
3187 EXPECT_EQ(conn1, ch.selected_connection()); | 3172 EXPECT_EQ(conn1, ch.selected_connection()); |
3188 // When it is nominated via use_candidate and writable, it is chosen as the | 3173 // When it is nominated via use_candidate and writable, it is chosen as the |
3189 // selected connection. | 3174 // selected connection. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3235 // the "selected connection". | 3220 // the "selected connection". |
3236 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { | 3221 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
3237 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3222 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3238 P2PTransportChannel ch("receiving state change", 1, &pa); | 3223 P2PTransportChannel ch("receiving state change", 1, &pa); |
3239 PrepareChannel(&ch); | 3224 PrepareChannel(&ch); |
3240 ch.SetIceRole(ICEROLE_CONTROLLED); | 3225 ch.SetIceRole(ICEROLE_CONTROLLED); |
3241 ch.MaybeStartGathering(); | 3226 ch.MaybeStartGathering(); |
3242 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10)); | 3227 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10)); |
3243 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3228 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3244 ASSERT_TRUE(conn1 != nullptr); | 3229 ASSERT_TRUE(conn1 != nullptr); |
3245 EXPECT_EQ(conn1, ch.selected_connection()); | 3230 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
| 3231 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); |
3246 | 3232 |
3247 // If a data packet is received on conn2, the selected connection should | 3233 // If a data packet is received on conn2, the selected connection should |
3248 // switch to conn2 because the controlled side must mirror the media path | 3234 // switch to conn2 because the controlled side must mirror the media path |
3249 // chosen by the controlling side. | 3235 // chosen by the controlling side. |
3250 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); | 3236 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
3251 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3237 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3252 ASSERT_TRUE(conn2 != nullptr); | 3238 ASSERT_TRUE(conn2 != nullptr); |
3253 conn2->ReceivedPing(); // Start receiving. | 3239 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable and receiving. |
3254 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 3240 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
3255 EXPECT_EQ(conn2, ch.selected_connection()); | 3241 EXPECT_EQ(conn2, ch.selected_connection()); |
3256 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. | 3242 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. |
3257 | 3243 |
3258 // Now another STUN message with an unknown address and use_candidate will | 3244 // Now another STUN message with an unknown address and use_candidate will |
3259 // nominate the selected connection. | 3245 // nominate the selected connection. |
3260 IceMessage request; | 3246 IceMessage request; |
3261 request.SetType(STUN_BINDING_REQUEST); | 3247 request.SetType(STUN_BINDING_REQUEST); |
3262 request.AddAttribute( | 3248 request.AddAttribute( |
3263 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); | 3249 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3309 SIMULATED_WAIT(false, 1, clock); | 3295 SIMULATED_WAIT(false, 1, clock); |
3310 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 3296 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
3311 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | 3297 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3312 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 3298 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
3313 | 3299 |
3314 // conn1 also receives data; it becomes selected due to priority again. | 3300 // conn1 also receives data; it becomes selected due to priority again. |
3315 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 3301 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
3316 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | 3302 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3317 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 3303 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
3318 | 3304 |
| 3305 // conn2 received data more recently; it is selected now because it |
| 3306 // received data more recently. |
| 3307 SIMULATED_WAIT(false, 1, clock); |
| 3308 // Need to become writable again because it was pruned. |
| 3309 conn2->ReceivedPingResponse(LOW_RTT, "id"); |
| 3310 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
| 3311 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
| 3312 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
| 3313 |
3319 // Make sure sorting won't reselect candidate pair. | 3314 // Make sure sorting won't reselect candidate pair. |
3320 SIMULATED_WAIT(false, 10, clock); | 3315 SIMULATED_WAIT(false, 10, clock); |
3321 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); | 3316 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
3322 } | 3317 } |
3323 | 3318 |
3324 TEST_F(P2PTransportChannelPingTest, | 3319 TEST_F(P2PTransportChannelPingTest, |
3325 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) { | 3320 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) { |
3326 rtc::ScopedFakeClock clock; | 3321 rtc::ScopedFakeClock clock; |
3327 | 3322 |
3328 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3323 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3329 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); | 3324 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); |
3330 PrepareChannel(&ch); | 3325 PrepareChannel(&ch); |
3331 ch.SetIceRole(ICEROLE_CONTROLLED); | 3326 ch.SetIceRole(ICEROLE_CONTROLLED); |
3332 ch.MaybeStartGathering(); | 3327 ch.MaybeStartGathering(); |
3333 // The connections have decreasing priority. | 3328 // The connections have decreasing priority. |
3334 Connection* conn1 = | 3329 Connection* conn1 = |
3335 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); | 3330 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); |
3336 ASSERT_TRUE(conn1 != nullptr); | 3331 ASSERT_TRUE(conn1 != nullptr); |
3337 Connection* conn2 = | 3332 Connection* conn2 = |
3338 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); | 3333 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true); |
3339 ASSERT_TRUE(conn2 != nullptr); | 3334 ASSERT_TRUE(conn2 != nullptr); |
3340 | 3335 |
3341 // conn1 received data; it is the selected connection. | 3336 // conn1 received data; it is the selected connection. |
3342 // Advance the clock to have a non-zero last-data-receiving time. | 3337 // Advance the clock to have a non-zero last-data-receiving time. |
3343 SIMULATED_WAIT(false, 1, clock); | 3338 SIMULATED_WAIT(false, 1, clock); |
3344 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 3339 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
3345 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | 3340 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3346 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 3341 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
3347 | 3342 |
3348 // conn2 is nominated; it becomes the selected connection. | 3343 // conn2 is nominated; it becomes the selected connection. |
3349 NominateConnection(conn2); | 3344 NominateConnection(conn2); |
3350 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | 3345 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3351 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 3346 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
3352 | 3347 |
| 3348 // conn1 is selected because it has higher priority and also nominated. |
3353 NominateConnection(conn1); | 3349 NominateConnection(conn1); |
3354 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | 3350 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3355 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 3351 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
3356 | 3352 |
3357 // conn2 received data more recently; it is selected now because it | |
3358 // received data more recently. | |
3359 SIMULATED_WAIT(false, 1, clock); | |
3360 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | |
3361 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | |
3362 EXPECT_EQ(conn2, last_selected_candidate_pair()); | |
3363 | |
3364 // Make sure sorting won't reselect candidate pair. | 3353 // Make sure sorting won't reselect candidate pair. |
3365 SIMULATED_WAIT(false, 10, clock); | 3354 SIMULATED_WAIT(false, 10, clock); |
3366 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); | 3355 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
3367 } | 3356 } |
3368 | 3357 |
3369 TEST_F(P2PTransportChannelPingTest, | 3358 TEST_F(P2PTransportChannelPingTest, |
3370 TestControlledAgentSelectsConnectionWithHigherNomination) { | 3359 TestControlledAgentSelectsConnectionWithHigherNomination) { |
3371 rtc::ScopedFakeClock clock; | 3360 rtc::ScopedFakeClock clock; |
3372 | 3361 |
3373 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3362 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3374 P2PTransportChannel ch("test", 1, &pa); | 3363 P2PTransportChannel ch("test", 1, &pa); |
3375 PrepareChannel(&ch); | 3364 PrepareChannel(&ch); |
3376 ch.SetIceRole(ICEROLE_CONTROLLED); | 3365 ch.SetIceRole(ICEROLE_CONTROLLED); |
3377 ch.MaybeStartGathering(); | 3366 ch.MaybeStartGathering(); |
3378 // The connections have decreasing priority. | 3367 // The connections have decreasing priority. |
3379 Connection* conn1 = | 3368 Connection* conn1 = |
3380 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); | 3369 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); |
3381 ASSERT_TRUE(conn1 != nullptr); | 3370 ASSERT_TRUE(conn1 != nullptr); |
3382 Connection* conn2 = | 3371 Connection* conn2 = |
3383 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); | 3372 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true); |
3384 ASSERT_TRUE(conn2 != nullptr); | 3373 ASSERT_TRUE(conn2 != nullptr); |
3385 | 3374 |
3386 // conn1 is the selected connection because it has a higher priority, | 3375 // conn1 is the selected connection because it has a higher priority, |
3387 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), | 3376 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), |
3388 kDefaultTimeout, clock); | 3377 kDefaultTimeout, clock); |
3389 reset_selected_candidate_pair_switches(); | 3378 reset_selected_candidate_pair_switches(); |
3390 | 3379 |
3391 // conn2 is nominated; it becomes selected. | 3380 // conn2 is nominated; it becomes selected. |
3392 NominateConnection(conn2); | 3381 NominateConnection(conn2); |
3393 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | 3382 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3436 ch.MaybeStartGathering(); | 3425 ch.MaybeStartGathering(); |
3437 // The connections have decreasing priority. | 3426 // The connections have decreasing priority. |
3438 Connection* conn1 = | 3427 Connection* conn1 = |
3439 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); | 3428 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); |
3440 ASSERT_TRUE(conn1 != nullptr); | 3429 ASSERT_TRUE(conn1 != nullptr); |
3441 Connection* conn2 = | 3430 Connection* conn2 = |
3442 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); | 3431 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); |
3443 ASSERT_TRUE(conn2 != nullptr); | 3432 ASSERT_TRUE(conn2 != nullptr); |
3444 | 3433 |
3445 NominateConnection(conn1); | 3434 NominateConnection(conn1); |
3446 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | 3435 // There is no selected connection because no connection is writable. |
| 3436 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
3447 | 3437 |
3448 // conn2 becomes writable; it is selected even though it is not nominated. | 3438 // conn2 becomes writable; it is selected even though it is not nominated. |
3449 conn2->ReceivedPingResponse(LOW_RTT, "id"); | 3439 conn2->ReceivedPingResponse(LOW_RTT, "id"); |
3450 | |
3451 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), | 3440 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), |
3452 kDefaultTimeout, clock); | 3441 kDefaultTimeout, clock); |
3453 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), | 3442 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), |
3454 kDefaultTimeout, clock); | 3443 kDefaultTimeout, clock); |
3455 | 3444 |
3456 // If conn1 is also writable, it will become selected. | 3445 // If conn1 is also writable, it will become selected. |
3457 conn1->ReceivedPingResponse(LOW_RTT, "id"); | 3446 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
3458 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), | 3447 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), |
3459 kDefaultTimeout, clock); | 3448 kDefaultTimeout, clock); |
3460 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), | 3449 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3499 // Verify that a ping with the new ufrag can be received on the new | 3488 // Verify that a ping with the new ufrag can be received on the new |
3500 // connection. | 3489 // connection. |
3501 EXPECT_EQ(0, conn2->last_ping_received()); | 3490 EXPECT_EQ(0, conn2->last_ping_received()); |
3502 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); | 3491 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); |
3503 EXPECT_TRUE(conn2->last_ping_received() > 0); | 3492 EXPECT_TRUE(conn2->last_ping_received() > 0); |
3504 } | 3493 } |
3505 | 3494 |
3506 // When the current selected connection is strong, lower-priority connections | 3495 // When the current selected connection is strong, lower-priority connections |
3507 // will be pruned. Otherwise, lower-priority connections are kept. | 3496 // will be pruned. Otherwise, lower-priority connections are kept. |
3508 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { | 3497 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
| 3498 rtc::ScopedFakeClock clock; |
3509 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3499 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3510 P2PTransportChannel ch("test channel", 1, &pa); | 3500 P2PTransportChannel ch("test channel", 1, &pa); |
3511 PrepareChannel(&ch); | 3501 PrepareChannel(&ch); |
3512 ch.SetIceRole(ICEROLE_CONTROLLED); | 3502 ch.SetIceRole(ICEROLE_CONTROLLED); |
3513 ch.MaybeStartGathering(); | 3503 ch.MaybeStartGathering(); |
3514 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3504 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
3515 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3505 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3516 ASSERT_TRUE(conn1 != nullptr); | 3506 ASSERT_TRUE(conn1 != nullptr); |
3517 EXPECT_EQ(conn1, ch.selected_connection()); | 3507 EXPECT_EQ(nullptr, ch.selected_connection()); |
3518 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving | 3508 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving |
3519 | 3509 |
3520 // When a higher-priority, nominated candidate comes in, the connections with | 3510 // When a higher-priority, nominated candidate comes in, the connections with |
3521 // lower-priority are pruned. | 3511 // lower-priority are pruned. |
3522 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); | 3512 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); |
3523 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3513 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); |
3524 ASSERT_TRUE(conn2 != nullptr); | 3514 ASSERT_TRUE(conn2 != nullptr); |
3525 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving | 3515 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving |
3526 NominateConnection(conn2); | 3516 NominateConnection(conn2); |
3527 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 3517 EXPECT_TRUE_SIMULATED_WAIT(conn1->pruned(), 3000, clock); |
3528 | 3518 |
3529 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); | 3519 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); |
3530 // Wait until conn2 becomes not receiving. | 3520 // Wait until conn2 becomes not receiving. |
3531 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | 3521 EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), 3000, clock); |
3532 | 3522 |
3533 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); | 3523 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); |
3534 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 3524 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock); |
3535 ASSERT_TRUE(conn3 != nullptr); | 3525 ASSERT_TRUE(conn3 != nullptr); |
3536 // The selected connection should still be conn2. Even through conn3 has lower | 3526 // The selected connection should still be conn2. Even through conn3 has lower |
3537 // priority and is not receiving/writable, it is not pruned because the | 3527 // priority and is not receiving/writable, it is not pruned because the |
3538 // selected connection is not receiving. | 3528 // selected connection is not receiving. |
3539 WAIT(conn3->pruned(), 1000); | 3529 SIMULATED_WAIT(conn3->pruned(), 1000, clock); |
3540 EXPECT_FALSE(conn3->pruned()); | 3530 EXPECT_FALSE(conn3->pruned()); |
3541 } | 3531 } |
3542 | 3532 |
3543 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) { | 3533 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) { |
3544 rtc::ScopedFakeClock clock; | 3534 rtc::ScopedFakeClock clock; |
3545 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3535 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3546 P2PTransportChannel ch("test channel", 1, &pa); | 3536 P2PTransportChannel ch("test channel", 1, &pa); |
3547 PrepareChannel(&ch); | 3537 PrepareChannel(&ch); |
3548 ch.SetIceRole(ICEROLE_CONTROLLED); | 3538 ch.SetIceRole(ICEROLE_CONTROLLED); |
3549 ch.MaybeStartGathering(); | 3539 ch.MaybeStartGathering(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3582 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | 3572 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); |
3583 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); | 3573 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
3584 conn1->Prune(); // All connections are pruned. | 3574 conn1->Prune(); // All connections are pruned. |
3585 // Need to wait until the channel state is updated. | 3575 // Need to wait until the channel state is updated. |
3586 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); | 3576 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); |
3587 } | 3577 } |
3588 | 3578 |
3589 // Test that when a low-priority connection is pruned, it is not deleted | 3579 // Test that when a low-priority connection is pruned, it is not deleted |
3590 // right away, and it can become active and be pruned again. | 3580 // right away, and it can become active and be pruned again. |
3591 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 3581 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
| 3582 rtc::ScopedFakeClock clock; |
3592 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3583 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3593 P2PTransportChannel ch("test channel", 1, &pa); | 3584 P2PTransportChannel ch("test channel", 1, &pa); |
3594 PrepareChannel(&ch); | 3585 PrepareChannel(&ch); |
3595 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); | 3586 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
3596 config.receiving_switching_delay = rtc::Optional<int>(800); | 3587 config.receiving_switching_delay = rtc::Optional<int>(800); |
3597 ch.SetIceConfig(config); | 3588 ch.SetIceConfig(config); |
3598 ch.MaybeStartGathering(); | 3589 ch.MaybeStartGathering(); |
3599 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3590 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
3600 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3591 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock); |
3601 ASSERT_TRUE(conn1 != nullptr); | 3592 ASSERT_TRUE(conn1 != nullptr); |
3602 EXPECT_EQ(conn1, ch.selected_connection()); | 3593 EXPECT_EQ(nullptr, ch.selected_connection()); |
3603 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving | 3594 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving |
| 3595 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, |
| 3596 clock); |
3604 | 3597 |
3605 // Add a low-priority connection |conn2|, which will be pruned, but it will | 3598 // Add a low-priority connection |conn2|, which will be pruned, but it will |
3606 // not be deleted right away. Once the current selected connection becomes not | 3599 // not be deleted right away. Once the current selected connection becomes not |
3607 // receiving, |conn2| will start to ping and upon receiving the ping response, | 3600 // receiving, |conn2| will start to ping and upon receiving the ping response, |
3608 // it will become the selected connection. | 3601 // it will become the selected connection. |
3609 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); | 3602 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
3610 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3603 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); |
3611 ASSERT_TRUE(conn2 != nullptr); | 3604 ASSERT_TRUE(conn2 != nullptr); |
3612 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 3605 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); |
3613 // |conn2| should not send a ping yet. | 3606 // |conn2| should not send a ping yet. |
3614 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); | 3607 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); |
3615 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); | 3608 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
3616 // Wait for |conn1| becoming not receiving. | 3609 // Wait for |conn1| becoming not receiving. |
3617 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); | 3610 EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), 3000, clock); |
3618 // Make sure conn2 is not deleted. | 3611 // Make sure conn2 is not deleted. |
3619 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3612 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); |
3620 ASSERT_TRUE(conn2 != nullptr); | 3613 ASSERT_TRUE(conn2 != nullptr); |
3621 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000); | 3614 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_INPROGRESS, conn2->state(), |
| 3615 kDefaultTimeout, clock); |
3622 conn2->ReceivedPingResponse(LOW_RTT, "id"); | 3616 conn2->ReceivedPingResponse(LOW_RTT, "id"); |
3623 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000); | 3617 EXPECT_EQ_SIMULATED_WAIT(conn2, ch.selected_connection(), kDefaultTimeout, |
| 3618 clock); |
3624 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); | 3619 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); |
3625 | 3620 |
3626 // When |conn1| comes back again, |conn2| will be pruned again. | 3621 // When |conn1| comes back again, |conn2| will be pruned again. |
3627 conn1->ReceivedPingResponse(LOW_RTT, "id"); | 3622 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
3628 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000); | 3623 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, |
3629 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 3624 clock); |
| 3625 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); |
3630 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); | 3626 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
3631 } | 3627 } |
3632 | 3628 |
3633 // Test that if all connections in a channel has timed out on writing, they | 3629 // Test that if all connections in a channel has timed out on writing, they |
3634 // will all be deleted. We use Prune to simulate write_time_out. | 3630 // will all be deleted. We use Prune to simulate write_time_out. |
3635 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 3631 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
3636 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3632 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3637 P2PTransportChannel ch("test channel", 1, &pa); | 3633 P2PTransportChannel ch("test channel", 1, &pa); |
3638 PrepareChannel(&ch); | 3634 PrepareChannel(&ch); |
3639 ch.MaybeStartGathering(); | 3635 ch.MaybeStartGathering(); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3978 | 3974 |
3979 // TCP Relay/Relay is the next. | 3975 // TCP Relay/Relay is the next. |
3980 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 3976 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
3981 TCP_PROTOCOL_NAME); | 3977 TCP_PROTOCOL_NAME); |
3982 | 3978 |
3983 // Finally, Local/Relay will be pinged. | 3979 // Finally, Local/Relay will be pinged. |
3984 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 3980 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3985 } | 3981 } |
3986 | 3982 |
3987 } // namespace cricket { | 3983 } // namespace cricket { |
OLD | NEW |