Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Unified Diff: webrtc/p2p/client/basicportallocator.cc

Issue 1956453003: Relanding: Implement RTCConfiguration.iceCandidatePoolSize. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing uninitialized variable (noticed by msan) Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/client/basicportallocator.h ('k') | webrtc/p2p/client/basicportallocator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/client/basicportallocator.cc
diff --git a/webrtc/p2p/client/basicportallocator.cc b/webrtc/p2p/client/basicportallocator.cc
index 22abf33e93639d90b276ca9d6c5cc025fca3a6e0..82cd5fcc5bbcc8109485e8c191b73ce6e1ea07e3 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,61 @@ void BasicPortAllocatorSession::ClearGettingPorts() {
sequences_[i]->Stop();
}
+std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const {
+ std::vector<PortInterface*> ret;
+ for (const PortData& port : ports_) {
+ if (port.ready() || port.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 (not running).
+ if (std::any_of(sequences_.begin(), sequences_.end(),
+ [](const AllocationSequence* sequence) {
+ return sequence->state() == AllocationSequence::kRunning;
+ })) {
+ return false;
+ }
+
+ // If all allocated ports are in complete state, session must have got all
+ // expected candidates. Session will trigger candidates allocation complete
+ // signal.
+ if (!std::all_of(ports_.begin(), ports_.end(), [](const PortData& port) {
+ return (port.complete() || port.error());
+ })) {
+ return false;
+ }
+
+ return true;
+}
+
void BasicPortAllocatorSession::OnMessage(rtc::Message *message) {
switch (message->message_id) {
case MSG_CONFIG_START:
@@ -241,6 +293,13 @@ void BasicPortAllocatorSession::OnMessage(rtc::Message *message) {
}
}
+void BasicPortAllocatorSession::UpdateIceParametersInternal() {
+ for (PortData& port : ports_) {
+ port.port()->set_content_name(content_name());
+ port.port()->SetIceParameters(component(), ice_ufrag(), ice_pwd());
+ }
+}
+
void BasicPortAllocatorSession::GetPortConfigurations() {
PortConfiguration* config = new PortConfiguration(allocator_->stun_servers(),
username(),
@@ -274,7 +333,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() && !it->error()) {
// Updating port state to error, which didn't finish allocating candidates
// yet.
it->set_error();
@@ -436,12 +495,12 @@ 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());
- port->set_send_retransmit_count_attribute((allocator_->flags() &
- PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0);
+ port->set_send_retransmit_count_attribute(
+ (flags() & PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0);
// Push down the candidate_filter to individual port.
uint32_t candidate_filter = allocator_->candidate_filter();
@@ -484,8 +543,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() || data->error()) {
return;
+ }
ProtocolType pvalue;
bool candidate_signalable = CheckCandidateFilter(c);
@@ -536,8 +596,9 @@ void BasicPortAllocatorSession::OnPortComplete(Port* port) {
ASSERT(data != NULL);
// Ignore any late signals.
- if (data->complete())
+ if (data->complete() || data->error()) {
return;
+ }
// Moving to COMPLETE state.
data->set_complete();
@@ -550,8 +611,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() || data->error()) {
return;
+ }
// SignalAddressError is currently sent from StunPort/TurnPort.
// But this signal itself is generic.
@@ -587,7 +649,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 +687,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 (pooled()) {
+ 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(
« no previous file with comments | « webrtc/p2p/client/basicportallocator.h ('k') | webrtc/p2p/client/basicportallocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698