[tor-commits] [stem/master] Drop deprecated controller methods
atagar at torproject.org
atagar at torproject.org
Mon Feb 10 03:14:50 UTC 2020
commit 2b77697806d916f5d1f51b73213625b0cadcd8ea
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Feb 1 15:32:12 2020 -0800
Drop deprecated controller methods
Removing get_socks_listeners and is_geoip_unavailable as both have better
counterparts nowadays.
---
stem/control.py | 56 +-------------------
test/integ/control/controller.py | 9 ----
test/unit/control/controller.py | 110 ---------------------------------------
3 files changed, 2 insertions(+), 173 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index e48f6bcd..271a67ec 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -140,7 +140,6 @@ If you're fine with allowing your script to raise exceptions then this can be mo
|- is_newnym_available - true if tor would currently accept a NEWNYM signal
|- get_newnym_wait - seconds until tor would accept a NEWNYM signal
|- get_effective_rate - provides our effective relaying rate limit
- |- is_geoip_unavailable - true if we've discovered our geoip db to be unavailable
|- map_address - maps one address to another such that connections to the original are replaced with the other
+- drop_guards - drops our set of guard relays and picks a new set
@@ -374,6 +373,7 @@ CACHEABLE_GETINFO_PARAMS = (
'config/names',
'config/defaults',
'info/names',
+ 'ip-to-country/ipv4-available',
'events/names',
'features/names',
'process/descriptor-limit',
@@ -1042,7 +1042,6 @@ class Controller(BaseController):
self._event_listeners = {}
self._event_listeners_lock = threading.RLock()
self._enabled_features = []
- self._is_geoip_unavailable = None
self._last_address_exc = None
self._last_fingerprint_exc = None
@@ -1158,7 +1157,7 @@ class Controller(BaseController):
params = set(params)
for param in params:
- if param.startswith('ip-to-country/') and param != 'ip-to-country/0.0.0.0' and self.is_geoip_unavailable():
+ if param.startswith('ip-to-country/') and param != 'ip-to-country/0.0.0.0' and self.get_info('ip-to-country/ipv4-available', '0') != '1':
raise stem.ProtocolError('Tor geoip database is unavailable')
elif param == 'address' and self._last_address_exc:
raise self._last_address_exc # we already know we can't resolve an address
@@ -1480,25 +1479,6 @@ class Controller(BaseController):
write_limit = used_written + left_written,
)
- def get_socks_listeners(self, default = UNDEFINED):
- """
- Provides the SOCKS **(address, port)** tuples that tor has open.
-
- .. deprecated:: 1.2.0
- Use :func:`~stem.control.Controller.get_listeners` with
- **Listener.SOCKS** instead.
-
- :param object default: response if the query fails
-
- :returns: list of **(address, port)** tuples for the available SOCKS
- listeners
-
- :raises: :class:`stem.ControllerError` if unable to determine the listeners
- and no default was provided
- """
-
- return self.get_listeners(Listener.SOCKS, default)
-
@with_default()
def get_protocolinfo(self, default = UNDEFINED):
"""
@@ -3329,7 +3309,6 @@ class Controller(BaseController):
with self._cache_lock:
self._request_cache = {}
self._last_newnym = 0.0
- self._is_geoip_unavailable = None
def load_conf(self, configtext):
"""
@@ -3849,37 +3828,6 @@ class Controller(BaseController):
return value
- def is_geoip_unavailable(self):
- """
- Provides **True** if tor's geoip database is unavailable, **False**
- otherwise.
-
- .. versionchanged:: 1.6.0
- No longer requires previously failed GETINFO requests to determine this.
-
- .. deprecated:: 1.6.0
- This is available as of Tor 0.3.2.1 through the following instead...
-
- ::
-
- controller.get_info('ip-to-country/ipv4-available', 0) == '1'
-
- :returns: **bool** indicating if we've determined tor's geoip database to
- be unavailable or not
- """
-
- if self._is_geoip_unavailable is None:
- try:
- self.get_info('ip-to-country/0.0.0.0')
- self._is_geoip_unavailable = False
- except stem.ControllerError as exc:
- if 'GeoIP data not loaded' in str(exc):
- self._is_geoip_unavailable = True
- else:
- return False # unexpected issue, fail open and don't cache
-
- return self._is_geoip_unavailable
-
def map_address(self, mapping):
"""
Map addresses to replacement addresses. Tor replaces subseqent connections
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 6903c65b..7113ea67 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -952,15 +952,6 @@ class TestController(unittest.TestCase):
self.assertEqual([], controller.get_listeners(Listener.CONTROL))
@test.require.controller
- def test_get_socks_listeners(self):
- """
- Test Controller.get_socks_listeners against a running tor instance.
- """
-
- with test.runner.get_runner().get_tor_controller() as controller:
- self.assertEqual([('127.0.0.1', 1112)], controller.get_socks_listeners())
-
- @test.require.controller
@test.require.online
@test.require.version(stem.version.Version('0.1.2.2-alpha'))
def test_enable_feature(self):
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index 34429f49..1ba3001a 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -265,116 +265,6 @@ class TestControl(unittest.TestCase):
self.assertEqual([], self.controller.get_ports(Listener.CONTROL))
@patch('stem.control.Controller.get_info')
- @patch('stem.control.Controller.get_conf')
- def test_get_socks_listeners_old(self, get_conf_mock, get_info_mock):
- """
- Exercises the get_socks_listeners() method as though talking to an old tor
- instance.
- """
-
- # An old tor raises stem.InvalidArguments for get_info about socks, but
- # get_socks_listeners should work anyway.
-
- get_info_mock.side_effect = InvalidArguments
-
- get_conf_mock.side_effect = lambda param, **kwargs: {
- 'SocksPort': '9050',
- 'SocksListenAddress': ['127.0.0.1'],
- }[param]
-
- self.assertEqual([('127.0.0.1', 9050)], self.controller.get_socks_listeners())
- self.controller.clear_cache()
-
- # Again, an old tor, but SocksListenAddress overrides the port number.
-
- get_conf_mock.side_effect = lambda param, **kwargs: {
- 'SocksPort': '9050',
- 'SocksListenAddress': ['127.0.0.1:1112'],
- }[param]
-
- self.assertEqual([('127.0.0.1', 1112)], self.controller.get_socks_listeners())
- self.controller.clear_cache()
-
- # Again, an old tor, but multiple listeners
-
- get_conf_mock.side_effect = lambda param, **kwargs: {
- 'SocksPort': '9050',
- 'SocksListenAddress': ['127.0.0.1:1112', '127.0.0.1:1114'],
- }[param]
-
- self.assertEqual([('127.0.0.1', 1112), ('127.0.0.1', 1114)], self.controller.get_socks_listeners())
- self.controller.clear_cache()
-
- # Again, an old tor, but no SOCKS listeners
-
- get_conf_mock.side_effect = lambda param, **kwargs: {
- 'SocksPort': '0',
- 'SocksListenAddress': [],
- }[param]
-
- self.assertEqual([], self.controller.get_socks_listeners())
- self.controller.clear_cache()
-
- # Where tor provides invalid ports or addresses
-
- get_conf_mock.side_effect = lambda param, **kwargs: {
- 'SocksPort': 'blarg',
- 'SocksListenAddress': ['127.0.0.1'],
- }[param]
-
- self.assertRaises(stem.ProtocolError, self.controller.get_socks_listeners)
-
- get_conf_mock.side_effect = lambda param, **kwargs: {
- 'SocksPort': '0',
- 'SocksListenAddress': ['127.0.0.1:abc'],
- }[param]
-
- self.assertRaises(stem.ProtocolError, self.controller.get_socks_listeners)
-
- get_conf_mock.side_effect = lambda param, **kwargs: {
- 'SocksPort': '40',
- 'SocksListenAddress': ['500.0.0.1'],
- }[param]
-
- self.assertRaises(stem.ProtocolError, self.controller.get_socks_listeners)
-
- @patch('stem.control.Controller.get_info')
- def test_get_socks_listeners_new(self, get_info_mock):
- """
- Exercises the get_socks_listeners() method as if talking to a newer tor
- instance.
- """
-
- # multiple SOCKS listeners
-
- get_info_mock.return_value = '"127.0.0.1:1112" "127.0.0.1:1114"'
-
- self.assertEqual(
- [('127.0.0.1', 1112), ('127.0.0.1', 1114)],
- self.controller.get_socks_listeners()
- )
-
- # no SOCKS listeners
-
- self.controller.clear_cache()
- get_info_mock.return_value = ''
- self.assertEqual([], self.controller.get_socks_listeners())
-
- # check where GETINFO provides malformed content
-
- invalid_responses = (
- '"127.0.0.1"', # address only
- '"1112"', # port only
- '"5127.0.0.1:1112"', # invlaid address
- '"127.0.0.1:991112"', # invalid port
- )
-
- for response in invalid_responses:
- self.controller.clear_cache()
- get_info_mock.return_value = response
- self.assertRaises(stem.ProtocolError, self.controller.get_socks_listeners)
-
- @patch('stem.control.Controller.get_info')
@patch('time.time', Mock(return_value = 1410723598.276578))
def test_get_accounting_stats(self, get_info_mock):
"""
More information about the tor-commits
mailing list