Reduced redundant function for subscriptions in connection activation

This commit is contained in:
SimplifiedPrivacy 2026-07-19 15:37:27 -04:00
parent a116597a38
commit d8273171b5

View file

@ -3,6 +3,7 @@ from core.services.networking.systemwide.systemwide_wireguard import establish_s
from core.services.keys_and_verifications.wireguard_keys import register_wireguard_session from core.services.keys_and_verifications.wireguard_keys import register_wireguard_session
from core.models.session.SessionConnection import SessionConnectionTypes from core.models.session.SessionConnection import SessionConnectionTypes
from core.models.system.SystemConnection import SystemConnectionTypes from core.models.system.SystemConnection import SystemConnectionTypes
from core.services.subscriptions.subscriptions import activate_subscription
from core.errors.logger import logger from core.errors.logger import logger
from core.errors.exceptions import * from core.errors.exceptions import *
@ -13,7 +14,6 @@ from core.Errors import ConnectionTerminationError, InvalidSubscriptionError
from core.services.WebServiceApiService import WebServiceApiService from core.services.WebServiceApiService import WebServiceApiService
from core.controllers.ConnectionController import ConnectionController from core.controllers.ConnectionController import ConnectionController
from core.models.BaseProfile import ProfileType from core.models.BaseProfile import ProfileType
from core.services.subscriptions.subscriptions import activate_subscription
from core.observers.ConnectionObserver import ConnectionObserver from core.observers.ConnectionObserver import ConnectionObserver
from core.controllers.SystemStateController import SystemStateController from core.controllers.SystemStateController import SystemStateController
@ -27,7 +27,7 @@ def establish_connection(
"""Establish a connection for the given profile.""" """Establish a connection for the given profile."""
logger.info(f"[CONNECTION] Checking subscription..") logger.info(f"[CONNECTION] Checking subscription..")
_ensure_subscription_ready(profile, connection_observer) activate_subscription(profile, connection_observer)
logger.info(f"[CONNECTION] Checking proxy configuration..") logger.info(f"[CONNECTION] Checking proxy configuration..")
_ensure_proxy_configured(profile, connection_observer) _ensure_proxy_configured(profile, connection_observer)
@ -43,14 +43,6 @@ def establish_connection(
return _establish_with_renegotiation(profile, establish_fn, ignore, connection_observer) return _establish_with_renegotiation(profile, establish_fn, ignore, connection_observer)
def _ensure_subscription_ready(
profile: Union[SessionProfile, SystemProfile],
connection_observer: Optional[ConnectionObserver],
):
"""Activate subscription (idempotent)."""
activate_subscription(profile, connection_observer=connection_observer)
def _ensure_proxy_configured( def _ensure_proxy_configured(
profile: Union[SessionProfile, SystemProfile], profile: Union[SessionProfile, SystemProfile],
connection_observer: Optional[ConnectionObserver], connection_observer: Optional[ConnectionObserver],
@ -61,7 +53,7 @@ def _ensure_proxy_configured(
if not profile.has_proxy_configuration(): if not profile.has_proxy_configuration():
logger.info(f"[CONNECTION] You need a new proxy configuration") logger.info(f"[CONNECTION] You need a new proxy configuration")
_ensure_subscription_ready(profile, connection_observer) activate_subscription(profile, connection_observer)
logger.info(f"[CONNECTION] Getting a proxy config from web service..") logger.info(f"[CONNECTION] Getting a proxy config from web service..")
proxy_config = ConnectionController.with_preferred_connection( proxy_config = ConnectionController.with_preferred_connection(
@ -95,7 +87,7 @@ def _ensure_wireguard_configured(
except ConnectionTerminationError as e: except ConnectionTerminationError as e:
logger.error(f"[CONNECTION] Previous Systemwide Wireguard connection could not be disabled. {e}") logger.error(f"[CONNECTION] Previous Systemwide Wireguard connection could not be disabled. {e}")
_ensure_subscription_ready(profile, connection_observer) activate_subscription(profile, connection_observer)
logger.info(f"[CONNECTION] Checking if the profile already has a wg config..") logger.info(f"[CONNECTION] Checking if the profile already has a wg config..")
if not profile.has_wireguard_configuration(): if not profile.has_wireguard_configuration():
logger.info(f"[CONNECTION] Profile does NOT have WG keys and it needs it. Registering a NEW wg session..") logger.info(f"[CONNECTION] Profile does NOT have WG keys and it needs it. Registering a NEW wg session..")