aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-02-02 19:08:13 -0600
committerJP Dillingham <jp@dillingham.me>2026-02-02 19:08:13 -0600
commit0a8c9afbc2d435b230f745c7ed6f2e142668c65f (patch)
treea37759271d38523acfdea0c001b47e7985ae5c02 /src
parent2fa649934b70edc40350343eb583574dce8c7617 (diff)
downloadslskd-0a8c9afbc2d435b230f745c7ed6f2e142668c65f.tar.gz
docs and interface renames
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Integrations/VPN/GluetunClient.cs23
-rw-r--r--src/slskd/Integrations/VPN/IVPNClient.cs6
2 files changed, 21 insertions, 8 deletions
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<Options> OptionsMonitor { get; }
private GluetunVpnOptions Options => OptionsMonitor.CurrentValue.Integration.Vpn.Gluetun;
- public async Task<bool> GetConnectionStatusAsync()
+ /// <summary>
+ /// Fetch the VPN connection status from the Gluetun control server.
+ /// </summary>
+ /// <returns>A value indicating whether the VPN is connected.</returns>
+ public async Task<bool> GetIsConnectedAsync()
{
using var http = HttpClientFactory.CreateClient();
http.Timeout = TimeSpan.FromMilliseconds(1000);
@@ -69,7 +73,11 @@ public class GluetunClient : IVPNClient
}
}
- public async Task<int> GetForwardedPortAsync()
+ /// <summary>
+ /// Fetch the forwarded port from the Gluetun control server.
+ /// </summary>
+ /// <returns>The forwarded port, or null if one hasn't been provided yet.</returns>
+ public async Task<int?> 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<GluetunPortForwardResponse>()
?? 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.
/// </summary>
/// <returns>A value indicating whether the VPN is connected.</returns>
- public Task<bool> GetConnectionStatusAsync();
+ public Task<bool> GetIsConnectedAsync();
/// <summary>
/// Fetch the forwarded port configured with the provider, if enabled.
/// </summary>
- /// <returns>The forwarded port.</returns>
- public Task<int> GetForwardedPortAsync();
+ /// <returns>The forwarded port, or null if one hasn't been provided yet.</returns>
+ public Task<int?> GetForwardedPortAsync();
} \ No newline at end of file