diff options
author | jiayl@webrtc.org <jiayl@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2014-07-18 21:34:11 +0000 |
---|---|---|
committer | jiayl@webrtc.org <jiayl@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2014-07-18 21:34:11 +0000 |
commit | 4417c9c01fccd9f057f9c460d2a0a7736823fd9b (patch) | |
tree | 3c78018cf3852e2ed62e36c21dc4b369f0582de8 /p2p/client | |
parent | 624cbc5fee98efebec2f9aa734d0d503cdfc48b2 (diff) | |
download | talk-4417c9c01fccd9f057f9c460d2a0a7736823fd9b.tar.gz |
Reland r6707 with the fix for callclient.cc.
TBR=mallinath@webrtc.org
BUG=3310
Review URL: https://webrtc-codereview.appspot.com/13039004
git-svn-id: http://webrtc.googlecode.com/svn/trunk/talk@6737 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'p2p/client')
-rw-r--r-- | p2p/client/basicportallocator.cc | 57 | ||||
-rw-r--r-- | p2p/client/basicportallocator.h | 26 | ||||
-rw-r--r-- | p2p/client/connectivitychecker.cc | 14 | ||||
-rw-r--r-- | p2p/client/connectivitychecker.h | 2 | ||||
-rw-r--r-- | p2p/client/connectivitychecker_unittest.cc | 7 | ||||
-rw-r--r-- | p2p/client/httpportallocator.cc | 16 | ||||
-rw-r--r-- | p2p/client/portallocator_unittest.cc | 21 |
7 files changed, 100 insertions, 43 deletions
diff --git a/p2p/client/basicportallocator.cc b/p2p/client/basicportallocator.cc index aa16517..46fbf49 100644 --- a/p2p/client/basicportallocator.cc +++ b/p2p/client/basicportallocator.cc @@ -186,23 +186,23 @@ BasicPortAllocator::BasicPortAllocator( BasicPortAllocator::BasicPortAllocator( talk_base::NetworkManager* network_manager, talk_base::PacketSocketFactory* socket_factory, - const talk_base::SocketAddress& stun_address) + const ServerAddresses& stun_servers) : network_manager_(network_manager), socket_factory_(socket_factory), - stun_address_(stun_address) { + stun_servers_(stun_servers) { ASSERT(socket_factory_ != NULL); Construct(); } BasicPortAllocator::BasicPortAllocator( talk_base::NetworkManager* network_manager, - const talk_base::SocketAddress& stun_address, + const ServerAddresses& stun_servers, const talk_base::SocketAddress& relay_address_udp, const talk_base::SocketAddress& relay_address_tcp, const talk_base::SocketAddress& relay_address_ssl) : network_manager_(network_manager), socket_factory_(NULL), - stun_address_(stun_address) { + stun_servers_(stun_servers) { RelayServerConfig config(RELAY_GTURN); if (!relay_address_udp.IsNil()) @@ -333,7 +333,7 @@ void BasicPortAllocatorSession::OnMessage(talk_base::Message *message) { } void BasicPortAllocatorSession::GetPortConfigurations() { - PortConfiguration* config = new PortConfiguration(allocator_->stun_address(), + PortConfiguration* config = new PortConfiguration(allocator_->stun_servers(), username(), password()); @@ -422,7 +422,7 @@ void BasicPortAllocatorSession::DoAllocate() { } // Disables phases that are not specified in this config. - if (!config || config->stun_address.IsNil()) { + if (!config || config->StunServers().empty()) { // No STUN ports specified in this config. sequence_flags |= PORTALLOCATOR_DISABLE_STUN; } @@ -753,8 +753,8 @@ void AllocationSequence::DisableEquivalentPhases(talk_base::Network* network, *flags |= PORTALLOCATOR_DISABLE_TCP; if (config_ && config) { - if (config_->stun_address == config->stun_address) { - // Already got this STUN server covered. + if (config_->StunServers() == config->StunServers()) { + // Already got this STUN servers covered. *flags |= PORTALLOCATOR_DISABLE_STUN; } if (!config_->relays.empty()) { @@ -878,15 +878,15 @@ void AllocationSequence::CreateUDPPorts() { // If STUN is not disabled, setting stun server address to port. if (!IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) { - // If config has stun_address, use it to get server reflexive candidate + // If config has stun_servers, use it to get server reflexive candidate // otherwise use first TURN server which supports UDP. - if (config_ && !config_->stun_address.IsNil()) { + if (config_ && !config_->StunServers().empty()) { LOG(LS_INFO) << "AllocationSequence: UDPPort will be handling the " << "STUN candidate generation."; - port->set_server_addr(config_->stun_address); + port->set_server_addresses(config_->StunServers()); } else if (config_ && config_->SupportsProtocol(RELAY_TURN, PROTO_UDP)) { - port->set_server_addr(config_->GetFirstRelayServerAddress( + port->set_server_addresses(config_->GetRelayServerAddresses( RELAY_TURN, PROTO_UDP)); LOG(LS_INFO) << "AllocationSequence: TURN Server address will be " << " used for generating STUN candidate."; @@ -931,8 +931,8 @@ void AllocationSequence::CreateStunPorts() { // If BasicPortAllocatorSession::OnAllocate left STUN ports enabled then we // ought to have an address for them here. - ASSERT(config_ && !config_->stun_address.IsNil()); - if (!(config_ && !config_->stun_address.IsNil())) { + ASSERT(config_ && !config_->StunServers().empty()); + if (!(config_ && !config_->StunServers().empty())) { LOG(LS_WARNING) << "AllocationSequence: No STUN server configured, skipping."; return; @@ -944,7 +944,7 @@ void AllocationSequence::CreateStunPorts() { session_->allocator()->min_port(), session_->allocator()->max_port(), session_->username(), session_->password(), - config_->stun_address); + config_->StunServers()); if (port) { session_->AddAllocatedPort(port, this, true); // Since StunPort is not created using shared socket, |port| will not be @@ -1115,9 +1115,27 @@ PortConfiguration::PortConfiguration( const talk_base::SocketAddress& stun_address, const std::string& username, const std::string& password) - : stun_address(stun_address), + : stun_address(stun_address), username(username), password(password) { + if (!stun_address.IsNil()) + stun_servers.insert(stun_address); +} + +PortConfiguration::PortConfiguration(const ServerAddresses& stun_servers, + const std::string& username, + const std::string& password) + : stun_servers(stun_servers), username(username), password(password) { + if (!stun_servers.empty()) + stun_address = *(stun_servers.begin()); +} + +ServerAddresses PortConfiguration::StunServers() { + if (!stun_address.IsNil() && + stun_servers.find(stun_address) == stun_servers.end()) { + stun_servers.insert(stun_address); + } + return stun_servers; } void PortConfiguration::AddRelay(const RelayServerConfig& config) { @@ -1146,14 +1164,15 @@ bool PortConfiguration::SupportsProtocol(RelayType turn_type, return false; } -talk_base::SocketAddress PortConfiguration::GetFirstRelayServerAddress( +ServerAddresses PortConfiguration::GetRelayServerAddresses( RelayType turn_type, ProtocolType type) const { + ServerAddresses servers; for (size_t i = 0; i < relays.size(); ++i) { if (relays[i].type == turn_type && SupportsProtocol(relays[i], type)) { - return relays[i].ports.front().address; + servers.insert(relays[i].ports.front().address); } } - return talk_base::SocketAddress(); + return servers; } } // namespace cricket diff --git a/p2p/client/basicportallocator.h b/p2p/client/basicportallocator.h index 5c43b42..aee6135 100644 --- a/p2p/client/basicportallocator.h +++ b/p2p/client/basicportallocator.h @@ -69,9 +69,9 @@ class BasicPortAllocator : public PortAllocator { explicit BasicPortAllocator(talk_base::NetworkManager* network_manager); BasicPortAllocator(talk_base::NetworkManager* network_manager, talk_base::PacketSocketFactory* socket_factory, - const talk_base::SocketAddress& stun_server); + const ServerAddresses& stun_servers); BasicPortAllocator(talk_base::NetworkManager* network_manager, - const talk_base::SocketAddress& stun_server, + const ServerAddresses& stun_servers, const talk_base::SocketAddress& relay_server_udp, const talk_base::SocketAddress& relay_server_tcp, const talk_base::SocketAddress& relay_server_ssl); @@ -83,8 +83,8 @@ class BasicPortAllocator : public PortAllocator { // creates its own socket factory. talk_base::PacketSocketFactory* socket_factory() { return socket_factory_; } - const talk_base::SocketAddress& stun_address() const { - return stun_address_; + const ServerAddresses& stun_servers() const { + return stun_servers_; } const std::vector<RelayServerConfig>& relays() const { @@ -105,7 +105,7 @@ class BasicPortAllocator : public PortAllocator { talk_base::NetworkManager* network_manager_; talk_base::PacketSocketFactory* socket_factory_; - const talk_base::SocketAddress stun_address_; + const ServerAddresses stun_servers_; std::vector<RelayServerConfig> relays_; bool allow_tcp_listen_; }; @@ -218,17 +218,27 @@ class BasicPortAllocatorSession : public PortAllocatorSession, // Records configuration information useful in creating ports. struct PortConfiguration : public talk_base::MessageData { + // TODO(jiayl): remove |stun_address| when Chrome is updated. talk_base::SocketAddress stun_address; + ServerAddresses stun_servers; std::string username; std::string password; typedef std::vector<RelayServerConfig> RelayList; RelayList relays; + // TODO(jiayl): remove this ctor when Chrome is updated. PortConfiguration(const talk_base::SocketAddress& stun_address, const std::string& username, const std::string& password); + PortConfiguration(const ServerAddresses& stun_servers, + const std::string& username, + const std::string& password); + + // TODO(jiayl): remove when |stun_address| is removed. + ServerAddresses StunServers(); + // Adds another relay server, with the given ports and modifier, to the list. void AddRelay(const RelayServerConfig& config); @@ -236,9 +246,9 @@ struct PortConfiguration : public talk_base::MessageData { bool SupportsProtocol(const RelayServerConfig& relay, ProtocolType type) const; bool SupportsProtocol(RelayType turn_type, ProtocolType type) const; - // Helper method returns the first server address for the matching - // RelayType and Protocol type. - talk_base::SocketAddress GetFirstRelayServerAddress( + // Helper method returns the server addresses for the matching RelayType and + // Protocol type. + ServerAddresses GetRelayServerAddresses( RelayType turn_type, ProtocolType type) const; }; diff --git a/p2p/client/connectivitychecker.cc b/p2p/client/connectivitychecker.cc index 1b59943..facb01e 100644 --- a/p2p/client/connectivitychecker.cc +++ b/p2p/client/connectivitychecker.cc @@ -288,7 +288,9 @@ void ConnectivityChecker::OnStunPortComplete(Port* port) { uint32 now = talk_base::Time(); NicInfo* nic_info = &i->second; nic_info->external_address = c.address(); - nic_info->stun_server_address = static_cast<StunPort*>(port)->server_addr(); + + nic_info->stun_server_addresses = + static_cast<StunPort*>(port)->server_addresses(); nic_info->stun.rtt = now - nic_info->stun.start_time_ms; } else { LOG(LS_ERROR) << "Got stun address for non-existing nic"; @@ -303,7 +305,9 @@ void ConnectivityChecker::OnStunPortError(Port* port) { if (i != nics_.end()) { // We have it already, add the new information. NicInfo* nic_info = &i->second; - nic_info->stun_server_address = static_cast<StunPort*>(port)->server_addr(); + + nic_info->stun_server_addresses = + static_cast<StunPort*>(port)->server_addresses(); } } @@ -335,7 +339,7 @@ StunPort* ConnectivityChecker::CreateStunPort( const PortConfiguration* config, talk_base::Network* network) { return StunPort::Create(worker_, socket_factory_.get(), network, network->ip(), 0, 0, - username, password, config->stun_address); + username, password, config->stun_servers); } RelayPort* ConnectivityChecker::CreateRelayPort( @@ -407,7 +411,9 @@ void ConnectivityChecker::CreateRelayPorts( void ConnectivityChecker::AllocatePorts() { const std::string username = talk_base::CreateRandomString(ICE_UFRAG_LENGTH); const std::string password = talk_base::CreateRandomString(ICE_PWD_LENGTH); - PortConfiguration config(stun_address_, username, password); + ServerAddresses stun_servers; + stun_servers.insert(stun_address_); + PortConfiguration config(stun_servers, username, password); std::vector<talk_base::Network*> networks; network_manager_->GetNetworks(&networks); if (networks.empty()) { diff --git a/p2p/client/connectivitychecker.h b/p2p/client/connectivitychecker.h index 95b736d..3f10c57 100644 --- a/p2p/client/connectivitychecker.h +++ b/p2p/client/connectivitychecker.h @@ -96,7 +96,7 @@ struct NicInfo { talk_base::IPAddress ip; talk_base::ProxyInfo proxy_info; talk_base::SocketAddress external_address; - talk_base::SocketAddress stun_server_address; + ServerAddresses stun_server_addresses; talk_base::SocketAddress media_server_address; ConnectInfo stun; ConnectInfo http; diff --git a/p2p/client/connectivitychecker_unittest.cc b/p2p/client/connectivitychecker_unittest.cc index c62120b..8d6fa9d 100644 --- a/p2p/client/connectivitychecker_unittest.cc +++ b/p2p/client/connectivitychecker_unittest.cc @@ -66,7 +66,7 @@ class FakeStunPort : public StunPort { const talk_base::IPAddress& ip, int min_port, int max_port, const std::string& username, const std::string& password, - const talk_base::SocketAddress& server_addr) + const ServerAddresses& server_addr) : StunPort(thread, factory, network, ip, min_port, max_port, username, password, server_addr) { } @@ -215,7 +215,7 @@ class ConnectivityCheckerForTest : public ConnectivityChecker { network, network->ip(), kMinPort, kMaxPort, username, password, - config->stun_address); + config->stun_servers); } virtual RelayPort* CreateRelayPort( const std::string& username, const std::string& password, @@ -254,7 +254,8 @@ class ConnectivityCheckerTest : public testing::Test { EXPECT_EQ(kExternalAddr, info.external_address); // Verify that the stun server address has been set. - EXPECT_EQ(kStunAddr, info.stun_server_address); + EXPECT_EQ(1U, info.stun_server_addresses.size()); + EXPECT_EQ(kStunAddr, *(info.stun_server_addresses.begin())); // Verify that the media server address has been set. Don't care // about port since it is different for different protocols. diff --git a/p2p/client/httpportallocator.cc b/p2p/client/httpportallocator.cc index b881d43..1529770 100644 --- a/p2p/client/httpportallocator.cc +++ b/p2p/client/httpportallocator.cc @@ -142,7 +142,13 @@ void HttpPortAllocatorSessionBase::GetPortConfigurations() { // but for now is done here and added to the initial config. Note any later // configs will have unresolved stun ips and will be discarded by the // AllocationSequence. - PortConfiguration* config = new PortConfiguration(stun_hosts_[0], + ServerAddresses hosts; + for (std::vector<talk_base::SocketAddress>::iterator it = stun_hosts_.begin(); + it != stun_hosts_.end(); ++it) { + hosts.insert(*it); + } + + PortConfiguration* config = new PortConfiguration(hosts, username(), password()); ConfigReady(config); @@ -206,7 +212,13 @@ void HttpPortAllocatorSessionBase::ReceiveSessionResponse( std::string relay_tcp_port = map["relay.tcp_port"]; std::string relay_ssltcp_port = map["relay.ssltcp_port"]; - PortConfiguration* config = new PortConfiguration(stun_hosts_[0], + ServerAddresses hosts; + for (std::vector<talk_base::SocketAddress>::iterator it = stun_hosts_.begin(); + it != stun_hosts_.end(); ++it) { + hosts.insert(*it); + } + + PortConfiguration* config = new PortConfiguration(hosts, map["username"], map["password"]); diff --git a/p2p/client/portallocator_unittest.cc b/p2p/client/portallocator_unittest.cc index b9def30..760d168 100644 --- a/p2p/client/portallocator_unittest.cc +++ b/p2p/client/portallocator_unittest.cc @@ -48,6 +48,7 @@ #include "talk/p2p/client/basicportallocator.h" #include "talk/p2p/client/httpportallocator.h" +using cricket::ServerAddresses; using talk_base::SocketAddress; using talk_base::Thread; @@ -115,10 +116,13 @@ class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { kRelayTcpIntAddr, kRelayTcpExtAddr, kRelaySslTcpIntAddr, kRelaySslTcpExtAddr), turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), - allocator_(new cricket::BasicPortAllocator( - &network_manager_, kStunAddr, - kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)), candidate_allocation_done_(false) { + cricket::ServerAddresses stun_servers; + stun_servers.insert(kStunAddr); + allocator_.reset(new cricket::BasicPortAllocator( + &network_manager_, + stun_servers, + kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); allocator_->set_step_delay(cricket::kMinimumStepDelay); } @@ -265,7 +269,7 @@ class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { // Tests that we can init the port allocator and create a session. TEST_F(PortAllocatorTest, TestBasic) { EXPECT_EQ(&network_manager_, allocator().network_manager()); - EXPECT_EQ(kStunAddr, allocator().stun_address()); + EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin()); ASSERT_EQ(1u, allocator().relays().size()); EXPECT_EQ(cricket::RELAY_GTURN, allocator().relays()[0].type); // Empty relay credentials are used for GTURN. @@ -696,8 +700,10 @@ TEST_F(PortAllocatorTest, TestSharedSocketWithNat) { AddInterface(kClientAddr); talk_base::scoped_ptr<talk_base::NATServer> nat_server( CreateNatServer(kNatAddr, talk_base::NAT_OPEN_CONE)); + ServerAddresses stun_servers; + stun_servers.insert(kStunAddr); allocator_.reset(new cricket::BasicPortAllocator( - &network_manager_, &nat_socket_factory_, kStunAddr)); + &network_manager_, &nat_socket_factory_, stun_servers)); allocator_->set_step_delay(cricket::kMinimumStepDelay); allocator_->set_flags(allocator().flags() | cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | @@ -786,8 +792,10 @@ TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) { AddInterface(kClientAddr); talk_base::scoped_ptr<talk_base::NATServer> nat_server( CreateNatServer(kNatAddr, talk_base::NAT_OPEN_CONE)); + ServerAddresses stun_servers; + stun_servers.insert(kStunAddr); allocator_.reset(new cricket::BasicPortAllocator( - &network_manager_, &nat_socket_factory_, kStunAddr)); + &network_manager_, &nat_socket_factory_, stun_servers)); cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); relay_server.credentials = credentials; @@ -895,6 +903,7 @@ TEST(HttpPortAllocatorTest, TestHttpPortAllocatorHostLists) { talk_base::SocketAddress("1.unittest.corp.google.com", 0)); stun_servers.push_back( talk_base::SocketAddress("2.unittest.corp.google.com", 0)); + alloc.SetRelayHosts(relay_servers); alloc.SetStunHosts(stun_servers); EXPECT_EQ(2U, alloc.relay_hosts().size()); |