Use uint16s for port numbers in webrtc/p2p/base.

This is a necessary precursor to using uint16s for port numbers more
consistently in Chromium code.

This also makes some minor formatting changes in surrounding code (function declaration wrapping, virtual -> override).

BUG=chromium:81439
TEST=none
R=henrike@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/32379004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7656 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pkasting@chromium.org 2014-11-06 20:19:22 +00:00
parent d89b69aade
commit 332331fb01
14 changed files with 182 additions and 111 deletions

View File

@ -44,7 +44,7 @@ BasicPacketSocketFactory::~BasicPacketSocketFactory() {
}
AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket(
const SocketAddress& address, int min_port, int max_port) {
const SocketAddress& address, uint16 min_port, uint16 max_port) {
// UDP sockets are simple.
rtc::AsyncSocket* socket =
socket_factory()->CreateAsyncSocket(
@ -62,7 +62,8 @@ AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket(
}
AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket(
const SocketAddress& local_address, int min_port, int max_port, int opts) {
const SocketAddress& local_address, uint16 min_port, uint16 max_port,
int opts) {
// Fail if TLS is required.
if (opts & PacketSocketFactory::OPT_TLS) {
@ -177,7 +178,7 @@ AsyncResolverInterface* BasicPacketSocketFactory::CreateAsyncResolver() {
int BasicPacketSocketFactory::BindSocket(
AsyncSocket* socket, const SocketAddress& local_address,
int min_port, int max_port) {
uint16 min_port, uint16 max_port) {
int ret = -1;
if (min_port == 0 && max_port == 0) {
// If there's no port range, let the OS pick a port for us.

View File

@ -24,21 +24,28 @@ class BasicPacketSocketFactory : public PacketSocketFactory {
BasicPacketSocketFactory();
explicit BasicPacketSocketFactory(Thread* thread);
explicit BasicPacketSocketFactory(SocketFactory* socket_factory);
virtual ~BasicPacketSocketFactory();
~BasicPacketSocketFactory() override;
virtual AsyncPacketSocket* CreateUdpSocket(
const SocketAddress& local_address, int min_port, int max_port);
virtual AsyncPacketSocket* CreateServerTcpSocket(
const SocketAddress& local_address, int min_port, int max_port, int opts);
virtual AsyncPacketSocket* CreateClientTcpSocket(
const SocketAddress& local_address, const SocketAddress& remote_address,
const ProxyInfo& proxy_info, const std::string& user_agent, int opts);
AsyncPacketSocket* CreateUdpSocket(const SocketAddress& local_address,
uint16 min_port,
uint16 max_port) override;
AsyncPacketSocket* CreateServerTcpSocket(const SocketAddress& local_address,
uint16 min_port,
uint16 max_port,
int opts) override;
AsyncPacketSocket* CreateClientTcpSocket(const SocketAddress& local_address,
const SocketAddress& remote_address,
const ProxyInfo& proxy_info,
const std::string& user_agent,
int opts) override;
virtual AsyncResolverInterface* CreateAsyncResolver();
AsyncResolverInterface* CreateAsyncResolver() override;
private:
int BindSocket(AsyncSocket* socket, const SocketAddress& local_address,
int min_port, int max_port);
int BindSocket(AsyncSocket* socket,
const SocketAddress& local_address,
uint16 min_port,
uint16 max_port);
SocketFactory* socket_factory();

View File

@ -29,17 +29,23 @@ class PacketSocketFactory {
PacketSocketFactory() { }
virtual ~PacketSocketFactory() { }
virtual AsyncPacketSocket* CreateUdpSocket(
const SocketAddress& address, int min_port, int max_port) = 0;
virtual AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address,
uint16 min_port,
uint16 max_port) = 0;
virtual AsyncPacketSocket* CreateServerTcpSocket(
const SocketAddress& local_address, int min_port, int max_port,
const SocketAddress& local_address,
uint16 min_port,
uint16 max_port,
int opts) = 0;
// TODO: |proxy_info| and |user_agent| should be set
// per-factory and not when socket is created.
virtual AsyncPacketSocket* CreateClientTcpSocket(
const SocketAddress& local_address, const SocketAddress& remote_address,
const ProxyInfo& proxy_info, const std::string& user_agent, int opts) = 0;
const SocketAddress& local_address,
const SocketAddress& remote_address,
const ProxyInfo& proxy_info,
const std::string& user_agent,
int opts) = 0;
virtual AsyncResolverInterface* CreateAsyncResolver() = 0;

View File

@ -152,9 +152,12 @@ static std::string ComputeFoundation(
return rtc::ToString<uint32>(rtc::ComputeCrc32(ost.str()));
}
Port::Port(rtc::Thread* thread, rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
const std::string& username_fragment, const std::string& password)
Port::Port(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
const std::string& username_fragment,
const std::string& password)
: thread_(thread),
factory_(factory),
send_retransmit_count_attribute_(false),
@ -176,10 +179,14 @@ Port::Port(rtc::Thread* thread, rtc::PacketSocketFactory* factory,
Construct();
}
Port::Port(rtc::Thread* thread, const std::string& type,
Port::Port(rtc::Thread* thread,
const std::string& type,
rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
int min_port, int max_port, const std::string& username_fragment,
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username_fragment,
const std::string& password)
: thread_(thread),
factory_(factory),

View File

@ -107,13 +107,20 @@ typedef std::set<rtc::SocketAddress> ServerAddresses;
class Port : public PortInterface, public rtc::MessageHandler,
public sigslot::has_slots<> {
public:
Port(rtc::Thread* thread, rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
const std::string& username_fragment, const std::string& password);
Port(rtc::Thread* thread, const std::string& type,
Port(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
int min_port, int max_port, const std::string& username_fragment,
rtc::Network* network,
const rtc::IPAddress& ip,
const std::string& username_fragment,
const std::string& password);
Port(rtc::Thread* thread,
const std::string& type,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username_fragment,
const std::string& password);
virtual ~Port();
@ -256,8 +263,8 @@ class Port : public PortInterface, public rtc::MessageHandler,
// Debugging description of this port
virtual std::string ToString() const;
rtc::IPAddress& ip() { return ip_; }
int min_port() { return min_port_; }
int max_port() { return max_port_; }
uint16 min_port() { return min_port_; }
uint16 max_port() { return max_port_; }
// Timeout shortening function to speed up unit tests.
void set_timeout_delay(int delay) { timeout_delay_ = delay; }
@ -354,8 +361,8 @@ class Port : public PortInterface, public rtc::MessageHandler,
bool send_retransmit_count_attribute_;
rtc::Network* network_;
rtc::IPAddress ip_;
int min_port_;
int max_port_;
uint16 min_port_;
uint16 max_port_;
std::string content_name_;
int component_;
uint32 generation_;

View File

@ -100,12 +100,17 @@ static bool WriteStunMessage(const StunMessage* msg, ByteBuffer* buf) {
// Stub port class for testing STUN generation and processing.
class TestPort : public Port {
public:
TestPort(rtc::Thread* thread, const std::string& type,
rtc::PacketSocketFactory* factory, rtc::Network* network,
const rtc::IPAddress& ip, int min_port, int max_port,
const std::string& username_fragment, const std::string& password)
: Port(thread, type, factory, network, ip,
min_port, max_port, username_fragment, password) {
TestPort(rtc::Thread* thread,
const std::string& type,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username_fragment,
const std::string& password)
: Port(thread, type, factory, network, ip, min_port, max_port,
username_fragment, password) {
}
~TestPort() {}
@ -762,19 +767,21 @@ class FakePacketSocketFactory : public rtc::PacketSocketFactory {
next_server_tcp_socket_(NULL),
next_client_tcp_socket_(NULL) {
}
virtual ~FakePacketSocketFactory() { }
~FakePacketSocketFactory() override { }
virtual AsyncPacketSocket* CreateUdpSocket(
const SocketAddress& address, int min_port, int max_port) {
AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address,
uint16 min_port,
uint16 max_port) override {
EXPECT_TRUE(next_udp_socket_ != NULL);
AsyncPacketSocket* result = next_udp_socket_;
next_udp_socket_ = NULL;
return result;
}
virtual AsyncPacketSocket* CreateServerTcpSocket(
const SocketAddress& local_address, int min_port, int max_port,
int opts) {
AsyncPacketSocket* CreateServerTcpSocket(const SocketAddress& local_address,
uint16 min_port,
uint16 max_port,
int opts) override {
EXPECT_TRUE(next_server_tcp_socket_ != NULL);
AsyncPacketSocket* result = next_server_tcp_socket_;
next_server_tcp_socket_ = NULL;
@ -783,10 +790,11 @@ class FakePacketSocketFactory : public rtc::PacketSocketFactory {
// TODO: |proxy_info| and |user_agent| should be set
// per-factory and not when socket is created.
virtual AsyncPacketSocket* CreateClientTcpSocket(
const SocketAddress& local_address, const SocketAddress& remote_address,
const rtc::ProxyInfo& proxy_info,
const std::string& user_agent, int opts) {
AsyncPacketSocket* CreateClientTcpSocket(const SocketAddress& local_address,
const SocketAddress& remote_address,
const rtc::ProxyInfo& proxy_info,
const std::string& user_agent,
int opts) override {
EXPECT_TRUE(next_client_tcp_socket_ != NULL);
AsyncPacketSocket* result = next_client_tcp_socket_;
next_client_tcp_socket_ = NULL;

View File

@ -172,11 +172,14 @@ class AllocateRequest : public StunRequest {
uint32 start_time_;
};
RelayPort::RelayPort(
rtc::Thread* thread, rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
int min_port, int max_port, const std::string& username,
const std::string& password)
RelayPort::RelayPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password)
: Port(thread, RELAY_PORT_TYPE, factory, network, ip, min_port, max_port,
username, password),
ready_(false),

View File

@ -36,9 +36,13 @@ class RelayPort : public Port {
// RelayPort doesn't yet do anything fancy in the ctor.
static RelayPort* Create(
rtc::Thread* thread, rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
int min_port, int max_port, const std::string& username,
rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password) {
return new RelayPort(thread, factory, network, ip, min_port, max_port,
username, password);
@ -66,9 +70,13 @@ class RelayPort : public Port {
sigslot::signal1<const ProtocolAddress*> SignalSoftTimeout;
protected:
RelayPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory,
rtc::Network*, const rtc::IPAddress& ip,
int min_port, int max_port, const std::string& username,
RelayPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network*,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password);
bool Init();

View File

@ -162,7 +162,8 @@ UDPPort::UDPPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
rtc::AsyncPacketSocket* socket,
const std::string& username, const std::string& password)
const std::string& username,
const std::string& password)
: Port(thread, factory, network, socket->GetLocalAddress().ipaddr(),
username, password),
requests_(thread),
@ -175,8 +176,11 @@ UDPPort::UDPPort(rtc::Thread* thread,
UDPPort::UDPPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip, int min_port, int max_port,
const std::string& username, const std::string& password)
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password)
: Port(thread, LOCAL_PORT_TYPE, factory, network, ip, min_port, max_port,
username, password),
requests_(thread),

View File

@ -34,8 +34,8 @@ class UDPPort : public Port {
rtc::AsyncPacketSocket* socket,
const std::string& username,
const std::string& password) {
UDPPort* port = new UDPPort(thread, factory, network, socket,
username, password);
UDPPort* port =
new UDPPort(thread, factory, network, socket, username, password);
if (!port->Init()) {
delete port;
port = NULL;
@ -47,12 +47,12 @@ class UDPPort : public Port {
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
int min_port, int max_port,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password) {
UDPPort* port = new UDPPort(thread, factory, network,
ip, min_port, max_port,
username, password);
UDPPort* port = new UDPPort(thread, factory, network, ip, min_port,
max_port, username, password);
if (!port->Init()) {
delete port;
port = NULL;
@ -98,14 +98,21 @@ class UDPPort : public Port {
}
protected:
UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
int min_port, int max_port,
const std::string& username, const std::string& password);
UDPPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password);
UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory,
rtc::Network* network, rtc::AsyncPacketSocket* socket,
const std::string& username, const std::string& password);
UDPPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
rtc::AsyncPacketSocket* socket,
const std::string& username,
const std::string& password);
bool Init();
@ -194,18 +201,16 @@ class UDPPort : public Port {
class StunPort : public UDPPort {
public:
static StunPort* Create(
rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
int min_port, int max_port,
const std::string& username,
const std::string& password,
const ServerAddresses& servers) {
StunPort* port = new StunPort(thread, factory, network,
ip, min_port, max_port,
username, password, servers);
static StunPort* Create(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port, uint16 max_port,
const std::string& username,
const std::string& password,
const ServerAddresses& servers) {
StunPort* port = new StunPort(thread, factory, network, ip, min_port,
max_port, username, password, servers);
if (!port->Init()) {
delete port;
port = NULL;
@ -220,10 +225,14 @@ class StunPort : public UDPPort {
}
protected:
StunPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
int min_port, int max_port,
const std::string& username, const std::string& password,
StunPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password,
const ServerAddresses& servers)
: UDPPort(thread, factory, network, ip, min_port, max_port, username,
password) {

View File

@ -18,9 +18,13 @@ namespace cricket {
TCPPort::TCPPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
int min_port, int max_port, const std::string& username,
const std::string& password, bool allow_listen)
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password,
bool allow_listen)
: Port(thread, LOCAL_PORT_TYPE, factory, network, ip, min_port, max_port,
username, password),
incoming_only_(false),

View File

@ -32,13 +32,13 @@ class TCPPort : public Port {
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
int min_port, int max_port,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password,
bool allow_listen) {
TCPPort* port = new TCPPort(thread, factory, network,
ip, min_port, max_port,
username, password, allow_listen);
TCPPort* port = new TCPPort(thread, factory, network, ip, min_port,
max_port, username, password, allow_listen);
if (!port->Init()) {
delete port;
port = NULL;
@ -57,10 +57,15 @@ class TCPPort : public Port {
virtual int GetError();
protected:
TCPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory,
rtc::Network* network, const rtc::IPAddress& ip,
int min_port, int max_port, const std::string& username,
const std::string& password, bool allow_listen);
TCPPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password,
bool allow_listen);
bool Init();
// Handles sending using the local TCP socket.

View File

@ -184,7 +184,8 @@ TurnPort::TurnPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
int min_port, int max_port,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password,
const ProtocolAddress& server_address,

View File

@ -42,16 +42,16 @@ class TurnPort : public Port {
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority) {
return new TurnPort(thread, factory, network, socket,
username, password, server_address,
credentials, server_priority);
return new TurnPort(thread, factory, network, socket, username, password,
server_address, credentials, server_priority);
}
static TurnPort* Create(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
int min_port, int max_port,
uint16 min_port,
uint16 max_port,
const std::string& username, // ice username.
const std::string& password, // ice password.
const ProtocolAddress& server_address,
@ -135,7 +135,8 @@ class TurnPort : public Port {
rtc::PacketSocketFactory* factory,
rtc::Network* network,
const rtc::IPAddress& ip,
int min_port, int max_port,
uint16 min_port,
uint16 max_port,
const std::string& username,
const std::string& password,
const ProtocolAddress& server_address,