diff --git a/webrtc/p2p/base/port.cc b/webrtc/p2p/base/port.cc index 55d6b876dc..ca162b86fa 100644 --- a/webrtc/p2p/base/port.cc +++ b/webrtc/p2p/base/port.cc @@ -130,6 +130,7 @@ static std::string ComputeFoundation(const std::string& type, } Port::Port(rtc::Thread* thread, + const std::string& type, rtc::PacketSocketFactory* factory, rtc::Network* network, const rtc::IPAddress& ip, @@ -137,6 +138,7 @@ Port::Port(rtc::Thread* thread, const std::string& password) : thread_(thread), factory_(factory), + type_(type), send_retransmit_count_attribute_(false), network_(network), ip_(ip), diff --git a/webrtc/p2p/base/port.h b/webrtc/p2p/base/port.h index 53056c1569..6cae6f8ae9 100644 --- a/webrtc/p2p/base/port.h +++ b/webrtc/p2p/base/port.h @@ -123,6 +123,7 @@ class Port : public PortInterface, public rtc::MessageHandler, public sigslot::has_slots<> { public: Port(rtc::Thread* thread, + const std::string& type, rtc::PacketSocketFactory* factory, rtc::Network* network, const rtc::IPAddress& ip, diff --git a/webrtc/p2p/base/stunport.cc b/webrtc/p2p/base/stunport.cc index e56d454b80..c25b8b10e6 100644 --- a/webrtc/p2p/base/stunport.cc +++ b/webrtc/p2p/base/stunport.cc @@ -168,6 +168,7 @@ UDPPort::UDPPort(rtc::Thread* thread, const std::string& origin, bool emit_local_for_anyaddress) : Port(thread, + LOCAL_PORT_TYPE, factory, network, socket->GetLocalAddress().ipaddr(), diff --git a/webrtc/p2p/base/stunport_unittest.cc b/webrtc/p2p/base/stunport_unittest.cc index e5146512df..522369d487 100644 --- a/webrtc/p2p/base/stunport_unittest.cc +++ b/webrtc/p2p/base/stunport_unittest.cc @@ -92,7 +92,7 @@ class StunPortTest : public testing::Test, &StunPortTest::OnPortError); } - void CreateSharedStunPort(const rtc::SocketAddress& server_addr) { + void CreateSharedUdpPort(const rtc::SocketAddress& server_addr) { socket_.reset(socket_factory_.CreateUdpSocket( rtc::SocketAddress(kLocalAddr.ipaddr(), 0), 0, 0)); ASSERT_TRUE(socket_ != NULL); @@ -176,13 +176,20 @@ class StunPortTest : public testing::Test, int stun_keepalive_lifetime_; }; -// Test that we can create a STUN port -TEST_F(StunPortTest, TestBasic) { +// Test that we can create a STUN port. +TEST_F(StunPortTest, TestCreateStunPort) { CreateStunPort(kStunAddr1); EXPECT_EQ("stun", port()->Type()); EXPECT_EQ(0U, port()->Candidates().size()); } +// Test that we can create a UDP port. +TEST_F(StunPortTest, TestCreateUdpPort) { + CreateSharedUdpPort(kStunAddr1); + EXPECT_EQ("local", port()->Type()); + EXPECT_EQ(0U, port()->Candidates().size()); +} + // Test that we can get an address from a STUN server. TEST_F(StunPortTest, TestPrepareAddress) { CreateStunPort(kStunAddr1); @@ -240,7 +247,7 @@ TEST_F(StunPortTest, TestKeepAliveResponse) { // Test that a local candidate can be generated using a shared socket. TEST_F(StunPortTest, TestSharedSocketPrepareAddress) { - CreateSharedStunPort(kStunAddr1); + CreateSharedUdpPort(kStunAddr1); PrepareAddress(); EXPECT_TRUE_WAIT(done(), kTimeoutMs); ASSERT_EQ(1U, port()->Candidates().size()); @@ -251,7 +258,7 @@ TEST_F(StunPortTest, TestSharedSocketPrepareAddress) { // Also verifing that UDPPort can receive packets when stun address can't be // resolved. TEST_F(StunPortTest, TestSharedSocketPrepareAddressInvalidHostname) { - CreateSharedStunPort(kBadHostnameAddr); + CreateSharedUdpPort(kBadHostnameAddr); PrepareAddress(); EXPECT_TRUE_WAIT(done(), kTimeoutMs); ASSERT_EQ(1U, port()->Candidates().size()); @@ -333,7 +340,7 @@ TEST_F(StunPortTest, TestStunPortGetStunKeepaliveLifetime) { // if the network type changes. TEST_F(StunPortTest, TestUdpPortGetStunKeepaliveLifetime) { // Lifetime for the default (unknown) network type is |kInfiniteLifetime|. - CreateSharedStunPort(kStunAddr1); + CreateSharedUdpPort(kStunAddr1); EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime()); // Lifetime for the cellular network is |kHighCostPortKeepaliveLifetimeMs|. SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); @@ -342,7 +349,7 @@ TEST_F(StunPortTest, TestUdpPortGetStunKeepaliveLifetime) { // Lifetime for the wifi network type is |kInfiniteLifetime|. SetNetworkType(rtc::ADAPTER_TYPE_WIFI); - CreateSharedStunPort(kStunAddr2); + CreateSharedUdpPort(kStunAddr2); EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime()); } diff --git a/webrtc/p2p/base/turnport.cc b/webrtc/p2p/base/turnport.cc index 567916f4ba..573ca907d6 100644 --- a/webrtc/p2p/base/turnport.cc +++ b/webrtc/p2p/base/turnport.cc @@ -190,6 +190,7 @@ TurnPort::TurnPort(rtc::Thread* thread, int server_priority, const std::string& origin) : Port(thread, + RELAY_PORT_TYPE, factory, network, socket->GetLocalAddress().ipaddr(), diff --git a/webrtc/p2p/base/turnport_unittest.cc b/webrtc/p2p/base/turnport_unittest.cc index e82f10f51d..edb345447b 100644 --- a/webrtc/p2p/base/turnport_unittest.cc +++ b/webrtc/p2p/base/turnport_unittest.cc @@ -584,6 +584,11 @@ class TurnPortTest : public testing::Test, rtc::PacketOptions options; }; +TEST_F(TurnPortTest, TestTurnPortType) { + CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); + EXPECT_EQ(cricket::RELAY_PORT_TYPE, turn_port_->Type()); +} + // Do a normal TURN allocation. TEST_F(TurnPortTest, TestTurnAllocate) { CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);