From f10a4aa2cad193a01b14fe52e1bb6350f41a474b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 6 Feb 2026 09:23:28 -0600 Subject: abort connection attempts if the VPN is required and not ready --- src/slskd/Core/ConnectionWatchdog.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/slskd/Core/ConnectionWatchdog.cs b/src/slskd/Core/ConnectionWatchdog.cs index b7a4fa34..0cf30484 100644 --- a/src/slskd/Core/ConnectionWatchdog.cs +++ b/src/slskd/Core/ConnectionWatchdog.cs @@ -23,6 +23,7 @@ namespace slskd using System.Threading; using System.Threading.Tasks; using Serilog; + using slskd.Integrations.VPN; using Soulseek; /// @@ -41,15 +42,21 @@ namespace slskd /// Initializes a new instance of the class. /// /// + /// /// + /// /// public ConnectionWatchdog( ISoulseekClient soulseekClient, + VPNService vpnService, IOptionsMonitor optionsMonitor, + OptionsAtStartup optionsAtStartup, IManagedState applicationState) { Client = soulseekClient; + VPN = vpnService; OptionsMonitor = optionsMonitor; + OptionsAtStartup = optionsAtStartup; ApplicationState = applicationState; WatchdogTimer = new System.Timers.Timer() @@ -77,9 +84,11 @@ namespace slskd public bool IsAttemptingConnection => SyncRoot.CurrentCount == 0; private ISoulseekClient Client { get; } + private VPNService VPN { get; } private bool Disposed { get; set; } private ILogger Log { get; } = Serilog.Log.ForContext(); private IOptionsMonitor OptionsMonitor { get; set; } + private OptionsAtStartup OptionsAtStartup { get; set; } private IManagedState ApplicationState { get; } private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1, 1); private object StateLock { get; } = new object(); @@ -232,6 +241,12 @@ namespace slskd return; } + if (OptionsAtStartup.Integration.Vpn.Required && !VPN.IsReady) + { + Log.Debug("AttemptConnection aborted; VPN is not yet ready (status: {Status})", VPN.Status); + return; + } + CancellationTokenSource = new CancellationTokenSource(); if (attempts > 0) -- cgit v1.2.3