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

[tor-commits] [stem/master] Tor added default IPv6 ORPort



commit 435b980c62aa7bc68323de90911c9dbe4cb37b6d
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Jul 23 15:37:07 2020 -0700

    Tor added default IPv6 ORPort
    
    Tor recently changed its ORPort behavior so it provides both an IPv4 and IPv6
    endpoint by default...
    
      https://github.com/torproject/stem/issues/70
    
    Adjusting our tests. Our get_ports() method now provides a set rather than a
    list so we don't return duplicate values.
---
 stem/control.py                  |  8 ++++----
 test/integ/control/controller.py | 18 +++++++++---------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 7b90eed0..47b8a37c 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -271,7 +271,7 @@ import stem.version
 from stem import UNDEFINED, CircStatus, Signal
 from stem.util import Synchronous, log
 from types import TracebackType
-from typing import Any, AsyncIterator, Awaitable, Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Type, Union
+from typing import Any, AsyncIterator, Awaitable, Callable, Dict, List, Mapping, Optional, Sequence, Set, Tuple, Type, Union
 
 # When closing the controller we attempt to finish processing enqueued events,
 # but if it takes longer than this we terminate.
@@ -1352,7 +1352,7 @@ class Controller(BaseController):
     return policy
 
   @with_default()
-  async def get_ports(self, listener_type: 'stem.control.Listener', default: Any = UNDEFINED) -> Sequence[int]:
+  async def get_ports(self, listener_type: 'stem.control.Listener', default: Any = UNDEFINED) -> Set[int]:
     """
     get_ports(listener_type, default = UNDEFINED)
 
@@ -1366,7 +1366,7 @@ class Controller(BaseController):
     :param listener_type: connection type being handled by the ports we return
     :param default: response if the query fails
 
-    :returns: **list** of **ints** for the local ports where tor handles
+    :returns: **set** of **ints** for the local ports where tor handles
       connections of the given type
 
     :raises: :class:`stem.ControllerError` if unable to determine the ports
@@ -1385,7 +1385,7 @@ class Controller(BaseController):
         log.info("Request for %s ports got an address that's neither IPv4 or IPv6: %s" % (listener_type, address))
         return False
 
-    return [port for (addr, port) in (await self.get_listeners(listener_type)) if is_localhost(addr)]
+    return set([port for (addr, port) in (await self.get_listeners(listener_type)) if is_localhost(addr)])
 
   @with_default()
   async def get_listeners(self, listener_type: 'stem.control.Listener', default: Any = UNDEFINED) -> Sequence[Tuple[str, int]]:
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index b539fc0e..40e036a7 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -951,17 +951,17 @@ class TestController(unittest.TestCase):
     runner = test.runner.get_runner()
 
     async with await runner.get_tor_controller() as controller:
-      self.assertEqual([test.runner.ORPORT], await controller.get_ports(Listener.OR))
-      self.assertEqual([], await controller.get_ports(Listener.DIR))
-      self.assertEqual([test.runner.SOCKS_PORT], await controller.get_ports(Listener.SOCKS))
-      self.assertEqual([], await controller.get_ports(Listener.TRANS))
-      self.assertEqual([], await controller.get_ports(Listener.NATD))
-      self.assertEqual([], await controller.get_ports(Listener.DNS))
+      self.assertEqual(set([test.runner.ORPORT]), await controller.get_ports(Listener.OR))
+      self.assertEqual(set(), await controller.get_ports(Listener.DIR))
+      self.assertEqual(set([test.runner.SOCKS_PORT]), await controller.get_ports(Listener.SOCKS))
+      self.assertEqual(set(), await controller.get_ports(Listener.TRANS))
+      self.assertEqual(set(), await controller.get_ports(Listener.NATD))
+      self.assertEqual(set(), await controller.get_ports(Listener.DNS))
 
       if test.runner.Torrc.PORT in runner.get_options():
-        self.assertEqual([test.runner.CONTROL_PORT], await controller.get_ports(Listener.CONTROL))
+        self.assertEqual(set([test.runner.CONTROL_PORT]), await controller.get_ports(Listener.CONTROL))
       else:
-        self.assertEqual([], await controller.get_ports(Listener.CONTROL))
+        self.assertEqual(set(), await controller.get_ports(Listener.CONTROL))
 
   @test.require.controller
   @async_test
@@ -973,7 +973,7 @@ class TestController(unittest.TestCase):
     runner = test.runner.get_runner()
 
     async with await runner.get_tor_controller() as controller:
-      self.assertEqual([('0.0.0.0', test.runner.ORPORT)], await controller.get_listeners(Listener.OR))
+      self.assertEqual([('0.0.0.0', test.runner.ORPORT), ('::', test.runner.ORPORT)], await controller.get_listeners(Listener.OR))
       self.assertEqual([], await controller.get_listeners(Listener.DIR))
       self.assertEqual([('127.0.0.1', test.runner.SOCKS_PORT)], await controller.get_listeners(Listener.SOCKS))
       self.assertEqual([], await controller.get_listeners(Listener.TRANS))

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