Fixed a bug in teardown of failed attempt, to properly kill firewall
This commit is contained in:
parent
f54ed5686a
commit
8a72ae76fd
1 changed files with 12 additions and 11 deletions
|
|
@ -55,15 +55,15 @@ def verify_connection_integrity(connection_observer: ConnectionObserver, server_
|
||||||
return Result(valid=True, data=observed_ip)
|
return Result(valid=True, data=observed_ip)
|
||||||
|
|
||||||
|
|
||||||
def teardown_failed_connection(current_state: SystemState) -> None:
|
# def teardown_failed_connection(current_state: SystemState) -> None:
|
||||||
"""Performs a full cleanup: closes the interface and dissolves system state."""
|
# """Performs a full cleanup: closes the interface and dissolves system state."""
|
||||||
logger.info("Performing full teardown of failed connection...")
|
# logger.info("Performing full teardown of failed connection...")
|
||||||
|
|
||||||
closed = orchestrate_closing(current_state=current_state, interface=Constants.SINGBOX_TUN_IF)
|
# closed = orchestrate_closing(current_state=current_state, interface=Constants.SINGBOX_TUN_IF)
|
||||||
|
|
||||||
if closed.valid:
|
# if closed.valid:
|
||||||
logger.info("Closed singbox. Performing redundant state removal...")
|
# logger.info("Closed singbox. Performing redundant state removal...")
|
||||||
SystemStateController.dissolve()
|
# SystemStateController.dissolve()
|
||||||
|
|
||||||
|
|
||||||
def confirm_proxy_started(protocol_choice: str) -> bool:
|
def confirm_proxy_started(protocol_choice: str) -> bool:
|
||||||
|
|
@ -169,13 +169,14 @@ def _attempt_start_with_retry(profile_id: int, quantity_of_attempts: int = 2) ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def end_singbox() -> Result:
|
def end_singbox(current_state: Optional[SystemState] = None) -> Result:
|
||||||
"""Orchestrate closing singbox's process, firewall, dns, and json state."""
|
"""Orchestrate closing singbox's process, firewall, dns, and json state."""
|
||||||
|
|
||||||
logger.info("Starting end_singbox")
|
logger.info("Starting end_singbox")
|
||||||
|
|
||||||
# ======== JSON STATE ========
|
# ======== JSON STATE ========
|
||||||
current_state = SystemState.get()
|
if not current_state:
|
||||||
|
current_state = SystemStateController.get()
|
||||||
|
|
||||||
# 1. WireGuard Cleanup. In case, it was a different protocol.
|
# 1. WireGuard Cleanup. In case, it was a different protocol.
|
||||||
if current_state and get_protocol_enum(current_state.profile_id) == ProtocolChoice.WIREGUARD:
|
if current_state and get_protocol_enum(current_state.profile_id) == ProtocolChoice.WIREGUARD:
|
||||||
|
|
@ -337,14 +338,14 @@ def start_singbox(
|
||||||
net_result = apply_network_settings(current_state, server_ip, connection_observer)
|
net_result = apply_network_settings(current_state, server_ip, connection_observer)
|
||||||
if not net_result.valid:
|
if not net_result.valid:
|
||||||
logger.error(f"Network Config Failed: {net_result.message}")
|
logger.error(f"Network Config Failed: {net_result.message}")
|
||||||
teardown_failed_connection(current_state) # <--- Full teardown
|
end_singbox(current_state) # <--- Full teardown
|
||||||
return net_result
|
return net_result
|
||||||
|
|
||||||
# 6. Final IP Integrity Check
|
# 6. Final IP Integrity Check
|
||||||
validation = verify_connection_integrity(connection_observer, server_ip)
|
validation = verify_connection_integrity(connection_observer, server_ip)
|
||||||
if not validation.valid:
|
if not validation.valid:
|
||||||
logger.error(validation.message)
|
logger.error(validation.message)
|
||||||
teardown_failed_connection(current_state) # <--- Full teardown
|
end_singbox(current_state) # <--- Full teardown
|
||||||
if validation.error_type == ResultError.LEAK_ISSUE and connection_observer:
|
if validation.error_type == ResultError.LEAK_ISSUE and connection_observer:
|
||||||
connection_observer.notify("connecting", "Failed Connection! Test showed leak!")
|
connection_observer.notify("connecting", "Failed Connection! Test showed leak!")
|
||||||
return validation
|
return validation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue