[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Making use of stem's is_private_address()



commit 47c55e2bca002ee9dab805ca3762f46112f60f0a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Sep 21 17:53:53 2013 -0700

    Making use of stem's is_private_address()
    
    Dropping our isIpAddressPrivate() in favor of stem's new, tested
    is_private_address() alternative.
---
 arm/connections/connEntry.py |   14 ++++++++------
 arm/util/connections.py      |   24 ------------------------
 2 files changed, 8 insertions(+), 30 deletions(-)

diff --git a/arm/connections/connEntry.py b/arm/connections/connEntry.py
index bd83cca..e052a59 100644
--- a/arm/connections/connEntry.py
+++ b/arm/connections/connEntry.py
@@ -6,10 +6,12 @@ Connection panel entries related to actual connections to or from the system
 import time
 import curses
 
-from arm.util import connections, torTools, uiTools
+from arm.util import torTools, uiTools
 from arm.connections import entries
 
-from stem.util import conf, enum, str_tools
+from stem.util import conf, connection, enum, str_tools
+
+from arm.util.connections import ipToInt, getPortUsage
 
 # Connection Categories:
 #   Inbound      Relay connection, coming to us.
@@ -183,7 +185,7 @@ class ConnectionEntry(entries.ConnectionPanelEntry):
     elif attr == entries.SortAttr.UPTIME:
       return connLine.startTime
     elif attr == entries.SortAttr.COUNTRY:
-      if connections.isIpAddressPrivate(self.lines[0].foreign.getIpAddr()): return ""
+      if connection.is_private_address(self.lines[0].foreign.getIpAddr()): return ""
       else: return connLine.foreign.getLocale("")
     else:
       return entries.ConnectionPanelEntry.getSortValue(self, attr, listingType)
@@ -251,7 +253,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
     self.includeExpandedIpAddr = includeExpandedIpAddr
 
     # cached immutable values used for sorting
-    self.sortIpAddr = connections.ipToInt(self.foreign.getIpAddr())
+    self.sortIpAddr = ipToInt(self.foreign.getIpAddr())
     self.sortPort = int(self.foreign.getPort())
 
   def getListingEntry(self, width, currentTime, listingType):
@@ -809,7 +811,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
       spaceAvailable = maxLength - len(dstAddress) - 3
 
       if self.getType() == Category.EXIT and includePort:
-        purpose = connections.getPortUsage(self.foreign.getPort())
+        purpose = getPortUsage(self.foreign.getPort())
 
         if purpose:
           # BitTorrent is a common protocol to truncate, so just use "Torrent"
@@ -821,7 +823,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
           purpose = uiTools.cropStr(purpose, spaceAvailable, endType = uiTools.Ending.HYPHEN)
 
           dstAddress += " (%s)" % purpose
-      elif not connections.isIpAddressPrivate(self.foreign.getIpAddr()):
+      elif not connection.is_private_address(self.foreign.getIpAddr()):
         extraInfo = []
         conn = torTools.getConn()
 
diff --git a/arm/util/connections.py b/arm/util/connections.py
index 65ba52b..1c18233 100644
--- a/arm/util/connections.py
+++ b/arm/util/connections.py
@@ -107,30 +107,6 @@ CONFIG = conf.config_dict("arm", {
 
 PORT_USAGE = {}
 
-def isIpAddressPrivate(ipAddr):
-  """
-  Provides true if the IP address belongs on the local network or belongs to
-  loopback, false otherwise. These include:
-  Private ranges: 10.*, 172.16.* - 172.31.*, 192.168.*
-  Loopback: 127.*
-
-  Arguments:
-    ipAddr - IP address to be checked
-  """
-
-  # checks for any of the simple wildcard ranges
-  if ipAddr.startswith("10.") or ipAddr.startswith("192.168.") or ipAddr.startswith("127."):
-    return True
-
-  # checks for the 172.16.* - 172.31.* range
-  if ipAddr.startswith("172.") and ipAddr.count(".") == 3:
-    secondOctet = ipAddr[4:ipAddr.find(".", 4)]
-
-    if secondOctet.isdigit() and int(secondOctet) >= 16 and int(secondOctet) <= 31:
-      return True
-
-  return False
-
 def ipToInt(ipAddr):
   """
   Provides an integer representation of the ip address, suitable for sorting.



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits