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

Unified Diff: remoting/protocol/port_allocator_base.cc

Issue 1571943002: Simplify PortAllocatorBase and make PortAllocator creation synchronous. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
Index: remoting/protocol/port_allocator_base.cc
diff --git a/remoting/protocol/port_allocator_base.cc b/remoting/protocol/port_allocator_base.cc
index a62d528f0d84fbdc5fa9251ccf25b785ef7b65d6..37f4ab9876b48c755a7422e77699c9257ef13246 100644
--- a/remoting/protocol/port_allocator_base.cc
+++ b/remoting/protocol/port_allocator_base.cc
@@ -7,10 +7,13 @@
#include <algorithm>
#include <map>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "net/base/escape.h"
+#include "remoting/protocol/network_settings.h"
+#include "remoting/protocol/transport_context.h"
namespace {
@@ -36,47 +39,65 @@ namespace protocol {
const int PortAllocatorBase::kNumRetries = 5;
-PortAllocatorBase::PortAllocatorBase(rtc::NetworkManager* network_manager,
- rtc::PacketSocketFactory* socket_factory)
- : BasicPortAllocator(network_manager, socket_factory) {}
-
-PortAllocatorBase::~PortAllocatorBase() {}
-
-void PortAllocatorBase::SetStunHosts(
- const std::vector<rtc::SocketAddress>& hosts) {
- stun_hosts_ = hosts;
-}
-
-void PortAllocatorBase::SetRelayHosts(const std::vector<std::string>& hosts) {
- relay_hosts_ = hosts;
+PortAllocatorBase::PortAllocatorBase(
+ scoped_ptr<rtc::NetworkManager> network_manager,
+ scoped_ptr<rtc::PacketSocketFactory> socket_factory,
+ scoped_refptr<TransportContext> transport_context)
+ : BasicPortAllocator(network_manager.get(), socket_factory.get()),
+ network_manager_(std::move(network_manager)),
+ socket_factory_(std::move(socket_factory)),
+ transport_context_(transport_context) {
+ // We always use PseudoTcp to provide a reliable channel. It provides poor
+ // performance when combined with TCP-based transport, so we have to disable
+ // TCP ports. ENABLE_SHARED_UFRAG flag is specified so that the same username
+ // fragment is shared between all candidates.
+ int flags = cricket::PORTALLOCATOR_DISABLE_TCP |
+ cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
+ cricket::PORTALLOCATOR_ENABLE_IPV6;
+
+ NetworkSettings network_settings = transport_context_->network_settings();
+
+ if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_STUN))
+ flags |= cricket::PORTALLOCATOR_DISABLE_STUN;
+
+ if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_RELAY))
+ flags |= cricket::PORTALLOCATOR_DISABLE_RELAY;
+
+ set_flags(flags);
+ SetPortRange(network_settings.port_range.min_port,
+ network_settings.port_range.max_port);
}
-void PortAllocatorBase::SetRelayToken(const std::string& relay) {
- relay_token_ = relay;
-}
+PortAllocatorBase::~PortAllocatorBase() {}
PortAllocatorSessionBase::PortAllocatorSessionBase(
PortAllocatorBase* allocator,
const std::string& content_name,
int component,
const std::string& ice_ufrag,
- const std::string& ice_pwd,
- const std::vector<rtc::SocketAddress>& stun_hosts,
- const std::vector<std::string>& relay_hosts,
- const std::string& relay_token)
+ const std::string& ice_pwd)
: BasicPortAllocatorSession(allocator,
content_name,
component,
ice_ufrag,
ice_pwd),
- relay_hosts_(relay_hosts),
- stun_hosts_(stun_hosts),
- relay_token_(relay_token),
- attempts_(0) {}
+ weak_factory_(this) {}
PortAllocatorSessionBase::~PortAllocatorSessionBase() {}
void PortAllocatorSessionBase::GetPortConfigurations() {
+ allocator()->transport_context()->GetJingleInfo(base::Bind(
+ &PortAllocatorSessionBase::OnJingleInfo, weak_factory_.GetWeakPtr()));
+}
+
+void PortAllocatorSessionBase::OnJingleInfo(
+ std::vector<rtc::SocketAddress> stun_hosts,
+ std::vector<std::string> relay_hosts,
+ std::string relay_token) {
+ stun_hosts_ = stun_hosts;
+ relay_hosts_ = relay_hosts;
+ relay_token_ = relay_token;
+
// Creating relay sessions can take time and is done asynchronously.
// Creating stun sessions could also take time and could be done aysnc also,
// but for now is done here and added to the initial config. Note any later

Powered by Google App Engine
This is Rietveld 408576698