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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2099783002: Fixing bug where Connection drops packets when presumed writable. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merge with master. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0)); 1691 CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0));
1692 // Expect that the TURN-TURN candidate pair will be prioritized since it's 1692 // Expect that the TURN-TURN candidate pair will be prioritized since it's
1693 // "probably writable". 1693 // "probably writable".
1694 EXPECT_TRUE(ep1_ch1()->selected_connection() != nullptr); 1694 EXPECT_TRUE(ep1_ch1()->selected_connection() != nullptr);
1695 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); 1695 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type());
1696 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); 1696 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type());
1697 // Also expect that the channel instantly indicates that it's writable since 1697 // Also expect that the channel instantly indicates that it's writable since
1698 // it has a TURN-TURN pair. 1698 // it has a TURN-TURN pair.
1699 EXPECT_TRUE(ep1_ch1()->writable()); 1699 EXPECT_TRUE(ep1_ch1()->writable());
1700 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_); 1700 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_);
1701 // Also make sure we can immediately send packets.
1702 const char* data = "test";
1703 int len = static_cast<int>(strlen(data));
1704 EXPECT_EQ(len, SendData(ep1_ch1(), data, len));
1701 } 1705 }
1702 1706
1703 // Test that a TURN/peer reflexive candidate pair is also presumed writable. 1707 // Test that a TURN/peer reflexive candidate pair is also presumed writable.
1704 TEST_F(P2PTransportChannelTest, TurnToPrflxPresumedWritable) { 1708 TEST_F(P2PTransportChannelTest, TurnToPrflxPresumedWritable) {
1705 rtc::ScopedFakeClock fake_clock; 1709 rtc::ScopedFakeClock fake_clock;
1706 1710
1707 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1711 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1708 kDefaultPortAllocatorFlags); 1712 kDefaultPortAllocatorFlags);
1709 // We want the remote TURN candidate to show up as prflx. To do this we need 1713 // We want the remote TURN candidate to show up as prflx. To do this we need
1710 // to configure the server to accept packets from an address we haven't 1714 // to configure the server to accept packets from an address we haven't
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 } 2230 }
2227 2231
2228 void NominateConnection(Connection* conn) { 2232 void NominateConnection(Connection* conn) {
2229 conn->set_nominated(true); 2233 conn->set_nominated(true);
2230 conn->SignalNominated(conn); 2234 conn->SignalNominated(conn);
2231 } 2235 }
2232 2236
2233 void OnSelectedCandidatePairChanged( 2237 void OnSelectedCandidatePairChanged(
2234 TransportChannel* transport_channel, 2238 TransportChannel* transport_channel,
2235 CandidatePairInterface* selected_candidate_pair, 2239 CandidatePairInterface* selected_candidate_pair,
2236 int last_sent_packet_id) { 2240 int last_sent_packet_id,
2241 bool ready_to_send) {
2237 last_selected_candidate_pair_ = selected_candidate_pair; 2242 last_selected_candidate_pair_ = selected_candidate_pair;
2238 last_sent_packet_id_ = last_sent_packet_id; 2243 last_sent_packet_id_ = last_sent_packet_id;
2239 ++selected_candidate_pair_switches_; 2244 ++selected_candidate_pair_switches_;
2240 } 2245 }
2241 2246
2242 void ReceivePingOnConnection(Connection* conn, 2247 void ReceivePingOnConnection(Connection* conn,
2243 const std::string& remote_ufrag, 2248 const std::string& remote_ufrag,
2244 int priority) { 2249 int priority) {
2245 IceMessage msg; 2250 IceMessage msg;
2246 msg.SetType(STUN_BINDING_REQUEST); 2251 msg.SetType(STUN_BINDING_REQUEST);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2632 ASSERT_TRUE(conn1 != nullptr); 2637 ASSERT_TRUE(conn1 != nullptr);
2633 EXPECT_EQ(conn1, ch.selected_connection()); 2638 EXPECT_EQ(conn1, ch.selected_connection());
2634 EXPECT_EQ(conn1, last_selected_candidate_pair()); 2639 EXPECT_EQ(conn1, last_selected_candidate_pair());
2635 EXPECT_EQ(-1, last_sent_packet_id()); 2640 EXPECT_EQ(-1, last_sent_packet_id());
2636 // Channel is not ready to send because it is not writable. 2641 // Channel is not ready to send because it is not writable.
2637 EXPECT_FALSE(channel_ready_to_send()); 2642 EXPECT_FALSE(channel_ready_to_send());
2638 2643
2639 int last_packet_id = 0; 2644 int last_packet_id = 0;
2640 const char* data = "ABCDEFGH"; 2645 const char* data = "ABCDEFGH";
2641 int len = static_cast<int>(strlen(data)); 2646 int len = static_cast<int>(strlen(data));
2642 SendData(ch, data, len, ++last_packet_id); 2647 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id));
2643 // When a higher priority candidate comes in, the new connection is chosen 2648 // When a higher priority candidate comes in, the new connection is chosen
2644 // as the selected connection. 2649 // as the selected connection.
2645 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 2650 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
2646 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2651 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2647 ASSERT_TRUE(conn2 != nullptr); 2652 ASSERT_TRUE(conn2 != nullptr);
2648 EXPECT_EQ(conn2, ch.selected_connection()); 2653 EXPECT_EQ(conn2, ch.selected_connection());
2649 EXPECT_EQ(conn2, last_selected_candidate_pair()); 2654 EXPECT_EQ(conn2, last_selected_candidate_pair());
2650 EXPECT_EQ(last_packet_id, last_sent_packet_id()); 2655 EXPECT_EQ(-1, last_sent_packet_id());
2651 EXPECT_FALSE(channel_ready_to_send()); 2656 EXPECT_FALSE(channel_ready_to_send());
2652 2657
2653 // If a stun request with use-candidate attribute arrives, the receiving 2658 // If a stun request with use-candidate attribute arrives, the receiving
2654 // connection will be set as the selected connection, even though 2659 // connection will be set as the selected connection, even though
2655 // its priority is lower. 2660 // its priority is lower.
2656 SendData(ch, data, len, ++last_packet_id); 2661 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id));
2657 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 2662 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
2658 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 2663 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2659 ASSERT_TRUE(conn3 != nullptr); 2664 ASSERT_TRUE(conn3 != nullptr);
2660 // Because it has a lower priority, the selected connection is still conn2. 2665 // Because it has a lower priority, the selected connection is still conn2.
2661 EXPECT_EQ(conn2, ch.selected_connection()); 2666 EXPECT_EQ(conn2, ch.selected_connection());
2662 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 2667 conn3->ReceivedPingResponse(LOW_RTT); // Become writable.
2663 // But if it is nominated via use_candidate, it is chosen as the selected 2668 // But if it is nominated via use_candidate, it is chosen as the selected
2664 // connection. 2669 // connection.
2665 conn3->set_nominated(true); 2670 conn3->set_nominated(true);
2666 conn3->SignalNominated(conn3); 2671 conn3->SignalNominated(conn3);
2667 EXPECT_EQ(conn3, ch.selected_connection()); 2672 EXPECT_EQ(conn3, ch.selected_connection());
2668 EXPECT_EQ(conn3, last_selected_candidate_pair()); 2673 EXPECT_EQ(conn3, last_selected_candidate_pair());
2669 EXPECT_EQ(last_packet_id, last_sent_packet_id()); 2674 EXPECT_EQ(-1, last_sent_packet_id());
2670 EXPECT_TRUE(channel_ready_to_send()); 2675 EXPECT_TRUE(channel_ready_to_send());
2671 2676
2672 // Even if another higher priority candidate arrives, it will not be set as 2677 // Even if another higher priority candidate arrives, it will not be set as
2673 // the selected connection because the selected connection is nominated by 2678 // the selected connection because the selected connection is nominated by
2674 // the controlling side. 2679 // the controlling side.
2675 SendData(ch, data, len, ++last_packet_id); 2680 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id));
2676 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); 2681 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100));
2677 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 2682 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
2678 ASSERT_TRUE(conn4 != nullptr); 2683 ASSERT_TRUE(conn4 != nullptr);
2679 EXPECT_EQ(conn3, ch.selected_connection()); 2684 EXPECT_EQ(conn3, ch.selected_connection());
2680 // But if it is nominated via use_candidate and writable, it will be set as 2685 // But if it is nominated via use_candidate and writable, it will be set as
2681 // the selected connection. 2686 // the selected connection.
2682 conn4->set_nominated(true); 2687 conn4->set_nominated(true);
2683 conn4->SignalNominated(conn4); 2688 conn4->SignalNominated(conn4);
2684 // Not switched yet because conn4 is not writable. 2689 // Not switched yet because conn4 is not writable.
2685 EXPECT_EQ(conn3, ch.selected_connection()); 2690 EXPECT_EQ(conn3, ch.selected_connection());
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
3474 3479
3475 // TCP Relay/Relay is the next. 3480 // TCP Relay/Relay is the next.
3476 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3481 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3477 TCP_PROTOCOL_NAME); 3482 TCP_PROTOCOL_NAME);
3478 3483
3479 // Finally, Local/Relay will be pinged. 3484 // Finally, Local/Relay will be pinged.
3480 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3485 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3481 } 3486 }
3482 3487
3483 } // namespace cricket { 3488 } // namespace cricket {
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698