OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 EXPECT_TRUE(ch2.remote_address().IsNil()); | 814 EXPECT_TRUE(ch2.remote_address().IsNil()); |
815 | 815 |
816 // Send a ping from dst to src. Again, this may or may not make it. | 816 // Send a ping from dst to src. Again, this may or may not make it. |
817 ch2.CreateConnection(GetCandidate(port1)); | 817 ch2.CreateConnection(GetCandidate(port1)); |
818 ASSERT_TRUE(ch2.conn() != NULL); | 818 ASSERT_TRUE(ch2.conn() != NULL); |
819 ch2.Ping(); | 819 ch2.Ping(); |
820 WAIT(ch2.conn()->write_state() == Connection::STATE_WRITABLE, kTimeout); | 820 WAIT(ch2.conn()->write_state() == Connection::STATE_WRITABLE, kTimeout); |
821 | 821 |
822 if (same_addr1 && same_addr2) { | 822 if (same_addr1 && same_addr2) { |
823 // The new ping got back to the source. | 823 // The new ping got back to the source. |
824 EXPECT_EQ(Connection::STATE_READABLE, ch1.conn()->read_state()); | 824 EXPECT_TRUE(ch1.conn()->receiving()); |
825 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); | 825 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); |
826 | 826 |
827 // First connection may not be writable if the first ping did not get | 827 // First connection may not be writable if the first ping did not get |
828 // through. So we will have to do another. | 828 // through. So we will have to do another. |
829 if (ch1.conn()->write_state() == Connection::STATE_WRITE_INIT) { | 829 if (ch1.conn()->write_state() == Connection::STATE_WRITE_INIT) { |
830 ch1.Ping(); | 830 ch1.Ping(); |
831 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 831 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), |
832 kTimeout); | 832 kTimeout); |
833 } | 833 } |
834 } else if (!same_addr1 && possible) { | 834 } else if (!same_addr1 && possible) { |
835 // The new ping went to the candidate address, but that address was bad. | 835 // The new ping went to the candidate address, but that address was bad. |
836 // This will happen when the source NAT is symmetric. | 836 // This will happen when the source NAT is symmetric. |
837 EXPECT_TRUE(ch1.remote_address().IsNil()); | 837 EXPECT_TRUE(ch1.remote_address().IsNil()); |
838 EXPECT_TRUE(ch2.remote_address().IsNil()); | 838 EXPECT_TRUE(ch2.remote_address().IsNil()); |
839 | 839 |
840 // However, since we have now sent a ping to the source IP, we should be | 840 // However, since we have now sent a ping to the source IP, we should be |
841 // able to get a ping from it. This gives us the real source address. | 841 // able to get a ping from it. This gives us the real source address. |
842 ch1.Ping(); | 842 ch1.Ping(); |
843 EXPECT_TRUE_WAIT(!ch2.remote_address().IsNil(), kTimeout); | 843 EXPECT_TRUE_WAIT(!ch2.remote_address().IsNil(), kTimeout); |
844 EXPECT_EQ(Connection::STATE_READ_INIT, ch2.conn()->read_state()); | 844 EXPECT_FALSE(ch2.conn()->receiving()); |
845 EXPECT_TRUE(ch1.remote_address().IsNil()); | 845 EXPECT_TRUE(ch1.remote_address().IsNil()); |
846 | 846 |
847 // Pick up the actual address and establish the connection. | 847 // Pick up the actual address and establish the connection. |
848 ch2.AcceptConnection(GetCandidate(port1)); | 848 ch2.AcceptConnection(GetCandidate(port1)); |
849 ASSERT_TRUE(ch2.conn() != NULL); | 849 ASSERT_TRUE(ch2.conn() != NULL); |
850 ch2.Ping(); | 850 ch2.Ping(); |
851 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(), | 851 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch2.conn()->write_state(), |
852 kTimeout); | 852 kTimeout); |
853 } else if (!same_addr2 && possible) { | 853 } else if (!same_addr2 && possible) { |
854 // The new ping came in, but from an unexpected address. This will happen | 854 // The new ping came in, but from an unexpected address. This will happen |
855 // when the destination NAT is symmetric. | 855 // when the destination NAT is symmetric. |
856 EXPECT_FALSE(ch1.remote_address().IsNil()); | 856 EXPECT_FALSE(ch1.remote_address().IsNil()); |
857 EXPECT_EQ(Connection::STATE_READ_INIT, ch1.conn()->read_state()); | 857 EXPECT_FALSE(ch1.conn()->receiving()); |
858 | 858 |
859 // Update our address and complete the connection. | 859 // Update our address and complete the connection. |
860 ch1.AcceptConnection(GetCandidate(port2)); | 860 ch1.AcceptConnection(GetCandidate(port2)); |
861 ch1.Ping(); | 861 ch1.Ping(); |
862 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), | 862 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, ch1.conn()->write_state(), |
863 kTimeout); | 863 kTimeout); |
864 } else { // (!possible) | 864 } else { // (!possible) |
865 // There should be s no way for the pings to reach each other. Check it. | 865 // There should be s no way for the pings to reach each other. Check it. |
866 EXPECT_TRUE(ch1.remote_address().IsNil()); | 866 EXPECT_TRUE(ch1.remote_address().IsNil()); |
867 EXPECT_TRUE(ch2.remote_address().IsNil()); | 867 EXPECT_TRUE(ch2.remote_address().IsNil()); |
868 ch1.Ping(); | 868 ch1.Ping(); |
869 WAIT(!ch2.remote_address().IsNil(), kTimeout); | 869 WAIT(!ch2.remote_address().IsNil(), kTimeout); |
870 EXPECT_TRUE(ch1.remote_address().IsNil()); | 870 EXPECT_TRUE(ch1.remote_address().IsNil()); |
871 EXPECT_TRUE(ch2.remote_address().IsNil()); | 871 EXPECT_TRUE(ch2.remote_address().IsNil()); |
872 } | 872 } |
873 } | 873 } |
874 | 874 |
875 // Everything should be good, unless we know the situation is impossible. | 875 // Everything should be good, unless we know the situation is impossible. |
876 ASSERT_TRUE(ch1.conn() != NULL); | 876 ASSERT_TRUE(ch1.conn() != NULL); |
877 ASSERT_TRUE(ch2.conn() != NULL); | 877 ASSERT_TRUE(ch2.conn() != NULL); |
878 if (possible) { | 878 if (possible) { |
879 EXPECT_EQ(Connection::STATE_READABLE, ch1.conn()->read_state()); | 879 EXPECT_TRUE(ch1.conn()->receiving()); |
880 EXPECT_EQ(Connection::STATE_WRITABLE, ch1.conn()->write_state()); | 880 EXPECT_EQ(Connection::STATE_WRITABLE, ch1.conn()->write_state()); |
881 EXPECT_EQ(Connection::STATE_READABLE, ch2.conn()->read_state()); | 881 EXPECT_TRUE(ch2.conn()->receiving()); |
882 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); | 882 EXPECT_EQ(Connection::STATE_WRITABLE, ch2.conn()->write_state()); |
883 } else { | 883 } else { |
884 EXPECT_NE(Connection::STATE_READABLE, ch1.conn()->read_state()); | 884 EXPECT_FALSE(ch1.conn()->receiving()); |
885 EXPECT_NE(Connection::STATE_WRITABLE, ch1.conn()->write_state()); | 885 EXPECT_NE(Connection::STATE_WRITABLE, ch1.conn()->write_state()); |
886 EXPECT_NE(Connection::STATE_READABLE, ch2.conn()->read_state()); | 886 EXPECT_FALSE(ch2.conn()->receiving()); |
887 EXPECT_NE(Connection::STATE_WRITABLE, ch2.conn()->write_state()); | 887 EXPECT_NE(Connection::STATE_WRITABLE, ch2.conn()->write_state()); |
888 } | 888 } |
889 | 889 |
890 // Tear down and ensure that goes smoothly. | 890 // Tear down and ensure that goes smoothly. |
891 ch1.Stop(); | 891 ch1.Stop(); |
892 ch2.Stop(); | 892 ch2.Stop(); |
893 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); | 893 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); |
894 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); | 894 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); |
895 } | 895 } |
896 | 896 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 lport->last_stun_buf()->Length(), | 1266 lport->last_stun_buf()->Length(), |
1267 rtc::PacketTime()); | 1267 rtc::PacketTime()); |
1268 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1268 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
1269 msg = lport->last_stun_msg(); | 1269 msg = lport->last_stun_msg(); |
1270 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); | 1270 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); |
1271 | 1271 |
1272 // If the tiebreaker value is different from port, we expect a error | 1272 // If the tiebreaker value is different from port, we expect a error |
1273 // response. | 1273 // response. |
1274 lport->Reset(); | 1274 lport->Reset(); |
1275 lport->AddCandidateAddress(kLocalAddr2); | 1275 lport->AddCandidateAddress(kLocalAddr2); |
1276 // Creating a different connection as |conn| is in STATE_READABLE. | 1276 // Creating a different connection as |conn| is receiving. |
1277 Connection* conn1 = lport->CreateConnection(lport->Candidates()[1], | 1277 Connection* conn1 = lport->CreateConnection(lport->Candidates()[1], |
1278 Port::ORIGIN_MESSAGE); | 1278 Port::ORIGIN_MESSAGE); |
1279 conn1->Ping(0); | 1279 conn1->Ping(0); |
1280 | 1280 |
1281 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1281 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
1282 msg = lport->last_stun_msg(); | 1282 msg = lport->last_stun_msg(); |
1283 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | 1283 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); |
1284 rtc::scoped_ptr<IceMessage> modified_req( | 1284 rtc::scoped_ptr<IceMessage> modified_req( |
1285 CreateStunMessage(STUN_BINDING_REQUEST)); | 1285 CreateStunMessage(STUN_BINDING_REQUEST)); |
1286 const StunByteStringAttribute* username_attr = msg->GetByteString( | 1286 const StunByteStringAttribute* username_attr = msg->GetByteString( |
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 // Set up channels and ensure both ports will be deleted. | 2403 // Set up channels and ensure both ports will be deleted. |
2404 TestChannel ch1(port1); | 2404 TestChannel ch1(port1); |
2405 TestChannel ch2(port2); | 2405 TestChannel ch2(port2); |
2406 | 2406 |
2407 // Simulate a connection that succeeds, and then is destroyed. | 2407 // Simulate a connection that succeeds, and then is destroyed. |
2408 StartConnectAndStopChannels(&ch1, &ch2); | 2408 StartConnectAndStopChannels(&ch1, &ch2); |
2409 | 2409 |
2410 // The controlled port should be destroyed after 10 milliseconds. | 2410 // The controlled port should be destroyed after 10 milliseconds. |
2411 EXPECT_TRUE_WAIT(destroyed(), kTimeout); | 2411 EXPECT_TRUE_WAIT(destroyed(), kTimeout); |
2412 } | 2412 } |
OLD | NEW |