diff options
Diffstat (limited to 'p2p/base')
-rw-r--r-- | p2p/base/basicpacketsocketfactory.cc | 7 | ||||
-rw-r--r-- | p2p/base/basicpacketsocketfactory.h | 33 | ||||
-rw-r--r-- | p2p/base/packetsocketfactory.h | 16 | ||||
-rw-r--r-- | p2p/base/port.cc | 19 | ||||
-rw-r--r-- | p2p/base/port.h | 27 | ||||
-rw-r--r-- | p2p/base/port_unittest.cc | 40 | ||||
-rw-r--r-- | p2p/base/relayport.cc | 13 | ||||
-rw-r--r-- | p2p/base/relayport.h | 20 | ||||
-rw-r--r-- | p2p/base/stunport.cc | 10 | ||||
-rw-r--r-- | p2p/base/stunport.h | 69 | ||||
-rw-r--r-- | p2p/base/tcpport.cc | 10 | ||||
-rw-r--r-- | p2p/base/tcpport.h | 21 | ||||
-rw-r--r-- | p2p/base/turnport.cc | 3 | ||||
-rw-r--r-- | p2p/base/turnport.h | 11 |
14 files changed, 185 insertions, 114 deletions
diff --git a/p2p/base/basicpacketsocketfactory.cc b/p2p/base/basicpacketsocketfactory.cc index 06dfe76e..9b12e78d 100644 --- a/p2p/base/basicpacketsocketfactory.cc +++ b/p2p/base/basicpacketsocketfactory.cc @@ -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. diff --git a/p2p/base/basicpacketsocketfactory.h b/p2p/base/basicpacketsocketfactory.h index fb3a5269..b23a6772 100644 --- a/p2p/base/basicpacketsocketfactory.h +++ b/p2p/base/basicpacketsocketfactory.h @@ -24,21 +24,28 @@ class BasicPacketSocketFactory : public PacketSocketFactory { BasicPacketSocketFactory(); explicit BasicPacketSocketFactory(Thread* thread); explicit BasicPacketSocketFactory(SocketFactory* socket_factory); - virtual ~BasicPacketSocketFactory(); - - 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); - - virtual AsyncResolverInterface* CreateAsyncResolver(); + ~BasicPacketSocketFactory() override; + + 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; + + 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(); diff --git a/p2p/base/packetsocketfactory.h b/p2p/base/packetsocketfactory.h index 1f45feca..d2d7b1b1 100644 --- a/p2p/base/packetsocketfactory.h +++ b/p2p/base/packetsocketfactory.h @@ -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; diff --git a/p2p/base/port.cc b/p2p/base/port.cc index f569d9f5..a8357ad6 100644 --- a/p2p/base/port.cc +++ b/p2p/base/port.cc @@ -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), diff --git a/p2p/base/port.h b/p2p/base/port.h index 48b85302..87072e67 100644 --- a/p2p/base/port.h +++ b/p2p/base/port.h @@ -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_; diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc index 8805709a..f09db284 100644 --- a/p2p/base/port_unittest.cc +++ b/p2p/base/port_unittest.cc @@ -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; diff --git a/p2p/base/relayport.cc b/p2p/base/relayport.cc index 4c40b3da..1a07f8fe 100644 --- a/p2p/base/relayport.cc +++ b/p2p/base/relayport.cc @@ -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), diff --git a/p2p/base/relayport.h b/p2p/base/relayport.h index 3d9538da..62971426 100644 --- a/p2p/base/relayport.h +++ b/p2p/base/relayport.h @@ -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(); diff --git a/p2p/base/stunport.cc b/p2p/base/stunport.cc index ec6232a6..5ef9e9ea 100644 --- a/p2p/base/stunport.cc +++ b/p2p/base/stunport.cc @@ -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), diff --git a/p2p/base/stunport.h b/p2p/base/stunport.h index eda7bb90..9ca60462 100644 --- a/p2p/base/stunport.h +++ b/p2p/base/stunport.h @@ -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, rtc::AsyncPacketSocket* socket, - 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); 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) { diff --git a/p2p/base/tcpport.cc b/p2p/base/tcpport.cc index be3068be..b37f4d3f 100644 --- a/p2p/base/tcpport.cc +++ b/p2p/base/tcpport.cc @@ -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), diff --git a/p2p/base/tcpport.h b/p2p/base/tcpport.h index 43e49366..b3655a80 100644 --- a/p2p/base/tcpport.h +++ b/p2p/base/tcpport.h @@ -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. diff --git a/p2p/base/turnport.cc b/p2p/base/turnport.cc index e7626fe0..fbdcfeb6 100644 --- a/p2p/base/turnport.cc +++ b/p2p/base/turnport.cc @@ -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, diff --git a/p2p/base/turnport.h b/p2p/base/turnport.h index 17fad176..4ed77a0c 100644 --- a/p2p/base/turnport.h +++ b/p2p/base/turnport.h @@ -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, |