1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-22 12:10:11 +01:00

Allow 'using_tor_proxy' to be set for each engine individually

Check 'using_tor_proxy' for each engine individually instead of checking globally

[fix] searx.network: update _rdns test to the last httpx version

Co-authored-by: Alexandre Flament <alex@al-f.net>
This commit is contained in:
Léon Tiekötter 2022-01-22 19:51:40 +01:00
parent 1b03db4c73
commit 0cbf73a1f4
No known key found for this signature in database
GPG Key ID: 02869F7817D9EC08
2 changed files with 17 additions and 10 deletions

View File

@ -42,6 +42,7 @@ ENGINE_DEFAULT_ARGS = {
"safesearch": False, "safesearch": False,
"time_range_support": False, "time_range_support": False,
"enable_http": False, "enable_http": False,
"using_tor_proxy": False,
"display_error_messages": True, "display_error_messages": True,
"tokens": [], "tokens": [],
"about": {}, "about": {},
@ -230,8 +231,8 @@ def set_language_attributes(engine: Engine):
) )
def update_attributes_for_tor(engine): def update_attributes_for_tor(engine: Engine) -> bool:
if settings['outgoing'].get('using_tor_proxy') and hasattr(engine, 'onion_url'): if using_tor_proxy(engine) and hasattr(engine, 'onion_url'):
engine.search_url = engine.onion_url + getattr(engine, 'search_path', '') engine.search_url = engine.onion_url + getattr(engine, 'search_path', '')
engine.timeout += settings['outgoing'].get('extra_proxy_timeout', 0) engine.timeout += settings['outgoing'].get('extra_proxy_timeout', 0)
@ -249,13 +250,18 @@ def is_missing_required_attributes(engine):
return missing return missing
def using_tor_proxy(engine: Engine):
"""Return True if the engine configuration declares to use Tor."""
return settings['outgoing'].get('using_tor_proxy') or getattr(engine, 'using_tor_proxy', False)
def is_engine_active(engine: Engine): def is_engine_active(engine: Engine):
# check if engine is inactive # check if engine is inactive
if engine.inactive is True: if engine.inactive is True:
return False return False
# exclude onion engines if not using tor # exclude onion engines if not using tor
if 'onions' in engine.categories and not settings['outgoing'].get('using_tor_proxy'): if 'onions' in engine.categories and not using_tor_proxy(engine):
return False return False
return True return True

View File

@ -167,13 +167,14 @@ class Network:
for transport in client._mounts.values(): # pylint: disable=protected-access for transport in client._mounts.values(): # pylint: disable=protected-access
if isinstance(transport, AsyncHTTPTransportNoHttp): if isinstance(transport, AsyncHTTPTransportNoHttp):
continue continue
if not getattr(transport, '_rdns', False): if getattr(transport, "_pool") and getattr(
result = False transport._pool, "_rdns", False # pylint: disable=protected-access
break ):
else: continue
response = await client.get('https://check.torproject.org/api/ip') return False
if not response.json()['IsTor']: response = await client.get("https://check.torproject.org/api/ip", timeout=10)
result = False if not response.json()["IsTor"]:
result = False
Network._TOR_CHECK_RESULT[proxies] = result Network._TOR_CHECK_RESULT[proxies] = result
return result return result