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/webrtc@7656 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/p2p/base/basicpacketsocketfactory.cc b/p2p/base/basicpacketsocketfactory.cc
index 06dfe76..9b12e78 100644
--- a/p2p/base/basicpacketsocketfactory.cc
+++ b/p2p/base/basicpacketsocketfactory.cc
@@ -44,7 +44,7 @@
 }
 
 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::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 @@
 
 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 fb3a526..b23a677 100644
--- a/p2p/base/basicpacketsocketfactory.h
+++ b/p2p/base/basicpacketsocketfactory.h
@@ -24,21 +24,28 @@
   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();
 
diff --git a/p2p/base/packetsocketfactory.h b/p2p/base/packetsocketfactory.h
index 1f45fec..d2d7b1b 100644
--- a/p2p/base/packetsocketfactory.h
+++ b/p2p/base/packetsocketfactory.h
@@ -29,17 +29,23 @@
   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 f569d9f..a8357ad 100644
--- a/p2p/base/port.cc
+++ b/p2p/base/port.cc
@@ -152,9 +152,12 @@
   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 @@
   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 48b8530..87072e6 100644
--- a/p2p/base/port.h
+++ b/p2p/base/port.h
@@ -107,13 +107,20 @@
 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 @@
   // 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 @@
   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 8805709..f09db28 100644
--- a/p2p/base/port_unittest.cc
+++ b/p2p/base/port_unittest.cc
@@ -100,12 +100,17 @@
 // 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 @@
         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 @@
 
   // 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 4c40b3d..1a07f8f 100644
--- a/p2p/base/relayport.cc
+++ b/p2p/base/relayport.cc
@@ -172,11 +172,14 @@
   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 3d9538d..6297142 100644
--- a/p2p/base/relayport.h
+++ b/p2p/base/relayport.h
@@ -36,9 +36,13 @@
 
   // 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 @@
   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 ec6232a..5ef9e9e 100644
--- a/p2p/base/stunport.cc
+++ b/p2p/base/stunport.cc
@@ -162,7 +162,8 @@
                  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,
                  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 eda7bb9..9ca6046 100644
--- a/p2p/base/stunport.h
+++ b/p2p/base/stunport.h
@@ -34,8 +34,8 @@
                          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 @@
                          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 @@
   }
 
  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 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 @@
   }
 
  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 be3068b..b37f4d3 100644
--- a/p2p/base/tcpport.cc
+++ b/p2p/base/tcpport.cc
@@ -18,9 +18,13 @@
 
 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 43e4936..b3655a8 100644
--- a/p2p/base/tcpport.h
+++ b/p2p/base/tcpport.h
@@ -32,13 +32,13 @@
                          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 @@
   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 e7626fe..fbdcfeb 100644
--- a/p2p/base/turnport.cc
+++ b/p2p/base/turnport.cc
@@ -184,7 +184,8 @@
                    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 17fad17..4ed77a0 100644
--- a/p2p/base/turnport.h
+++ b/p2p/base/turnport.h
@@ -42,16 +42,16 @@
                           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 @@
            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,