Change Port::Create methods to return a unique_ptr

Bug: webrtc:9198
Change-Id: Iab3387857b7e7826b0d71863893912f3a8a9b95b
Reviewed-on: https://webrtc-review.googlesource.com/c/104260
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25097}
This commit is contained in:
Steve Anton
2018-10-10 11:29:44 -07:00
committed by Commit Bot
parent 7940da0f2e
commit a8f1e56532
10 changed files with 175 additions and 118 deletions

View File

@ -485,26 +485,25 @@ class PortTest : public testing::Test, public sigslot::has_slots<> {
} }
std::unique_ptr<UDPPort> CreateUdpPort(const SocketAddress& addr, std::unique_ptr<UDPPort> CreateUdpPort(const SocketAddress& addr,
PacketSocketFactory* socket_factory) { PacketSocketFactory* socket_factory) {
return absl::WrapUnique(UDPPort::Create( return UDPPort::Create(&main_, socket_factory, MakeNetwork(addr), 0, 0,
&main_, socket_factory, MakeNetwork(addr), 0, 0, username_, password_, username_, password_, std::string(), true,
std::string(), true, absl::nullopt)); absl::nullopt);
} }
std::unique_ptr<TCPPort> CreateTcpPort(const SocketAddress& addr) { std::unique_ptr<TCPPort> CreateTcpPort(const SocketAddress& addr) {
return CreateTcpPort(addr, &socket_factory_); return CreateTcpPort(addr, &socket_factory_);
} }
std::unique_ptr<TCPPort> CreateTcpPort(const SocketAddress& addr, std::unique_ptr<TCPPort> CreateTcpPort(const SocketAddress& addr,
PacketSocketFactory* socket_factory) { PacketSocketFactory* socket_factory) {
return absl::WrapUnique(TCPPort::Create(&main_, socket_factory, return TCPPort::Create(&main_, socket_factory, MakeNetwork(addr), 0, 0,
MakeNetwork(addr), 0, 0, username_, username_, password_, true);
password_, true));
} }
std::unique_ptr<StunPort> CreateStunPort(const SocketAddress& addr, std::unique_ptr<StunPort> CreateStunPort(const SocketAddress& addr,
rtc::PacketSocketFactory* factory) { rtc::PacketSocketFactory* factory) {
ServerAddresses stun_servers; ServerAddresses stun_servers;
stun_servers.insert(kStunAddr); stun_servers.insert(kStunAddr);
return absl::WrapUnique(StunPort::Create( return StunPort::Create(&main_, factory, MakeNetwork(addr), 0, 0, username_,
&main_, factory, MakeNetwork(addr), 0, 0, username_, password_, password_, stun_servers, std::string(),
stun_servers, std::string(), absl::nullopt)); absl::nullopt);
} }
std::unique_ptr<Port> CreateRelayPort(const SocketAddress& addr, std::unique_ptr<Port> CreateRelayPort(const SocketAddress& addr,
RelayType rtype, RelayType rtype,
@ -531,10 +530,10 @@ class PortTest : public testing::Test, public sigslot::has_slots<> {
ProtocolType int_proto, ProtocolType int_proto,
ProtocolType ext_proto, ProtocolType ext_proto,
const rtc::SocketAddress& server_addr) { const rtc::SocketAddress& server_addr) {
return absl::WrapUnique(TurnPort::Create( return TurnPort::CreateUnique(
&main_, socket_factory, MakeNetwork(addr), 0, 0, username_, password_, &main_, socket_factory, MakeNetwork(addr), 0, 0, username_, password_,
ProtocolAddress(server_addr, int_proto), kRelayCredentials, 0, "", {}, ProtocolAddress(server_addr, int_proto), kRelayCredentials, 0, "", {},
{}, nullptr, nullptr)); {}, nullptr, nullptr);
} }
std::unique_ptr<RelayPort> CreateGturnPort(const SocketAddress& addr, std::unique_ptr<RelayPort> CreateGturnPort(const SocketAddress& addr,
ProtocolType int_proto, ProtocolType int_proto,
@ -549,9 +548,8 @@ class PortTest : public testing::Test, public sigslot::has_slots<> {
// TODO(pthatcher): Remove GTURN. // TODO(pthatcher): Remove GTURN.
// Generate a username with length of 16 for Gturn only. // Generate a username with length of 16 for Gturn only.
std::string username = rtc::CreateRandomString(kGturnUserNameLength); std::string username = rtc::CreateRandomString(kGturnUserNameLength);
return absl::WrapUnique(RelayPort::Create(&main_, &socket_factory_, return RelayPort::Create(&main_, &socket_factory_, MakeNetwork(addr), 0, 0,
MakeNetwork(addr), 0, 0, username, username, password_);
password_));
// TODO(?): Add an external address for ext_proto, so that the // TODO(?): Add an external address for ext_proto, so that the
// other side can connect to this port using a non-UDP protocol. // other side can connect to this port using a non-UDP protocol.
} }

View File

@ -12,6 +12,7 @@
#define P2P_BASE_RELAYPORT_H_ #define P2P_BASE_RELAYPORT_H_
#include <deque> #include <deque>
#include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -35,15 +36,16 @@ class RelayPort : public Port {
typedef std::pair<rtc::Socket::Option, int> OptionValue; typedef std::pair<rtc::Socket::Option, int> OptionValue;
// RelayPort doesn't yet do anything fancy in the ctor. // RelayPort doesn't yet do anything fancy in the ctor.
static RelayPort* Create(rtc::Thread* thread, static std::unique_ptr<RelayPort> Create(rtc::Thread* thread,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
rtc::Network* network, rtc::Network* network,
uint16_t min_port, uint16_t min_port,
uint16_t max_port, uint16_t max_port,
const std::string& username, const std::string& username,
const std::string& password) { const std::string& password) {
return new RelayPort(thread, factory, network, min_port, max_port, username, // Using `new` to access a non-public constructor.
password); return absl::WrapUnique(new RelayPort(thread, factory, network, min_port,
max_port, username, password));
} }
~RelayPort() override; ~RelayPort() override;

View File

@ -563,7 +563,8 @@ bool UDPPort::HasCandidateWithAddress(const rtc::SocketAddress& addr) const {
return false; return false;
} }
StunPort* StunPort::Create(rtc::Thread* thread, std::unique_ptr<StunPort> StunPort::Create(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
rtc::Network* network, rtc::Network* network,
uint16_t min_port, uint16_t min_port,
@ -573,12 +574,13 @@ StunPort* StunPort::Create(rtc::Thread* thread,
const ServerAddresses& servers, const ServerAddresses& servers,
const std::string& origin, const std::string& origin,
absl::optional<int> stun_keepalive_interval) { absl::optional<int> stun_keepalive_interval) {
StunPort* port = new StunPort(thread, factory, network, min_port, max_port, // Using `new` to access a non-public constructor.
username, password, servers, origin); auto port = absl::WrapUnique(new StunPort(thread, factory, network, min_port,
max_port, username, password,
servers, origin));
port->set_stun_keepalive_delay(stun_keepalive_interval); port->set_stun_keepalive_delay(stun_keepalive_interval);
if (!port->Init()) { if (!port->Init()) {
delete port; return nullptr;
port = NULL;
} }
return port; return port;
} }

View File

@ -35,7 +35,8 @@ static const int HIGH_COST_PORT_KEEPALIVE_LIFETIME = 2 * 60 * 1000;
// Communicates using the address on the outside of a NAT. // Communicates using the address on the outside of a NAT.
class UDPPort : public Port { class UDPPort : public Port {
public: public:
static UDPPort* Create(rtc::Thread* thread, static std::unique_ptr<UDPPort> Create(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
rtc::Network* network, rtc::Network* network,
rtc::AsyncPacketSocket* socket, rtc::AsyncPacketSocket* socket,
@ -44,17 +45,19 @@ class UDPPort : public Port {
const std::string& origin, const std::string& origin,
bool emit_local_for_anyaddress, bool emit_local_for_anyaddress,
absl::optional<int> stun_keepalive_interval) { absl::optional<int> stun_keepalive_interval) {
UDPPort* port = new UDPPort(thread, factory, network, socket, username, // Using `new` to access a non-public constructor.
password, origin, emit_local_for_anyaddress); auto port = absl::WrapUnique(new UDPPort(thread, factory, network, socket,
username, password, origin,
emit_local_for_anyaddress));
port->set_stun_keepalive_delay(stun_keepalive_interval); port->set_stun_keepalive_delay(stun_keepalive_interval);
if (!port->Init()) { if (!port->Init()) {
delete port; return nullptr;
port = NULL;
} }
return port; return port;
} }
static UDPPort* Create(rtc::Thread* thread, static std::unique_ptr<UDPPort> Create(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
rtc::Network* network, rtc::Network* network,
uint16_t min_port, uint16_t min_port,
@ -64,13 +67,13 @@ class UDPPort : public Port {
const std::string& origin, const std::string& origin,
bool emit_local_for_anyaddress, bool emit_local_for_anyaddress,
absl::optional<int> stun_keepalive_interval) { absl::optional<int> stun_keepalive_interval) {
UDPPort* port = // Using `new` to access a non-public constructor.
auto port = absl::WrapUnique(
new UDPPort(thread, factory, network, min_port, max_port, username, new UDPPort(thread, factory, network, min_port, max_port, username,
password, origin, emit_local_for_anyaddress); password, origin, emit_local_for_anyaddress));
port->set_stun_keepalive_delay(stun_keepalive_interval); port->set_stun_keepalive_delay(stun_keepalive_interval);
if (!port->Init()) { if (!port->Init()) {
delete port; return nullptr;
port = NULL;
} }
return port; return port;
} }
@ -262,7 +265,8 @@ class UDPPort : public Port {
class StunPort : public UDPPort { class StunPort : public UDPPort {
public: public:
static StunPort* Create(rtc::Thread* thread, static std::unique_ptr<StunPort> Create(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
rtc::Network* network, rtc::Network* network,
uint16_t min_port, uint16_t min_port,

View File

@ -75,10 +75,10 @@ class StunPortTestBase : public testing::Test, public sigslot::has_slots<> {
} }
void CreateStunPort(const ServerAddresses& stun_servers) { void CreateStunPort(const ServerAddresses& stun_servers) {
stun_port_.reset(cricket::StunPort::Create( stun_port_ = cricket::StunPort::Create(
rtc::Thread::Current(), &socket_factory_, &network_, 0, 0, rtc::Thread::Current(), &socket_factory_, &network_, 0, 0,
rtc::CreateRandomString(16), rtc::CreateRandomString(22), stun_servers, rtc::CreateRandomString(16), rtc::CreateRandomString(22), stun_servers,
std::string(), absl::nullopt)); std::string(), absl::nullopt);
stun_port_->set_stun_keepalive_delay(stun_keepalive_delay_); stun_port_->set_stun_keepalive_delay(stun_keepalive_delay_);
// If |stun_keepalive_lifetime_| is negative, let the stun port // If |stun_keepalive_lifetime_| is negative, let the stun port
// choose its lifetime from the network type. // choose its lifetime from the network type.
@ -100,10 +100,10 @@ class StunPortTestBase : public testing::Test, public sigslot::has_slots<> {
} }
ASSERT_TRUE(socket_ != NULL); ASSERT_TRUE(socket_ != NULL);
socket_->SignalReadPacket.connect(this, &StunPortTestBase::OnReadPacket); socket_->SignalReadPacket.connect(this, &StunPortTestBase::OnReadPacket);
stun_port_.reset(cricket::UDPPort::Create( stun_port_ = cricket::UDPPort::Create(
rtc::Thread::Current(), &socket_factory_, &network_, socket_.get(), rtc::Thread::Current(), &socket_factory_, &network_, socket_.get(),
rtc::CreateRandomString(16), rtc::CreateRandomString(22), std::string(), rtc::CreateRandomString(16), rtc::CreateRandomString(22), std::string(),
false, absl::nullopt)); false, absl::nullopt);
ASSERT_TRUE(stun_port_ != NULL); ASSERT_TRUE(stun_port_ != NULL);
ServerAddresses stun_servers; ServerAddresses stun_servers;
stun_servers.insert(server_addr); stun_servers.insert(server_addr);

View File

@ -30,7 +30,7 @@ class TCPConnection;
// call this TCPPort::OnReadPacket (3 arg) to dispatch to a connection. // call this TCPPort::OnReadPacket (3 arg) to dispatch to a connection.
class TCPPort : public Port { class TCPPort : public Port {
public: public:
static TCPPort* Create(rtc::Thread* thread, static std::unique_ptr<TCPPort> Create(rtc::Thread* thread,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
rtc::Network* network, rtc::Network* network,
uint16_t min_port, uint16_t min_port,
@ -38,8 +38,10 @@ class TCPPort : public Port {
const std::string& username, const std::string& username,
const std::string& password, const std::string& password,
bool allow_listen) { bool allow_listen) {
return new TCPPort(thread, factory, network, min_port, max_port, username, // Using `new` to access a non-public constructor.
password, allow_listen); return absl::WrapUnique(new TCPPort(thread, factory, network, min_port,
max_port, username, password,
allow_listen));
} }
~TCPPort() override; ~TCPPort() override;

View File

@ -14,6 +14,7 @@
#include <stdio.h> #include <stdio.h>
#include <list> #include <list>
#include <map> #include <map>
#include <memory>
#include <set> #include <set>
#include <string> #include <string>
#include <vector> #include <vector>
@ -50,6 +51,8 @@ class TurnPort : public Port {
// packets. // packets.
}; };
// Create a TURN port using the shared UDP socket, |socket|. // Create a TURN port using the shared UDP socket, |socket|.
// TODO(steveanton): Change to unique_ptr once downstream clients have
// converted.
static TurnPort* Create(rtc::Thread* thread, static TurnPort* Create(rtc::Thread* thread,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
rtc::Network* network, rtc::Network* network,
@ -61,13 +64,33 @@ class TurnPort : public Port {
int server_priority, int server_priority,
const std::string& origin, const std::string& origin,
webrtc::TurnCustomizer* customizer) { webrtc::TurnCustomizer* customizer) {
return new TurnPort(thread, factory, network, socket, username, password, return CreateUnique(thread, factory, network, socket, username, password,
server_address, credentials, server_priority, origin, server_address, credentials, server_priority, origin,
customizer); customizer)
.release();
}
static std::unique_ptr<TurnPort> CreateUnique(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
rtc::AsyncPacketSocket* socket,
const std::string& username, // ice username.
const std::string& password, // ice password.
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
const std::string& origin,
webrtc::TurnCustomizer* customizer) {
// Using `new` to access a non-public constructor.
return absl::WrapUnique(new TurnPort(
thread, factory, network, socket, username, password, server_address,
credentials, server_priority, origin, customizer));
} }
// Create a TURN port that will use a new socket, bound to |network| and // Create a TURN port that will use a new socket, bound to |network| and
// using a port in the range between |min_port| and |max_port|. // using a port in the range between |min_port| and |max_port|.
// TODO(steveanton): Change to unique_ptr once downstream clients have
// converted.
static TurnPort* Create( static TurnPort* Create(
rtc::Thread* thread, rtc::Thread* thread,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
@ -84,10 +107,35 @@ class TurnPort : public Port {
const std::vector<std::string>& tls_elliptic_curves, const std::vector<std::string>& tls_elliptic_curves,
webrtc::TurnCustomizer* customizer, webrtc::TurnCustomizer* customizer,
rtc::SSLCertificateVerifier* tls_cert_verifier = nullptr) { rtc::SSLCertificateVerifier* tls_cert_verifier = nullptr) {
return new TurnPort(thread, factory, network, min_port, max_port, username, // Using `new` to access a non-public constructor.
return CreateUnique(thread, factory, network, min_port, max_port, username,
password, server_address, credentials, server_priority, password, server_address, credentials, server_priority,
origin, tls_alpn_protocols, tls_elliptic_curves, origin, tls_alpn_protocols, tls_elliptic_curves,
customizer, tls_cert_verifier); customizer, tls_cert_verifier)
.release();
}
static std::unique_ptr<TurnPort> CreateUnique(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username, // ice username.
const std::string& password, // ice password.
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
const std::string& origin,
const std::vector<std::string>& tls_alpn_protocols,
const std::vector<std::string>& tls_elliptic_curves,
webrtc::TurnCustomizer* customizer,
rtc::SSLCertificateVerifier* tls_cert_verifier = nullptr) {
// Using `new` to access a non-public constructor.
return absl::WrapUnique(
new TurnPort(thread, factory, network, min_port, max_port, username,
password, server_address, credentials, server_priority,
origin, tls_alpn_protocols, tls_elliptic_curves,
customizer, tls_cert_verifier));
} }
~TurnPort() override; ~TurnPort() override;

View File

@ -270,10 +270,9 @@ class TurnPortTest : public testing::Test,
const ProtocolAddress& server_address, const ProtocolAddress& server_address,
const std::string& origin) { const std::string& origin) {
RelayCredentials credentials(username, password); RelayCredentials credentials(username, password);
turn_port_.reset(TurnPort::Create( turn_port_ = TurnPort::CreateUnique(
&main_, &socket_factory_, network, 0, 0, kIceUfrag1, kIcePwd1, &main_, &socket_factory_, network, 0, 0, kIceUfrag1, kIcePwd1,
server_address, credentials, 0, origin, std::vector<std::string>(), server_address, credentials, 0, origin, {}, {}, turn_customizer_.get());
std::vector<std::string>(), turn_customizer_.get()));
// This TURN port will be the controlling. // This TURN port will be the controlling.
turn_port_->SetIceRole(ICEROLE_CONTROLLING); turn_port_->SetIceRole(ICEROLE_CONTROLLING);
ConnectSignals(); ConnectSignals();
@ -301,10 +300,10 @@ class TurnPortTest : public testing::Test,
} }
RelayCredentials credentials(username, password); RelayCredentials credentials(username, password);
turn_port_.reset(TurnPort::Create(&main_, &socket_factory_, turn_port_ = TurnPort::CreateUnique(&main_, &socket_factory_,
MakeNetwork(kLocalAddr1), socket_.get(), MakeNetwork(kLocalAddr1), socket_.get(),
kIceUfrag1, kIcePwd1, server_address, kIceUfrag1, kIcePwd1, server_address,
credentials, 0, std::string(), nullptr)); credentials, 0, std::string(), nullptr);
// This TURN port will be the controlling. // This TURN port will be the controlling.
turn_port_->SetIceRole(ICEROLE_CONTROLLING); turn_port_->SetIceRole(ICEROLE_CONTROLLING);
ConnectSignals(); ConnectSignals();
@ -329,9 +328,9 @@ class TurnPortTest : public testing::Test,
void CreateUdpPort() { CreateUdpPort(kLocalAddr2); } void CreateUdpPort() { CreateUdpPort(kLocalAddr2); }
void CreateUdpPort(const SocketAddress& address) { void CreateUdpPort(const SocketAddress& address) {
udp_port_.reset(UDPPort::Create( udp_port_ = UDPPort::Create(&main_, &socket_factory_, MakeNetwork(address),
&main_, &socket_factory_, MakeNetwork(address), 0, 0, kIceUfrag2, 0, 0, kIceUfrag2, kIcePwd2, std::string(),
kIcePwd2, std::string(), false, absl::nullopt)); false, absl::nullopt);
// UDP port will be controlled. // UDP port will be controlled.
udp_port_->SetIceRole(ICEROLE_CONTROLLED); udp_port_->SetIceRole(ICEROLE_CONTROLLED);
udp_port_->SignalPortComplete.connect(this, udp_port_->SignalPortComplete.connect(this,

View File

@ -1362,7 +1362,7 @@ void AllocationSequence::CreateUDPPorts() {
// TODO(mallinath) - Remove UDPPort creating socket after shared socket // TODO(mallinath) - Remove UDPPort creating socket after shared socket
// is enabled completely. // is enabled completely.
UDPPort* port = NULL; std::unique_ptr<UDPPort> port;
bool emit_local_candidate_for_anyaddress = bool emit_local_candidate_for_anyaddress =
!IsFlagSet(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); !IsFlagSet(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE);
if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && udp_socket_) { if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET) && udp_socket_) {
@ -1384,7 +1384,7 @@ void AllocationSequence::CreateUDPPorts() {
// If shared socket is enabled, STUN candidate will be allocated by the // If shared socket is enabled, STUN candidate will be allocated by the
// UDPPort. // UDPPort.
if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) { if (IsFlagSet(PORTALLOCATOR_ENABLE_SHARED_SOCKET)) {
udp_port_ = port; udp_port_ = port.get();
port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed); port->SignalDestroyed.connect(this, &AllocationSequence::OnPortDestroyed);
// If STUN is not disabled, setting stun server address to port. // If STUN is not disabled, setting stun server address to port.
@ -1398,7 +1398,7 @@ void AllocationSequence::CreateUDPPorts() {
} }
} }
session_->AddAllocatedPort(port, this, true); session_->AddAllocatedPort(port.release(), this, true);
} }
} }
@ -1408,13 +1408,13 @@ void AllocationSequence::CreateTCPPorts() {
return; return;
} }
Port* port = TCPPort::Create( std::unique_ptr<Port> port = TCPPort::Create(
session_->network_thread(), session_->socket_factory(), network_, session_->network_thread(), session_->socket_factory(), network_,
session_->allocator()->min_port(), session_->allocator()->max_port(), session_->allocator()->min_port(), session_->allocator()->max_port(),
session_->username(), session_->password(), session_->username(), session_->password(),
session_->allocator()->allow_tcp_listen()); session_->allocator()->allow_tcp_listen());
if (port) { if (port) {
session_->AddAllocatedPort(port, this, true); session_->AddAllocatedPort(port.release(), this, true);
// Since TCPPort is not created using shared socket, |port| will not be // Since TCPPort is not created using shared socket, |port| will not be
// added to the dequeue. // added to the dequeue.
} }
@ -1436,14 +1436,14 @@ void AllocationSequence::CreateStunPorts() {
return; return;
} }
StunPort* port = StunPort::Create( std::unique_ptr<StunPort> port = StunPort::Create(
session_->network_thread(), session_->socket_factory(), network_, session_->network_thread(), session_->socket_factory(), network_,
session_->allocator()->min_port(), session_->allocator()->max_port(), session_->allocator()->min_port(), session_->allocator()->max_port(),
session_->username(), session_->password(), config_->StunServers(), session_->username(), session_->password(), config_->StunServers(),
session_->allocator()->origin(), session_->allocator()->origin(),
session_->allocator()->stun_candidate_keepalive_interval()); session_->allocator()->stun_candidate_keepalive_interval());
if (port) { if (port) {
session_->AddAllocatedPort(port, this, true); session_->AddAllocatedPort(port.release(), this, true);
// Since StunPort is not created using shared socket, |port| will not be // Since StunPort is not created using shared socket, |port| will not be
// added to the dequeue. // added to the dequeue.
} }
@ -1479,11 +1479,12 @@ void AllocationSequence::CreateRelayPorts() {
void AllocationSequence::CreateGturnPort(const RelayServerConfig& config) { void AllocationSequence::CreateGturnPort(const RelayServerConfig& config) {
// TODO(mallinath) - Rename RelayPort to GTurnPort. // TODO(mallinath) - Rename RelayPort to GTurnPort.
RelayPort* port = RelayPort::Create( std::unique_ptr<RelayPort> port = RelayPort::Create(
session_->network_thread(), session_->socket_factory(), network_, session_->network_thread(), session_->socket_factory(), network_,
session_->allocator()->min_port(), session_->allocator()->max_port(), session_->allocator()->min_port(), session_->allocator()->max_port(),
config_->username, config_->password); config_->username, config_->password);
if (port) { if (port) {
RelayPort* port_ptr = port.release();
// Since RelayPort is not created using shared socket, |port| will not be // Since RelayPort is not created using shared socket, |port| will not be
// added to the dequeue. // added to the dequeue.
// Note: We must add the allocated port before we add addresses because // Note: We must add the allocated port before we add addresses because
@ -1491,17 +1492,17 @@ void AllocationSequence::CreateGturnPort(const RelayServerConfig& config) {
// settings. However, we also can't prepare the address (normally // settings. However, we also can't prepare the address (normally
// done by AddAllocatedPort) until we have these addresses. So we // done by AddAllocatedPort) until we have these addresses. So we
// wait to do that until below. // wait to do that until below.
session_->AddAllocatedPort(port, this, false); session_->AddAllocatedPort(port_ptr, this, false);
// Add the addresses of this protocol. // Add the addresses of this protocol.
PortList::const_iterator relay_port; PortList::const_iterator relay_port;
for (relay_port = config.ports.begin(); relay_port != config.ports.end(); for (relay_port = config.ports.begin(); relay_port != config.ports.end();
++relay_port) { ++relay_port) {
port->AddServerAddress(*relay_port); port_ptr->AddServerAddress(*relay_port);
port->AddExternalAddress(*relay_port); port_ptr->AddExternalAddress(*relay_port);
} }
// Start fetching an address for this port. // Start fetching an address for this port.
port->PrepareAddress(); port_ptr->PrepareAddress();
} }
} }

View File

@ -11,6 +11,7 @@
#include "p2p/client/turnportfactory.h" #include "p2p/client/turnportfactory.h"
#include <memory> #include <memory>
#include <utility>
#include "p2p/base/turnport.h" #include "p2p/base/turnport.h"
@ -21,26 +22,26 @@ TurnPortFactory::~TurnPortFactory() {}
std::unique_ptr<Port> TurnPortFactory::Create( std::unique_ptr<Port> TurnPortFactory::Create(
const CreateRelayPortArgs& args, const CreateRelayPortArgs& args,
rtc::AsyncPacketSocket* udp_socket) { rtc::AsyncPacketSocket* udp_socket) {
TurnPort* port = TurnPort::Create( auto port = TurnPort::CreateUnique(
args.network_thread, args.socket_factory, args.network, udp_socket, args.network_thread, args.socket_factory, args.network, udp_socket,
args.username, args.password, *args.server_address, args.username, args.password, *args.server_address,
args.config->credentials, args.config->priority, args.origin, args.config->credentials, args.config->priority, args.origin,
args.turn_customizer); args.turn_customizer);
port->SetTlsCertPolicy(args.config->tls_cert_policy); port->SetTlsCertPolicy(args.config->tls_cert_policy);
return std::unique_ptr<Port>(port); return std::move(port);
} }
std::unique_ptr<Port> TurnPortFactory::Create(const CreateRelayPortArgs& args, std::unique_ptr<Port> TurnPortFactory::Create(const CreateRelayPortArgs& args,
int min_port, int min_port,
int max_port) { int max_port) {
TurnPort* port = TurnPort::Create( auto port = TurnPort::CreateUnique(
args.network_thread, args.socket_factory, args.network, min_port, args.network_thread, args.socket_factory, args.network, min_port,
max_port, args.username, args.password, *args.server_address, max_port, args.username, args.password, *args.server_address,
args.config->credentials, args.config->priority, args.origin, args.config->credentials, args.config->priority, args.origin,
args.config->tls_alpn_protocols, args.config->tls_elliptic_curves, args.config->tls_alpn_protocols, args.config->tls_elliptic_curves,
args.turn_customizer, args.config->tls_cert_verifier); args.turn_customizer, args.config->tls_cert_verifier);
port->SetTlsCertPolicy(args.config->tls_cert_policy); port->SetTlsCertPolicy(args.config->tls_cert_policy);
return std::unique_ptr<Port>(port); return std::move(port);
} }
} // namespace cricket } // namespace cricket