From 0a8c9afbc2d435b230f745c7ed6f2e142668c65f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 2 Feb 2026 19:08:13 -0600 Subject: docs and interface renames --- src/slskd/Integrations/VPN/GluetunClient.cs | 23 ++++++++++++++++++----- src/slskd/Integrations/VPN/IVPNClient.cs | 6 +++--- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/slskd/Integrations/VPN/GluetunClient.cs b/src/slskd/Integrations/VPN/GluetunClient.cs index 81757c5c..0d2d7fd0 100644 --- a/src/slskd/Integrations/VPN/GluetunClient.cs +++ b/src/slskd/Integrations/VPN/GluetunClient.cs @@ -46,7 +46,11 @@ public class GluetunClient : IVPNClient private IOptionsMonitor OptionsMonitor { get; } private GluetunVpnOptions Options => OptionsMonitor.CurrentValue.Integration.Vpn.Gluetun; - public async Task GetConnectionStatusAsync() + /// + /// Fetch the VPN connection status from the Gluetun control server. + /// + /// A value indicating whether the VPN is connected. + public async Task GetIsConnectedAsync() { using var http = HttpClientFactory.CreateClient(); http.Timeout = TimeSpan.FromMilliseconds(1000); @@ -69,7 +73,11 @@ public class GluetunClient : IVPNClient } } - public async Task GetForwardedPortAsync() + /// + /// Fetch the forwarded port from the Gluetun control server. + /// + /// The forwarded port, or null if one hasn't been provided yet. + public async Task GetForwardedPortAsync() { using var http = HttpClientFactory.CreateClient(); http.Timeout = TimeSpan.FromMilliseconds(1000); @@ -83,7 +91,8 @@ public class GluetunClient : IVPNClient var port = await response.Content.ReadFromJsonAsync() ?? throw new Exception($"Failed to deserialize Gluetun port forward response; got: {await response.Content.ReadAsStringAsync()}"); - return port.Port; + // Gluetun will return 0 if the port hasn't been retrieved yet, or if port forwarding is turned off + return port.Port == 0 ? null : port.Port; } catch (Exception ex) { @@ -99,10 +108,14 @@ public class GluetunClient : IVPNClient var creds = $"{Options.Username}:{Options.Password}".ToBase64(); client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"Basic {creds}"); } - else + else if (Options.Auth.Equals(GluetunClientAuthenticationMethod.ApiKey.ToString(), StringComparison.OrdinalIgnoreCase)) { client.DefaultRequestHeaders.TryAddWithoutValidation("X-API-Key", Options.ApiKey); } + else + { + // no auth + } } private class GluetunStatusResponse @@ -112,6 +125,6 @@ public class GluetunClient : IVPNClient private class GluetunPortForwardResponse { - public int Port { get; init; } + public int? Port { get; init; } } } \ No newline at end of file diff --git a/src/slskd/Integrations/VPN/IVPNClient.cs b/src/slskd/Integrations/VPN/IVPNClient.cs index 5a111ccd..7c6c5022 100644 --- a/src/slskd/Integrations/VPN/IVPNClient.cs +++ b/src/slskd/Integrations/VPN/IVPNClient.cs @@ -28,11 +28,11 @@ public interface IVPNClient /// Fetch the VPN connection status from the provider. /// /// A value indicating whether the VPN is connected. - public Task GetConnectionStatusAsync(); + public Task GetIsConnectedAsync(); /// /// Fetch the forwarded port configured with the provider, if enabled. /// - /// The forwarded port. - public Task GetForwardedPortAsync(); + /// The forwarded port, or null if one hasn't been provided yet. + public Task GetForwardedPortAsync(); } \ No newline at end of file -- cgit v1.2.3