Compare commits
No commits in common. "f7a05f81434c81535ba4816e5ce5c3af7a85254f" and "093e9aacd8a4fdc7a538aaea4b90be9be0da49d8" have entirely different histories.
f7a05f8143
...
093e9aacd8
7 changed files with 18 additions and 59 deletions
|
|
@ -59,7 +59,7 @@ class ClientController:
|
|||
if client_observer is not None:
|
||||
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}")
|
||||
|
||||
|
|
|
|||
|
|
@ -221,16 +221,9 @@ class ConnectionController:
|
|||
ConnectionController.terminate_tor_connection()
|
||||
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
|
||||
def establish_tor_connection(connection_observer: Optional[ConnectionObserver] = None):
|
||||
try:
|
||||
|
||||
tor_module = TorModule(Constants.HV_TOR_STATE_HOME)
|
||||
tor_module.start_service(connection_observer)
|
||||
|
||||
|
|
@ -238,9 +231,6 @@ class ConnectionController:
|
|||
|
||||
for port_number in session_state.network_port_numbers.tor:
|
||||
tor_module.create_session(port_number)
|
||||
except:
|
||||
if connection_observer is not None:
|
||||
connection_observer.notify('custom_message', "Tor Can't Initialize")
|
||||
|
||||
@staticmethod
|
||||
def terminate_tor_connection():
|
||||
|
|
@ -255,8 +245,6 @@ class ConnectionController:
|
|||
tor_module.create_session(port_number, connection_observer)
|
||||
except TorServiceInitializationError as 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:
|
||||
logger.error(f"Tor Can't Start: {e}")
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ from core.errors.logger import logger
|
|||
def evaluate_regular_networking_problem(
|
||||
url: str,
|
||||
connection_observer: ConnectionObserver,
|
||||
client_observer: Optional[ClientObserver] = None
|
||||
port_number: int | None = None,
|
||||
proxies: dict | None = None,
|
||||
) -> dict:
|
||||
|
||||
domain_only = extract_domain(url)
|
||||
|
|
@ -45,7 +46,6 @@ def evaluate_regular_networking_problem(
|
|||
def evaluate_tor_networking_problem(
|
||||
url: str,
|
||||
connection_observer: ConnectionObserver,
|
||||
client_observer: Optional[ClientObserver] = None,
|
||||
) -> dict:
|
||||
|
||||
domain_only = extract_domain(url)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
# if TYPE_CHECKING:
|
||||
from core.observers.ClientObserver import ClientObserver
|
||||
from essentials.observers.ConnectionObserver import ConnectionObserver
|
||||
|
||||
from core.observers.ClientObserver import ClientObserver
|
||||
from core.services.networking.evaluate_networking_problem import evaluate_tor_networking_problem
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from essentials.observers.ConnectionObserver import ConnectionObserver
|
||||
# services
|
||||
from core.services.networking.get_connection_type import get_connection_type
|
||||
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)
|
||||
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:
|
||||
connection_type = get_connection_type()
|
||||
logger.debug(f"connection type is: {connection_type}")
|
||||
|
||||
if connection_type == "tor":
|
||||
response = tor_get_request(url, connection_observer, client_observer)
|
||||
response = tor_get_request(url, connection_observer)
|
||||
|
||||
else:
|
||||
response = regular_get_request(url, connection_observer)
|
||||
|
|
|
|||
|
|
@ -7,9 +7,6 @@ if TYPE_CHECKING:
|
|||
from essentials.modules.TorModule import TorModule
|
||||
from essentials.observers.ConnectionObserver import ConnectionObserver
|
||||
from essentials.services.ConnectionService import ConnectionService
|
||||
|
||||
from core.observers.ClientObserver import ClientObserver
|
||||
|
||||
# services
|
||||
from core.services.networking.evaluate_networking_problem import evaluate_tor_networking_problem
|
||||
# errors
|
||||
|
|
@ -21,7 +18,7 @@ from typing import Any
|
|||
from core.Constants import Constants
|
||||
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
|
||||
|
||||
# ============================================================================
|
||||
|
|
@ -29,25 +26,18 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
|
|||
# ============================================================================
|
||||
port_number = ConnectionService.get_random_available_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:
|
||||
tor_module = TorModule(Constants.HV_TOR_STATE_HOME)
|
||||
tor_module.create_session(port_number, connection_observer)
|
||||
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:
|
||||
error_msg = f"[USE TOR SERVICE] Tor failed to start: {e}"
|
||||
tor_module.destroy_session(port_number)
|
||||
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(
|
||||
custom_url, connection_observer, client_observer
|
||||
custom_url, connection_observer
|
||||
)
|
||||
return problem_results
|
||||
except Exception as e:
|
||||
|
|
@ -83,9 +73,6 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
|
|||
return final_reply
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
if client_observer is not None:
|
||||
client_observer.notify('synchronizing', f"Tor Connection Error")
|
||||
|
||||
tor_module.destroy_session(port_number)
|
||||
problem_results = evaluate_tor_networking_problem(
|
||||
custom_url, connection_observer
|
||||
|
|
@ -94,9 +81,6 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
|
|||
|
||||
except requests.exceptions.Timeout:
|
||||
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)
|
||||
problem_results = evaluate_tor_networking_problem(
|
||||
custom_url, connection_observer
|
||||
|
|
@ -104,11 +88,7 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
|
|||
return problem_results
|
||||
|
||||
except requests.exceptions.HTTPError:
|
||||
tor_http_error = f"Tor HTTP error: {response.status_code}"
|
||||
logger.debug(tor_http_error)
|
||||
if client_observer is not None:
|
||||
client_observer.notify('synchronizing', tor_http_error)
|
||||
|
||||
logger.debug(f"HTTP error: {response.status_code}")
|
||||
tor_module.destroy_session(port_number)
|
||||
problem_results = evaluate_tor_networking_problem(
|
||||
custom_url, connection_observer
|
||||
|
|
@ -125,9 +105,6 @@ def tor_get_request(custom_url: str, connection_observer: ConnectionObserver, cl
|
|||
|
||||
except Exception as 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)
|
||||
problem_results = evaluate_tor_networking_problem(
|
||||
custom_url, connection_observer
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ def get_data_from_api(
|
|||
|
||||
try:
|
||||
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:
|
||||
error_msg = "API returned no data"
|
||||
|
|
@ -39,7 +39,6 @@ def get_data_from_api(
|
|||
|
||||
logger.debug(f"Raw API response: {sync_results}")
|
||||
|
||||
final_result = sync_results.get("data", None)
|
||||
final_result = sync_results.get("data", None)
|
||||
|
||||
if final_result:
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ def coordinate_cache_sync(
|
|||
- '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:
|
||||
if not api_result.get("success"):
|
||||
|
|
|
|||
Loading…
Reference in a new issue