Isolate connect's bootstrap, so non-connect users can bootstrap when making clients outside connect

This commit is contained in:
SimplifiedPrivacy 2026-08-13 07:59:27 -04:00
parent d9bee758a8
commit 1d8c508c52
3 changed files with 40 additions and 20 deletions

View file

@ -77,13 +77,19 @@ def download_file_and_verify(
def _get_httpx_client(target_app_name: str, connection_observer: Optional[ConnectionObserver]) -> httpx.Client: def _get_httpx_client(target_app_name: str, connection_observer: Optional[ConnectionObserver]) -> httpx.Client:
connection_type = ConfigurationController.get_connection_enum() connection_type = ConfigurationController.get_connection_enum()
did_it_work = connect.make_client(connection_type, connection_observer) # always gets boolean made_client = connect.make_client(connection_type, connection_observer) # always gets boolean
if not did_it_work: if not made_client:
raise ConnectionError(f'Could not connect, to download {target_app_name}.') if connection_type == ConnectionChoice.SYSTEM:
else: raise ConnectionError(f'Could not connect, to download {target_app_name}.')
client = httpx_client.get_http_session() else: # Tor:
logger.info(f"client type is {type(client)}") if connection_observer:
connection_observer.notify('message', "Tor Bootstrap..")
bootstrap_results = connect.coordinate_bootstrap(connection_observer)
if not bootstrap_results.valid:
raise ConnectionError(f'Could not connect, to download {target_app_name}.')
client = httpx_client.get_http_session()
return client return client
def __calculate_file_hash(file): def __calculate_file_hash(file):

View file

@ -11,6 +11,7 @@ from core.models.orm_models.Dependency import Dependency
from core.models.orm_calls.dependency_calls import get_dependency_version from core.models.orm_calls.dependency_calls import get_dependency_version
from core.controllers.ConfigurationController import ConfigurationController from core.controllers.ConfigurationController import ConfigurationController
from core.utils.basic_operations.compare_versions import version_update_required from core.utils.basic_operations.compare_versions import version_update_required
from core.observers.ConnectionObserver import ConnectionObserver
import httpx import httpx
from io import BytesIO from io import BytesIO
@ -21,7 +22,10 @@ import os
SUDO_SINGBOX_LOCATION = f"{Constants.SUDO_TARGET_FOLDER}/sing-box" SUDO_SINGBOX_LOCATION = f"{Constants.SUDO_TARGET_FOLDER}/sing-box"
def setup_singbox_binary(application_version_observer: Optional[ApplicationVersionObserver]) -> Result: def setup_singbox_binary(
application_version_observer: Optional[ApplicationVersionObserver],
connection_observer: Optional[ConnectionObserver]
) -> Result:
""" """
Rank: Rank:
Module's Main Orchestrator Module's Main Orchestrator

View file

@ -5,6 +5,7 @@ from core.services.networking.tor_tools.tor_orchestrator import establish_tor_co
from core.services.networking.tor_tools.tor_dns import setup_SINGLE_use_resolver from core.services.networking.tor_tools.tor_dns import setup_SINGLE_use_resolver
from core.services.networking.api_requests.ApiResponseModel import ApiResponse, ErrorType from core.services.networking.api_requests.ApiResponseModel import ApiResponse, ErrorType
from core.models.Result import Result, ResultError
from core.services.networking.httpx.async_batch_requests import async_parallel from core.services.networking.httpx.async_batch_requests import async_parallel
from core.services.networking.tor_tools.pre_bootstrap import get_bootstrap_port from core.services.networking.tor_tools.pre_bootstrap import get_bootstrap_port
from core.services.networking.api_requests.subtools.get_connection_type import get_connection_type from core.services.networking.api_requests.subtools.get_connection_type import get_connection_type
@ -164,6 +165,24 @@ def bootstrap_and_try_again(method: str, url: str, observer: ConnectionObserver,
Called by: Called by:
single_endpoint single_endpoint
""" """
bootstrap_results = coordinate_bootstrap(observer)
if not bootstrap_results.valid:
return bootstrap_results
observer.notify('message', "Tor Confirmed")
client = httpx_client.get_http_session()
observer.notify('message', "Making Request..")
return make_request(
method=method,
url=url,
client=client,
payload=payload,
billing_code=billing_code
)
def coordinate_bootstrap(observer: ConnectionObserver) -> ApiResponse:
global _port_used global _port_used
if _port_used is None: if _port_used is None:
@ -178,22 +197,13 @@ def bootstrap_and_try_again(method: str, url: str, observer: ConnectionObserver,
# BOOTSTRAP SUCCESS # BOOTSTRAP SUCCESS
_port_used = bootstrap_results.port _port_used = bootstrap_results.port
observer.notify('message', "Testing Tor..") if observer:
observer.notify('message', "Testing Tor..")
made_client = httpx_client.init_tor_session(_port_used) made_client = httpx_client.init_tor_session(_port_used)
if not made_client: if not made_client:
return bootstrap_results return bootstrap_results
observer.notify('message', "Tor Confirmed") else:
return ApiResponse(valid=True)
client = httpx_client.get_http_session()
observer.notify('message', "Making Request..")
return make_request(
method=method,
url=url,
client=client,
payload=payload,
billing_code=billing_code
)
def bulk_async(wanted_list: list, observer: ConnectionObserver, client_observer: ClientObserver) -> ApiResponse: def bulk_async(wanted_list: list, observer: ConnectionObserver, client_observer: ClientObserver) -> ApiResponse: