[tor-commits] [arm/master] Dropping getPortUsage() in favor of stem's capability

atagar at torproject.org atagar at torproject.org
Tue Jan 7 17:20:50 UTC 2014


commit d2c8b3ce477ff3509b0dc8bda70e93cf1d5ac7a4
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Jan 5 22:00:53 2014 -0800

    Dropping getPortUsage() in favor of stem's capability
    
    Removing our getPortUsage() method now that this functionality has been moved
    to stem. Sooo very close to finally dropping this connections util...
---
 arm/config/ports.cfg          |  312 -----------------------------------------
 arm/connections/connEntry.py  |    4 +-
 arm/connections/countPopup.py |    6 +-
 arm/util/connections.py       |   62 +-------
 4 files changed, 5 insertions(+), 379 deletions(-)

diff --git a/arm/config/ports.cfg b/arm/config/ports.cfg
deleted file mode 100644
index b82edd3..0000000
--- a/arm/config/ports.cfg
+++ /dev/null
@@ -1,312 +0,0 @@
-################################################################################
-#
-# Common usages for ports. This is based on...
-#
-#   https://secure.wikimedia.org/wikipedia/en/wiki/List_of_TCP_and_UDP_port_numbers
-#   http://isc.sans.edu/services.html
-#
-################################################################################
-
-port.label.1 TCPMUX
-port.label.2 CompressNET
-port.label.3 CompressNET
-port.label.5 RJE
-port.label.7 Echo
-port.label.9 Discard
-port.label.11 SYSTAT
-port.label.13 Daytime
-port.label.15 netstat
-port.label.17 QOTD
-port.label.18 MSP
-port.label.19 CHARGEN
-port.label.20 FTP
-port.label.21 FTP
-port.label.22 SSH
-port.label.23 Telnet
-port.label.24 Priv-mail
-port.label.25 SMTP
-port.label.34 RF
-port.label.35 Printer
-port.label.37 TIME
-port.label.39 RLP
-port.label.41 Graphics
-port.label.42 WINS
-port.label.43 WHOIS
-port.label.47 NI FTP
-port.label.49 TACACS
-port.label.50 Remote Mail
-port.label.51 IMP
-port.label.52 XNS
-port.label.53 DNS
-port.label.54 XNS
-port.label.55 ISI-GL
-port.label.56 RAP
-port.label.57 MTP
-port.label.58 XNS
-port.label.67 BOOTP
-port.label.68 BOOTP
-port.label.69 TFTP
-port.label.70 Gopher
-port.label.79 Finger
-port.label.80 HTTP
-port.label.81 HTTP Alternate
-port.label.82 Torpark
-port.label.83 MIT ML
-port.label.88 Kerberos
-port.label.90 dnsix
-port.label.99 WIP
-port.label.101 NIC
-port.label.102 ISO-TSAP
-port.label.104 ACR/NEMA
-port.label.105 CCSO
-port.label.107 Telnet
-port.label.108 SNA
-port.label.109 POP2
-port.label.110 POP3
-port.label.111 ONC RPC
-port.label.113 ident
-port.label.115 SFTP
-port.label.117 UUCP
-port.label.118 SQL
-port.label.119 NNTP
-port.label.123 NTP
-port.label.135 DCE
-port.label.137 NetBIOS
-port.label.138 NetBIOS
-port.label.139 NetBIOS
-port.label.143 IMAP
-port.label.152 BFTP
-port.label.153 SGMP
-port.label.156 SQL
-port.label.158 DMSP
-port.label.161 SNMP
-port.label.162 SNMPTRAP
-port.label.170 Print-srv
-port.label.177 XDMCP
-port.label.179 BGP
-port.label.194 IRC
-port.label.199 SMUX
-port.label.201 AppleTalk
-port.label.209 QMTP
-port.label.210 ANSI
-port.label.213 IPX
-port.label.218 MPP
-port.label.220 IMAP
-port.label.256 2DEV
-port.label.259 ESRO
-port.label.264 BGMP
-port.label.308 Novastor
-port.label.311 OSX Admin
-port.label.318 PKIX TSP
-port.label.319 PTP
-port.label.320 PTP
-port.label.323 IMMP
-port.label.350 MATIP
-port.label.351 MATIP
-port.label.366 ODMR
-port.label.369 Rpc2portmap
-port.label.370 codaauth2
-port.label.371 ClearCase
-port.label.383 HP Alarm Mgr
-port.label.384 ARNS
-port.label.387 AURP
-port.label.389 LDAP
-port.label.401 UPS
-port.label.402 Altiris
-port.label.427 SLP
-port.label.443 HTTPS
-port.label.444 SNPP
-port.label.445 SMB
-port.label.464 Kerberos (kpasswd)
-port.label.465 SMTP
-port.label.475 tcpnethaspsrv
-port.label.497 Retrospect
-port.label.500 ISAKMP
-port.label.501 STMF
-port.label.502 Modbus
-port.label.504 Citadel
-port.label.510 FirstClass
-port.label.512 Rexec
-port.label.513 rlogin
-port.label.514 rsh
-port.label.515 LPD
-port.label.517 Talk
-port.label.518 NTalk
-port.label.520 efs
-port.label.524 NCP
-port.label.530 RPC
-port.label.531 AIM/IRC
-port.label.532 netnews
-port.label.533 netwall
-port.label.540 UUCP
-port.label.542 commerce
-port.label.543 Kerberos (klogin)
-port.label.544 Kerberos (kshell)
-port.label.545 OSISoft PI
-port.label.546 DHCPv6
-port.label.547 DHCPv6
-port.label.548 AFP
-port.label.550 new-who
-port.label.554 RTSP
-port.label.556 RFS
-port.label.560 rmonitor
-port.label.561 monitor
-port.label.563 NNTPS
-port.label.587 SMTP
-port.label.591 FileMaker
-port.label.593 HTTP RPC
-port.label.604 TUNNEL
-port.label.623 ASF-RMCP
-port.label.631 CUPS
-port.label.635 RLZ DBase
-port.label.636 LDAPS
-port.label.639 MSDP
-port.label.641 SupportSoft
-port.label.646 LDP
-port.label.647 DHCP
-port.label.648 RRP
-port.label.651 IEEE-MMS
-port.label.652 DTCP
-port.label.653 SupportSoft
-port.label.654 MMS/MMP
-port.label.657 RMC
-port.label.660 OSX Admin
-port.label.665 sun-dr
-port.label.666 Doom
-port.label.674 ACAP
-port.label.691 MS Exchange
-port.label.692 Hyperwave-ISP
-port.label.694 Linux-HA
-port.label.695 IEEE-MMS-SSL
-port.label.698 OLSR
-port.label.699 Access Network
-port.label.700 EPP
-port.label.701 LMP
-port.label.702 IRIS
-port.label.706 SILC
-port.label.711 MPLS
-port.label.712 TBRPF
-port.label.720 SMQP
-port.label.749 Kerberos (admin)
-port.label.750 rfile
-port.label.751 pump
-port.label.752 qrh
-port.label.753 rrh
-port.label.754 tell send
-port.label.760 ns
-port.label.782 Conserver
-port.label.783 spamd
-port.label.829 CMP
-port.label.843 Flash
-port.label.847 DHCP
-port.label.860 iSCSI
-port.label.873 rsync
-port.label.888 CDDB
-port.label.901 SWAT
-port.label.902-904 VMware
-port.label.911 NCA
-port.label.953 DNS RNDC
-port.label.981 SofaWare Firewall
-port.label.989 FTPS
-port.label.990 FTPS
-port.label.991 NAS
-port.label.992 Telnet
-port.label.993 IMAPS
-port.label.994 IRC
-port.label.995 POP3S
-port.label.999 ScimoreDB
-port.label.1001 JtoMB
-port.label.1002 cogbot
-
-port.label.1080 SOCKS
-port.label.1085 WebObjects
-port.label.1109 KPOP
-port.label.1169 Tripwire
-port.label.1194 OpenVPN
-port.label.1214 Kazaa
-port.label.1220 QuickTime
-port.label.1234 VLC
-port.label.1241 Nessus
-port.label.1270 SCOM
-port.label.1293 IPSec
-port.label.1433 MSSQL
-port.label.1434 MSSQL
-port.label.1500 NetGuard
-port.label.1503 MSN
-port.label.1512 WINS
-port.label.1521 Oracle
-port.label.1526 Oracle
-port.label.1533 Sametime
-port.label.1666 Perforce
-port.label.1677 GroupWise
-port.label.1723 PPTP
-port.label.1725 Steam
-port.label.1863 MSNP
-port.label.2049 NFS
-port.label.2082 Infowave
-port.label.2083 radsec
-port.label.2086 GNUnet
-port.label.2087 ELI
-port.label.2095 NBX SER
-port.label.2096 NBX DIR
-port.label.2102-2104 Zephyr
-port.label.2401 CVS
-port.label.2525 SMTP
-port.label.2710 BitTorrent
-port.label.3074 XBox LIVE
-port.label.3101 BlackBerry
-port.label.3128 SQUID
-port.label.3306 MySQL
-port.label.3389 WBT
-port.label.3690 SVN
-port.label.3723 Battle.net
-port.label.3724 WoW
-port.label.4321 RWHOIS
-port.label.4643 Virtuozzo
-port.label.4662 eMule
-port.label.5003 FileMaker
-port.label.5050 Yahoo IM
-port.label.5060 SIP
-port.label.5061 SIP
-port.label.5190 AIM/ICQ
-port.label.5222 Jabber
-port.label.5223 Jabber
-port.label.5228 Android Market
-port.label.5269 Jabber
-port.label.5298 Jabber
-port.label.5432 PostgreSQL
-port.label.5500 VNC
-port.label.5556 Freeciv
-port.label.5666 NRPE
-port.label.5667 NSCA
-port.label.5800 VNC
-port.label.5900 VNC
-port.label.6346 gnutella
-port.label.6347 gnutella
-port.label.6660-6669 IRC
-port.label.6679 IRC
-port.label.6697 IRC
-port.label.6881-6999 BitTorrent
-port.label.8000 iRDMI
-port.label.8008 HTTP Alternate
-port.label.8010 XMPP
-port.label.8074 Gadu-Gadu
-port.label.8080 HTTP Proxy
-port.label.8087 SPP
-port.label.8088 Radan HTTP
-port.label.8118 Privoxy
-port.label.8123 Polipo
-port.label.8443 PCsync HTTPS
-port.label.8888 NewsEDGE
-port.label.9030 Tor
-port.label.9050 Tor
-port.label.9051 Tor
-port.label.9418 Git
-port.label.9999 distinct
-port.label.10000 Webmin
-port.label.19294 Google Voice
-port.label.19638 Ensim
-port.label.23399 Skype
-port.label.30301 BitTorrent
-port.label.33434 traceroute
-
diff --git a/arm/connections/connEntry.py b/arm/connections/connEntry.py
index 681f5ec..592eb7b 100644
--- a/arm/connections/connEntry.py
+++ b/arm/connections/connEntry.py
@@ -11,8 +11,6 @@ from arm.connections import entries
 
 from stem.util import conf, connection, enum, str_tools
 
