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

[tor-commits] [stem/master] Drop sockstat connection resolution



commit f53715ebe6e36327d0bca1c8c9ffe800ffd8c4d5
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Feb 1 15:03:53 2020 -0800

    Drop sockstat connection resolution
    
    We disabled sockstat tests a while ago due to unreliability...
    
      https://github.com/torproject/stem/issues/42
    
    We have plently of better resolvers so simply dropping this one.
---
 stem/util/connection.py       | 15 +--------------
 test/integ/util/connection.py |  1 -
 test/unit/util/connection.py  | 34 ++--------------------------------
 3 files changed, 3 insertions(+), 47 deletions(-)

diff --git a/stem/util/connection.py b/stem/util/connection.py
index 5480f95a..eaeafec4 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -36,10 +36,6 @@ Connection and networking based utility functions.
   .. versionchanged:: 1.6.0
      Added **BSD_FSTAT**.
 
-  .. deprecated:: 1.6.0
-     The SOCKSTAT connection resolver is proving to be unreliable
-     (:trac:`23057`), and will be dropped in the 2.0.0 release unless fixed.
-
   ====================  ===========
   Resolver              Description
   ====================  ===========
@@ -48,7 +44,6 @@ Connection and networking based utility functions.
   **NETSTAT_WINDOWS**   netstat command under Windows
   **SS**                ss command
   **LSOF**              lsof command
-  **SOCKSTAT**          sockstat command under \\*nix
   **BSD_SOCKSTAT**      sockstat command under FreeBSD
   **BSD_PROCSTAT**      procstat command under FreeBSD
   **BSD_FSTAT**         fstat command under OpenBSD
@@ -84,7 +79,6 @@ Resolver = enum.Enum(
   ('NETSTAT_WINDOWS', 'netstat (windows)'),
   ('SS', 'ss'),
   ('LSOF', 'lsof'),
-  ('SOCKSTAT', 'sockstat'),
   ('BSD_SOCKSTAT', 'sockstat (bsd)'),
   ('BSD_PROCSTAT', 'procstat (bsd)'),
   ('BSD_FSTAT', 'fstat (bsd)')
@@ -111,8 +105,6 @@ RESOLVER_COMMAND = {
   # (lsof provides a '-p <pid>' but oddly in practice it seems to be ~11-28% slower)
   Resolver.LSOF: 'lsof -wnPi',
 
-  Resolver.SOCKSTAT: 'sockstat',
-
   # -4 = IPv4, -c = connected sockets
   Resolver.BSD_SOCKSTAT: 'sockstat -4c',
 
@@ -138,9 +130,6 @@ RESOLVER_FILTER = {
   # tor  3873  atagar  45u  IPv4  40994  0t0  TCP 10.243.55.20:45724->194.154.227.109:9001 (ESTABLISHED)
   Resolver.LSOF: '^{name}\\s+{pid}\\s+.*\\s+{protocol}\\s+{local}->{remote} \\(ESTABLISHED\\)$',
 
-  # atagar   tor                  15843    tcp4   192.168.0.20:44092        68.169.35.102:443         ESTABLISHED
-  Resolver.SOCKSTAT: '^\\S+\\s+{name}\\s+{pid}\\s+{protocol}4\\s+{local}\\s+{remote}\\s+ESTABLISHED$',
-
   # _tor     tor        4397  12 tcp4   172.27.72.202:54011   127.0.0.1:9001
   Resolver.BSD_SOCKSTAT: '^\\S+\\s+{name}\\s+{pid}\\s+\\S+\\s+{protocol}4\\s+{local}\\s+{remote}$',
 
@@ -380,9 +369,7 @@ def system_resolvers(system = None):
 
     resolvers = [Resolver.BSD_SOCKSTAT, Resolver.BSD_PROCSTAT, Resolver.LSOF]
   else:
-    # Sockstat isn't available by default on ubuntu.
-
-    resolvers = [Resolver.NETSTAT, Resolver.SOCKSTAT, Resolver.LSOF, Resolver.SS]
+    resolvers = [Resolver.NETSTAT, Resolver.LSOF, Resolver.SS]
 
   # remove any that aren't in the user's PATH
 
diff --git a/test/integ/util/connection.py b/test/integ/util/connection.py
index 861b8ba9..f1745ec0 100644
--- a/test/integ/util/connection.py
+++ b/test/integ/util/connection.py
@@ -92,7 +92,6 @@ class TestConnection(unittest.TestCase):
       Resolver.NETSTAT_WINDOWS,
       Resolver.SS,
       Resolver.LSOF,
-      Resolver.SOCKSTAT,
       Resolver.BSD_SOCKSTAT,
       Resolver.BSD_PROCSTAT,
       Resolver.BSD_FSTAT,
diff --git a/test/unit/util/connection.py b/test/unit/util/connection.py
index d848c40b..6f8d8ab8 100644
--- a/test/unit/util/connection.py
+++ b/test/unit/util/connection.py
@@ -108,17 +108,6 @@ tor       129 atagar   22u  IPv4 0xffffff35c9125500      0t0  TCP 192.168.1.20:9
 tor       129 atagar   23u  IPv4 0xffffff3236168160      0t0  TCP 192.168.1.20:9090->62.135.16.134:14456 (ESTABLISHED)
 """
 
-SOCKSTAT_OUTPUT = """\
-USER     PROCESS              PID      PROTO  SOURCE ADDRESS            FOREIGN ADDRESS           STATE
-atagar   ubuntu-geoip-pr      2164     tcp4   192.168.0.1:55395         141.18.34.33:80           CLOSE_WAIT
-atagar   tor                  15843    tcp4   127.0.0.1:9050            *:*                       LISTEN
-atagar   tor                  15843    tcp4   127.0.0.1:9051            *:*                       LISTEN
-atagar   tor                  15843    tcp4   192.168.0.1:44415         38.229.79.2:443           ESTABLISHED
-atagar   tor                  15843    tcp4   192.168.0.1:44092         68.169.35.102:443         ESTABLISHED
-atagar   firefox              20586    tcp4   192.168.0.1:47486         213.24.100.160:443        ESTABLISHED
-atagar   firefox              20586    tcp4   192.168.0.1:43762         32.188.221.72:443         CLOSE_WAIT
-"""
-
 # I don't have actual sockstat and procstat output for FreeBSD. Rather, these
 # are snippets of output from email threads.
 
@@ -216,10 +205,10 @@ class TestConnection(unittest.TestCase):
     self.assertEqual([Resolver.LSOF], stem.util.connection.system_resolvers('Darwin'))
     self.assertEqual([Resolver.BSD_FSTAT], stem.util.connection.system_resolvers('OpenBSD'))
     self.assertEqual([Resolver.BSD_SOCKSTAT, Resolver.BSD_PROCSTAT, Resolver.LSOF], stem.util.connection.system_resolvers('FreeBSD'))
-    self.assertEqual([Resolver.NETSTAT, Resolver.SOCKSTAT, Resolver.LSOF, Resolver.SS], stem.util.connection.system_resolvers('Linux'))
+    self.assertEqual([Resolver.NETSTAT, Resolver.LSOF, Resolver.SS], stem.util.connection.system_resolvers('Linux'))
 
     proc_mock.return_value = True
-    self.assertEqual([Resolver.PROC, Resolver.NETSTAT, Resolver.SOCKSTAT, Resolver.LSOF, Resolver.SS], stem.util.connection.system_resolvers('Linux'))
+    self.assertEqual([Resolver.PROC, Resolver.NETSTAT, Resolver.LSOF, Resolver.SS], stem.util.connection.system_resolvers('Linux'))
 
     # check that calling without an argument is equivalent to calling for this
     # platform
@@ -389,25 +378,6 @@ class TestConnection(unittest.TestCase):
     self.assertEqual(expected, stem.util.connection.get_connections(Resolver.LSOF, process_pid = 129, process_name = 'tor'))
 
   @patch('stem.util.system.call')
-  def test_get_connections_by_sockstat(self, call_mock):
-    """
-    Checks the get_connections function with the sockstat resolver.
-    """
-
-    call_mock.return_value = SOCKSTAT_OUTPUT.split('\n')
-    expected = [
-      Connection('192.168.0.1', 44415, '38.229.79.2', 443, 'tcp', False),
-      Connection('192.168.0.1', 44092, '68.169.35.102', 443, 'tcp', False),
-    ]
-    self.assertEqual(expected, stem.util.connection.get_connections(Resolver.SOCKSTAT, process_pid = 15843, process_name = 'tor'))
-
-    self.assertRaises(IOError, stem.util.connection.get_connections, Resolver.SOCKSTAT, process_pid = 15843, process_name = 'stuff')
-    self.assertRaises(IOError, stem.util.connection.get_connections, Resolver.SOCKSTAT, process_pid = 1111, process_name = 'tor')
-
-    call_mock.side_effect = OSError('Unable to call sockstat')
-    self.assertRaises(IOError, stem.util.connection.get_connections, Resolver.SOCKSTAT, process_pid = 1111)
-
-  @patch('stem.util.system.call')
   def test_get_connections_by_sockstat_for_bsd(self, call_mock):
     """
     Checks the get_connections function with the bsd variant of the sockstat



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