aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-02-07 18:55:51 -0600
committerJP Dillingham <jp@dillingham.me>2026-02-07 18:55:51 -0600
commit102046851d3233c791b069cbe75ddbfbafe675cc (patch)
tree62cd9ab9b42db96a7167a45260a266065c8d0d9f /src
parent1aff04b696f30ffbca057a20f68fbd71246d6fbb (diff)
downloadslskd-102046851d3233c791b069cbe75ddbfbafe675cc.tar.gz
tweaking of status updates and logs
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Integrations/VPN/VPNService.cs41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/slskd/Integrations/VPN/VPNService.cs b/src/slskd/Integrations/VPN/VPNService.cs
index 179c5436..4938e817 100644
--- a/src/slskd/Integrations/VPN/VPNService.cs
+++ b/src/slskd/Integrations/VPN/VPNService.cs
@@ -43,7 +43,7 @@ public class VPNService : IDisposable
if (OptionsAtStartup.Integration.Vpn.Enabled)
{
- Timer = new System.Timers.Timer(interval: 2500)
+ Timer = new System.Timers.Timer(interval: OptionsAtStartup.Integration.Vpn.PollingInterval)
{
AutoReset = true,
};
@@ -55,7 +55,6 @@ public class VPNService : IDisposable
if (!string.IsNullOrEmpty(OptionsMonitor.CurrentValue.Integration.Vpn.Gluetun.Url))
{
Client = new GluetunClient(HttpClientFactory, OptionsMonitor);
- Timer.Start();
Log.Information("VPN integration enabled using {Client}", typeof(GluetunClient).Name);
return;
@@ -79,6 +78,9 @@ public class VPNService : IDisposable
private bool Disposed { get; set; }
private SemaphoreSlim TimerElapsedLock { get; } = new SemaphoreSlim(1, 1);
+ public void StartPolling() => Timer?.Start();
+ public void StopPolling() => Timer?.Stop();
+
public void Dispose()
{
Dispose(disposing: true);
@@ -101,7 +103,7 @@ public class VPNService : IDisposable
private async Task CheckConnection()
{
bool isReadyNow = false;
- VPNStatus status = default;
+ VPNStatus status = new VPNStatus();
// one at a time!
await TimerElapsedLock.WaitAsync(0);
@@ -123,7 +125,7 @@ public class VPNService : IDisposable
catch (Exception ex)
{
// log, but don't throw. an exception here is treated as if the VPN is down; we have to assume it is
- Log.Warning("Failed to fetch status from VPN client: {Message}", ex.Message);
+ Log.Warning("Failed to fetch status from VPN client {Client}: {Message}", Client.GetType().Name, ex.Message);
}
/*
@@ -133,7 +135,7 @@ public class VPNService : IDisposable
* update application state (via StateMutator)
* if IsReady changed during this invocation, disposition the ReadyTaskCompletionSource
*/
- if (!status.IsConnected)
+ if (status is null || !status.IsConnected)
{
isReadyNow = false;
}
@@ -169,36 +171,45 @@ public class VPNService : IDisposable
if (!IsReady && isReadyNow)
{
- Log.Information("VPN client connected and ready! IP: {PublicIP} ({Location}), Forwarded port: {Port}", status.PublicIPAddress, status.Location, status.ForwardedPort.ToString() ?? "N/A");
+ 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");
}
else if (IsReady && !isReadyNow)
{
Log.Warning("VPN client disconnected");
+ }
+ else if (!IsReady && !isReadyNow)
+ {
+ string port = OptionsMonitor.CurrentValue.Integration.Vpn.PortForwarding ? status.ForwardedPort.ToString() : "N/A";
+ port = string.IsNullOrEmpty(port) ? "?" : port;
- if (OptionsAtStartup.Integration.Vpn.Required)
- {
- SoulseekClient.Disconnect("VPN client disconnected", new VPNClientException("VPN client disconnected"));
- }
+ 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;
+ if (OptionsAtStartup.Integration.Vpn.Required && !IsReady)
+ {
+ SoulseekClient.Disconnect("VPN client disconnected", new VPNClientException("VPN client disconnected"));
+ }
+
StateMutator.SetValue(state => state with
{
Vpn = new VpnState()
{
IsReady = IsReady,
- IsConnected = status.IsConnected,
- PublicIPAddress = status.PublicIPAddress,
- Location = status.Location,
- ForwardedPort = status.ForwardedPort,
+ IsConnected = Status?.IsConnected ?? false,
+ PublicIPAddress = status?.PublicIPAddress,
+ Location = status?.Location,
+ ForwardedPort = status?.ForwardedPort,
},
});
}
catch (Exception ex)
{
- Log.Warning("VPN client status check failed: {Message}", ex.Message);
+ Log.Warning(ex, "VPN client status check failed: {Message}", ex.Message);
}
finally
{