Chromium Code Reviews| 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 } | 459 } |
| 460 | 460 |
| 461 // Return true if the approprite parts of the expected Result, based | 461 // Return true if the approprite parts of the expected Result, based |
| 462 // on the local and remote candidate of ep2_ch1, match. This can be | 462 // on the local and remote candidate of ep2_ch1, match. This can be |
| 463 // used in an EXPECT_TRUE_WAIT. | 463 // used in an EXPECT_TRUE_WAIT. |
| 464 bool CheckCandidate2(const Result& expected) { | 464 bool CheckCandidate2(const Result& expected) { |
| 465 const std::string& local_type = LocalCandidate(ep2_ch1())->type(); | 465 const std::string& local_type = LocalCandidate(ep2_ch1())->type(); |
| 466 // const std::string& remote_type = RemoteCandidate(ep2_ch1())->type(); | 466 // const std::string& remote_type = RemoteCandidate(ep2_ch1())->type(); |
| 467 const std::string& local_proto = LocalCandidate(ep2_ch1())->protocol(); | 467 const std::string& local_proto = LocalCandidate(ep2_ch1())->protocol(); |
| 468 const std::string& remote_proto = RemoteCandidate(ep2_ch1())->protocol(); | 468 const std::string& remote_proto = RemoteCandidate(ep2_ch1())->protocol(); |
| 469 // Removed remote_type comparision aginst best connection remote | 469 // Removed remote_type comparision aginst selected connection remote |
| 470 // candidate. This is done to handle remote type discrepancy from | 470 // candidate. This is done to handle remote type discrepancy from |
| 471 // local to stun based on the test type. | 471 // local to stun based on the test type. |
| 472 // For example in case of Open -> NAT, ep2 channels will have LULU | 472 // For example in case of Open -> NAT, ep2 channels will have LULU |
| 473 // and in other cases like NAT -> NAT it will be LUSU. To avoid these | 473 // and in other cases like NAT -> NAT it will be LUSU. To avoid these |
| 474 // mismatches and we are doing comparision in different way. | 474 // mismatches and we are doing comparision in different way. |
| 475 // i.e. when don't match its remote type is either local or stun. | 475 // i.e. when don't match its remote type is either local or stun. |
| 476 // TODO(ronghuawu): Refine the test criteria. | 476 // TODO(ronghuawu): Refine the test criteria. |
| 477 // https://code.google.com/p/webrtc/issues/detail?id=1953 | 477 // https://code.google.com/p/webrtc/issues/detail?id=1953 |
| 478 return ((local_proto == expected.local_proto2 && | 478 return ((local_proto == expected.local_proto2 && |
| 479 remote_proto == expected.remote_proto2) && | 479 remote_proto == expected.remote_proto2) && |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 expected.connect_wait, | 519 expected.connect_wait, |
| 520 1000); | 520 1000); |
| 521 connect_time = rtc::TimeMillis() - connect_start; | 521 connect_time = rtc::TimeMillis() - connect_start; |
| 522 if (connect_time < expected.connect_wait) { | 522 if (connect_time < expected.connect_wait) { |
| 523 LOG(LS_INFO) << "Connect time: " << connect_time << " ms"; | 523 LOG(LS_INFO) << "Connect time: " << connect_time << " ms"; |
| 524 } else { | 524 } else { |
| 525 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" | 525 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" |
| 526 << expected.connect_wait << " ms)"; | 526 << expected.connect_wait << " ms)"; |
| 527 } | 527 } |
| 528 | 528 |
| 529 // Allow a few turns of the crank for the best connections to emerge. | 529 // Allow a few turns of the crank for the selected connections to emerge. |
| 530 // This may take up to 2 seconds. | 530 // This may take up to 2 seconds. |
| 531 if (ep1_ch1()->best_connection() && | 531 if (ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection()) { |
| 532 ep2_ch1()->best_connection()) { | |
| 533 int64_t converge_start = rtc::TimeMillis(); | 532 int64_t converge_start = rtc::TimeMillis(); |
| 534 int64_t converge_time; | 533 int64_t converge_time; |
| 535 int64_t converge_wait = 2000; | 534 int64_t converge_wait = 2000; |
| 536 // Verifying local and remote channel best connection information. This is | 535 // Verifying local and remote channel selected connection information. |
| 537 // done only for the RFC 5245 as controlled agent will use USE-CANDIDATE | 536 // This is done only for the RFC 5245 as controlled agent will use |
| 538 // from controlling (ep1) agent. We can easily predict from EP1 result | 537 // USE-CANDIDATE from controlling (ep1) agent. We can easily predict from |
| 539 // matrix. | 538 // EP1 result matrix. |
| 540 EXPECT_TRUE_WAIT_MARGIN( | 539 EXPECT_TRUE_WAIT_MARGIN( |
| 541 CheckCandidate1(expected) && CheckCandidate2(expected), converge_wait, | 540 CheckCandidate1(expected) && CheckCandidate2(expected), converge_wait, |
| 542 converge_wait); | 541 converge_wait); |
| 543 // Also do EXPECT_EQ on each part so that failures are more verbose. | 542 // Also do EXPECT_EQ on each part so that failures are more verbose. |
| 544 ExpectCandidate1(expected); | 543 ExpectCandidate1(expected); |
| 545 ExpectCandidate2(expected); | 544 ExpectCandidate2(expected); |
| 546 | 545 |
| 547 converge_time = rtc::TimeMillis() - converge_start; | 546 converge_time = rtc::TimeMillis() - converge_start; |
| 548 if (converge_time < converge_wait) { | 547 if (converge_time < converge_wait) { |
| 549 LOG(LS_INFO) << "Converge time: " << converge_time << " ms"; | 548 LOG(LS_INFO) << "Converge time: " << converge_time << " ms"; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. | 631 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. |
| 633 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); | 632 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); |
| 634 EXPECT_FALSE(GetRoleConflict(1)); | 633 EXPECT_FALSE(GetRoleConflict(1)); |
| 635 | 634 |
| 636 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && | 635 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && |
| 637 ep1_ch1()->writable() && | 636 ep1_ch1()->writable() && |
| 638 ep2_ch1()->receiving() && | 637 ep2_ch1()->receiving() && |
| 639 ep2_ch1()->writable(), | 638 ep2_ch1()->writable(), |
| 640 1000); | 639 1000); |
| 641 | 640 |
| 642 EXPECT_TRUE(ep1_ch1()->best_connection() && | 641 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 643 ep2_ch1()->best_connection()); | 642 ep2_ch1()->selected_connection()); |
| 644 | 643 |
| 645 TestSendRecv(1); | 644 TestSendRecv(1); |
| 646 } | 645 } |
| 647 | 646 |
| 648 // We pass the candidates directly to the other side. | 647 // We pass the candidates directly to the other side. |
| 649 void OnCandidateGathered(cricket::TransportChannelImpl* ch, | 648 void OnCandidateGathered(cricket::TransportChannelImpl* ch, |
| 650 const cricket::Candidate& c) { | 649 const cricket::Candidate& c) { |
| 651 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE) | 650 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE) |
| 652 return; | 651 return; |
| 653 | 652 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 const char* data, size_t len) { | 743 const char* data, size_t len) { |
| 745 rtc::PacketOptions options; | 744 rtc::PacketOptions options; |
| 746 return channel->SendPacket(data, len, options, 0); | 745 return channel->SendPacket(data, len, options, 0); |
| 747 } | 746 } |
| 748 bool CheckDataOnChannel(cricket::TransportChannel* channel, | 747 bool CheckDataOnChannel(cricket::TransportChannel* channel, |
| 749 const char* data, int len) { | 748 const char* data, int len) { |
| 750 return GetChannelData(channel)->CheckData(data, len); | 749 return GetChannelData(channel)->CheckData(data, len); |
| 751 } | 750 } |
| 752 static const cricket::Candidate* LocalCandidate( | 751 static const cricket::Candidate* LocalCandidate( |
| 753 cricket::P2PTransportChannel* ch) { | 752 cricket::P2PTransportChannel* ch) { |
| 754 return (ch && ch->best_connection()) ? | 753 return (ch && ch->selected_connection()) |
| 755 &ch->best_connection()->local_candidate() : NULL; | 754 ? &ch->selected_connection()->local_candidate() |
| 755 : NULL; | |
| 756 } | 756 } |
| 757 static const cricket::Candidate* RemoteCandidate( | 757 static const cricket::Candidate* RemoteCandidate( |
| 758 cricket::P2PTransportChannel* ch) { | 758 cricket::P2PTransportChannel* ch) { |
| 759 return (ch && ch->best_connection()) ? | 759 return (ch && ch->selected_connection()) |
| 760 &ch->best_connection()->remote_candidate() : NULL; | 760 ? &ch->selected_connection()->remote_candidate() |
| 761 : NULL; | |
| 761 } | 762 } |
| 762 Endpoint* GetEndpoint(cricket::TransportChannel* ch) { | 763 Endpoint* GetEndpoint(cricket::TransportChannel* ch) { |
| 763 if (ep1_.HasChannel(ch)) { | 764 if (ep1_.HasChannel(ch)) { |
| 764 return &ep1_; | 765 return &ep1_; |
| 765 } else if (ep2_.HasChannel(ch)) { | 766 } else if (ep2_.HasChannel(ch)) { |
| 766 return &ep2_; | 767 return &ep2_; |
| 767 } else { | 768 } else { |
| 768 return NULL; | 769 return NULL; |
| 769 } | 770 } |
| 770 } | 771 } |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 // Emulate no remote credentials coming in. | 1112 // Emulate no remote credentials coming in. |
| 1112 set_remote_ice_credential_source(FROM_CANDIDATE); | 1113 set_remote_ice_credential_source(FROM_CANDIDATE); |
| 1113 CreateChannels(1); | 1114 CreateChannels(1); |
| 1114 // Only have remote credentials come in for ep2, not ep1. | 1115 // Only have remote credentials come in for ep2, not ep1. |
| 1115 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1116 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
| 1116 | 1117 |
| 1117 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1118 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
| 1118 // candidate. | 1119 // candidate. |
| 1119 PauseCandidates(1); | 1120 PauseCandidates(1); |
| 1120 | 1121 |
| 1121 // The caller should have the best connection connected to the peer reflexive | 1122 // The caller should have the selected connection connected to the peer |
| 1122 // candidate. | 1123 // reflexive candidate. |
| 1123 const cricket::Connection* best_connection = NULL; | 1124 const cricket::Connection* selected_connection = NULL; |
| 1124 WAIT((best_connection = ep1_ch1()->best_connection()) != NULL, 2000); | 1125 WAIT((selected_connection = ep1_ch1()->selected_connection()) != NULL, 2000); |
| 1125 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); | 1126 EXPECT_EQ("prflx", |
| 1127 ep1_ch1()->selected_connection()->remote_candidate().type()); | |
| 1126 | 1128 |
| 1127 // Because we don't have a remote pwd, we don't ping yet. | 1129 // Because we don't have a remote pwd, we don't ping yet. |
| 1128 EXPECT_EQ(kIceUfrag[1], | 1130 EXPECT_EQ(kIceUfrag[1], |
| 1129 ep1_ch1()->best_connection()->remote_candidate().username()); | 1131 ep1_ch1()->selected_connection()->remote_candidate().username()); |
| 1130 EXPECT_EQ("", ep1_ch1()->best_connection()->remote_candidate().password()); | 1132 EXPECT_EQ("", |
| 1133 ep1_ch1()->selected_connection()->remote_candidate().password()); | |
| 1131 // Because we don't have ICE credentials yet, we don't know the generation. | 1134 // Because we don't have ICE credentials yet, we don't know the generation. |
| 1132 EXPECT_EQ(0u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1135 EXPECT_EQ(0u, |
| 1136 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
| 1133 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); | 1137 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); |
| 1134 | 1138 |
| 1135 // Add two sets of remote ICE credentials, so that the ones used by the | 1139 // Add two sets of remote ICE credentials, so that the ones used by the |
| 1136 // candidate will be generation 1 instead of 0. | 1140 // candidate will be generation 1 instead of 0. |
| 1137 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1141 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
| 1138 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1142 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 1139 // After setting the remote ICE credentials, the password and generation | 1143 // After setting the remote ICE credentials, the password and generation |
| 1140 // of the peer reflexive candidate should be updated. | 1144 // of the peer reflexive candidate should be updated. |
| 1141 EXPECT_EQ(kIcePwd[1], | 1145 EXPECT_EQ(kIcePwd[1], |
| 1142 ep1_ch1()->best_connection()->remote_candidate().password()); | 1146 ep1_ch1()->selected_connection()->remote_candidate().password()); |
| 1143 EXPECT_EQ(1u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1147 EXPECT_EQ(1u, |
| 1148 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
| 1144 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection()); | 1149 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection()); |
| 1145 | 1150 |
| 1146 ResumeCandidates(1); | 1151 ResumeCandidates(1); |
| 1147 | 1152 |
| 1148 WAIT(ep2_ch1()->best_connection() != NULL, 2000); | 1153 WAIT(ep2_ch1()->selected_connection() != NULL, 2000); |
| 1149 // Verify ep1's best connection is updated to use the 'local' candidate. | 1154 // Verify ep1's selected connection is updated to use the 'local' candidate. |
| 1150 EXPECT_EQ_WAIT( | 1155 EXPECT_EQ_WAIT("local", |
| 1151 "local", | 1156 ep1_ch1()->selected_connection()->remote_candidate().type(), |
| 1152 ep1_ch1()->best_connection()->remote_candidate().type(), | 1157 2000); |
| 1153 2000); | 1158 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); |
| 1154 EXPECT_EQ(best_connection, ep1_ch1()->best_connection()); | |
| 1155 DestroyChannels(); | 1159 DestroyChannels(); |
| 1156 } | 1160 } |
| 1157 | 1161 |
| 1158 // Test that we properly create a connection on a STUN ping from unknown address | 1162 // Test that we properly create a connection on a STUN ping from unknown address |
| 1159 // when the signaling is slow and the end points are behind NAT. | 1163 // when the signaling is slow and the end points are behind NAT. |
| 1160 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { | 1164 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { |
| 1161 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, | 1165 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
| 1162 kDefaultPortAllocatorFlags); | 1166 kDefaultPortAllocatorFlags); |
| 1163 // Emulate no remote credentials coming in. | 1167 // Emulate no remote credentials coming in. |
| 1164 set_remote_ice_credential_source(FROM_CANDIDATE); | 1168 set_remote_ice_credential_source(FROM_CANDIDATE); |
| 1165 CreateChannels(1); | 1169 CreateChannels(1); |
| 1166 // Only have remote credentials come in for ep2, not ep1. | 1170 // Only have remote credentials come in for ep2, not ep1. |
| 1167 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1171 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
| 1168 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1172 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
| 1169 // candidate. | 1173 // candidate. |
| 1170 PauseCandidates(1); | 1174 PauseCandidates(1); |
| 1171 | 1175 |
| 1172 // The caller should have the best connection connected to the peer reflexive | 1176 // The caller should have the selected connection connected to the peer |
| 1173 // candidate. | 1177 // reflexive candidate. |
| 1174 WAIT(ep1_ch1()->best_connection() != NULL, 2000); | 1178 WAIT(ep1_ch1()->selected_connection() != NULL, 2000); |
| 1175 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); | 1179 EXPECT_EQ("prflx", |
| 1180 ep1_ch1()->selected_connection()->remote_candidate().type()); | |
| 1176 | 1181 |
| 1177 // Because we don't have a remote pwd, we don't ping yet. | 1182 // Because we don't have a remote pwd, we don't ping yet. |
| 1178 EXPECT_EQ(kIceUfrag[1], | 1183 EXPECT_EQ(kIceUfrag[1], |
| 1179 ep1_ch1()->best_connection()->remote_candidate().username()); | 1184 ep1_ch1()->selected_connection()->remote_candidate().username()); |
| 1180 EXPECT_EQ("", ep1_ch1()->best_connection()->remote_candidate().password()); | 1185 EXPECT_EQ("", |
| 1186 ep1_ch1()->selected_connection()->remote_candidate().password()); | |
| 1181 // Because we don't have ICE credentials yet, we don't know the generation. | 1187 // Because we don't have ICE credentials yet, we don't know the generation. |
| 1182 EXPECT_EQ(0u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1188 EXPECT_EQ(0u, |
| 1189 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
| 1183 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); | 1190 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); |
| 1184 | 1191 |
| 1185 // Add two sets of remote ICE credentials, so that the ones used by the | 1192 // Add two sets of remote ICE credentials, so that the ones used by the |
| 1186 // candidate will be generation 1 instead of 0. | 1193 // candidate will be generation 1 instead of 0. |
| 1187 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1194 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
| 1188 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1195 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 1189 // After setting the remote ICE credentials, the password and generation | 1196 // After setting the remote ICE credentials, the password and generation |
| 1190 // of the peer reflexive candidate should be updated. | 1197 // of the peer reflexive candidate should be updated. |
| 1191 EXPECT_EQ(kIcePwd[1], | 1198 EXPECT_EQ(kIcePwd[1], |
| 1192 ep1_ch1()->best_connection()->remote_candidate().password()); | 1199 ep1_ch1()->selected_connection()->remote_candidate().password()); |
| 1193 EXPECT_EQ(1u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1200 EXPECT_EQ(1u, |
| 1201 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
| 1194 | 1202 |
| 1195 ResumeCandidates(1); | 1203 ResumeCandidates(1); |
| 1196 | 1204 |
| 1197 const cricket::Connection* best_connection = NULL; | 1205 const cricket::Connection* selected_connection = NULL; |
| 1198 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 2000); | 1206 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 2000); |
| 1199 | 1207 |
| 1200 // Wait to verify the connection is not culled. | 1208 // Wait to verify the connection is not culled. |
| 1201 WAIT(ep1_ch1()->writable(), 2000); | 1209 WAIT(ep1_ch1()->writable(), 2000); |
| 1202 EXPECT_EQ(ep2_ch1()->best_connection(), best_connection); | 1210 EXPECT_EQ(ep2_ch1()->selected_connection(), selected_connection); |
| 1203 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); | 1211 EXPECT_EQ("prflx", |
| 1212 ep1_ch1()->selected_connection()->remote_candidate().type()); | |
| 1204 DestroyChannels(); | 1213 DestroyChannels(); |
| 1205 } | 1214 } |
| 1206 | 1215 |
| 1207 // Test that we properly create a connection on a STUN ping from unknown address | 1216 // Test that we properly create a connection on a STUN ping from unknown address |
| 1208 // when the signaling is slow, even if the new candidate is created due to the | 1217 // when the signaling is slow, even if the new candidate is created due to the |
| 1209 // remote peer doing an ICE restart, pairing this candidate across generations. | 1218 // remote peer doing an ICE restart, pairing this candidate across generations. |
| 1210 // | 1219 // |
| 1211 // Previously this wasn't working due to a bug where the peer reflexive | 1220 // Previously this wasn't working due to a bug where the peer reflexive |
| 1212 // candidate was only updated for the newest generation candidate pairs, and | 1221 // candidate was only updated for the newest generation candidate pairs, and |
| 1213 // not older-generation candidate pairs created by pairing candidates across | 1222 // not older-generation candidate pairs created by pairing candidates across |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1231 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1240 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1232 kDefaultTimeout); | 1241 kDefaultTimeout); |
| 1233 | 1242 |
| 1234 // Simulate an ICE restart on ep2, but don't signal the candidate or new | 1243 // Simulate an ICE restart on ep2, but don't signal the candidate or new |
| 1235 // ICE credentials until after a prflx connection has been made. | 1244 // ICE credentials until after a prflx connection has been made. |
| 1236 PauseCandidates(1); | 1245 PauseCandidates(1); |
| 1237 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1246 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); |
| 1238 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1247 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
| 1239 ep2_ch1()->MaybeStartGathering(); | 1248 ep2_ch1()->MaybeStartGathering(); |
| 1240 | 1249 |
| 1241 // The caller should have the best connection connected to the peer reflexive | 1250 // The caller should have the selected connection connected to the peer |
| 1242 // candidate. | 1251 // reflexive candidate. |
| 1243 EXPECT_EQ_WAIT("prflx", | 1252 EXPECT_EQ_WAIT("prflx", |
| 1244 ep1_ch1()->best_connection()->remote_candidate().type(), | 1253 ep1_ch1()->selected_connection()->remote_candidate().type(), |
| 1245 kDefaultTimeout); | 1254 kDefaultTimeout); |
| 1246 const cricket::Connection* prflx_best_connection = | 1255 const cricket::Connection* prflx_selected_connection = |
| 1247 ep1_ch1()->best_connection(); | 1256 ep1_ch1()->selected_connection(); |
| 1248 | 1257 |
| 1249 // Now simulate the ICE restart on ep1. | 1258 // Now simulate the ICE restart on ep1. |
| 1250 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); | 1259 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); |
| 1251 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 1260 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
| 1252 ep1_ch1()->MaybeStartGathering(); | 1261 ep1_ch1()->MaybeStartGathering(); |
| 1253 | 1262 |
| 1254 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses | 1263 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses |
| 1255 // their information to update the peer reflexive candidate. | 1264 // their information to update the peer reflexive candidate. |
| 1256 ResumeCandidates(1); | 1265 ResumeCandidates(1); |
| 1257 | 1266 |
| 1258 EXPECT_EQ_WAIT("relay", | 1267 EXPECT_EQ_WAIT("relay", |
| 1259 ep1_ch1()->best_connection()->remote_candidate().type(), | 1268 ep1_ch1()->selected_connection()->remote_candidate().type(), |
| 1260 kDefaultTimeout); | 1269 kDefaultTimeout); |
| 1261 EXPECT_EQ(prflx_best_connection, ep1_ch1()->best_connection()); | 1270 EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection()); |
| 1262 DestroyChannels(); | 1271 DestroyChannels(); |
| 1263 } | 1272 } |
| 1264 | 1273 |
| 1265 // Test that if remote candidates don't have ufrag and pwd, we still work. | 1274 // Test that if remote candidates don't have ufrag and pwd, we still work. |
| 1266 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { | 1275 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { |
| 1267 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); | 1276 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); |
| 1268 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1277 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1269 kDefaultPortAllocatorFlags); | 1278 kDefaultPortAllocatorFlags); |
| 1270 CreateChannels(1); | 1279 CreateChannels(1); |
| 1271 const cricket::Connection* best_connection = NULL; | 1280 const cricket::Connection* selected_connection = NULL; |
| 1272 // Wait until the callee's connections are created. | 1281 // Wait until the callee's connections are created. |
| 1273 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000); | 1282 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000); |
| 1274 // Wait to see if they get culled; they shouldn't. | 1283 // Wait to see if they get culled; they shouldn't. |
| 1275 WAIT(ep2_ch1()->best_connection() != best_connection, 1000); | 1284 WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000); |
| 1276 EXPECT_TRUE(ep2_ch1()->best_connection() == best_connection); | 1285 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection); |
| 1277 DestroyChannels(); | 1286 DestroyChannels(); |
| 1278 } | 1287 } |
| 1279 | 1288 |
| 1280 // Test that a host behind NAT cannot be reached when incoming_only | 1289 // Test that a host behind NAT cannot be reached when incoming_only |
| 1281 // is set to true. | 1290 // is set to true. |
| 1282 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) { | 1291 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) { |
| 1283 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, | 1292 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, |
| 1284 kDefaultPortAllocatorFlags); | 1293 kDefaultPortAllocatorFlags); |
| 1285 | 1294 |
| 1286 SetAllocatorFlags(0, kOnlyLocalPorts); | 1295 SetAllocatorFlags(0, kOnlyLocalPorts); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1342 VerifySavedTcpCandidates(0, cricket::TCPTYPE_PASSIVE_STR); | 1351 VerifySavedTcpCandidates(0, cricket::TCPTYPE_PASSIVE_STR); |
| 1343 VerifySavedTcpCandidates(1, cricket::TCPTYPE_ACTIVE_STR); | 1352 VerifySavedTcpCandidates(1, cricket::TCPTYPE_ACTIVE_STR); |
| 1344 | 1353 |
| 1345 // Resume candidates. | 1354 // Resume candidates. |
| 1346 ResumeCandidates(0); | 1355 ResumeCandidates(0); |
| 1347 ResumeCandidates(1); | 1356 ResumeCandidates(1); |
| 1348 | 1357 |
| 1349 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1358 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1350 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1359 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1351 1000); | 1360 1000); |
| 1352 EXPECT_TRUE( | 1361 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 1353 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1362 ep2_ch1()->selected_connection() && |
| 1354 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1363 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1355 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1364 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1356 | 1365 |
| 1357 TestSendRecv(1); | 1366 TestSendRecv(1); |
| 1358 DestroyChannels(); | 1367 DestroyChannels(); |
| 1359 } | 1368 } |
| 1360 | 1369 |
| 1361 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { | 1370 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { |
| 1362 AddAddress(0, kPublicAddrs[0]); | 1371 AddAddress(0, kPublicAddrs[0]); |
| 1363 AddAddress(1, kPublicAddrs[1]); | 1372 AddAddress(1, kPublicAddrs[1]); |
| 1364 TestSignalRoleConflict(); | 1373 TestSignalRoleConflict(); |
| 1365 } | 1374 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1402 // original value. | 1411 // original value. |
| 1403 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); | 1412 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); |
| 1404 } | 1413 } |
| 1405 | 1414 |
| 1406 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && | 1415 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && |
| 1407 ep1_ch1()->writable() && | 1416 ep1_ch1()->writable() && |
| 1408 ep2_ch1()->receiving() && | 1417 ep2_ch1()->receiving() && |
| 1409 ep2_ch1()->writable(), | 1418 ep2_ch1()->writable(), |
| 1410 1000); | 1419 1000); |
| 1411 | 1420 |
| 1412 EXPECT_TRUE(ep1_ch1()->best_connection() && | 1421 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 1413 ep2_ch1()->best_connection()); | 1422 ep2_ch1()->selected_connection()); |
| 1414 | 1423 |
| 1415 TestSendRecv(1); | 1424 TestSendRecv(1); |
| 1416 DestroyChannels(); | 1425 DestroyChannels(); |
| 1417 } | 1426 } |
| 1418 | 1427 |
| 1419 // Verify that we can set DSCP value and retrieve properly from P2PTC. | 1428 // Verify that we can set DSCP value and retrieve properly from P2PTC. |
| 1420 TEST_F(P2PTransportChannelTest, TestDefaultDscpValue) { | 1429 TEST_F(P2PTransportChannelTest, TestDefaultDscpValue) { |
| 1421 AddAddress(0, kPublicAddrs[0]); | 1430 AddAddress(0, kPublicAddrs[0]); |
| 1422 AddAddress(1, kPublicAddrs[1]); | 1431 AddAddress(1, kPublicAddrs[1]); |
| 1423 | 1432 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1457 // Enable IPv6 | 1466 // Enable IPv6 |
| 1458 SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6); | 1467 SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 1459 SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6); | 1468 SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 1460 | 1469 |
| 1461 CreateChannels(1); | 1470 CreateChannels(1); |
| 1462 | 1471 |
| 1463 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1472 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1464 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1473 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1465 1000); | 1474 1000); |
| 1466 EXPECT_TRUE( | 1475 EXPECT_TRUE( |
| 1467 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1476 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
| 1468 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && | 1477 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && |
| 1469 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); | 1478 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); |
| 1470 | 1479 |
| 1471 TestSendRecv(1); | 1480 TestSendRecv(1); |
| 1472 DestroyChannels(); | 1481 DestroyChannels(); |
| 1473 } | 1482 } |
| 1474 | 1483 |
| 1475 // Testing forceful TURN connections. | 1484 // Testing forceful TURN connections. |
| 1476 TEST_F(P2PTransportChannelTest, TestForceTurn) { | 1485 TEST_F(P2PTransportChannelTest, TestForceTurn) { |
| 1477 ConfigureEndpoints( | 1486 ConfigureEndpoints( |
| 1478 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, | 1487 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, |
| 1479 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, | 1488 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, |
| 1480 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1489 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 1481 set_force_relay(true); | 1490 set_force_relay(true); |
| 1482 | 1491 |
| 1483 SetAllocationStepDelay(0, kMinimumStepDelay); | 1492 SetAllocationStepDelay(0, kMinimumStepDelay); |
| 1484 SetAllocationStepDelay(1, kMinimumStepDelay); | 1493 SetAllocationStepDelay(1, kMinimumStepDelay); |
| 1485 | 1494 |
| 1486 CreateChannels(1); | 1495 CreateChannels(1); |
| 1487 | 1496 |
| 1488 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1497 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1489 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1498 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1490 2000); | 1499 2000); |
| 1491 | 1500 |
| 1492 EXPECT_TRUE(ep1_ch1()->best_connection() && | 1501 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 1493 ep2_ch1()->best_connection()); | 1502 ep2_ch1()->selected_connection()); |
| 1494 | 1503 |
| 1495 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); | 1504 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); |
| 1496 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); | 1505 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); |
| 1497 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); | 1506 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); |
| 1498 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); | 1507 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); |
| 1499 | 1508 |
| 1500 TestSendRecv(1); | 1509 TestSendRecv(1); |
| 1501 DestroyChannels(); | 1510 DestroyChannels(); |
| 1502 } | 1511 } |
| 1503 | 1512 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1559 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1568 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1560 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1569 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1561 1000, 1000); | 1570 1000, 1000); |
| 1562 TestSendRecv(1); | 1571 TestSendRecv(1); |
| 1563 // Make sure the P2PTransportChannels are actually using ports from the | 1572 // Make sure the P2PTransportChannels are actually using ports from the |
| 1564 // pooled sessions. | 1573 // pooled sessions. |
| 1565 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); | 1574 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); |
| 1566 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); | 1575 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); |
| 1567 EXPECT_NE(pooled_ports_1.end(), | 1576 EXPECT_NE(pooled_ports_1.end(), |
| 1568 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), | 1577 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), |
| 1569 ep1_ch1()->best_connection()->port())); | 1578 ep1_ch1()->selected_connection()->port())); |
| 1570 EXPECT_NE(pooled_ports_2.end(), | 1579 EXPECT_NE(pooled_ports_2.end(), |
| 1571 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), | 1580 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), |
| 1572 ep2_ch1()->best_connection()->port())); | 1581 ep2_ch1()->selected_connection()->port())); |
| 1573 } | 1582 } |
| 1574 | 1583 |
| 1575 // Test that a connection succeeds when the P2PTransportChannel uses a pooled | 1584 // Test that a connection succeeds when the P2PTransportChannel uses a pooled |
| 1576 // PortAllocatorSession that already finished gathering candidates. | 1585 // PortAllocatorSession that already finished gathering candidates. |
| 1577 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) { | 1586 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) { |
| 1578 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1587 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1579 kDefaultPortAllocatorFlags); | 1588 kDefaultPortAllocatorFlags); |
| 1580 // First create a pooled session for each endpoint. | 1589 // First create a pooled session for each endpoint. |
| 1581 auto& allocator_1 = GetEndpoint(0)->allocator_; | 1590 auto& allocator_1 = GetEndpoint(0)->allocator_; |
| 1582 auto& allocator_2 = GetEndpoint(1)->allocator_; | 1591 auto& allocator_2 = GetEndpoint(1)->allocator_; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1602 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1611 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1603 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1612 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1604 1000, 1000); | 1613 1000, 1000); |
| 1605 TestSendRecv(1); | 1614 TestSendRecv(1); |
| 1606 // Make sure the P2PTransportChannels are actually using ports from the | 1615 // Make sure the P2PTransportChannels are actually using ports from the |
| 1607 // pooled sessions. | 1616 // pooled sessions. |
| 1608 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); | 1617 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); |
| 1609 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); | 1618 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); |
| 1610 EXPECT_NE(pooled_ports_1.end(), | 1619 EXPECT_NE(pooled_ports_1.end(), |
| 1611 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), | 1620 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), |
| 1612 ep1_ch1()->best_connection()->port())); | 1621 ep1_ch1()->selected_connection()->port())); |
| 1613 EXPECT_NE(pooled_ports_2.end(), | 1622 EXPECT_NE(pooled_ports_2.end(), |
| 1614 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), | 1623 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), |
| 1615 ep2_ch1()->best_connection()->port())); | 1624 ep2_ch1()->selected_connection()->port())); |
| 1616 } | 1625 } |
| 1617 | 1626 |
| 1618 // Test what happens when we have 2 users behind the same NAT. This can lead | 1627 // Test what happens when we have 2 users behind the same NAT. This can lead |
| 1619 // to interesting behavior because the STUN server will only give out the | 1628 // to interesting behavior because the STUN server will only give out the |
| 1620 // address of the outermost NAT. | 1629 // address of the outermost NAT. |
| 1621 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { | 1630 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { |
| 1622 protected: | 1631 protected: |
| 1623 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { | 1632 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { |
| 1624 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); | 1633 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); |
| 1625 rtc::NATSocketServer::Translator* outer_nat = | 1634 rtc::NATSocketServer::Translator* outer_nat = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1676 // Use only local ports for simplicity. | 1685 // Use only local ports for simplicity. |
| 1677 SetAllocatorFlags(0, kOnlyLocalPorts); | 1686 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1678 SetAllocatorFlags(1, kOnlyLocalPorts); | 1687 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1679 | 1688 |
| 1680 // Create channels and let them go writable, as usual. | 1689 // Create channels and let them go writable, as usual. |
| 1681 CreateChannels(1); | 1690 CreateChannels(1); |
| 1682 | 1691 |
| 1683 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1692 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1684 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1693 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1685 1000, 1000); | 1694 1000, 1000); |
| 1686 EXPECT_TRUE( | 1695 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 1687 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1696 ep2_ch1()->selected_connection() && |
| 1688 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1697 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1689 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1698 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1690 | 1699 |
| 1691 // Make the receiving timeout shorter for testing. | 1700 // Make the receiving timeout shorter for testing. |
| 1692 cricket::IceConfig config = CreateIceConfig(1000, false); | 1701 cricket::IceConfig config = CreateIceConfig(1000, false); |
| 1693 ep1_ch1()->SetIceConfig(config); | 1702 ep1_ch1()->SetIceConfig(config); |
| 1694 ep2_ch1()->SetIceConfig(config); | 1703 ep2_ch1()->SetIceConfig(config); |
| 1695 | 1704 |
| 1696 // Blackhole any traffic to or from the public addrs. | 1705 // Blackhole any traffic to or from the public addrs. |
| 1697 LOG(LS_INFO) << "Failing over..."; | 1706 LOG(LS_INFO) << "Failing over..."; |
| 1698 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); | 1707 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); |
| 1699 // The best connections will switch, so keep references to them. | 1708 // The selected connections will switch, so keep references to them. |
| 1700 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); | 1709 const cricket::Connection* selected_connection1 = |
| 1701 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); | 1710 ep1_ch1()->selected_connection(); |
| 1711 const cricket::Connection* selected_connection2 = | |
| 1712 ep2_ch1()->selected_connection(); | |
| 1702 // We should detect loss of receiving within 1 second or so. | 1713 // We should detect loss of receiving within 1 second or so. |
| 1703 EXPECT_TRUE_WAIT( | 1714 EXPECT_TRUE_WAIT( |
| 1704 !best_connection1->receiving() && !best_connection2->receiving(), 3000); | 1715 !selected_connection1->receiving() && !selected_connection2->receiving(), |
| 1716 3000); | |
| 1705 | 1717 |
| 1706 // We should switch over to use the alternate addr immediately on both sides | 1718 // We should switch over to use the alternate addr immediately on both sides |
| 1707 // when we are not receiving. | 1719 // when we are not receiving. |
| 1708 EXPECT_TRUE_WAIT( | 1720 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection()->receiving() && |
| 1709 ep1_ch1()->best_connection()->receiving() && | 1721 ep2_ch1()->selected_connection()->receiving(), |
| 1710 ep2_ch1()->best_connection()->receiving(), 1000); | 1722 1000); |
| 1711 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); | 1723 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); |
| 1712 EXPECT_TRUE( | 1724 EXPECT_TRUE( |
| 1713 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); | 1725 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); |
| 1714 EXPECT_TRUE( | 1726 EXPECT_TRUE( |
| 1715 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1])); | 1727 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1])); |
| 1716 | 1728 |
| 1717 DestroyChannels(); | 1729 DestroyChannels(); |
| 1718 } | 1730 } |
| 1719 | 1731 |
| 1720 // Test that we can quickly switch links if an interface goes down. | 1732 // Test that we can quickly switch links if an interface goes down. |
| 1721 // The controlling side has two interfaces and one will die. | 1733 // The controlling side has two interfaces and one will die. |
| 1722 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { | 1734 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { |
| 1723 // Adding alternate address will make sure |kPublicAddrs| has the higher | 1735 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 1724 // priority than others. This is due to FakeNetwork::AddInterface method. | 1736 // priority than others. This is due to FakeNetwork::AddInterface method. |
| 1725 AddAddress(0, kAlternateAddrs[0]); | 1737 AddAddress(0, kAlternateAddrs[0]); |
| 1726 AddAddress(0, kPublicAddrs[0]); | 1738 AddAddress(0, kPublicAddrs[0]); |
| 1727 AddAddress(1, kPublicAddrs[1]); | 1739 AddAddress(1, kPublicAddrs[1]); |
| 1728 | 1740 |
| 1729 // Use only local ports for simplicity. | 1741 // Use only local ports for simplicity. |
| 1730 SetAllocatorFlags(0, kOnlyLocalPorts); | 1742 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1731 SetAllocatorFlags(1, kOnlyLocalPorts); | 1743 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1732 | 1744 |
| 1733 // Create channels and let them go writable, as usual. | 1745 // Create channels and let them go writable, as usual. |
| 1734 CreateChannels(1); | 1746 CreateChannels(1); |
| 1735 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1747 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1736 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1748 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1737 1000, 1000); | 1749 1000, 1000); |
| 1738 EXPECT_TRUE( | 1750 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 1739 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1751 ep2_ch1()->selected_connection() && |
| 1740 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1752 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1741 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1753 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1742 | 1754 |
| 1743 // Make the receiving timeout shorter for testing. | 1755 // Make the receiving timeout shorter for testing. |
| 1744 cricket::IceConfig config = CreateIceConfig(1000, false); | 1756 cricket::IceConfig config = CreateIceConfig(1000, false); |
| 1745 ep1_ch1()->SetIceConfig(config); | 1757 ep1_ch1()->SetIceConfig(config); |
| 1746 ep2_ch1()->SetIceConfig(config); | 1758 ep2_ch1()->SetIceConfig(config); |
| 1747 | 1759 |
| 1748 // Blackhole any traffic to or from the public addrs. | 1760 // Blackhole any traffic to or from the public addrs. |
| 1749 LOG(LS_INFO) << "Failing over..."; | 1761 LOG(LS_INFO) << "Failing over..."; |
| 1750 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); | 1762 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
| 1751 // The best connections will switch, so keep references to them. | 1763 // The selected connections will switch, so keep references to them. |
| 1752 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); | 1764 const cricket::Connection* selected_connection1 = |
| 1753 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); | 1765 ep1_ch1()->selected_connection(); |
| 1766 const cricket::Connection* selected_connection2 = | |
| 1767 ep2_ch1()->selected_connection(); | |
| 1754 // We should detect loss of receiving within 1 second or so. | 1768 // We should detect loss of receiving within 1 second or so. |
| 1755 EXPECT_TRUE_WAIT( | 1769 EXPECT_TRUE_WAIT( |
| 1756 !best_connection1->receiving() && !best_connection2->receiving(), 3000); | 1770 !selected_connection1->receiving() && !selected_connection2->receiving(), |
| 1771 3000); | |
| 1757 | 1772 |
| 1758 // We should switch over to use the alternate addr immediately on both sides | 1773 // We should switch over to use the alternate addr immediately on both sides |
| 1759 // when we are not receiving. | 1774 // when we are not receiving. |
| 1760 EXPECT_TRUE_WAIT( | 1775 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection()->receiving() && |
| 1761 ep1_ch1()->best_connection()->receiving() && | 1776 ep2_ch1()->selected_connection()->receiving(), |
| 1762 ep2_ch1()->best_connection()->receiving(), 1000); | 1777 1000); |
| 1763 EXPECT_TRUE( | 1778 EXPECT_TRUE( |
| 1764 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1779 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
| 1765 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1780 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1766 EXPECT_TRUE( | 1781 EXPECT_TRUE( |
| 1767 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1782 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
| 1768 | 1783 |
| 1769 DestroyChannels(); | 1784 DestroyChannels(); |
| 1770 } | 1785 } |
| 1771 | 1786 |
| 1772 // Tests that a Wifi-Wifi connection has the highest precedence. | 1787 // Tests that a Wifi-Wifi connection has the highest precedence. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1784 SetAllocatorFlags(0, kOnlyLocalPorts); | 1799 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1785 SetAllocatorFlags(1, kOnlyLocalPorts); | 1800 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1786 | 1801 |
| 1787 // Create channels and let them go writable, as usual. | 1802 // Create channels and let them go writable, as usual. |
| 1788 CreateChannels(1); | 1803 CreateChannels(1); |
| 1789 | 1804 |
| 1790 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1805 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1791 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1806 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1792 1000, 1000); | 1807 1000, 1000); |
| 1793 // Need to wait to make sure the connections on both networks are writable. | 1808 // Need to wait to make sure the connections on both networks are writable. |
| 1794 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() && | 1809 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && |
| 1795 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && | 1810 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
| 1796 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | 1811 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
| 1797 1000); | 1812 1000); |
| 1798 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() && | 1813 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && |
| 1799 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && | 1814 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && |
| 1800 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), | 1815 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), |
| 1801 1000); | 1816 1000); |
| 1802 } | 1817 } |
| 1803 | 1818 |
| 1804 // Tests that a Wifi-Cellular connection has higher precedence than | 1819 // Tests that a Wifi-Cellular connection has higher precedence than |
| 1805 // a Cellular-Cellular connection. | 1820 // a Cellular-Cellular connection. |
| 1806 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { | 1821 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { |
| 1807 // The interface names are chosen so that |cellular| would have higher | 1822 // The interface names are chosen so that |cellular| would have higher |
| 1808 // candidate priority if it is not for the network type. | 1823 // candidate priority if it is not for the network type. |
| 1809 auto& wifi = kAlternateAddrs; | 1824 auto& wifi = kAlternateAddrs; |
| 1810 auto& cellular = kPublicAddrs; | 1825 auto& cellular = kPublicAddrs; |
| 1811 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 1826 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
| 1812 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); | 1827 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); |
| 1813 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 1828 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
| 1814 | 1829 |
| 1815 // Use only local ports for simplicity. | 1830 // Use only local ports for simplicity. |
| 1816 SetAllocatorFlags(0, kOnlyLocalPorts); | 1831 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1817 SetAllocatorFlags(1, kOnlyLocalPorts); | 1832 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1818 | 1833 |
| 1819 // Create channels and let them go writable, as usual. | 1834 // Create channels and let them go writable, as usual. |
| 1820 CreateChannels(1); | 1835 CreateChannels(1); |
| 1821 | 1836 |
| 1822 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1837 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1823 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1838 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1824 1000, 1000); | 1839 1000, 1000); |
| 1825 // Need to wait to make sure the connections on both networks are writable. | 1840 // Need to wait to make sure the connections on both networks are writable. |
| 1826 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() && | 1841 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && |
| 1827 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | 1842 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
| 1828 1000); | 1843 1000); |
| 1829 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() && | 1844 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && |
| 1830 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), | 1845 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), |
| 1831 1000); | 1846 1000); |
| 1832 } | 1847 } |
| 1833 | 1848 |
| 1834 // Test that the backup connection is pinged at a rate no faster than | 1849 // Test that the backup connection is pinged at a rate no faster than |
| 1835 // what was configured. | 1850 // what was configured. |
| 1836 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { | 1851 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { |
| 1837 AddAddress(0, kPublicAddrs[0]); | 1852 AddAddress(0, kPublicAddrs[0]); |
| 1838 // Adding alternate address will make sure |kPublicAddrs| has the higher | 1853 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 1839 // priority than others. This is due to FakeNetwork::AddInterface method. | 1854 // priority than others. This is due to FakeNetwork::AddInterface method. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1934 // Use only local ports for simplicity. | 1949 // Use only local ports for simplicity. |
| 1935 SetAllocatorFlags(0, kOnlyLocalPorts); | 1950 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1936 SetAllocatorFlags(1, kOnlyLocalPorts); | 1951 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1937 | 1952 |
| 1938 // Create channels and let them go writable, as usual. | 1953 // Create channels and let them go writable, as usual. |
| 1939 CreateChannels(1); | 1954 CreateChannels(1); |
| 1940 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1955 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1941 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1956 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1942 1000); | 1957 1000); |
| 1943 EXPECT_TRUE( | 1958 EXPECT_TRUE( |
| 1944 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1959 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
| 1945 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1960 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1946 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1961 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1947 | 1962 |
| 1948 | 1963 |
| 1949 // Remove the public interface, add the alternate interface, and allocate | 1964 // Remove the public interface, add the alternate interface, and allocate |
| 1950 // a new generation of candidates for the new interface (via | 1965 // a new generation of candidates for the new interface (via |
| 1951 // MaybeStartGathering()). | 1966 // MaybeStartGathering()). |
| 1952 LOG(LS_INFO) << "Draining..."; | 1967 LOG(LS_INFO) << "Draining..."; |
| 1953 AddAddress(1, kAlternateAddrs[1]); | 1968 AddAddress(1, kAlternateAddrs[1]); |
| 1954 RemoveAddress(1, kPublicAddrs[1]); | 1969 RemoveAddress(1, kPublicAddrs[1]); |
| 1955 ep2_ch1()->MaybeStartGathering(); | 1970 ep2_ch1()->MaybeStartGathering(); |
| 1956 | 1971 |
| 1957 // We should switch over to use the alternate address after | 1972 // We should switch over to use the alternate address after |
| 1958 // an exchange of pings. | 1973 // an exchange of pings. |
| 1959 EXPECT_TRUE_WAIT( | 1974 EXPECT_TRUE_WAIT( |
| 1960 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1975 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
| 1961 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1976 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1962 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), | 1977 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), |
| 1963 3000); | 1978 3000); |
| 1964 | 1979 |
| 1965 DestroyChannels(); | 1980 DestroyChannels(); |
| 1966 } | 1981 } |
| 1967 | 1982 |
| 1968 */ | 1983 */ |
| 1969 | 1984 |
| 1970 // A collection of tests which tests a single P2PTransportChannel by sending | 1985 // A collection of tests which tests a single P2PTransportChannel by sending |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2039 | 2054 |
| 2040 int SendData(cricket::TransportChannel& channel, | 2055 int SendData(cricket::TransportChannel& channel, |
| 2041 const char* data, | 2056 const char* data, |
| 2042 size_t len, | 2057 size_t len, |
| 2043 int packet_id) { | 2058 int packet_id) { |
| 2044 rtc::PacketOptions options; | 2059 rtc::PacketOptions options; |
| 2045 options.packet_id = packet_id; | 2060 options.packet_id = packet_id; |
| 2046 return channel.SendPacket(data, len, options, 0); | 2061 return channel.SendPacket(data, len, options, 0); |
| 2047 } | 2062 } |
| 2048 | 2063 |
| 2064 cricket::Connection* CreateConnectionWithCandidate( | |
| 2065 cricket::P2PTransportChannel& channel, | |
| 2066 rtc::ScopedFakeClock& clock, | |
| 2067 const std::string& ip_addr, | |
| 2068 int port, | |
| 2069 int priority, | |
| 2070 bool writable) { | |
| 2071 channel.AddRemoteCandidate(CreateHostCandidate(ip_addr, port, priority)); | |
| 2072 EXPECT_TRUE_SIMULATED_WAIT( | |
| 2073 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock); | |
| 2074 cricket::Connection* conn = GetConnectionTo(&channel, ip_addr, port); | |
| 2075 | |
| 2076 if (conn && writable) { | |
| 2077 conn->ReceivedPingResponse(LOW_RTT); // make it writable | |
| 2078 } | |
| 2079 return conn; | |
| 2080 } | |
| 2081 | |
| 2082 void NominateConnection(cricket::Connection* conn) { | |
| 2083 conn->set_nominated(true); | |
| 2084 conn->SignalNominated(conn); | |
| 2085 } | |
| 2086 | |
| 2049 void OnSelectedCandidatePairChanged( | 2087 void OnSelectedCandidatePairChanged( |
| 2050 cricket::TransportChannel* transport_channel, | 2088 cricket::TransportChannel* transport_channel, |
| 2051 cricket::CandidatePairInterface* selected_candidate_pair, | 2089 cricket::CandidatePairInterface* selected_candidate_pair, |
| 2052 int last_sent_packet_id) { | 2090 int last_sent_packet_id) { |
| 2053 last_selected_candidate_pair_ = selected_candidate_pair; | 2091 last_selected_candidate_pair_ = selected_candidate_pair; |
| 2054 last_sent_packet_id_ = last_sent_packet_id; | 2092 last_sent_packet_id_ = last_sent_packet_id; |
| 2093 ++selected_candidate_pair_switches_; | |
| 2055 } | 2094 } |
| 2056 | 2095 |
| 2057 void ReceivePingOnConnection(cricket::Connection* conn, | 2096 void ReceivePingOnConnection(cricket::Connection* conn, |
| 2058 const std::string& remote_ufrag, | 2097 const std::string& remote_ufrag, |
| 2059 int priority) { | 2098 int priority) { |
| 2060 cricket::IceMessage msg; | 2099 cricket::IceMessage msg; |
| 2061 msg.SetType(cricket::STUN_BINDING_REQUEST); | 2100 msg.SetType(cricket::STUN_BINDING_REQUEST); |
| 2062 msg.AddAttribute(new cricket::StunByteStringAttribute( | 2101 msg.AddAttribute(new cricket::StunByteStringAttribute( |
| 2063 cricket::STUN_ATTR_USERNAME, | 2102 cricket::STUN_ATTR_USERNAME, |
| 2064 conn->local_candidate().username() + ":" + remote_ufrag)); | 2103 conn->local_candidate().username() + ":" + remote_ufrag)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2080 channel_state_ = channel->GetState(); | 2119 channel_state_ = channel->GetState(); |
| 2081 } | 2120 } |
| 2082 | 2121 |
| 2083 cricket::CandidatePairInterface* last_selected_candidate_pair() { | 2122 cricket::CandidatePairInterface* last_selected_candidate_pair() { |
| 2084 return last_selected_candidate_pair_; | 2123 return last_selected_candidate_pair_; |
| 2085 } | 2124 } |
| 2086 int last_sent_packet_id() { return last_sent_packet_id_; } | 2125 int last_sent_packet_id() { return last_sent_packet_id_; } |
| 2087 bool channel_ready_to_send() { return channel_ready_to_send_; } | 2126 bool channel_ready_to_send() { return channel_ready_to_send_; } |
| 2088 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } | 2127 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } |
| 2089 cricket::TransportChannelState channel_state() { return channel_state_; } | 2128 cricket::TransportChannelState channel_state() { return channel_state_; } |
| 2129 int get_and_reset_selected_candidate_pair_switches() { | |
| 2130 int switches = selected_candidate_pair_switches_; | |
| 2131 selected_candidate_pair_switches_ = 0; | |
| 2132 return switches; | |
| 2133 } | |
| 2090 | 2134 |
| 2091 private: | 2135 private: |
| 2092 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 2136 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
| 2093 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 2137 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 2094 rtc::SocketServerScope ss_scope_; | 2138 rtc::SocketServerScope ss_scope_; |
| 2095 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; | 2139 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; |
| 2140 int selected_candidate_pair_switches_ = 0; | |
| 2096 int last_sent_packet_id_ = -1; | 2141 int last_sent_packet_id_ = -1; |
| 2097 bool channel_ready_to_send_ = false; | 2142 bool channel_ready_to_send_ = false; |
| 2098 cricket::TransportChannelState channel_state_ = cricket::STATE_INIT; | 2143 cricket::TransportChannelState channel_state_ = cricket::STATE_INIT; |
| 2099 }; | 2144 }; |
| 2100 | 2145 |
| 2101 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 2146 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
| 2102 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2147 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2103 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 2148 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
| 2104 PrepareChannel(&ch); | 2149 PrepareChannel(&ch); |
| 2105 ch.Connect(); | 2150 ch.Connect(); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2398 EXPECT_EQ(500, ch.receiving_timeout()); | 2443 EXPECT_EQ(500, ch.receiving_timeout()); |
| 2399 EXPECT_EQ(50, ch.check_receiving_interval()); | 2444 EXPECT_EQ(50, ch.check_receiving_interval()); |
| 2400 ch.Connect(); | 2445 ch.Connect(); |
| 2401 ch.MaybeStartGathering(); | 2446 ch.MaybeStartGathering(); |
| 2402 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2447 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
| 2403 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2448 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2404 ASSERT_TRUE(conn1 != nullptr); | 2449 ASSERT_TRUE(conn1 != nullptr); |
| 2405 | 2450 |
| 2406 conn1->ReceivedPing(); | 2451 conn1->ReceivedPing(); |
| 2407 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2452 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
| 2408 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); | 2453 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000); |
| 2409 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 2454 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
| 2410 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 2455 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
| 2411 } | 2456 } |
| 2412 | 2457 |
| 2413 // The controlled side will select a connection as the "best connection" based | 2458 // The controlled side will select a connection as the "selected connection" |
| 2414 // on priority until the controlling side nominates a connection, at which | 2459 // based on priority until the controlling side nominates a connection, at which |
| 2415 // point the controlled side will select that connection as the | 2460 // point the controlled side will select that connection as the |
| 2416 // "best connection". Plus, SignalSelectedCandidatePair will be fired if the | 2461 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the |
| 2417 // best connection changes and SignalReadyToSend will be fired if the new best | 2462 // selected connection changes and SignalReadyToSend will be fired if the new |
| 2418 // connection is writable. | 2463 // selected connection is writable. |
| 2419 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 2464 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
| 2420 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2465 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2421 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2466 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
| 2422 PrepareChannel(&ch); | 2467 PrepareChannel(&ch); |
| 2423 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2468 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2424 ch.Connect(); | 2469 ch.Connect(); |
| 2425 ch.MaybeStartGathering(); | 2470 ch.MaybeStartGathering(); |
| 2426 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2471 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
| 2427 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2472 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2428 ASSERT_TRUE(conn1 != nullptr); | 2473 ASSERT_TRUE(conn1 != nullptr); |
| 2429 EXPECT_EQ(conn1, ch.best_connection()); | 2474 EXPECT_EQ(conn1, ch.selected_connection()); |
| 2430 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 2475 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
| 2431 EXPECT_EQ(-1, last_sent_packet_id()); | 2476 EXPECT_EQ(-1, last_sent_packet_id()); |
| 2432 // Channel is not ready to send because it is not writable. | 2477 // Channel is not ready to send because it is not writable. |
| 2433 EXPECT_FALSE(channel_ready_to_send()); | 2478 EXPECT_FALSE(channel_ready_to_send()); |
| 2434 | 2479 |
| 2435 int last_packet_id = 0; | 2480 int last_packet_id = 0; |
| 2436 const char* data = "ABCDEFGH"; | 2481 const char* data = "ABCDEFGH"; |
| 2437 int len = static_cast<int>(strlen(data)); | 2482 int len = static_cast<int>(strlen(data)); |
| 2438 SendData(ch, data, len, ++last_packet_id); | 2483 SendData(ch, data, len, ++last_packet_id); |
| 2439 // When a higher priority candidate comes in, the new connection is chosen | 2484 // When a higher priority candidate comes in, the new connection is chosen |
| 2440 // as the best connection. | 2485 // as the selected connection. |
| 2441 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); | 2486 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); |
| 2442 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2487 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2443 ASSERT_TRUE(conn2 != nullptr); | 2488 ASSERT_TRUE(conn2 != nullptr); |
| 2444 EXPECT_EQ(conn2, ch.best_connection()); | 2489 EXPECT_EQ(conn2, ch.selected_connection()); |
| 2445 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 2490 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
| 2446 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2491 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
| 2447 EXPECT_FALSE(channel_ready_to_send()); | 2492 EXPECT_FALSE(channel_ready_to_send()); |
| 2448 | 2493 |
| 2449 // If a stun request with use-candidate attribute arrives, the receiving | 2494 // If a stun request with use-candidate attribute arrives, the receiving |
| 2450 // connection will be set as the best connection, even though | 2495 // connection will be set as the selected connection, even though |
| 2451 // its priority is lower. | 2496 // its priority is lower. |
| 2452 SendData(ch, data, len, ++last_packet_id); | 2497 SendData(ch, data, len, ++last_packet_id); |
| 2453 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); | 2498 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); |
| 2454 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2499 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
| 2455 ASSERT_TRUE(conn3 != nullptr); | 2500 ASSERT_TRUE(conn3 != nullptr); |
| 2456 // Because it has a lower priority, the best connection is still conn2. | 2501 // Because it has a lower priority, the selected connection is still conn2. |
| 2457 EXPECT_EQ(conn2, ch.best_connection()); | 2502 EXPECT_EQ(conn2, ch.selected_connection()); |
| 2458 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. | 2503 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. |
| 2459 // But if it is nominated via use_candidate, it is chosen as the best | 2504 // But if it is nominated via use_candidate, it is chosen as the selected |
| 2460 // connection. | 2505 // connection. |
| 2461 conn3->set_nominated(true); | 2506 conn3->set_nominated(true); |
| 2462 conn3->SignalNominated(conn3); | 2507 conn3->SignalNominated(conn3); |
| 2463 EXPECT_EQ(conn3, ch.best_connection()); | 2508 EXPECT_EQ(conn3, ch.selected_connection()); |
| 2464 EXPECT_EQ(conn3, last_selected_candidate_pair()); | 2509 EXPECT_EQ(conn3, last_selected_candidate_pair()); |
| 2465 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2510 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
| 2466 EXPECT_TRUE(channel_ready_to_send()); | 2511 EXPECT_TRUE(channel_ready_to_send()); |
| 2467 | 2512 |
| 2468 // Even if another higher priority candidate arrives, | 2513 // Even if another higher priority candidate arrives, it will not be set as |
| 2469 // it will not be set as the best connection because the best connection | 2514 // the selected connection because the selected connection is nominated by |
| 2470 // is nominated by the controlling side. | 2515 // the controlling side. |
| 2471 SendData(ch, data, len, ++last_packet_id); | 2516 SendData(ch, data, len, ++last_packet_id); |
| 2472 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); | 2517 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); |
| 2473 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2518 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
| 2474 ASSERT_TRUE(conn4 != nullptr); | 2519 ASSERT_TRUE(conn4 != nullptr); |
| 2475 EXPECT_EQ(conn3, ch.best_connection()); | 2520 EXPECT_EQ(conn3, ch.selected_connection()); |
| 2476 // But if it is nominated via use_candidate and writable, it will be set as | 2521 // But if it is nominated via use_candidate and writable, it will be set as |
| 2477 // the best connection. | 2522 // the selected connection. |
| 2478 conn4->set_nominated(true); | 2523 conn4->set_nominated(true); |
| 2479 conn4->SignalNominated(conn4); | 2524 conn4->SignalNominated(conn4); |
| 2480 // Not switched yet because conn4 is not writable. | 2525 // Not switched yet because conn4 is not writable. |
| 2481 EXPECT_EQ(conn3, ch.best_connection()); | 2526 EXPECT_EQ(conn3, ch.selected_connection()); |
| 2482 reset_channel_ready_to_send(); | 2527 reset_channel_ready_to_send(); |
| 2483 // The best connection switches after conn4 becomes writable. | 2528 // The selected connection switches after conn4 becomes writable. |
| 2484 conn4->ReceivedPingResponse(LOW_RTT); | 2529 conn4->ReceivedPingResponse(LOW_RTT); |
| 2485 EXPECT_EQ(conn4, ch.best_connection()); | 2530 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); |
| 2486 EXPECT_EQ(conn4, last_selected_candidate_pair()); | 2531 EXPECT_EQ(conn4, last_selected_candidate_pair()); |
| 2487 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2532 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
| 2488 // SignalReadyToSend is fired again because conn4 is writable. | 2533 // SignalReadyToSend is fired again because conn4 is writable. |
| 2489 EXPECT_TRUE(channel_ready_to_send()); | 2534 EXPECT_TRUE(channel_ready_to_send()); |
| 2490 } | 2535 } |
| 2491 | 2536 |
| 2492 // The controlled side will select a connection as the "best connection" based | 2537 // The controlled side will select a connection as the "selected connection" |
| 2493 // on requests from an unknown address before the controlling side nominates | 2538 // based on requests from an unknown address before the controlling side |
| 2494 // a connection, and will nominate a connection from an unknown address if the | 2539 // nominates a connection, and will nominate a connection from an unknown |
| 2495 // request contains the use_candidate attribute. Plus, it will also sends back | 2540 // address if the request contains the use_candidate attribute. Plus, it will |
| 2496 // a ping response and set the ICE pwd in the remote candidate appropriately. | 2541 // also sends back a ping response and set the ICE pwd in the remote candidate |
| 2542 // appropriately. | |
| 2497 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { | 2543 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { |
| 2498 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2544 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2499 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2545 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
| 2500 PrepareChannel(&ch); | 2546 PrepareChannel(&ch); |
| 2501 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2547 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2502 ch.Connect(); | 2548 ch.Connect(); |
| 2503 ch.MaybeStartGathering(); | 2549 ch.MaybeStartGathering(); |
| 2504 // A minimal STUN message with prflx priority. | 2550 // A minimal STUN message with prflx priority. |
| 2505 cricket::IceMessage request; | 2551 cricket::IceMessage request; |
| 2506 request.SetType(cricket::STUN_BINDING_REQUEST); | 2552 request.SetType(cricket::STUN_BINDING_REQUEST); |
| 2507 request.AddAttribute(new cricket::StunByteStringAttribute( | 2553 request.AddAttribute(new cricket::StunByteStringAttribute( |
| 2508 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 2554 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
| 2509 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2555 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
| 2510 request.AddAttribute(new cricket::StunUInt32Attribute( | 2556 request.AddAttribute(new cricket::StunUInt32Attribute( |
| 2511 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 2557 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
| 2512 cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch)); | 2558 cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch)); |
| 2513 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 2559 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), |
| 2514 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2560 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
| 2515 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2561 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2516 ASSERT_TRUE(conn1 != nullptr); | 2562 ASSERT_TRUE(conn1 != nullptr); |
| 2517 EXPECT_TRUE(port->sent_binding_response()); | 2563 EXPECT_TRUE(port->sent_binding_response()); |
| 2518 EXPECT_EQ(conn1, ch.best_connection()); | 2564 EXPECT_EQ(conn1, ch.selected_connection()); |
| 2519 conn1->ReceivedPingResponse(LOW_RTT); | 2565 conn1->ReceivedPingResponse(LOW_RTT); |
| 2520 EXPECT_EQ(conn1, ch.best_connection()); | 2566 EXPECT_EQ(conn1, ch.selected_connection()); |
| 2521 port->set_sent_binding_response(false); | 2567 port->set_sent_binding_response(false); |
| 2522 | 2568 |
| 2523 // Another connection is nominated via use_candidate. | 2569 // Another connection is nominated via use_candidate. |
| 2524 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2570 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
| 2525 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2571 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2526 ASSERT_TRUE(conn2 != nullptr); | 2572 ASSERT_TRUE(conn2 != nullptr); |
| 2527 // Because it has a lower priority, the best connection is still conn1. | 2573 // Because it has a lower priority, the selected connection is still conn1. |
| 2528 EXPECT_EQ(conn1, ch.best_connection()); | 2574 EXPECT_EQ(conn1, ch.selected_connection()); |
| 2529 // When it is nominated via use_candidate and writable, it is chosen as the | 2575 // When it is nominated via use_candidate and writable, it is chosen as the |
| 2530 // best connection. | 2576 // selected connection. |
| 2531 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. | 2577 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. |
| 2532 conn2->set_nominated(true); | 2578 conn2->set_nominated(true); |
| 2533 conn2->SignalNominated(conn2); | 2579 conn2->SignalNominated(conn2); |
| 2534 EXPECT_EQ(conn2, ch.best_connection()); | 2580 EXPECT_EQ(conn2, ch.selected_connection()); |
| 2535 | 2581 |
| 2536 // Another request with unknown address, it will not be set as the best | 2582 // Another request with unknown address, it will not be set as the selected |
| 2537 // connection because the best connection was nominated by the controlling | 2583 // connection because the selected connection was nominated by the controlling |
| 2538 // side. | 2584 // side. |
| 2539 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), | 2585 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), |
| 2540 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2586 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
| 2541 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2587 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
| 2542 ASSERT_TRUE(conn3 != nullptr); | 2588 ASSERT_TRUE(conn3 != nullptr); |
| 2543 EXPECT_TRUE(port->sent_binding_response()); | 2589 EXPECT_TRUE(port->sent_binding_response()); |
| 2544 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. | 2590 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. |
| 2545 EXPECT_EQ(conn2, ch.best_connection()); | 2591 EXPECT_EQ(conn2, ch.selected_connection()); |
| 2546 port->set_sent_binding_response(false); | 2592 port->set_sent_binding_response(false); |
| 2547 | 2593 |
| 2548 // However if the request contains use_candidate attribute, it will be | 2594 // However if the request contains use_candidate attribute, it will be |
| 2549 // selected as the best connection. | 2595 // selected as the selected connection. |
| 2550 request.AddAttribute( | 2596 request.AddAttribute( |
| 2551 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); | 2597 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); |
| 2552 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), | 2598 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), |
| 2553 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2599 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
| 2554 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2600 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
| 2555 ASSERT_TRUE(conn4 != nullptr); | 2601 ASSERT_TRUE(conn4 != nullptr); |
| 2556 EXPECT_TRUE(port->sent_binding_response()); | 2602 EXPECT_TRUE(port->sent_binding_response()); |
| 2557 // conn4 is not the best connection yet because it is not writable. | 2603 // conn4 is not the selected connection yet because it is not writable. |
| 2558 EXPECT_EQ(conn2, ch.best_connection()); | 2604 EXPECT_EQ(conn2, ch.selected_connection()); |
| 2559 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. | 2605 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. |
| 2560 EXPECT_EQ(conn4, ch.best_connection()); | 2606 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); |
| 2561 | 2607 |
| 2562 // Test that the request from an unknown address contains a ufrag from an old | 2608 // Test that the request from an unknown address contains a ufrag from an old |
| 2563 // generation. | 2609 // generation. |
| 2564 port->set_sent_binding_response(false); | 2610 port->set_sent_binding_response(false); |
| 2565 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 2611 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
| 2566 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 2612 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
| 2567 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), | 2613 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), |
| 2568 cricket::PROTO_UDP, &request, kIceUfrag[2], false); | 2614 cricket::PROTO_UDP, &request, kIceUfrag[2], false); |
| 2569 cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); | 2615 cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); |
| 2570 ASSERT_TRUE(conn5 != nullptr); | 2616 ASSERT_TRUE(conn5 != nullptr); |
| 2571 EXPECT_TRUE(port->sent_binding_response()); | 2617 EXPECT_TRUE(port->sent_binding_response()); |
| 2572 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); | 2618 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); |
| 2573 } | 2619 } |
| 2574 | 2620 |
| 2575 // The controlled side will select a connection as the "best connection" | 2621 // The controlled side will select a connection as the "selected connection" |
| 2576 // based on media received until the controlling side nominates a connection, | 2622 // based on media received until the controlling side nominates a connection, |
| 2577 // at which point the controlled side will select that connection as | 2623 // at which point the controlled side will select that connection as |
| 2578 // the "best connection". | 2624 // the "selected connection". |
| 2579 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { | 2625 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
| 2580 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2626 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2581 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2627 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
| 2582 PrepareChannel(&ch); | 2628 PrepareChannel(&ch); |
| 2583 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2629 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2584 ch.Connect(); | 2630 ch.Connect(); |
| 2585 ch.MaybeStartGathering(); | 2631 ch.MaybeStartGathering(); |
| 2586 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 10)); | 2632 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 10)); |
| 2587 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2633 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2588 ASSERT_TRUE(conn1 != nullptr); | 2634 ASSERT_TRUE(conn1 != nullptr); |
| 2589 EXPECT_EQ(conn1, ch.best_connection()); | 2635 EXPECT_EQ(conn1, ch.selected_connection()); |
| 2590 | 2636 |
| 2591 // If a data packet is received on conn2, the best connection should | 2637 // If a data packet is received on conn2, the selected connection should |
| 2592 // switch to conn2 because the controlled side must mirror the media path | 2638 // switch to conn2 because the controlled side must mirror the media path |
| 2593 // chosen by the controlling side. | 2639 // chosen by the controlling side. |
| 2594 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2640 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
| 2595 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2641 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2596 ASSERT_TRUE(conn2 != nullptr); | 2642 ASSERT_TRUE(conn2 != nullptr); |
| 2597 conn2->ReceivedPing(); // Start receiving. | 2643 conn2->ReceivedPing(); // Start receiving. |
| 2598 // Do not switch because it is not writable. | |
| 2599 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2644 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
| 2600 EXPECT_EQ(conn1, ch.best_connection()); | 2645 EXPECT_EQ(conn2, ch.selected_connection()); |
| 2601 | |
| 2602 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. | 2646 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. |
| 2603 // Switch because it is writable. | |
| 2604 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); | |
| 2605 EXPECT_EQ(conn2, ch.best_connection()); | |
| 2606 | 2647 |
| 2607 // Now another STUN message with an unknown address and use_candidate will | 2648 // Now another STUN message with an unknown address and use_candidate will |
| 2608 // nominate the best connection. | 2649 // nominate the selected connection. |
| 2609 cricket::IceMessage request; | 2650 cricket::IceMessage request; |
| 2610 request.SetType(cricket::STUN_BINDING_REQUEST); | 2651 request.SetType(cricket::STUN_BINDING_REQUEST); |
| 2611 request.AddAttribute(new cricket::StunByteStringAttribute( | 2652 request.AddAttribute(new cricket::StunByteStringAttribute( |
| 2612 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 2653 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
| 2613 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2654 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
| 2614 request.AddAttribute(new cricket::StunUInt32Attribute( | 2655 request.AddAttribute(new cricket::StunUInt32Attribute( |
| 2615 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 2656 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
| 2616 request.AddAttribute( | 2657 request.AddAttribute( |
| 2617 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); | 2658 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); |
| 2618 cricket::Port* port = GetPort(&ch); | 2659 cricket::Port* port = GetPort(&ch); |
| 2619 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), | 2660 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), |
| 2620 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2661 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
| 2621 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2662 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
| 2622 ASSERT_TRUE(conn3 != nullptr); | 2663 ASSERT_TRUE(conn3 != nullptr); |
| 2623 EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet. | 2664 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. |
| 2624 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. | 2665 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. |
| 2625 EXPECT_EQ(conn3, ch.best_connection()); | 2666 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); |
| 2626 | 2667 |
| 2627 // Now another data packet will not switch the best connection because the | 2668 // Now another data packet will not switch the selected connection because the |
| 2628 // best connection was nominated by the controlling side. | 2669 // selected connection was nominated by the controlling side. |
| 2629 conn2->ReceivedPing(); | 2670 conn2->ReceivedPing(); |
| 2630 conn2->ReceivedPingResponse(LOW_RTT); | 2671 conn2->ReceivedPingResponse(LOW_RTT); |
| 2631 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 2672 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
| 2632 EXPECT_EQ(conn3, ch.best_connection()); | 2673 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); |
| 2674 } | |
| 2675 | |
| 2676 TEST_F(P2PTransportChannelPingTest, | |
| 2677 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) { | |
| 2678 rtc::ScopedFakeClock clock; | |
| 2679 | |
| 2680 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
| 2681 cricket::P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); | |
| 2682 PrepareChannel(&ch); | |
| 2683 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 2684 ch.Connect(); | |
| 2685 ch.MaybeStartGathering(); | |
| 2686 // The connections have decreasing priority. | |
| 2687 cricket::Connection* conn1 = | |
| 2688 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); | |
| 2689 ASSERT_TRUE(conn1 != nullptr); | |
| 2690 cricket::Connection* conn2 = | |
| 2691 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true); | |
| 2692 ASSERT_TRUE(conn2 != nullptr); | |
| 2693 | |
| 2694 // Initially, connections are selected based on priority. | |
| 2695 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
| 2696 EXPECT_EQ(conn1, last_selected_candidate_pair()); | |
| 2697 | |
| 2698 // conn2 receives data; it becomes selected. | |
| 2699 // Advance the clock by 1ms so that the last data receiving timestamp of | |
| 2700 // conn2 is larger. | |
| 2701 SIMULATED_WAIT(false, 1, clock); | |
| 2702 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | |
| 2703 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
| 2704 EXPECT_EQ(conn2, last_selected_candidate_pair()); | |
| 2705 | |
| 2706 // conn1 also receives data; it becomes selected due to priority again. | |
| 2707 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | |
| 2708 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
| 2709 EXPECT_EQ(conn1, last_selected_candidate_pair()); | |
| 2710 | |
| 2711 // Make sure sorting won't reselect candidate pair. | |
| 2712 SIMULATED_WAIT(false, 10, clock); | |
| 2713 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | |
| 2714 } | |
| 2715 | |
| 2716 TEST_F(P2PTransportChannelPingTest, | |
| 2717 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) { | |
| 2718 rtc::ScopedFakeClock clock; | |
| 2719 | |
| 2720 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
| 2721 cricket::P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); | |
| 2722 PrepareChannel(&ch); | |
| 2723 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 2724 ch.Connect(); | |
| 2725 ch.MaybeStartGathering(); | |
| 2726 // The connections have decreasing priority. | |
| 2727 cricket::Connection* conn1 = | |
| 2728 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); | |
| 2729 ASSERT_TRUE(conn1 != nullptr); | |
| 2730 cricket::Connection* conn2 = | |
| 2731 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); | |
| 2732 ASSERT_TRUE(conn2 != nullptr); | |
| 2733 | |
| 2734 // conn1 received data; it is the selected connection. | |
| 2735 // Advance the clock to have a non-zero last-data-receiving time. | |
| 2736 SIMULATED_WAIT(false, 1, clock); | |
| 2737 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | |
| 2738 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
| 2739 EXPECT_EQ(conn1, last_selected_candidate_pair()); | |
| 2740 | |
| 2741 // conn2 is nominated; it becomes the selected connection. | |
| 2742 NominateConnection(conn2); | |
| 2743 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
| 2744 EXPECT_EQ(conn2, last_selected_candidate_pair()); | |
| 2745 | |
| 2746 NominateConnection(conn1); | |
| 2747 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
| 2748 EXPECT_EQ(conn1, last_selected_candidate_pair()); | |
| 2749 | |
| 2750 // conn2 received data more recently; it is selected now because it | |
| 2751 // received data more recently. | |
| 2752 SIMULATED_WAIT(false, 1, clock); | |
| 2753 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | |
| 2754 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
| 2755 EXPECT_EQ(conn2, last_selected_candidate_pair()); | |
| 2756 | |
| 2757 // Make sure sorting won't reselect candidate pair. | |
| 2758 SIMULATED_WAIT(false, 10, clock); | |
| 2759 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | |
| 2760 } | |
| 2761 | |
| 2762 TEST_F(P2PTransportChannelPingTest, | |
| 2763 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) { | |
| 2764 rtc::ScopedFakeClock clock; | |
| 2765 | |
| 2766 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
| 2767 cricket::P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); | |
| 2768 PrepareChannel(&ch); | |
| 2769 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 2770 ch.Connect(); | |
| 2771 ch.MaybeStartGathering(); | |
| 2772 // The connections have decreasing priority. | |
| 2773 cricket::Connection* conn1 = | |
| 2774 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); | |
| 2775 ASSERT_TRUE(conn1 != nullptr); | |
| 2776 cricket::Connection* conn2 = | |
| 2777 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); | |
| 2778 ASSERT_TRUE(conn2 != nullptr); | |
| 2779 | |
| 2780 NominateConnection(conn1); | |
| 2781 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
| 2782 | |
| 2783 // conn2 becomes writable; it is selected even though it is not nominated. | |
| 2784 conn2->ReceivedPingResponse(LOW_RTT); | |
| 2785 | |
| 2786 EXPECT_EQ_SIMULATED_WAIT(1, get_and_reset_selected_candidate_pair_switches(), | |
| 2787 kDefaultTimeout, clock); | |
| 2788 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), | |
| 2789 kDefaultTimeout, clock); | |
| 2790 | |
| 2791 // If conn1 is also writable, it will become selected. | |
| 2792 conn1->ReceivedPingResponse(LOW_RTT); | |
| 2793 EXPECT_EQ_SIMULATED_WAIT(1, get_and_reset_selected_candidate_pair_switches(), | |
| 2794 kDefaultTimeout, clock); | |
| 2795 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), | |
| 2796 kDefaultTimeout, clock); | |
| 2797 | |
| 2798 // Make sure sorting won't reselect candidate pair. | |
| 2799 SIMULATED_WAIT(false, 10, clock); | |
| 2800 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | |
| 2633 } | 2801 } |
| 2634 | 2802 |
| 2635 // Test that if a new remote candidate has the same address and port with | 2803 // Test that if a new remote candidate has the same address and port with |
| 2636 // an old one, it will be used to create a new connection. | 2804 // an old one, it will be used to create a new connection. |
| 2637 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { | 2805 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { |
| 2638 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2806 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2639 cricket::P2PTransportChannel ch("candidate reuse", 1, &pa); | 2807 cricket::P2PTransportChannel ch("candidate reuse", 1, &pa); |
| 2640 PrepareChannel(&ch); | 2808 PrepareChannel(&ch); |
| 2641 ch.Connect(); | 2809 ch.Connect(); |
| 2642 ch.MaybeStartGathering(); | 2810 ch.MaybeStartGathering(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2664 EXPECT_EQ(kIceUfrag[2], conn2->remote_candidate().username()); | 2832 EXPECT_EQ(kIceUfrag[2], conn2->remote_candidate().username()); |
| 2665 EXPECT_EQ(1u, conn2->remote_candidate().generation()); | 2833 EXPECT_EQ(1u, conn2->remote_candidate().generation()); |
| 2666 | 2834 |
| 2667 // Verify that a ping with the new ufrag can be received on the new | 2835 // Verify that a ping with the new ufrag can be received on the new |
| 2668 // connection. | 2836 // connection. |
| 2669 EXPECT_EQ(0, conn2->last_ping_received()); | 2837 EXPECT_EQ(0, conn2->last_ping_received()); |
| 2670 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); | 2838 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); |
| 2671 EXPECT_TRUE(conn2->last_ping_received() > 0); | 2839 EXPECT_TRUE(conn2->last_ping_received() > 0); |
| 2672 } | 2840 } |
| 2673 | 2841 |
| 2674 // When the current best connection is strong, lower-priority connections will | 2842 // When the current selected connection is strong, lower-priority connections |
| 2675 // be pruned. Otherwise, lower-priority connections are kept. | 2843 // will be pruned. Otherwise, lower-priority connections are kept. |
| 2676 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { | 2844 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
| 2677 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2845 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2678 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2846 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
| 2679 PrepareChannel(&ch); | 2847 PrepareChannel(&ch); |
| 2680 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2848 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2681 ch.Connect(); | 2849 ch.Connect(); |
| 2682 ch.MaybeStartGathering(); | 2850 ch.MaybeStartGathering(); |
| 2683 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2851 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
| 2684 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2852 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2685 ASSERT_TRUE(conn1 != nullptr); | 2853 ASSERT_TRUE(conn1 != nullptr); |
| 2686 EXPECT_EQ(conn1, ch.best_connection()); | 2854 EXPECT_EQ(conn1, ch.selected_connection()); |
| 2687 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 2855 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
| 2688 | 2856 |
| 2689 // When a higher-priority, nominated candidate comes in, the connections with | 2857 // When a higher-priority, nominated candidate comes in, the connections with |
| 2690 // lower-priority are pruned. | 2858 // lower-priority are pruned. |
| 2691 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); | 2859 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); |
| 2692 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2860 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2693 ASSERT_TRUE(conn2 != nullptr); | 2861 ASSERT_TRUE(conn2 != nullptr); |
| 2694 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 2862 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
| 2695 conn2->set_nominated(true); | 2863 conn2->set_nominated(true); |
| 2696 conn2->SignalNominated(conn2); | 2864 conn2->SignalNominated(conn2); |
| 2697 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 2865 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
| 2698 | 2866 |
| 2699 ch.SetIceConfig(CreateIceConfig(500, false)); | 2867 ch.SetIceConfig(CreateIceConfig(500, false)); |
| 2700 // Wait until conn2 becomes not receiving. | 2868 // Wait until conn2 becomes not receiving. |
| 2701 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | 2869 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); |
| 2702 | 2870 |
| 2703 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); | 2871 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); |
| 2704 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2872 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
| 2705 ASSERT_TRUE(conn3 != nullptr); | 2873 ASSERT_TRUE(conn3 != nullptr); |
| 2706 // The best connection should still be conn2. Even through conn3 has lower | 2874 // The selected connection should still be conn2. Even through conn3 has lower |
| 2707 // priority and is not receiving/writable, it is not pruned because the best | 2875 // priority and is not receiving/writable, it is not pruned because the |
| 2708 // connection is not receiving. | 2876 // selected connection is not receiving. |
| 2709 WAIT(conn3->pruned(), 1000); | 2877 WAIT(conn3->pruned(), 1000); |
| 2710 EXPECT_FALSE(conn3->pruned()); | 2878 EXPECT_FALSE(conn3->pruned()); |
| 2711 } | 2879 } |
| 2712 | 2880 |
| 2881 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) { | |
| 2882 rtc::ScopedFakeClock clock; | |
| 2883 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
| 2884 cricket::P2PTransportChannel ch("test channel", 1, &pa); | |
| 2885 PrepareChannel(&ch); | |
| 2886 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | |
| 2887 ch.Connect(); | |
| 2888 ch.MaybeStartGathering(); | |
| 2889 cricket::Connection* conn1 = | |
| 2890 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 100, true); | |
| 2891 ASSERT_TRUE(conn1 != nullptr); | |
| 2892 cricket::Connection* conn2 = | |
| 2893 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 200, false); | |
| 2894 ASSERT_TRUE(conn2 != nullptr); | |
| 2895 // Even if conn1 is writable, nominated, receiving data, it should not prune | |
| 2896 // conn2. | |
| 2897 NominateConnection(conn1); | |
| 2898 SIMULATED_WAIT(false, 1, clock); | |
| 2899 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | |
| 2900 SIMULATED_WAIT(conn2->pruned(), 100, clock); | |
| 2901 EXPECT_TRUE(!conn2->pruned()); | |
|
Taylor Brandstetter
2016/06/22 16:12:23
EXPECT_FALSE?
honghaiz3
2016/06/22 16:29:28
Done.
| |
| 2902 } | |
| 2903 | |
| 2713 // Test that GetState returns the state correctly. | 2904 // Test that GetState returns the state correctly. |
| 2714 TEST_F(P2PTransportChannelPingTest, TestGetState) { | 2905 TEST_F(P2PTransportChannelPingTest, TestGetState) { |
| 2715 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2906 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2716 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2907 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
| 2717 PrepareChannel(&ch); | 2908 PrepareChannel(&ch); |
| 2718 ch.Connect(); | 2909 ch.Connect(); |
| 2719 ch.MaybeStartGathering(); | 2910 ch.MaybeStartGathering(); |
| 2720 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); | 2911 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); |
| 2721 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2912 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
| 2722 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2913 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2741 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 2932 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
| 2742 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2933 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2743 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2934 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
| 2744 PrepareChannel(&ch); | 2935 PrepareChannel(&ch); |
| 2745 ch.SetIceConfig(CreateIceConfig(1000, false)); | 2936 ch.SetIceConfig(CreateIceConfig(1000, false)); |
| 2746 ch.Connect(); | 2937 ch.Connect(); |
| 2747 ch.MaybeStartGathering(); | 2938 ch.MaybeStartGathering(); |
| 2748 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2939 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
| 2749 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2940 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2750 ASSERT_TRUE(conn1 != nullptr); | 2941 ASSERT_TRUE(conn1 != nullptr); |
| 2751 EXPECT_EQ(conn1, ch.best_connection()); | 2942 EXPECT_EQ(conn1, ch.selected_connection()); |
| 2752 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 2943 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
| 2753 | 2944 |
| 2754 // Add a low-priority connection |conn2|, which will be pruned, but it will | 2945 // Add a low-priority connection |conn2|, which will be pruned, but it will |
| 2755 // not be deleted right away. Once the current best connection becomes not | 2946 // not be deleted right away. Once the current selected connection becomes not |
| 2756 // receiving, |conn2| will start to ping and upon receiving the ping response, | 2947 // receiving, |conn2| will start to ping and upon receiving the ping response, |
| 2757 // it will become the best connection. | 2948 // it will become the selected connection. |
| 2758 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2949 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
| 2759 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2950 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2760 ASSERT_TRUE(conn2 != nullptr); | 2951 ASSERT_TRUE(conn2 != nullptr); |
| 2761 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2952 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
| 2762 // |conn2| should not send a ping yet. | 2953 // |conn2| should not send a ping yet. |
| 2763 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state()); | 2954 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state()); |
| 2764 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2955 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
| 2765 // Wait for |conn1| becoming not receiving. | 2956 // Wait for |conn1| becoming not receiving. |
| 2766 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); | 2957 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); |
| 2767 // Make sure conn2 is not deleted. | 2958 // Make sure conn2 is not deleted. |
| 2768 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2959 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2769 ASSERT_TRUE(conn2 != nullptr); | 2960 ASSERT_TRUE(conn2 != nullptr); |
| 2770 EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000); | 2961 EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000); |
| 2771 conn2->ReceivedPingResponse(LOW_RTT); | 2962 conn2->ReceivedPingResponse(LOW_RTT); |
| 2772 EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000); | 2963 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000); |
| 2773 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2964 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); |
| 2774 | 2965 |
| 2775 // When |conn1| comes back again, |conn2| will be pruned again. | 2966 // When |conn1| comes back again, |conn2| will be pruned again. |
| 2776 conn1->ReceivedPingResponse(LOW_RTT); | 2967 conn1->ReceivedPingResponse(LOW_RTT); |
| 2777 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); | 2968 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000); |
| 2778 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2969 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
| 2779 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2970 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
| 2780 } | 2971 } |
| 2781 | 2972 |
| 2782 // Test that if all connections in a channel has timed out on writing, they | 2973 // Test that if all connections in a channel has timed out on writing, they |
| 2783 // will all be deleted. We use Prune to simulate write_time_out. | 2974 // will all be deleted. We use Prune to simulate write_time_out. |
| 2784 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 2975 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
| 2785 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2976 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2786 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2977 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
| 2787 PrepareChannel(&ch); | 2978 PrepareChannel(&ch); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2991 | 3182 |
| 2992 private: | 3183 private: |
| 2993 std::unique_ptr<cricket::BasicPortAllocator> allocator_; | 3184 std::unique_ptr<cricket::BasicPortAllocator> allocator_; |
| 2994 rtc::FakeNetworkManager network_manager_; | 3185 rtc::FakeNetworkManager network_manager_; |
| 2995 cricket::TestTurnServer turn_server_; | 3186 cricket::TestTurnServer turn_server_; |
| 2996 std::unique_ptr<cricket::P2PTransportChannel> channel_; | 3187 std::unique_ptr<cricket::P2PTransportChannel> channel_; |
| 2997 }; | 3188 }; |
| 2998 | 3189 |
| 2999 // Test that Relay/Relay connections will be pinged first when no other | 3190 // Test that Relay/Relay connections will be pinged first when no other |
| 3000 // connections have been pinged yet, unless we need to ping a trigger check or | 3191 // connections have been pinged yet, unless we need to ping a trigger check or |
| 3001 // we have a best connection. | 3192 // we have a selected connection. |
| 3002 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, | 3193 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
| 3003 TestRelayRelayFirstWhenNothingPingedYet) { | 3194 TestRelayRelayFirstWhenNothingPingedYet) { |
| 3004 const int max_strong_interval = 100; | 3195 const int max_strong_interval = 100; |
| 3005 cricket::P2PTransportChannel& ch = | 3196 cricket::P2PTransportChannel& ch = |
| 3006 StartTransportChannel(true, max_strong_interval); | 3197 StartTransportChannel(true, max_strong_interval); |
| 3007 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); | 3198 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
| 3008 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); | 3199 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); |
| 3009 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); | 3200 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
| 3010 | 3201 |
| 3011 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); | 3202 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); |
| 3012 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 3203 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
| 3013 | 3204 |
| 3014 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); | 3205 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
| 3015 | 3206 |
| 3016 // Relay/Relay should be the first pingable connection. | 3207 // Relay/Relay should be the first pingable connection. |
| 3017 cricket::Connection* conn = FindNextPingableConnectionAndPingIt(&ch); | 3208 cricket::Connection* conn = FindNextPingableConnectionAndPingIt(&ch); |
| 3018 EXPECT_EQ(conn->local_candidate().type(), cricket::RELAY_PORT_TYPE); | 3209 EXPECT_EQ(conn->local_candidate().type(), cricket::RELAY_PORT_TYPE); |
| 3019 EXPECT_EQ(conn->remote_candidate().type(), cricket::RELAY_PORT_TYPE); | 3210 EXPECT_EQ(conn->remote_candidate().type(), cricket::RELAY_PORT_TYPE); |
| 3020 | 3211 |
| 3021 // Unless that we have a trigger check waiting to be pinged. | 3212 // Unless that we have a trigger check waiting to be pinged. |
| 3022 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3213 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 3023 EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE); | 3214 EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE); |
| 3024 EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE); | 3215 EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE); |
| 3025 conn2->ReceivedPing(); | 3216 conn2->ReceivedPing(); |
| 3026 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 3217 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
| 3027 | 3218 |
| 3028 // Make conn3 the best connection. | 3219 // Make conn3 the selected connection. |
| 3029 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3220 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 3030 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); | 3221 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); |
| 3031 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); | 3222 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); |
| 3032 conn3->ReceivedPingResponse(LOW_RTT); | 3223 conn3->ReceivedPingResponse(LOW_RTT); |
| 3033 ASSERT_TRUE(conn3->writable()); | 3224 ASSERT_TRUE(conn3->writable()); |
| 3034 conn3->ReceivedPing(); | 3225 conn3->ReceivedPing(); |
| 3035 | 3226 |
| 3036 /* | 3227 /* |
| 3037 | 3228 |
| 3038 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix | 3229 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix |
| 3039 the flakiness. The following test becomes flaky because we now ping the | 3230 the flakiness. The following test becomes flaky because we now ping the |
| 3040 connections with fast rates until every connection is pinged at least three | 3231 connections with fast rates until every connection is pinged at least three |
| 3041 times. The best connection may have been pinged before |max_strong_interval|, | 3232 times. The selected connection may have been pinged before |
| 3042 so it may not be the next connection to be pinged as expected in the test. | 3233 |max_strong_interval|, so it may not be the next connection to be pinged as |
| 3234 expected in the test. | |
| 3043 | 3235 |
| 3044 // Verify that conn3 will be the "best connection" since it is readable and | 3236 // Verify that conn3 will be the "selected connection" since it is readable |
| 3045 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next | 3237 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next |
| 3046 // pingable connection. | 3238 // pingable connection. |
| 3047 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); | 3239 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000); |
| 3048 WAIT(false, max_strong_interval + 100); | 3240 WAIT(false, max_strong_interval + 100); |
| 3049 conn3->ReceivedPingResponse(LOW_RTT); | 3241 conn3->ReceivedPingResponse(LOW_RTT); |
| 3050 ASSERT_TRUE(conn3->writable()); | 3242 ASSERT_TRUE(conn3->writable()); |
| 3051 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); | 3243 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); |
| 3052 | 3244 |
| 3053 */ | 3245 */ |
| 3054 } | 3246 } |
| 3055 | 3247 |
| 3056 // Test that Relay/Relay connections will be pinged first when everything has | 3248 // Test that Relay/Relay connections will be pinged first when everything has |
| 3057 // been pinged even if the Relay/Relay connection wasn't the first to be pinged | 3249 // been pinged even if the Relay/Relay connection wasn't the first to be pinged |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3155 | 3347 |
| 3156 // TCP Relay/Relay is the next. | 3348 // TCP Relay/Relay is the next. |
| 3157 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3349 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 3158 cricket::RELAY_PORT_TYPE, | 3350 cricket::RELAY_PORT_TYPE, |
| 3159 cricket::TCP_PROTOCOL_NAME); | 3351 cricket::TCP_PROTOCOL_NAME); |
| 3160 | 3352 |
| 3161 // Finally, Local/Relay will be pinged. | 3353 // Finally, Local/Relay will be pinged. |
| 3162 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 3354 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
| 3163 cricket::RELAY_PORT_TYPE); | 3355 cricket::RELAY_PORT_TYPE); |
| 3164 } | 3356 } |
| OLD | NEW |