Fix the turn and udp port type.

The port type was not set if it was created on a shared socket.

BUG=
R=pthatcher@webrtc.org

Review URL: https://codereview.webrtc.org/2099023002 .

Cr-Commit-Position: refs/heads/master@{#13313}
This commit is contained in:
Honghai Zhang 2016-06-28 09:44:47 -07:00
parent 70fae2ccc6
commit d00c05788f
6 changed files with 24 additions and 7 deletions

View File

@ -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),

View File

@ -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,

View File

@ -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(),

View File

@ -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());
}

View File

@ -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(),

View File

@ -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);