Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc |
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
index 485449fa88d6aa7b821f129de11290c66cdf5bd4..d0277f481461015f67320fc6f1eadc4166a59813 100644 |
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
@@ -297,8 +297,10 @@ |
const std::string& remote_ice_pwd) { |
cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( |
"test content name", component, NULL, GetAllocator(endpoint)); |
- channel->SignalCandidateGathered.connect( |
- this, &P2PTransportChannelTestBase::OnCandidate); |
+ channel->SignalRequestSignaling.connect( |
+ this, &P2PTransportChannelTestBase::OnChannelRequestSignaling); |
+ channel->SignalCandidateReady.connect(this, |
+ &P2PTransportChannelTestBase::OnCandidate); |
channel->SignalReadPacket.connect( |
this, &P2PTransportChannelTestBase::OnReadPacket); |
channel->SignalRoleConflict.connect( |
@@ -312,7 +314,6 @@ |
channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); |
channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); |
channel->Connect(); |
- channel->MaybeStartGathering(); |
return channel; |
} |
void DestroyChannels() { |
@@ -388,9 +389,10 @@ |
} |
bool IsLocalToPrflxOrTheReverse(const Result& expected) { |
- return ( |
- (expected.local_type == "local" && expected.remote_type == "prflx") || |
- (expected.local_type == "prflx" && expected.remote_type == "local")); |
+ return ((expected.local_type == "local" && |
+ expected.remote_type == "prflx") || |
+ (expected.local_type == "prflx" && |
+ expected.remote_type == "local")); |
} |
// Return true if the approprite parts of the expected Result, based |
@@ -510,8 +512,8 @@ |
ep2_ch1()->best_connection()) { |
int32 converge_start = rtc::Time(), converge_time; |
int converge_wait = 2000; |
- EXPECT_TRUE_WAIT_MARGIN(CheckCandidate1(expected), converge_wait, |
- converge_wait); |
+ EXPECT_TRUE_WAIT_MARGIN(CheckCandidate1(expected), |
+ converge_wait, converge_wait); |
// Also do EXPECT_EQ on each part so that failures are more verbose. |
ExpectCandidate1(expected); |
@@ -560,7 +562,7 @@ |
} |
// This test waits for the transport to become receiving and writable on both |
- // end points. Once they are, the end points set new local ice credentials and |
+ // end points. Once they are, the end points set new local ice credentials to |
// restart the ice gathering. Finally it waits for the transport to select a |
// new connection using the newly generated ice candidates. |
// Before calling this function the end points must be configured. |
@@ -580,10 +582,8 @@ |
ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); |
ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
- ep1_ch1()->MaybeStartGathering(); |
ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); |
ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
- ep2_ch1()->MaybeStartGathering(); |
EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != |
old_local_candidate1->generation(), |
@@ -626,6 +626,9 @@ |
TestSendRecv(1); |
} |
+ void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) { |
+ channel->OnSignalingReady(); |
+ } |
// We pass the candidates directly to the other side. |
void OnCandidate(cricket::TransportChannelImpl* ch, |
const cricket::Candidate& c) { |
@@ -666,7 +669,7 @@ |
} |
LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" |
<< rch->component() << "): " << c.ToString(); |
- rch->AddRemoteCandidate(c); |
+ rch->OnCandidate(c); |
break; |
} |
} |
@@ -801,10 +804,8 @@ |
static const Result* kMatrixSharedUfrag[NUM_CONFIGS][NUM_CONFIGS]; |
static const Result* kMatrixSharedSocketAsGice[NUM_CONFIGS][NUM_CONFIGS]; |
static const Result* kMatrixSharedSocketAsIce[NUM_CONFIGS][NUM_CONFIGS]; |
- void ConfigureEndpoints(Config config1, |
- Config config2, |
- int allocator_flags1, |
- int allocator_flags2) { |
+ void ConfigureEndpoints(Config config1, Config config2, |
+ int allocator_flags1, int allocator_flags2) { |
ServerAddresses stun_servers; |
stun_servers.insert(kStunAddr); |
GetEndpoint(0)->allocator_.reset( |
@@ -820,8 +821,8 @@ |
cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); |
relay_server.credentials = kRelayCredentials; |
- relay_server.ports.push_back( |
- cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
+ relay_server.ports.push_back(cricket::ProtocolAddress( |
+ kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
GetEndpoint(0)->allocator_->AddRelay(relay_server); |
GetEndpoint(1)->allocator_->AddRelay(relay_server); |
@@ -1025,14 +1026,15 @@ |
// The actual tests that exercise all the various configurations. |
// Test names are of the form P2PTransportChannelTest_TestOPENToNAT_FULL_CONE |
-#define P2P_TEST_DECLARATION(x, y, z) \ |
- TEST_F(P2PTransportChannelTest, z##Test##x##To##y) { \ |
- ConfigureEndpoints(x, y, PORTALLOCATOR_ENABLE_SHARED_SOCKET, \ |
- PORTALLOCATOR_ENABLE_SHARED_SOCKET); \ |
- if (kMatrixSharedSocketAsIce[x][y] != NULL) \ |
- Test(*kMatrixSharedSocketAsIce[x][y]); \ |
- else \ |
- LOG(LS_WARNING) << "Not yet implemented"; \ |
+#define P2P_TEST_DECLARATION(x, y, z) \ |
+ TEST_F(P2PTransportChannelTest, z##Test##x##To##y) { \ |
+ ConfigureEndpoints(x, y, \ |
+ PORTALLOCATOR_ENABLE_SHARED_SOCKET, \ |
+ PORTALLOCATOR_ENABLE_SHARED_SOCKET); \ |
+ if (kMatrixSharedSocketAsIce[x][y] != NULL) \ |
+ Test(*kMatrixSharedSocketAsIce[x][y]); \ |
+ else \ |
+ LOG(LS_WARNING) << "Not yet implemented"; \ |
} |
#define P2P_TEST(x, y) \ |
@@ -1087,7 +1089,8 @@ |
// Test that we restart candidate allocation when local ufrag&pwd changed. |
// Standard Ice protocol is used. |
TEST_F(P2PTransportChannelTest, HandleUfragPwdChange) { |
- ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
+ ConfigureEndpoints(OPEN, OPEN, |
+ kDefaultPortAllocatorFlags, |
kDefaultPortAllocatorFlags); |
CreateChannels(1); |
TestHandleIceUfragPasswordChanged(); |
@@ -1096,7 +1099,8 @@ |
// Test the operation of GetStats. |
TEST_F(P2PTransportChannelTest, GetStats) { |
- ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
+ ConfigureEndpoints(OPEN, OPEN, |
+ kDefaultPortAllocatorFlags, |
kDefaultPortAllocatorFlags); |
CreateChannels(1); |
EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
@@ -1122,7 +1126,8 @@ |
// Test that we properly create a connection on a STUN ping from unknown address |
// when the signaling is slow. |
TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { |
- ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
+ ConfigureEndpoints(OPEN, OPEN, |
+ kDefaultPortAllocatorFlags, |
kDefaultPortAllocatorFlags); |
// Emulate no remote credentials coming in. |
set_clear_remote_candidates_ufrag_pwd(false); |
@@ -1166,7 +1171,8 @@ |
// Test that we properly create a connection on a STUN ping from unknown address |
// when the signaling is slow and the end points are behind NAT. |
TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { |
- ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
+ ConfigureEndpoints(OPEN, NAT_SYMMETRIC, |
+ kDefaultPortAllocatorFlags, |
kDefaultPortAllocatorFlags); |
// Emulate no remote credentials coming in. |
set_clear_remote_candidates_ufrag_pwd(false); |
@@ -1208,7 +1214,8 @@ |
// Test that if remote candidates don't have ufrag and pwd, we still work. |
TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { |
set_clear_remote_candidates_ufrag_pwd(true); |
- ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
+ ConfigureEndpoints(OPEN, OPEN, |
+ kDefaultPortAllocatorFlags, |
kDefaultPortAllocatorFlags); |
CreateChannels(1); |
const cricket::Connection* best_connection = NULL; |
@@ -1223,7 +1230,8 @@ |
// Test that a host behind NAT cannot be reached when incoming_only |
// is set to true. |
TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) { |
- ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, |
+ ConfigureEndpoints(NAT_FULL_CONE, OPEN, |
+ kDefaultPortAllocatorFlags, |
kDefaultPortAllocatorFlags); |
SetAllocatorFlags(0, kOnlyLocalPorts); |
@@ -1244,7 +1252,8 @@ |
// Test that a peer behind NAT can connect to a peer that has |
// incoming_only flag set. |
TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) { |
- ConfigureEndpoints(OPEN, NAT_FULL_CONE, kDefaultPortAllocatorFlags, |
+ ConfigureEndpoints(OPEN, NAT_FULL_CONE, |
+ kDefaultPortAllocatorFlags, |
kDefaultPortAllocatorFlags); |
SetAllocatorFlags(0, kOnlyLocalPorts); |
@@ -1405,10 +1414,11 @@ |
// Testing forceful TURN connections. |
TEST_F(P2PTransportChannelTest, TestForceTurn) { |
- ConfigureEndpoints( |
- NAT_PORT_RESTRICTED, NAT_SYMMETRIC, |
- kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, |
- kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
+ ConfigureEndpoints(NAT_PORT_RESTRICTED, NAT_SYMMETRIC, |
+ kDefaultPortAllocatorFlags | |
+ cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, |
+ kDefaultPortAllocatorFlags | |
+ cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
set_force_relay(true); |
SetAllocationStepDelay(0, kMinimumStepDelay); |
@@ -1463,7 +1473,8 @@ |
TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) { |
ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE); |
Test(P2PTransportChannelTestBase::Result( |
- "prflx", "udp", "stun", "udp", "stun", "udp", "prflx", "udp", 1000)); |
+ "prflx", "udp", "stun", "udp", |
+ "stun", "udp", "prflx", "udp", 1000)); |
} |
// Test what happens when we have multiple available pathways. |
@@ -1549,12 +1560,11 @@ |
// Remove the public interface, add the alternate interface, and allocate |
- // a new generation of candidates for the new interface (via |
- // MaybeStartGathering()). |
+ // a new generation of candidates for the new interface (via Connect()). |
LOG(LS_INFO) << "Draining..."; |
AddAddress(1, kAlternateAddrs[1]); |
RemoveAddress(1, kPublicAddrs[1]); |
- ep2_ch1()->MaybeStartGathering(); |
+ ep2_ch1()->Connect(); |
// We should switch over to use the alternate address after |
// an exchange of pings. |
@@ -1581,9 +1591,15 @@ |
protected: |
void PrepareChannel(cricket::P2PTransportChannel* ch) { |
+ ch->SignalRequestSignaling.connect( |
+ this, &P2PTransportChannelPingTest::OnChannelRequestSignaling); |
ch->SetIceRole(cricket::ICEROLE_CONTROLLING); |
ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); |
ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
+ } |
+ |
+ void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) { |
+ channel->OnSignalingReady(); |
} |
cricket::Candidate CreateCandidate(const std::string& ip, |
@@ -1632,9 +1648,8 @@ |
cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |
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.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
+ ch.OnCandidate(CreateCandidate("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); |
@@ -1657,9 +1672,8 @@ |
cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |
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.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
+ ch.OnCandidate(CreateCandidate("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); |
@@ -1682,17 +1696,16 @@ |
cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); |
PrepareChannel(&ch); |
ch.Connect(); |
- ch.MaybeStartGathering(); |
// Create conn1 and keep track of original candidate priority. |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
+ ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
uint32 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.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
conn2->ReceivedPing(); |
@@ -1739,8 +1752,7 @@ |
EXPECT_EQ(500, ch.receiving_timeout()); |
EXPECT_EQ(50, ch.check_receiving_delay()); |
ch.Connect(); |
- ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
+ ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
ASSERT_TRUE(conn1 != nullptr); |
@@ -1761,15 +1773,14 @@ |
PrepareChannel(&ch); |
ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
ch.Connect(); |
- ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
+ ch.OnCandidate(CreateCandidate("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.OnCandidate(CreateCandidate("2.2.2.2", 2, 10)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn1 != nullptr); |
EXPECT_EQ(conn2, ch.best_connection()); |
@@ -1777,7 +1788,7 @@ |
// 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.OnCandidate(CreateCandidate("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. |
@@ -1792,7 +1803,7 @@ |
// 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.OnCandidate(CreateCandidate("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()); |
@@ -1817,7 +1828,6 @@ |
PrepareChannel(&ch); |
ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
ch.Connect(); |
- ch.MaybeStartGathering(); |
// A minimal STUN message with prflx priority. |
cricket::IceMessage request; |
request.SetType(cricket::STUN_BINDING_REQUEST); |
@@ -1836,7 +1846,7 @@ |
EXPECT_EQ(conn1, ch.best_connection()); |
// Another connection is nominated via use_candidate. |
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
+ ch.OnCandidate(CreateCandidate("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. |
@@ -1882,8 +1892,7 @@ |
PrepareChannel(&ch); |
ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
ch.Connect(); |
- ch.MaybeStartGathering(); |
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10)); |
+ ch.OnCandidate(CreateCandidate("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()); |
@@ -1891,7 +1900,7 @@ |
// 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.OnCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
ASSERT_TRUE(conn2 != nullptr); |
conn2->ReceivedPing(); // Start receiving. |