From 39e0600425bd7d6205dd12e610c5149738a2d3f9 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 25 Jan 2026 18:47:02 -0600 Subject: stub patch logic --- src/slskd/Application.cs | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'src') 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 Loggers { get; } = new ConcurrentDictionary(); private Options Options => OptionsMonitor.CurrentValue; private OptionsAtStartup OptionsAtStartup { get; set; } + private OptionsPatch OptionsPatch { get; set; } private IOptionsMonitor 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, -- cgit v1.2.3