In shared socket mode, use udp port as default receiver even if

stun server address is not set.

This can happen in a loopback scenarios where clients do not need
to provide any server information.

R=fischman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/12009004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5906 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mallinath@webrtc.org 2014-04-15 01:10:58 +00:00
parent 505f400f27
commit ad4440a64e
2 changed files with 52 additions and 14 deletions

View File

@ -1509,6 +1509,43 @@ TEST_F(P2PTransportChannelTest, TestIPv6Connections) {
DestroyChannels();
}
// Simple test without any stun or turn server addresses. Making sure ports
// can receive and send data.
TEST_F(P2PTransportChannelTest, TestSharedSocketModeWithStunTurnAddress) {
AddAddress(0, kPublicAddrs[0]);
AddAddress(1, kPublicAddrs[1]);
const talk_base::SocketAddress null_addr;
GetEndpoint(0)->allocator_.reset(new cricket::BasicPortAllocator(
&(GetEndpoint(0)->network_manager_), null_addr, null_addr,
null_addr, null_addr));
GetEndpoint(1)->allocator_.reset(new cricket::BasicPortAllocator(
&(GetEndpoint(1)->network_manager_), null_addr, null_addr,
null_addr, null_addr));
SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
SetAllocationStepDelay(0, kMinimumStepDelay);
SetAllocationStepDelay(1, kMinimumStepDelay);
CreateChannels(1);
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 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.

View File

@ -863,20 +863,19 @@ void AllocationSequence::CreateUDPPorts() {
if (port) {
// If shared socket is enabled, STUN candidate will be allocated by the
// UDPPort.
if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) &&
!IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) {
ASSERT(config_ && !config_->stun_address.IsNil());
if (!(config_ && !config_->stun_address.IsNil())) {
LOG(LS_WARNING)
<< "AllocationSequence: No STUN server configured, skipping.";
return;
}
if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) {
udp_port_ = port;
// If there is a TURN UDP server available, then we will use TURN port
// to get stun address, otherwise by UDP port.
// Shared socket mode is not used in GTURN mode.
if (config_ && !config_->SupportsProtocol(RELAY_TURN, PROTO_UDP)) {
port->set_server_addr(config_->stun_address);
// If STUN is not disabled, setting stun server address to port.
if (!IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) {
// If there is a TURN UDP server available, then we will use TURN port
// to get stun address, otherwise by UDP port.
// Shared socket mode is not used in GTURN mode.
if (config_ &&
!config_->SupportsProtocol(RELAY_TURN, PROTO_UDP) &&
!config_->stun_address.IsNil()) {
port->set_server_addr(config_->stun_address);
}
}
}
@ -1059,7 +1058,9 @@ void AllocationSequence::OnReadPacket(
port = udp_port_;
}
ASSERT(port != NULL);
port->HandleIncomingPacket(socket, data, size, remote_addr, packet_time);
if (port) {
port->HandleIncomingPacket(socket, data, size, remote_addr, packet_time);
}
}
void AllocationSequence::OnPortDestroyed(PortInterface* port) {