Index: webrtc/p2p/client/basicportallocator.cc |
diff --git a/webrtc/p2p/client/basicportallocator.cc b/webrtc/p2p/client/basicportallocator.cc |
index 22abf33e93639d90b276ca9d6c5cc025fca3a6e0..bc1801dbd269c20b3fbc03728a27892be475004b 100644 |
--- a/webrtc/p2p/client/basicportallocator.cc |
+++ b/webrtc/p2p/client/basicportallocator.cc |
@@ -64,33 +64,26 @@ const uint32_t DISABLE_ALL_PHASES = |
PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY; |
// BasicPortAllocator |
-BasicPortAllocator::BasicPortAllocator( |
- rtc::NetworkManager* network_manager, |
- rtc::PacketSocketFactory* socket_factory) |
- : network_manager_(network_manager), |
- socket_factory_(socket_factory), |
- stun_servers_() { |
+BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, |
+ rtc::PacketSocketFactory* socket_factory) |
+ : network_manager_(network_manager), socket_factory_(socket_factory) { |
ASSERT(network_manager_ != nullptr); |
ASSERT(socket_factory_ != nullptr); |
Construct(); |
} |
BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager) |
- : network_manager_(network_manager), |
- socket_factory_(nullptr), |
- stun_servers_() { |
+ : network_manager_(network_manager), socket_factory_(nullptr) { |
ASSERT(network_manager_ != nullptr); |
Construct(); |
} |
-BasicPortAllocator::BasicPortAllocator( |
- rtc::NetworkManager* network_manager, |
- rtc::PacketSocketFactory* socket_factory, |
- const ServerAddresses& stun_servers) |
- : network_manager_(network_manager), |
- socket_factory_(socket_factory), |
- stun_servers_(stun_servers) { |
+BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, |
+ rtc::PacketSocketFactory* socket_factory, |
+ const ServerAddresses& stun_servers) |
+ : network_manager_(network_manager), socket_factory_(socket_factory) { |
ASSERT(socket_factory_ != NULL); |
+ SetConfiguration(stun_servers, std::vector<RelayServerConfig>(), 0); |
Construct(); |
} |
@@ -100,10 +93,8 @@ BasicPortAllocator::BasicPortAllocator( |
const rtc::SocketAddress& relay_address_udp, |
const rtc::SocketAddress& relay_address_tcp, |
const rtc::SocketAddress& relay_address_ssl) |
- : network_manager_(network_manager), |
- socket_factory_(NULL), |
- stun_servers_(stun_servers) { |
- |
+ : network_manager_(network_manager), socket_factory_(NULL) { |
+ std::vector<RelayServerConfig> turn_servers; |
RelayServerConfig config(RELAY_GTURN); |
if (!relay_address_udp.IsNil()) { |
config.ports.push_back(ProtocolAddress(relay_address_udp, PROTO_UDP)); |
@@ -116,9 +107,10 @@ BasicPortAllocator::BasicPortAllocator( |
} |
if (!config.ports.empty()) { |
- AddTurnServer(config); |
+ turn_servers.push_back(config); |
} |
+ SetConfiguration(stun_servers, turn_servers, 0); |
Construct(); |
} |
@@ -136,6 +128,11 @@ PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( |
this, content_name, component, ice_ufrag, ice_pwd); |
} |
+void BasicPortAllocator::AddTurnServer(const RelayServerConfig& turn_server) { |
+ std::vector<RelayServerConfig> new_turn_servers = turn_servers(); |
+ new_turn_servers.push_back(turn_server); |
+ SetConfiguration(stun_servers(), new_turn_servers, candidate_pool_size()); |
+} |
// BasicPortAllocatorSession |
BasicPortAllocatorSession::BasicPortAllocatorSession( |
@@ -207,6 +204,60 @@ void BasicPortAllocatorSession::ClearGettingPorts() { |
sequences_[i]->Stop(); |
} |
+std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { |
pthatcher1
2016/05/05 21:51:25
Do we need to update the P2pPortAllocator in chrom
Taylor Brandstetter
2016/05/06 03:53:35
No, because at this point P2PPortAllocator just de
|
+ std::vector<PortInterface*> ret; |
+ for (const PortData& port : ports_) { |
+ if (port.ready_or_complete()) { |
+ ret.push_back(port.port()); |
+ } |
+ } |
+ return ret; |
+} |
+ |
+std::vector<Candidate> BasicPortAllocatorSession::ReadyCandidates() const { |
+ std::vector<Candidate> candidates; |
+ for (const PortData& data : ports_) { |
+ for (const Candidate& candidate : data.port()->Candidates()) { |
+ if (!CheckCandidateFilter(candidate)) { |
+ continue; |
+ } |
+ ProtocolType pvalue; |
+ if (!StringToProto(candidate.protocol().c_str(), &pvalue) || |
+ !data.sequence()->ProtocolEnabled(pvalue)) { |
+ continue; |
+ } |
+ candidates.push_back(candidate); |
+ } |
+ } |
+ return candidates; |
+} |
+ |
+bool BasicPortAllocatorSession::CandidatesAllocationDone() const { |
+ // Done only if all required AllocationSequence objects |
+ // are created. |
+ if (!allocation_sequences_created_) { |
+ return false; |
+ } |
+ |
+ // Check that all port allocation sequences are complete. |
+ for (AllocationSequence* sequence : sequences_) { |
+ if (sequence->state() == AllocationSequence::kRunning) { |
+ return false; |
+ } |
+ } |
pthatcher1
2016/05/05 21:51:25
std::all_of might be handy here and below.
Taylor Brandstetter
2016/05/06 03:53:35
Done.
|
+ |
+ // If all allocated ports are in complete state, session must have got all |
+ // expected candidates. Session will trigger candidates allocation complete |
+ // signal. |
+ for (const PortData& port : ports_) { |
+ if (!port.complete_or_error()) { |
+ return false; |
+ } |
+ } |
+ |
+ return true; |
+} |
+ |
void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { |
switch (message->message_id) { |
case MSG_CONFIG_START: |
@@ -241,6 +292,13 @@ void BasicPortAllocatorSession::OnMessage(rtc::Message *message) { |
} |
} |
+void BasicPortAllocatorSession::UpdateTransportInformationInternal() { |
+ for (PortData& port : ports_) { |
+ port.port()->set_content_name(content_name()); |
+ port.port()->SetTransportInformation(component(), ice_ufrag(), ice_pwd()); |
+ } |
+} |
+ |
void BasicPortAllocatorSession::GetPortConfigurations() { |
PortConfiguration* config = new PortConfiguration(allocator_->stun_servers(), |
username(), |
@@ -274,7 +332,7 @@ void BasicPortAllocatorSession::OnConfigStop() { |
bool send_signal = false; |
for (std::vector<PortData>::iterator it = ports_.begin(); |
it != ports_.end(); ++it) { |
- if (!it->complete()) { |
+ if (!it->complete_or_error()) { |
// Updating port state to error, which didn't finish allocating candidates |
// yet. |
it->set_error(); |
@@ -436,7 +494,7 @@ void BasicPortAllocatorSession::AddAllocatedPort(Port* port, |
LOG(LS_INFO) << "Adding allocated port for " << content_name(); |
port->set_content_name(content_name()); |
- port->set_component(component_); |
+ port->set_component(component()); |
port->set_generation(generation()); |
if (allocator_->proxy().type != rtc::PROXY_NONE) |
port->set_proxy(allocator_->user_agent(), allocator_->proxy()); |
@@ -484,8 +542,9 @@ void BasicPortAllocatorSession::OnCandidateReady( |
ASSERT(data != NULL); |
// Discarding any candidate signal if port allocation status is |
// already in completed state. |
- if (data->complete()) |
+ if (data->complete_or_error()) { |
return; |
+ } |
ProtocolType pvalue; |
bool candidate_signalable = CheckCandidateFilter(c); |
@@ -536,8 +595,9 @@ void BasicPortAllocatorSession::OnPortComplete(Port* port) { |
ASSERT(data != NULL); |
// Ignore any late signals. |
- if (data->complete()) |
+ if (data->complete_or_error()) { |
return; |
+ } |
// Moving to COMPLETE state. |
data->set_complete(); |
@@ -550,8 +610,9 @@ void BasicPortAllocatorSession::OnPortError(Port* port) { |
PortData* data = FindPort(port); |
ASSERT(data != NULL); |
// We might have already given up on this port and stopped it. |
- if (data->complete()) |
+ if (data->complete_or_error()) { |
return; |
+ } |
// SignalAddressError is currently sent from StunPort/TurnPort. |
// But this signal itself is generic. |
@@ -587,7 +648,7 @@ void BasicPortAllocatorSession::OnProtocolEnabled(AllocationSequence* seq, |
} |
} |
-bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) { |
+bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) const { |
uint32_t filter = allocator_->candidate_filter(); |
// When binding to any address, before sending packets out, the getsockname |
@@ -625,29 +686,15 @@ void BasicPortAllocatorSession::OnPortAllocationComplete( |
} |
void BasicPortAllocatorSession::MaybeSignalCandidatesAllocationDone() { |
- // Send signal only if all required AllocationSequence objects |
- // are created. |
- if (!allocation_sequences_created_) |
- return; |
- |
- // Check that all port allocation sequences are complete. |
- for (std::vector<AllocationSequence*>::iterator it = sequences_.begin(); |
- it != sequences_.end(); ++it) { |
- if ((*it)->state() == AllocationSequence::kRunning) |
- return; |
- } |
- |
- // If all allocated ports are in complete state, session must have got all |
- // expected candidates. Session will trigger candidates allocation complete |
- // signal. |
- for (std::vector<PortData>::iterator it = ports_.begin(); |
- it != ports_.end(); ++it) { |
- if (!it->complete()) |
- return; |
+ if (CandidatesAllocationDone()) { |
+ if (content_name().empty()) { |
pthatcher1
2016/05/05 21:51:25
Instead of having an implicit content_name().empty
Taylor Brandstetter
2016/05/06 03:53:35
Done.
|
+ LOG(LS_INFO) << "All candidates gathered for pooled session."; |
+ } else { |
+ LOG(LS_INFO) << "All candidates gathered for " << content_name() << ":" |
+ << component() << ":" << generation(); |
+ } |
+ SignalCandidatesAllocationDone(this); |
} |
- LOG(LS_INFO) << "All candidates gathered for " << content_name_ << ":" |
- << component_ << ":" << generation(); |
- SignalCandidatesAllocationDone(this); |
} |
void BasicPortAllocatorSession::OnPortDestroyed( |