-from arm.util.connections import getPortUsage
-
 # Connection Categories:
 #   Inbound      Relay connection, coming to us.
 #   Outbound     Relay connection, leaving us.
@@ -818,7 +816,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
       spaceAvailable = maxLength - len(dstAddress) - 3
 
       if self.getType() == Category.EXIT and includePort:
-        purpose = getPortUsage(self.foreign.getPort())
+        purpose = connection.port_usage(self.foreign.getPort())
 
         if purpose:
           # BitTorrent is a common protocol to truncate, so just use "Torrent"
diff --git a/arm/connections/countPopup.py b/arm/connections/countPopup.py
index 0c6d14a..5db8362 100644
--- a/arm/connections/countPopup.py
+++ b/arm/connections/countPopup.py
@@ -8,9 +8,9 @@ import operator
 import arm.controller
 import arm.popups
 
-from arm.util import connections, uiTools
+from arm.util import uiTools
 
-from stem.util import enum, log
+from stem.util import connection, enum, log
 
 CountType = enum.Enum("CLIENT_LOCALE", "EXIT_PORT")
 EXIT_USAGE_WIDTH = 15
@@ -74,7 +74,7 @@ def showCountDialog(countType, counts):
 
         # includes a port usage column
         if countType == CountType.EXIT_PORT:
-          usage = connections.getPortUsage(k)
+          usage = connection.port_usage(k)
 
           if usage:
             keyFormat = "%%-%is   %%s" % (keyWidth - EXIT_USAGE_WIDTH)
diff --git a/arm/util/connections.py b/arm/util/connections.py
index f4b107c..82ed62e 100644
--- a/arm/util/connections.py
+++ b/arm/util/connections.py
@@ -1,67 +1,7 @@
-"""
-Fetches connection data (IP addresses and ports) associated with a given
-process. This sort of data can be retrieved via a variety of common *nix
-utilities:
-- netstat   netstat -np | grep "ESTABLISHED <pid>/<process>"
-- sockstat  sockstat | egrep "<process> *<pid>.*ESTABLISHED"
-- lsof      lsof -wnPi | egrep "^<process> *<pid>.*((UDP.*)|(\(ESTABLISHED\)))"
-- ss        ss -nptu | grep "ESTAB.*\"<process>\",<pid>"
-
-all queries dump its stderr (directing it to /dev/null). Results include UDP
-and established TCP connections.
-
-FreeBSD lacks support for the needed netstat flags and has a completely
-different program for 'ss'. However, lsof works and there's a couple other
-options that perform even better (thanks to Fabian Keil and Hans Schnehl):
-- sockstat    sockstat -4c | grep '<process> *<pid>'
-- procstat    procstat -f <pid> | grep TCP | grep -v 0.0.0.0:0
-"""
-
 import os
 import threading
 
-from stem.util import conf, log, system
-
-def conf_handler(key, value):
-  if key.startswith("port.label."):
-    portEntry = key[11:]
-
-    divIndex = portEntry.find("-")
-    if divIndex == -1:
-      # single port
-      if portEntry.isdigit():
-        PORT_USAGE[portEntry] = value
-      else:
-        msg = "Port value isn't numeric for entry: %s" % key
-        log.notice(msg)
-    else:
-      try:
-        # range of ports (inclusive)
-        minPort = int(portEntry[:divIndex])
-        maxPort = int(portEntry[divIndex + 1:])
-        if minPort > maxPort: raise ValueError()
-
-        for port in range(minPort, maxPort + 1):
-          PORT_USAGE[str(port)] = value
-      except ValueError:
-        msg = "Unable to parse port range for entry: %s" % key
-        log.notice(msg)
-
-CONFIG = conf.config_dict('arm', {
-}, conf_handler)
-
-PORT_USAGE = {}
-
-def getPortUsage(port):
-  """
-  Provides the common use of a given port. If no useage is known then this
-  provides None.
-
-  Arguments:
-    port - port number to look up
-  """
-
-  return PORT_USAGE.get(port)
+from stem.util import system
 
 class AppResolver:
   """





More information about the tor-commits mailing list