diff --git a/talk/p2p/base/p2ptransportchannel.cc b/talk/p2p/base/p2ptransportchannel.cc index 1fd939bb7a..7a72d1008e 100644 --- a/talk/p2p/base/p2ptransportchannel.cc +++ b/talk/p2p/base/p2ptransportchannel.cc @@ -427,15 +427,6 @@ void P2PTransportChannel::OnUnknownAddress( const Candidate* candidate = NULL; bool known_username = false; std::string remote_password; - - // If we have not received any candidates from remote yet, as it can happen - // in case of trickle, but we have received remote ice_ufrag in O/A, we should - // check against it. - if (!remote_ice_ufrag_.empty() && (remote_username == remote_ice_ufrag_)) { - remote_password = remote_ice_pwd_; - known_username = true; - } - for (it = remote_candidates_.begin(); it != remote_candidates_.end(); ++it) { if (it->username() == remote_username) { remote_password = it->password(); diff --git a/talk/p2p/base/p2ptransportchannel_unittest.cc b/talk/p2p/base/p2ptransportchannel_unittest.cc index e86658a903..32504debba 100644 --- a/talk/p2p/base/p2ptransportchannel_unittest.cc +++ b/talk/p2p/base/p2ptransportchannel_unittest.cc @@ -601,9 +601,9 @@ class P2PTransportChannelTestBase : public testing::Test, c.set_password(""); } LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" - << rch->component() << "): " << c.type() << ", " - << c.protocol() << ", " << c.address().ToString() << ", " - << c.username() << ", " << c.generation(); + << rch->component() << "): " << c.type() << ", " << c.protocol() + << ", " << c.address().ToString() << ", " << c.username() + << ", " << c.generation(); rch->OnCandidate(c); } void OnReadPacket(cricket::TransportChannel* channel, const char* data, @@ -1266,169 +1266,6 @@ TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) { DestroyChannels(); } -TEST_F(P2PTransportChannelTest, TestBundleAllocatorToBundleAllocator) { - AddAddress(0, kPublicAddrs[0]); - AddAddress(1, kPublicAddrs[1]); - SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_BUNDLE); - SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_BUNDLE); - - CreateChannels(2); - - EXPECT_TRUE_WAIT(ep1_ch1()->readable() && - ep1_ch1()->writable() && - ep2_ch1()->readable() && - ep2_ch1()->writable(), - 1000); - EXPECT_TRUE(ep1_ch1()->best_connection() && - ep2_ch1()->best_connection()); - - EXPECT_FALSE(ep1_ch2()->readable()); - EXPECT_FALSE(ep1_ch2()->writable()); - EXPECT_FALSE(ep2_ch2()->readable()); - EXPECT_FALSE(ep2_ch2()->writable()); - - TestSendRecv(1); // Only 1 channel is writable per Endpoint. - DestroyChannels(); -} - -TEST_F(P2PTransportChannelTest, TestBundleAllocatorToNonBundleAllocator) { - AddAddress(0, kPublicAddrs[0]); - AddAddress(1, kPublicAddrs[1]); - // Enable BUNDLE flag at one side. - SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_BUNDLE); - - CreateChannels(2); - - EXPECT_TRUE_WAIT(ep1_ch1()->readable() && - ep1_ch1()->writable() && - ep2_ch1()->readable() && - ep2_ch1()->writable(), - 1000); - EXPECT_TRUE_WAIT(ep1_ch2()->readable() && - ep1_ch2()->writable() && - ep2_ch2()->readable() && - ep2_ch2()->writable(), - 1000); - - EXPECT_TRUE(ep1_ch1()->best_connection() && - ep2_ch1()->best_connection()); - EXPECT_TRUE(ep1_ch2()->best_connection() && - ep2_ch2()->best_connection()); - - TestSendRecv(2); - DestroyChannels(); -} - -TEST_F(P2PTransportChannelTest, TestIceRoleConflictWithoutBundle) { - AddAddress(0, kPublicAddrs[0]); - AddAddress(1, kPublicAddrs[1]); - TestSignalRoleConflict(); -} - -TEST_F(P2PTransportChannelTest, TestIceRoleConflictWithBundle) { - AddAddress(0, kPublicAddrs[0]); - AddAddress(1, kPublicAddrs[1]); - SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_BUNDLE); - SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_BUNDLE); - TestSignalRoleConflict(); -} - -// Tests that the ice configs (protocol, tiebreaker and role) can be passed -// down to ports. -TEST_F(P2PTransportChannelTest, TestIceConfigWillPassDownToPort) { - AddAddress(0, kPublicAddrs[0]); - AddAddress(1, kPublicAddrs[1]); - - SetIceRole(0, cricket::ICEROLE_CONTROLLING); - SetIceProtocol(0, cricket::ICEPROTO_GOOGLE); - SetIceTiebreaker(0, kTiebreaker1); - SetIceRole(1, cricket::ICEROLE_CONTROLLING); - SetIceProtocol(1, cricket::ICEPROTO_RFC5245); - SetIceTiebreaker(1, kTiebreaker2); - - CreateChannels(1); - - EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000); - - const std::vector ports_before = ep1_ch1()->ports(); - for (size_t i = 0; i < ports_before.size(); ++i) { - EXPECT_EQ(cricket::ICEROLE_CONTROLLING, ports_before[i]->GetIceRole()); - EXPECT_EQ(cricket::ICEPROTO_GOOGLE, ports_before[i]->IceProtocol()); - EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); - } - - ep1_ch1()->SetIceRole(cricket::ICEROLE_CONTROLLED); - ep1_ch1()->SetIceProtocolType(cricket::ICEPROTO_RFC5245); - ep1_ch1()->SetIceTiebreaker(kTiebreaker2); - - const std::vector ports_after = ep1_ch1()->ports(); - for (size_t i = 0; i < ports_after.size(); ++i) { - EXPECT_EQ(cricket::ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); - EXPECT_EQ(cricket::ICEPROTO_RFC5245, ports_before[i]->IceProtocol()); - // SetIceTiebreaker after Connect() has been called will fail. So expect the - // original value. - EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); - } - - EXPECT_TRUE_WAIT(ep1_ch1()->readable() && - ep1_ch1()->writable() && - ep2_ch1()->readable() && - ep2_ch1()->writable(), - 1000); - - EXPECT_TRUE(ep1_ch1()->best_connection() && - ep2_ch1()->best_connection()); - - TestSendRecv(1); - DestroyChannels(); -} - -// Test that channel will handle connectivity checks received before the -// candidates received and channel has remote ice credentials. -TEST_F(P2PTransportChannelTest, TestSlowSignalingAsIce) { - set_clear_remote_candidates_ufrag_pwd(true); - AddAddress(0, kPublicAddrs[0]); - AddAddress(1, kPublicAddrs[1]); - - // Disable all protocols except TCP. - SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG); - SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG); - - SetIceRole(0, cricket::ICEROLE_CONTROLLING); - SetIceProtocol(0, cricket::ICEPROTO_RFC5245); - SetIceTiebreaker(0, kTiebreaker1); - SetIceRole(1, cricket::ICEROLE_CONTROLLED); - SetIceProtocol(1, cricket::ICEPROTO_RFC5245); - SetIceTiebreaker(1, kTiebreaker2); - - // Delay handling of the candidates from Endpoint 1. - // Since remote ICE username and passwords are already provided during - // channel creation time using set_clear_remote_candidates_ufrag_pwd, - // channel should make a connection when it receives remote ping before - // candidates arrives. Channel will create connections only if remote username - // and passwords match with the one received in stun ping messages. - SetSignalingDelay(1, 1000); - CreateChannels(1); - - EXPECT_TRUE_WAIT(ep1_ch1()->readable() && - ep1_ch1()->writable() && - ep2_ch1()->readable() && - ep2_ch1()->writable(), - 1000); - - EXPECT_EQ(std::string(cricket::PRFLX_PORT_TYPE), - RemoteCandidate(ep1_ch1())->type()); - EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), - LocalCandidate(ep1_ch1())->type()); - EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), - RemoteCandidate(ep2_ch1())->type()); - EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), - LocalCandidate(ep2_ch1())->type()); - - TestSendRecv(1); - DestroyChannels(); -} - // Test what happens when we have 2 users behind the same NAT. This can lead // to interesting behavior because the STUN server will only give out the // address of the outermost NAT. @@ -1550,3 +1387,119 @@ TEST_F(P2PTransportChannelMultihomedTest, TestDrain) { DestroyChannels(); } + +TEST_F(P2PTransportChannelTest, TestBundleAllocatorToBundleAllocator) { + AddAddress(0, kPublicAddrs[0]); + AddAddress(1, kPublicAddrs[1]); + SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_BUNDLE); + SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_BUNDLE); + + CreateChannels(2); + + EXPECT_TRUE_WAIT(ep1_ch1()->readable() && + ep1_ch1()->writable() && + ep2_ch1()->readable() && + ep2_ch1()->writable(), + 1000); + EXPECT_TRUE(ep1_ch1()->best_connection() && + ep2_ch1()->best_connection()); + + EXPECT_FALSE(ep1_ch2()->readable()); + EXPECT_FALSE(ep1_ch2()->writable()); + EXPECT_FALSE(ep2_ch2()->readable()); + EXPECT_FALSE(ep2_ch2()->writable()); + + TestSendRecv(1); // Only 1 channel is writable per Endpoint. + DestroyChannels(); +} + +TEST_F(P2PTransportChannelTest, TestBundleAllocatorToNonBundleAllocator) { + AddAddress(0, kPublicAddrs[0]); + AddAddress(1, kPublicAddrs[1]); + // Enable BUNDLE flag at one side. + SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_BUNDLE); + + CreateChannels(2); + + EXPECT_TRUE_WAIT(ep1_ch1()->readable() && + ep1_ch1()->writable() && + ep2_ch1()->readable() && + ep2_ch1()->writable(), + 1000); + EXPECT_TRUE_WAIT(ep1_ch2()->readable() && + ep1_ch2()->writable() && + ep2_ch2()->readable() && + ep2_ch2()->writable(), + 1000); + + EXPECT_TRUE(ep1_ch1()->best_connection() && + ep2_ch1()->best_connection()); + EXPECT_TRUE(ep1_ch2()->best_connection() && + ep2_ch2()->best_connection()); + + TestSendRecv(2); + DestroyChannels(); +} + +TEST_F(P2PTransportChannelTest, TestIceRoleConflictWithoutBundle) { + AddAddress(0, kPublicAddrs[0]); + AddAddress(1, kPublicAddrs[1]); + TestSignalRoleConflict(); +} + +TEST_F(P2PTransportChannelTest, TestIceRoleConflictWithBundle) { + AddAddress(0, kPublicAddrs[0]); + AddAddress(1, kPublicAddrs[1]); + SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_BUNDLE); + SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_BUNDLE); + TestSignalRoleConflict(); +} + +// Tests that the ice configs (protocol, tiebreaker and role) can be passed +// down to ports. +TEST_F(P2PTransportChannelTest, TestIceConfigWillPassDownToPort) { + AddAddress(0, kPublicAddrs[0]); + AddAddress(1, kPublicAddrs[1]); + + SetIceRole(0, cricket::ICEROLE_CONTROLLING); + SetIceProtocol(0, cricket::ICEPROTO_GOOGLE); + SetIceTiebreaker(0, kTiebreaker1); + SetIceRole(1, cricket::ICEROLE_CONTROLLING); + SetIceProtocol(1, cricket::ICEPROTO_RFC5245); + SetIceTiebreaker(1, kTiebreaker2); + + CreateChannels(1); + + EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000); + + const std::vector ports_before = ep1_ch1()->ports(); + for (size_t i = 0; i < ports_before.size(); ++i) { + EXPECT_EQ(cricket::ICEROLE_CONTROLLING, ports_before[i]->GetIceRole()); + EXPECT_EQ(cricket::ICEPROTO_GOOGLE, ports_before[i]->IceProtocol()); + EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); + } + + ep1_ch1()->SetIceRole(cricket::ICEROLE_CONTROLLED); + ep1_ch1()->SetIceProtocolType(cricket::ICEPROTO_RFC5245); + ep1_ch1()->SetIceTiebreaker(kTiebreaker2); + + const std::vector ports_after = ep1_ch1()->ports(); + for (size_t i = 0; i < ports_after.size(); ++i) { + EXPECT_EQ(cricket::ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); + EXPECT_EQ(cricket::ICEPROTO_RFC5245, ports_before[i]->IceProtocol()); + // SetIceTiebreaker after Connect() has been called will fail. So expect the + // original value. + EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); + } + + EXPECT_TRUE_WAIT(ep1_ch1()->readable() && + ep1_ch1()->writable() && + ep2_ch1()->readable() && + ep2_ch1()->writable(), + 1000); + + EXPECT_TRUE(ep1_ch1()->best_connection() && + ep2_ch1()->best_connection()); + + TestSendRecv(1); +}