Compare commits

..

No commits in common. "f7a05f81434c81535ba4816e5ce5c3af7a85254f" and "093e9aacd8a4fdc7a538aaea4b90be9be0da49d8" have entirely different histories.

7 changed files with 18 additions and 59 deletions

View file

@ -59,7 +59,7 @@ class ClientController:
if client_observer is not None: if client_observer is not None:
client_observer.notify('synchronizing', "Fetching list of new data ..") client_observer.notify('synchronizing', "Fetching list of new data ..")
result = coordinate_cache_sync(client_observer, connection_observer) result = coordinate_cache_sync(ClientObserver, ConnectionObserver)
# logger.info(f"We got a Result from the API of {result}") # logger.info(f"We got a Result from the API of {result}")

View file

@ -221,16 +221,9 @@ class ConnectionController:
ConnectionController.terminate_tor_connection() ConnectionController.terminate_tor_connection()
time.sleep(1.0) time.sleep(1.0)
@staticmethod
def test_observer(connection_observer: Optional[ConnectionObserver] = None):
if connection_observer is not None:
connection_observer.notify('custom_message', "HELLO")
@staticmethod @staticmethod
def establish_tor_connection(connection_observer: Optional[ConnectionObserver] = None): def establish_tor_connection(connection_observer: Optional[ConnectionObserver] = None):
try:
tor_module = TorModule(Constants.HV_TOR_STATE_HOME) tor_module = TorModule(Constants.HV_TOR_STATE_HOME)
tor_module.start_service(connection_observer) tor_module.start_service(connection_observer)
@ -238,9 +231,6 @@ class ConnectionController:
for port_number in session_state.network_port_numbers.tor: for port_number in session_state.network_port_numbers.tor:
tor_module.create_session(port_number) tor_module.create_session(port_number)
except:
if connection_observer is not None:
connection_observer.notify('custom_message', "Tor Can't Initialize")
@staticmethod @staticmethod
def terminate_tor_connection(): def terminate_tor_connection():
@ -255,8 +245,6 @@ class ConnectionController:
tor_module.create_session(port_number, connection_observer) tor_module.create_session(port_number, connection_observer)
except TorServiceInitializationError as e: except TorServiceInitializationError as e:
logger.error(f"TorServiceInitializationError. Tor Can't Start: {e}") logger.error(f"TorServiceInitializationError. Tor Can't Start: {e}")
if connection_observer is not None:
connection_observer.notify('custom_message', "Tor Can't Initialize")
except Exception as e: except Exception as e:
logger.error(f"Tor Can't Start: {e}") logger.error(f"Tor Can't Start: {e}")

View file

