INNER CODE UNIT · Python

tor_test

KatrielMoses/voidaccess · api/main.py:622

async def tor_test(_=Depends(get_current_user)) -> dict:
    """
    Test Tor connectivity.
    TODO: Remove or protect in production.
    """
    try:
        import aiohttp  # noqa: PLC0415
        from aiohttp_socks import ProxyConnector  # noqa: PLC0415

        # Deliberately NOT the shared pool in scraper/tor_pool.py, and the one
        # justified exception to the "no private Tor connector" rule: this
        # endpoint exists to test whether the Tor transport itself works, so it
        # must not report health through the very session cache whose health is
        # in question — a pooled session would make a stale or broken cached
        # connector look like a working Tor.  It also fetches one fixed clearnet
        # URL, so no .onion stream isolation is at stake here.
        connector = ProxyConnector.from_url(f"socks5://{TOR_PROXY_HOST}:{TOR_PROXY_PORT}")
        timeout = aiohttp.ClientTimeout(total=10)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…