diff options
| -rw-r--r-- | config/slskd.example.yml | 1 | ||||
| -rw-r--r-- | src/slskd/Core/ConnectionWatchdog.cs | 9 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 6 | ||||
| -rw-r--r-- | src/slskd/Integrations/VPN/VPNService.cs | 31 |
4 files changed, 23 insertions, 24 deletions
diff --git a/config/slskd.example.yml b/config/slskd.example.yml index dcf419c6..7e820d9f 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -233,7 +233,6 @@ # integration: # vpn: # enabled: false -# required: false # wait for the VPN to connect before connecting to Soulseek # port_forwarding: false # polling_interval: 2500 # gluetun: diff --git a/src/slskd/Core/ConnectionWatchdog.cs b/src/slskd/Core/ConnectionWatchdog.cs index 7e0710a6..d2f7caa8 100644 --- a/src/slskd/Core/ConnectionWatchdog.cs +++ b/src/slskd/Core/ConnectionWatchdog.cs @@ -152,13 +152,6 @@ namespace slskd /// <remarks>This should be called when the application is reasonably certain that the connection is connected.</remarks> public virtual void Stop(bool abortReconnect = false) { - // if the VPN is required, we have to keep polling in the background so we can disconnect if it drops - // this is a belt-and-suspenders effort to ensure maximum protection in case someone doesn't have a kill switch - if (!OptionsAtStartup.Integration.Vpn.Required) - { - VPN.StopPolling(); - } - // stop the timer first to avoid having it start the connection process again when the cts is cancelled WatchdogTimer.Enabled = false; UpdateApplicationState(); @@ -257,7 +250,7 @@ namespace slskd return; } - if (OptionsAtStartup.Integration.Vpn.Required && !VPN.IsReady) + if (OptionsAtStartup.Integration.Vpn.Enabled && !VPN.IsReady) { IsAwaitingVpn = true; return; diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 08fb1166..a0b5f954 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -2317,12 +2317,6 @@ namespace slskd public bool Enabled { get; init; } = false; /// <summary> - /// Gets a value indicating whether a VPN connection is required before connecting to the Soulseek network. - /// </summary> - [RequiresRestart] - public bool Required { get; init; } = false; - - /// <summary> /// Gets a value indicating whether the configured VPN supports port forwarding. /// </summary> public bool PortForwarding { get; init; } = false; diff --git a/src/slskd/Integrations/VPN/VPNService.cs b/src/slskd/Integrations/VPN/VPNService.cs index 2c42ff97..bc3eb668 100644 --- a/src/slskd/Integrations/VPN/VPNService.cs +++ b/src/slskd/Integrations/VPN/VPNService.cs @@ -149,6 +149,7 @@ public class VPNService : IDisposable private async Task CheckConnection() { + var options = OptionsMonitor.CurrentValue.Integration.Vpn; bool isReadyNow = false; VPNStatus status = new VPNStatus(); @@ -172,7 +173,7 @@ public class VPNService : IDisposable if (status is not null && status.IsConnected) { - if (OptionsMonitor.CurrentValue.Integration.Vpn.PortForwarding) + if (options.PortForwarding) { if (status.ForwardedPort.HasValue) { @@ -202,8 +203,14 @@ public class VPNService : IDisposable if (!IsReady && isReadyNow) { - string port = OptionsMonitor.CurrentValue.Integration.Vpn.PortForwarding ? status.ForwardedPort.ToString() : "N/A"; - Log.Information("VPN client connected and ready. IP: {PublicIP} ({Location}), Forwarded port: {Port}", status.PublicIPAddress, status.Location, status.ForwardedPort.ToString() ?? "N/A"); + if (options.PortForwarding) + { + Log.Information("VPN client connected and ready. IP: {PublicIP} ({Location}), Forwarded port: {Port}", status.PublicIPAddress, status.Location, status.ForwardedPort); + } + else + { + Log.Information("VPN client connected and ready. IP: {PublicIP} ({Location})", status.PublicIPAddress, status.Location); + } } else if (IsReady && !isReadyNow) { @@ -211,17 +218,23 @@ public class VPNService : IDisposable } else if (!IsReady && !isReadyNow) { - string port = OptionsMonitor.CurrentValue.Integration.Vpn.PortForwarding ? status.ForwardedPort.ToString() : "N/A"; - port = string.IsNullOrEmpty(port) ? "?" : port; - - string ip = status.PublicIPAddress == default ? "?" : status.PublicIPAddress.ToString(); - Log.Information("Waiting for VPN client; IP: {PublicIP}, Forwarded port: {Port}", ip, port); + if (!options.PortForwarding) + { + Log.Information("Waiting for VPN client; IP: ?"); + } + else + { + // port could possibly come first, if the client allows the user to specify it + string port = status.ForwardedPort.HasValue ? status.ForwardedPort.ToString() : "?"; + string ip = status.PublicIPAddress == default ? "?" : status.PublicIPAddress.ToString(); + Log.Information("Waiting for VPN client; IP: {PublicIP}, Forwarded port: {Port}", ip, port); + } } IsReady = isReadyNow; Status = status ?? new VPNStatus(); - if (OptionsAtStartup.Integration.Vpn.Required && !IsReady) + if (!IsReady) { SoulseekClient.Disconnect("VPN client disconnected", new VPNClientException("VPN client disconnected")); } |