@ -20,7 +20,8 @@ from core.errors.logger import logger
def evaluate_regular_networking_problem( def evaluate_regular_networking_problem(
url: str, url: str,
connection_observer: ConnectionObserver, connection_observer: ConnectionObserver,
client_observer: Optional[ClientObserver] = None port_number: int | None = None,
proxies: dict | None = None,
) -> dict: ) -> dict:
domain_only = extract_domain(url) domain_only = extract_domain(url)
@ -45,7 +46,6 @@ def evaluate_regular_networking_problem(
def evaluate_tor_networking_problem( def evaluate_tor_networking_problem(
url: str, url: str,
connection_observer: ConnectionObserver, connection_observer: ConnectionObserver,
client_observer: Optional[ClientObserver] = None,
) -> dict: ) -> dict:
domain_only = extract_domain(url) domain_only = extract_domain(url)

View file

@ -1,13 +1,8 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
# if TYPE_CHECKING: if TYPE_CHECKING:
from core.observers.ClientObserver import ClientObserver from essentials.observers.ConnectionObserver import ConnectionObserver
from essentials.observers.ConnectionObserver import ConnectionObserver
from core.observers.ClientObserver import ClientObserver
from core.services.networking.evaluate_networking_problem import evaluate_tor_networking_problem
# services # services
from core.services.networking.get_connection_type import get_connection_type from core.services.networking.get_connection_type import get_connection_type
from core.services.networking.use_tor import tor_get_request from core.services.networking.use_tor import tor_get_request
@ -19,13 +14,13 @@ import traceback
# Generic GET request to an endpoint, filtered by the user's preference of connection type (Tor or Not) # Generic GET request to an endpoint, filtered by the user's preference of connection type (Tor or Not)
def get_data_from_server(url: str, connection_observer: ConnectionObserver, client_observer: Optional[ClientObserver] = None) -> dict: def get_data_from_server(url: str, connection_observer: ConnectionObserver) -> dict:
try: try:
connection_type = get_connection_type() connection_type = get_connection_type()
logger.debug(f"connection type is: {connection_type}") logger.debug(f"connection type is: {connection_type}")
if connection_type == "tor": if connection_type == "tor":
response = tor_get_request(url, connection_observer, client_observer) response = tor_get_request(url, connection_observer)
else: else:
response = regular_get_request(url, connection_observer) response = regular_get_request(url, connection_observer)

View file

@ -7,9 +7,6 @@ if TYPE_CHECKING:
from essentials.modules.TorModule import TorModule from essentials.modules.TorModule import TorModule
from essentials.observers.ConnectionObserver import ConnectionObserver from essentials.observers.ConnectionObserver import ConnectionObserver
from essentials.services.ConnectionService import ConnectionService from essentials.services.ConnectionService import ConnectionService
from core.observers.ClientObserver import ClientObserver
# services # services
from core.services.networking.evaluate_networking_problem import evaluate_tor_networking_problem from core.services.networking.evaluate_networking_problem import evaluate_tor_networking_problem
# errors # errors
@ -21,7 +18,7 @@ from typing import Any
from core.Constants import Constants from core.Constants import Constants
import time import time
def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, client_observer: Optional[ClientObserver] = None) -> dict: def tor_get_request(custom_url: str, connection_observer: ConnectionObserver) -> dict:
import requests import requests
# ============================================================================ # ============================================================================
@ -29,25 +26,18 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
# ============================================================================ # ============================================================================
port_number = ConnectionService.get_random_available_port_number() port_number = ConnectionService.get_random_available_port_number()
logger.debug(f"[USE TOR SERVICE] Using Tor on port number {port_number}") logger.debug(f"[USE TOR SERVICE] Using Tor on port number {port_number}")
if client_observer is not None:
client_observer.notify('synchronizing', f"Using Tor on Port {port_number}..")
try: try:
tor_module = TorModule(Constants.HV_TOR_STATE_HOME) tor_module = TorModule(Constants.HV_TOR_STATE_HOME)
tor_module.create_session(port_number, connection_observer) tor_module.create_session(port_number, connection_observer)
logger.debug(f"[USE TOR SERVICE] Tor Started a Session") logger.debug(f"[USE TOR SERVICE] Tor Started a Session")
if client_observer is not None:
client_observer.notify('synchronizing', f"Initialized Tor..")
except TorServiceInitializationError as e: except TorServiceInitializationError as e:
error_msg = f"[USE TOR SERVICE] Tor failed to start: {e}" error_msg = f"[USE TOR SERVICE] Tor failed to start: {e}"
tor_module.destroy_session(port_number) tor_module.destroy_session(port_number)
logger.error(error_msg, exc_info=True) logger.error(error_msg, exc_info=True)
if client_observer is not None:
client_observer.notify('synchronizing', f"Tor Failed to Initialize")
problem_results = evaluate_tor_networking_problem( problem_results = evaluate_tor_networking_problem(
custom_url, connection_observer, client_observer custom_url, connection_observer
) )
return problem_results return problem_results
except Exception as e: except Exception as e:
@ -83,9 +73,6 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
return final_reply return final_reply
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
if client_observer is not None:
client_observer.notify('synchronizing', f"Tor Connection Error")
tor_module.destroy_session(port_number) tor_module.destroy_session(port_number)
problem_results = evaluate_tor_networking_problem( problem_results = evaluate_tor_networking_problem(
custom_url, connection_observer custom_url, connection_observer
@ -94,9 +81,6 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
logger.debug("Connection timed out") logger.debug("Connection timed out")
if client_observer is not None:
client_observer.notify('synchronizing', f"Tor Connection Timeout")
tor_module.destroy_session(port_number) tor_module.destroy_session(port_number)
problem_results = evaluate_tor_networking_problem( problem_results = evaluate_tor_networking_problem(
custom_url, connection_observer custom_url, connection_observer
@ -104,11 +88,7 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
return problem_results return problem_results
except requests.exceptions.HTTPError: except requests.exceptions.HTTPError:
tor_http_error = f"Tor HTTP error: {response.status_code}" logger.debug(f"HTTP error: {response.status_code}")
logger.debug(tor_http_error)
if client_observer is not None:
client_observer.notify('synchronizing', tor_http_error)
tor_module.destroy_session(port_number) tor_module.destroy_session(port_number)
problem_results = evaluate_tor_networking_problem( problem_results = evaluate_tor_networking_problem(
custom_url, connection_observer custom_url, connection_observer
@ -125,9 +105,6 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
except Exception as e: except Exception as e:
logger.error(f"[USE TOR SERVICE] Unexpected Tor error: {e}") logger.error(f"[USE TOR SERVICE] Unexpected Tor error: {e}")
if client_observer is not None:
client_observer.notify('synchronizing', f"Tor Error: {e}")
tor_module.destroy_session(port_number) tor_module.destroy_session(port_number)
problem_results = evaluate_tor_networking_problem( problem_results = evaluate_tor_networking_problem(
custom_url, connection_observer custom_url, connection_observer

View file

@ -30,7 +30,7 @@ def get_data_from_api(
try: try:
logger.debug("Fetching data from API server...") logger.debug("Fetching data from API server...")
sync_results = get_data_from_server(url, connection_observer, client_observer) sync_results = get_data_from_server(url, connection_observer)
if sync_results in rejected_list: if sync_results in rejected_list:
error_msg = "API returned no data" error_msg = "API returned no data"
@ -39,7 +39,6 @@ def get_data_from_api(
logger.debug(f"Raw API response: {sync_results}") logger.debug(f"Raw API response: {sync_results}")
final_result = sync_results.get("data", None)
final_result = sync_results.get("data", None) final_result = sync_results.get("data", None)
if final_result: if final_result:

View file

@ -147,7 +147,7 @@ def coordinate_cache_sync(
- 'filtered_metadata': the metadata from the server after removing keys not in the ORM - 'filtered_metadata': the metadata from the server after removing keys not in the ORM
""" """
api_result = get_data_from_api("cachedsync", client_observer, connection_observer) api_result = get_data_from_api("cachedsync", ClientObserver, ConnectionObserver)
# we trust the 'get_data_from_api' function to give us a dictionary: # we trust the 'get_data_from_api' function to give us a dictionary:
if not api_result.get("success"): if not api_result.get("success"):