diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-01-25 18:47:02 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-01-25 18:47:02 -0600 |
| commit | 39e0600425bd7d6205dd12e610c5149738a2d3f9 (patch) | |
| tree | 91b10e5073b904b4c39e698be9c7b7cdcf107b95 /src | |
| parent | 385b54334209d06e2761a0c0f3c0b782065ce79c (diff) | |
| download | slskd-39e0600425bd7d6205dd12e610c5149738a2d3f9.tar.gz | |
stub patch logic
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index bed8aab2..3f4ae37f 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -56,6 +56,7 @@ namespace slskd { public Task CheckVersionAsync(); public void CollectGarbage(); + public Task ApplyOptionsPatchAsync(OptionsPatch patch); } public sealed class Application : IApplication @@ -228,6 +229,7 @@ namespace slskd private ConcurrentDictionary<string, ILogger> Loggers { get; } = new ConcurrentDictionary<string, ILogger>(); private Options Options => OptionsMonitor.CurrentValue; private OptionsAtStartup OptionsAtStartup { get; set; } + private OptionsPatch OptionsPatch { get; set; } private IOptionsMonitor<Options> OptionsMonitor { get; set; } private SemaphoreSlim OptionsSyncRoot { get; } = new SemaphoreSlim(1, 1); private SemaphoreSlim GlobalEnqueueSemaphore { get; } = new SemaphoreSlim(10, 10); @@ -315,6 +317,8 @@ namespace slskd } } + public Task ApplyOptionsPatchAsync(OptionsPatch patch) => PatchOptions(patch); + async Task IHostedService.StartAsync(CancellationToken cancellationToken) { Log.Information("Application started"); @@ -1391,7 +1395,26 @@ namespace slskd } } - private async Task OptionsMonitor_OnChange(Options newOptions) + private Task OptionsMonitor_OnChange(Options newOptions) + { + return UpdateOptions(newOptions); + } + + private async Task PatchOptions(OptionsPatch patch) + { + await OptionsSyncRoot.WaitAsync(); + + try + { + OptionsPatch = patch; + } + finally + { + OptionsSyncRoot.Release(); + } + } + + private async Task UpdateOptions(Options newOptions) { // this code is known to fire more than once per update. i'm not sure whether these might be executed concurrently. // lock to be safe, because we need to accurately track the last value of Options for diffing purposes. threading @@ -1520,8 +1543,29 @@ namespace slskd inactivityTimeout: connection.Timeout.Transfer); } + /* + apply options from the run-time options patch + + if options are present (are not null), they take precedent over any other options, regardless of + how they were defined (command line, envar, yaml) + + this needs to be done for every single property in OptionsPatch, or the next time options are updated + the value may be overwritten + */ + IPAddress listenIPAddress = !string.IsNullOrEmpty(OptionsPatch?.Soulseek?.ListenIpAddress) + ? IPAddress.Parse(OptionsPatch.Soulseek.ListenIpAddress) + : old.ListenIpAddress == update.ListenIpAddress + ? null + : IPAddress.Parse(update.ListenIpAddress); + + int? listenPort = (OptionsPatch?.Soulseek?.ListenPort.HasValue ?? false) + ? OptionsPatch.Soulseek.ListenPort.Value + : old.ListenPort == update.ListenPort + ? null + : update.ListenPort; + var patch = new SoulseekClientOptionsPatch( - listenIPAddress: old.ListenIpAddress == update.ListenIpAddress ? null : IPAddress.Parse(update.ListenIpAddress), + listenIPAddress: listenIPAddress, listenPort: old.ListenPort == update.ListenPort ? null : update.ListenPort, enableDistributedNetwork: old.DistributedNetwork.Disabled == update.DistributedNetwork.Disabled ? null : !update.DistributedNetwork.Disabled, distributedChildLimit: old.DistributedNetwork.ChildLimit == update.DistributedNetwork.ChildLimit ? null : update.DistributedNetwork.ChildLimit, |
