Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc |
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
index 90ddd43714daa8c55bdaa45139caf5f2b7812dbf..5f2be5f20c3628ab36220686d0011c4dd137fe21 100644 |
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
@@ -81,6 +81,8 @@ static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); |
// The addresses for the public turn server. |
static const SocketAddress kTurnUdpIntAddr("99.99.99.4", |
cricket::STUN_SERVER_PORT); |
+static const SocketAddress kTurnTcpIntAddr("99.99.99.4", |
+ cricket::STUN_SERVER_PORT + 1); |
static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); |
static const cricket::RelayCredentials kRelayCredentials("test", "test"); |
@@ -1765,10 +1767,10 @@ class P2PTransportChannelPingTest : public testing::Test, |
ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
} |
- cricket::Candidate CreateCandidate(const std::string& ip, |
- int port, |
- int priority, |
- const std::string& ufrag = "") { |
+ cricket::Candidate CreateLocalCandidate(const std::string& ip, |
+ int port, |
+ int priority, |
+ const std::string& ufrag = "") { |
cricket::Candidate c; |
c.set_address(rtc::SocketAddress(ip, port)); |
c.set_component(1); |
@@ -1814,8 +1816,8 @@ TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
PrepareChannel(&ch); |
ch.Connect(); |
ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
@@ -1839,8 +1841,8 @@ TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { |
PrepareChannel(&ch); |
ch.Connect(); |
ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
@@ -1871,7 +1873,7 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
ch.Connect(); |
ch.MaybeStartGathering(); |
// Add a candidate with a future ufrag. |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
const cricket::Candidate& candidate = conn1->remote_candidate(); |
@@ -1888,13 +1890,13 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
EXPECT_EQ(conn1, ch.FindNextPingableConnection()); |
// Add a candidate with an old ufrag. No connection will be created. |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2, kIceUfrag[1])); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2, kIceUfrag[1])); |
rtc::Thread::Current()->ProcessMessages(500); |
EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); |
// Add a candidate with the current ufrag, its pwd and generation will be |
// assigned, even if the generation is not set. |
- ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 0, kIceUfrag[2])); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("3.3.3.3", 3, 0, kIceUfrag[2])); |
cricket::Connection* conn3 = nullptr; |
ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr, |
3000); |
@@ -1922,14 +1924,14 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { |
ch.MaybeStartGathering(); |
// Create conn1 and keep track of original candidate priority. |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
uint32_t remote_priority = conn1->remote_candidate().priority(); |
// Create a higher priority candidate and make the connection |
// receiving/writable. This will prune conn1. |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
conn2->ReceivedPing(); |
@@ -1980,7 +1982,7 @@ TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { |
EXPECT_EQ(50, ch.check_receiving_delay()); |
ch.Connect(); |
ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
@@ -2002,14 +2004,14 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
ch.Connect(); |
ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
EXPECT_EQ(conn1, ch.best_connection()); |
// When a higher priority candidate comes in, the new connection is chosen |
// as the best connection. |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 10)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
EXPECT_EQ(conn2, ch.best_connection()); |
@@ -2017,7 +2019,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
// If a stun request with use-candidate attribute arrives, the receiving |
// connection will be set as the best connection, even though |
// its priority is lower. |
- ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("3.3.3.3", 3, 1)); |
cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
ASSERT_TRUE(conn3 != nullptr); |
// Because it has a lower priority, the best connection is still conn2. |
@@ -2032,7 +2034,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
// Even if another higher priority candidate arrives, |
// it will not be set as the best connection because the best connection |
// is nominated by the controlling side. |
- ch.AddRemoteCandidate(CreateCandidate("4.4.4.4", 4, 100)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("4.4.4.4", 4, 100)); |
cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
ASSERT_TRUE(conn4 != nullptr); |
EXPECT_EQ(conn3, ch.best_connection()); |
@@ -2079,7 +2081,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { |
port->set_sent_binding_response(false); |
// Another connection is nominated via use_candidate. |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
// Because it has a lower priority, the best connection is still conn1. |
@@ -2141,7 +2143,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
ch.Connect(); |
ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 10)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
EXPECT_EQ(conn1, ch.best_connection()); |
@@ -2149,7 +2151,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
// If a data packet is received on conn2, the best connection should |
// switch to conn2 because the controlled side must mirror the media path |
// chosen by the controlling side. |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
conn2->ReceivedPing(); // Start receiving. |
@@ -2199,7 +2201,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
ch.Connect(); |
ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
EXPECT_EQ(conn1, ch.best_connection()); |
@@ -2207,7 +2209,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
// When a higher-priority, nominated candidate comes in, the connections with |
// lower-priority are pruned. |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 10)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
conn2->ReceivedPingResponse(); // Becomes writable and receiving |
@@ -2219,7 +2221,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
// Wait until conn2 becomes not receiving. |
EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); |
- ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("3.3.3.3", 3, 1)); |
cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
ASSERT_TRUE(conn3 != nullptr); |
// The best connection should still be conn2. Even through conn3 has lower |
@@ -2237,8 +2239,8 @@ TEST_F(P2PTransportChannelPingTest, TestGetState) { |
ch.Connect(); |
ch.MaybeStartGathering(); |
EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 100)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn1 != nullptr); |
@@ -2264,7 +2266,7 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
ch.SetIceConfig(CreateIceConfig(1000, false)); |
ch.Connect(); |
ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 100)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
EXPECT_EQ(conn1, ch.best_connection()); |
@@ -2274,7 +2276,7 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
// not be deleted right away. Once the current best connection becomes not |
// receiving, |conn2| will start to ping and upon receiving the ping response, |
// it will become the best connection. |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
@@ -2307,7 +2309,7 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
ch.Connect(); |
ch.MaybeStartGathering(); |
// Have one connection only but later becomes write-time-out. |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 100)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
conn1->ReceivedPing(); // Becomes receiving |
@@ -2315,11 +2317,11 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); |
// Have two connections but both become write-time-out later. |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
conn2->ReceivedPing(); // Becomes receiving |
- ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 2)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("3.3.3.3", 3, 2)); |
cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
ASSERT_TRUE(conn3 != nullptr); |
conn3->ReceivedPing(); // Becomes receiving |
@@ -2339,7 +2341,7 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
ch.SetIceConfig(CreateIceConfig(2000, false)); |
ch.Connect(); |
ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 100)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
conn1->ReceivedPingResponse(); // Becomes writable and receiving |
@@ -2350,9 +2352,229 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
// connected. |
ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 100)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
conn2->ReceivedPingResponse(); // Becomes writable and receiving |
EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
} |
+ |
+#define P2PTransportChannelTurnTurnFirstTest \ |
+ DISABLED_P2PTransportChannelTurnTurnFirstTest |
+ |
+class P2PTransportChannelTurnTurnFirstTest |
+ : public P2PTransportChannelPingTest { |
+ public: |
+ P2PTransportChannelTurnTurnFirstTest() |
+ : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { |
+ network_manager_.AddInterface(kPublicAddrs[0]); |
+ allocator_.reset(new cricket::BasicPortAllocator( |
+ &network_manager_, ServerAddresses(), rtc::SocketAddress(), |
+ rtc::SocketAddress(), rtc::SocketAddress())); |
+ allocator_->set_flags(allocator_->flags() | |
+ cricket::PORTALLOCATOR_DISABLE_STUN | |
+ cricket::PORTALLOCATOR_DISABLE_TCP); |
+ cricket::RelayServerConfig config(cricket::RELAY_TURN); |
+ config.credentials = kRelayCredentials; |
+ config.ports.push_back( |
+ cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
+ allocator_->AddTurnServer(config); |
+ } |
+ |
+ cricket::BasicPortAllocator* allocator() { return allocator_.get(); } |
+ cricket::TestTurnServer* turn_server() { return &turn_server_; } |
+ |
+ // This verifies the next pingable connection has the expected candidates' |
+ // types and, for relay local candidate, the expected relay protocol and ping |
+ // it. |
+ void VerifyAndPingNextPingableConnection( |
+ cricket::P2PTransportChannel& ch, |
+ const std::string& local_candidate_type, |
+ const std::string& remote_candidate_type, |
+ const std::string& relay_protocol_type = cricket::UDP_PROTOCOL_NAME) { |
+ cricket::Connection* conn = ch.FindNextPingableConnection(); |
+ EXPECT_EQ(conn->local_candidate().type(), local_candidate_type); |
+ if (conn->local_candidate().type() == cricket::RELAY_PORT_TYPE) { |
+ EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type); |
+ } |
+ EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type); |
+ conn->Ping(rtc::Time()); |
+ } |
+ |
+ cricket::Candidate CreateRelayCandidate(const std::string& ip, |
+ int port, |
+ int priority, |
+ const std::string& ufrag = "") { |
+ cricket::Candidate c = CreateLocalCandidate(ip, port, priority, ufrag); |
+ c.set_type(cricket::RELAY_PORT_TYPE); |
+ return c; |
+ } |
+ |
+ private: |
+ rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; |
+ rtc::FakeNetworkManager network_manager_; |
+ cricket::TestTurnServer turn_server_; |
+}; |
+ |
+// Test that Relay/Relay candidate pair will be pinged when no any other pairs |
pthatcher1
2016/01/14 22:40:01
no any other => no other
pthatcher1
2016/01/14 22:40:01
Please use either "candidate pair" or "connection"
guoweis_webrtc
2016/01/15 17:47:52
Done.
guoweis_webrtc
2016/01/15 17:47:53
Done.
|
+// have been pinged yet, unless we need to ping a trigger check or we have a |
+// best connection. |
+TEST_F(P2PTransportChannelTurnTurnFirstTest, |
+ TestTurnTurnFirstWhenNothingPingedYet) { |
+ cricket::P2PTransportChannel ch("checks", 1, nullptr, allocator()); |
+ PrepareChannel(&ch); |
+ ch.Connect(); |
+ ch.MaybeStartGathering(); |
+ EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
+ EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); |
+ EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
+ ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2)); |
+ |
+ EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
+ |
+ // Relay/Relay should be the first pingable connection. |
+ cricket::Connection* conn = ch.FindNextPingableConnection(); |
+ EXPECT_EQ(conn->local_candidate().type(), cricket::RELAY_PORT_TYPE); |
+ EXPECT_EQ(conn->remote_candidate().type(), cricket::RELAY_PORT_TYPE); |
+ |
+ // Unless that we have a trigger check waiting to be pinged. |
+ cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
+ EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE); |
+ EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE); |
+ conn2->ReceivedPing(); |
+ EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |
+ |
+ // Make conn3 the best connection. |
+ cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 2); |
+ EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); |
+ EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); |
+ conn3->ReceivedPing(); |
+ conn3->Ping(rtc::Time()); |
+ conn3->ReceivedPingResponse(); |
+ |
+ // Verify that conn3 will be the "best connection" since it is readable and |
+ // writable. After |MAX_CURRENT_STRONG_DELAY|, it should be the next pingable |
+ // connection. |
+ EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); |
+ WAIT(false, cricket::MAX_CURRENT_STRONG_DELAY); |
+ EXPECT_EQ(conn3, ch.FindNextPingableConnection()); |
+} |
+ |
+// Test that Relay/Relay connection will be pinged first when everything has |
+// been pinged even if the connection didn't form the earliest. |
pthatcher1
2016/01/14 22:40:01
if the connection didn't form the earliest => even
guoweis_webrtc
2016/01/15 17:47:53
Done.
|
+TEST_F(P2PTransportChannelTurnTurnFirstTest, |
+ TestTurnTurnFirstWhenEverythingPinged) { |
+ cricket::P2PTransportChannel ch("checks", 1, nullptr, allocator()); |
+ PrepareChannel(&ch); |
+ ch.Connect(); |
+ ch.MaybeStartGathering(); |
+ EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
+ EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); |
+ EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
+ |
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1)); |
+ EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); |
+ |
+ // Initially, only have Local/Local and Local/Relay. |
+ VerifyAndPingNextPingableConnection(ch, cricket::LOCAL_PORT_TYPE, |
+ cricket::LOCAL_PORT_TYPE); |
+ VerifyAndPingNextPingableConnection(ch, cricket::RELAY_PORT_TYPE, |
+ cricket::LOCAL_PORT_TYPE); |
+ |
+ // Remote Relay candidate arrives. |
+ ch.AddRemoteCandidate(CreateRelayCandidate("2.2.2.2", 2, 2)); |
+ EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
+ |
+ // Relay/Relay should be the first since it's not pinged before. |
pthatcher1
2016/01/14 22:40:01
it's not => it hasn't been
guoweis_webrtc
2016/01/15 17:47:53
Done.
|
+ VerifyAndPingNextPingableConnection(ch, cricket::RELAY_PORT_TYPE, |
+ cricket::RELAY_PORT_TYPE); |
+ |
+ // Local/Relay is the final one. |
+ VerifyAndPingNextPingableConnection(ch, cricket::LOCAL_PORT_TYPE, |
+ cricket::RELAY_PORT_TYPE); |
+ |
+ // Now, every connection has been pinged once. The next one should be |
+ // Relay/Relay. |
+ VerifyAndPingNextPingableConnection(ch, cricket::RELAY_PORT_TYPE, |
+ cricket::RELAY_PORT_TYPE); |
+} |
+ |
+// Test that when we receive a new remote candidate, they will be tried first |
+// before we re-ping Relay/Relay connection. |
+TEST_F(P2PTransportChannelTurnTurnFirstTest, |
+ TestNoStarvationOnNonRelayConnection) { |
+ cricket::P2PTransportChannel ch("checks", 1, nullptr, allocator()); |
+ PrepareChannel(&ch); |
+ ch.Connect(); |
+ ch.MaybeStartGathering(); |
+ EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
+ EXPECT_EQ(ch.ports()[0]->Type(), cricket::RELAY_PORT_TYPE); |
+ EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
+ |
+ ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); |
+ EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); |
+ |
+ // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first. |
+ VerifyAndPingNextPingableConnection(ch, cricket::RELAY_PORT_TYPE, |
+ cricket::RELAY_PORT_TYPE); |
+ |
+ // Next, ping Local/Relay. |
+ VerifyAndPingNextPingableConnection(ch, cricket::LOCAL_PORT_TYPE, |
+ cricket::RELAY_PORT_TYPE); |
+ |
+ // Remote Local candidate arrives. |
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2)); |
+ EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
+ |
+ // Local/Local should be the first since it's not pinged before. |
pthatcher1
2016/01/14 22:40:01
it's not => it hasn't been
guoweis_webrtc
2016/01/15 17:47:52
Done.
|
+ VerifyAndPingNextPingableConnection(ch, cricket::LOCAL_PORT_TYPE, |
+ cricket::LOCAL_PORT_TYPE); |
+ |
+ // Relay/Local is the final one. |
+ VerifyAndPingNextPingableConnection(ch, cricket::RELAY_PORT_TYPE, |
+ cricket::LOCAL_PORT_TYPE); |
+ |
+ // Now, every connection has been pinged once. The next one should be |
+ // Relay/Relay. |
+ VerifyAndPingNextPingableConnection(ch, cricket::RELAY_PORT_TYPE, |
+ cricket::RELAY_PORT_TYPE); |
+} |
+ |
+// Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay, |
pthatcher1
2016/01/14 22:40:01
Hmm... that's a good question. Do we really want
|
+// followed by the rest. |
+TEST_F(P2PTransportChannelTurnTurnFirstTest, TestTcpTurn) { |
+ // Add a Tcp Turn server. |
+ turn_server()->AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
+ cricket::RelayServerConfig config(cricket::RELAY_TURN); |
+ config.credentials = kRelayCredentials; |
+ config.ports.push_back( |
+ cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false)); |
+ allocator()->AddTurnServer(config); |
+ |
+ cricket::P2PTransportChannel ch("checks", 1, nullptr, allocator()); |
+ PrepareChannel(&ch); |
+ ch.Connect(); |
+ ch.MaybeStartGathering(); |
+ EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000); |
+ EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); |
+ EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
+ EXPECT_EQ(ch.ports()[2]->Type(), cricket::RELAY_PORT_TYPE); |
+ |
+ // Remote Relay candidate arrives. |
+ ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); |
pthatcher1
2016/01/14 22:40:01
Can you add a non-relay candidate also, to be sure
guoweis_webrtc
2016/01/15 17:47:52
This was tested in the first test case, isn't it?
pthatcher1
2016/01/15 20:10:34
Yes, good point.
|
+ EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000); |
+ |
+ // UDP Relay/Relay should be pinged first. |
+ VerifyAndPingNextPingableConnection(ch, cricket::RELAY_PORT_TYPE, |
+ cricket::RELAY_PORT_TYPE); |
+ |
+ // TCP Relay/Relay is the next. |
+ VerifyAndPingNextPingableConnection(ch, cricket::RELAY_PORT_TYPE, |
+ cricket::RELAY_PORT_TYPE, |
+ cricket::TCP_PROTOCOL_NAME); |
+ |
+ // Finally, Local/Relay will be pinged. |
+ VerifyAndPingNextPingableConnection(ch, cricket::RELAY_PORT_TYPE, |
+ cricket::LOCAL_PORT_TYPE); |
+} |