diff --git a/talk/p2p/base/p2ptransportchannel_unittest.cc b/talk/p2p/base/p2ptransportchannel_unittest.cc index 566fd14a2..c59a34237 100644 --- a/talk/p2p/base/p2ptransportchannel_unittest.cc +++ b/talk/p2p/base/p2ptransportchannel_unittest.cc @@ -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. diff --git a/talk/p2p/client/basicportallocator.cc b/talk/p2p/client/basicportallocator.cc index 8338abed0..99d53f366 100644 --- a/talk/p2p/client/basicportallocator.cc +++ b/talk/p2p/client/basicportallocator.cc @@ -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) {