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 1966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1977 } | 1977 } |
1978 | 1978 |
1979 void OnSelectedCandidatePairChanged( | 1979 void OnSelectedCandidatePairChanged( |
1980 cricket::TransportChannel* transport_channel, | 1980 cricket::TransportChannel* transport_channel, |
1981 cricket::CandidatePairInterface* selected_candidate_pair, | 1981 cricket::CandidatePairInterface* selected_candidate_pair, |
1982 int last_sent_packet_id) { | 1982 int last_sent_packet_id) { |
1983 last_selected_candidate_pair_ = selected_candidate_pair; | 1983 last_selected_candidate_pair_ = selected_candidate_pair; |
1984 last_sent_packet_id_ = last_sent_packet_id; | 1984 last_sent_packet_id_ = last_sent_packet_id; |
1985 } | 1985 } |
1986 | 1986 |
1987 void ReceivedPingOnConnection(cricket::Connection* conn, | |
pthatcher1
2016/06/01 01:57:04
Should call this ReceivePingOnConnection or maybe
honghaiz3
2016/06/01 16:37:59
Done.
| |
1988 const std::string& remote_ufrag, | |
1989 int priority) { | |
1990 cricket::IceMessage msg; | |
1991 msg.SetType(cricket::STUN_BINDING_REQUEST); | |
1992 msg.AddAttribute(new cricket::StunByteStringAttribute( | |
1993 cricket::STUN_ATTR_USERNAME, | |
1994 conn->local_candidate().username() + ":" + remote_ufrag)); | |
1995 msg.AddAttribute(new cricket::StunUInt32Attribute( | |
1996 cricket::STUN_ATTR_PRIORITY, priority)); | |
1997 msg.SetTransactionID( | |
1998 rtc::CreateRandomString(cricket::kStunTransactionIdLength)); | |
1999 msg.AddMessageIntegrity(conn->local_candidate().password()); | |
2000 msg.AddFingerprint(); | |
2001 rtc::ByteBufferWriter buf; | |
2002 msg.Write(&buf); | |
2003 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); | |
2004 } | |
2005 | |
1987 void OnReadyToSend(cricket::TransportChannel* channel) { | 2006 void OnReadyToSend(cricket::TransportChannel* channel) { |
1988 channel_ready_to_send_ = true; | 2007 channel_ready_to_send_ = true; |
1989 } | 2008 } |
1990 void OnChannelStateChanged(cricket::TransportChannelImpl* channel) { | 2009 void OnChannelStateChanged(cricket::TransportChannelImpl* channel) { |
1991 channel_state_ = channel->GetState(); | 2010 channel_state_ = channel->GetState(); |
1992 } | 2011 } |
1993 | 2012 |
1994 cricket::CandidatePairInterface* last_selected_candidate_pair() { | 2013 cricket::CandidatePairInterface* last_selected_candidate_pair() { |
1995 return last_selected_candidate_pair_; | 2014 return last_selected_candidate_pair_; |
1996 } | 2015 } |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2446 EXPECT_EQ(conn3, ch.best_connection()); | 2465 EXPECT_EQ(conn3, ch.best_connection()); |
2447 | 2466 |
2448 // Now another data packet will not switch the best connection because the | 2467 // Now another data packet will not switch the best connection because the |
2449 // best connection was nominated by the controlling side. | 2468 // best connection was nominated by the controlling side. |
2450 conn2->ReceivedPing(); | 2469 conn2->ReceivedPing(); |
2451 conn2->ReceivedPingResponse(); | 2470 conn2->ReceivedPingResponse(); |
2452 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 2471 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
2453 EXPECT_EQ(conn3, ch.best_connection()); | 2472 EXPECT_EQ(conn3, ch.best_connection()); |
2454 } | 2473 } |
2455 | 2474 |
2475 // Test that if a new remote candidate has the same address and port with | |
2476 // an old one, it will be used to create a new connection. | |
2477 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { | |
2478 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
2479 cricket::P2PTransportChannel ch("candidate reuse", 1, &pa); | |
2480 PrepareChannel(&ch); | |
2481 ch.Connect(); | |
2482 ch.MaybeStartGathering(); | |
2483 const std::string host_address = "1.1.1.1"; | |
2484 const int port_num = 1; | |
2485 | |
2486 // kIceUfrag[1] is the current generation ufrag. | |
2487 cricket::Candidate candidate = | |
2488 CreateHostCandidate(host_address, port_num, 1, kIceUfrag[1]); | |
2489 ch.AddRemoteCandidate(candidate); | |
2490 cricket::Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num); | |
2491 ASSERT_TRUE(conn1 != nullptr); | |
2492 EXPECT_EQ(0u, conn1->remote_candidate().generation()); | |
2493 | |
2494 // Simply adding the same candidate again won't create a new connection. | |
2495 ch.AddRemoteCandidate(candidate); | |
2496 cricket::Connection* conn2 = GetConnectionTo(&ch, host_address, port_num); | |
2497 EXPECT_EQ(conn1, conn2); | |
2498 | |
2499 // Update the ufrag of the candidate and add it again. | |
2500 candidate.set_username(kIceUfrag[2]); | |
2501 ch.AddRemoteCandidate(candidate); | |
2502 conn2 = GetConnectionTo(&ch, host_address, port_num); | |
2503 EXPECT_NE(conn1, conn2); | |
2504 EXPECT_EQ(kIceUfrag[2], conn2->remote_candidate().username()); | |
2505 EXPECT_EQ(1u, conn2->remote_candidate().generation()); | |
2506 | |
2507 // Verify that the ping can be received on the new connection. | |
2508 EXPECT_EQ(0, conn2->last_ping_received()); | |
2509 ReceivedPingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); | |
2510 EXPECT_TRUE(conn2->last_ping_received() > 0); | |
2511 } | |
2512 | |
2456 // When the current best connection is strong, lower-priority connections will | 2513 // When the current best connection is strong, lower-priority connections will |
2457 // be pruned. Otherwise, lower-priority connections are kept. | 2514 // be pruned. Otherwise, lower-priority connections are kept. |
2458 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { | 2515 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
2459 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2516 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2460 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2517 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2461 PrepareChannel(&ch); | 2518 PrepareChannel(&ch); |
2462 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2519 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2463 ch.Connect(); | 2520 ch.Connect(); |
2464 ch.MaybeStartGathering(); | 2521 ch.MaybeStartGathering(); |
2465 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2522 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2857 | 2914 |
2858 // TCP Relay/Relay is the next. | 2915 // TCP Relay/Relay is the next. |
2859 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 2916 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
2860 cricket::RELAY_PORT_TYPE, | 2917 cricket::RELAY_PORT_TYPE, |
2861 cricket::TCP_PROTOCOL_NAME); | 2918 cricket::TCP_PROTOCOL_NAME); |
2862 | 2919 |
2863 // Finally, Local/Relay will be pinged. | 2920 // Finally, Local/Relay will be pinged. |
2864 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 2921 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
2865 cricket::RELAY_PORT_TYPE); | 2922 cricket::RELAY_PORT_TYPE); |
2866 } | 2923 } |
OLD | NEW |