From fbe80076abde85ae6465861f2ad9662682f5378c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 4 Aug 2025 09:14:45 -0500 Subject: check for enums when diffing objects --- src/slskd/Common/CommonExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 44e3c034..ec76b745 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -116,7 +116,7 @@ namespace slskd differences.Add((prop, fqn, leftVal, rightVal)); } } - else if (propType.IsPrimitive || Nullable.GetUnderlyingType(propType) != null || new[] { typeof(string), typeof(decimal) }.Contains(propType)) + else if (propType.IsPrimitive || propType.IsEnum || Nullable.GetUnderlyingType(propType) != null || new[] { typeof(string), typeof(decimal) }.Contains(propType)) { if (!Equals(leftVal, rightVal)) { -- cgit v1.2.3 From ffa2b220221040997e9ebacb4a08136e80c9a7b3 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 4 Aug 2025 09:15:01 -0500 Subject: add some debug statements to option monitoring --- src/slskd/Application.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index a28d2a2f..e1f8d762 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1270,6 +1270,8 @@ namespace slskd // shenanigans here could lead to missed updates. await OptionsSyncRoot.WaitAsync(); + Log.Debug("OptionsMonitor OnChange Invoked"); + try { var pendingRestart = false; @@ -1281,9 +1283,12 @@ namespace slskd // don't react to duplicate/no-change events https://github.com/slskd/slskd/issues/126 if (!diff.Any()) { + Log.Debug("Diff of previous and new options is the same; nothing to do"); return; } + Log.Debug("Diff of previous and new options contains {Count} changed properties: {Properties}", diff.Count(), diff.Select(p => p.FQN)); + foreach (var (property, fqn, left, right) in diff) { static bool HasAttribute(PropertyInfo property) => property.CustomAttributes.Any(a => a.AttributeType == typeof(T)); -- cgit v1.2.3 From 219aa156446e2465783cc018510cd9a18e643bb7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 4 Aug 2025 10:47:46 -0500 Subject: use a string for diagnostic level (match other enums) --- src/slskd/Core/Options.cs | 5 +++-- src/slskd/Program.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 1fed70f5..4d4c1e68 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -36,10 +36,10 @@ namespace slskd using slskd.Relay; using slskd.Shares; using slskd.Validation; - using Soulseek.Diagnostics; using Utility.CommandLine; using Utility.EnvironmentVariables; using YamlDotNet.Serialization; + using SoulseekDiagnostics = Soulseek.Diagnostics; /// /// Disambiguates options derived at startup from options that may update at run time. @@ -1572,8 +1572,9 @@ namespace slskd [Argument(default, "slsk-diag-level")] [EnvironmentVariable("SLSK_DIAG_LEVEL")] [Description("minimum diagnostic level (None, Warning, Info, Debug)")] + [Enum(typeof(SoulseekDiagnostics.DiagnosticLevel))] [RequiresRestart] - public DiagnosticLevel DiagnosticLevel { get; init; } = DiagnosticLevel.Info; + public string DiagnosticLevel { get; init; } = SoulseekDiagnostics.DiagnosticLevel.Info.ToString().ToLowerInvariant(); /// /// Gets options for the distributed network. diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 89230e2a..645e395c 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -584,7 +584,7 @@ namespace slskd new SoulseekClient(options: new SoulseekClientOptions( maximumConcurrentUploads: OptionsAtStartup.Global.Upload.Slots, maximumConcurrentDownloads: OptionsAtStartup.Global.Download.Slots, - minimumDiagnosticLevel: OptionsAtStartup.Soulseek.DiagnosticLevel))); + minimumDiagnosticLevel: OptionsAtStartup.Soulseek.DiagnosticLevel.ToEnum()))); // add the core application service to DI as well as a hosted service so that other services can // access instance methods -- cgit v1.2.3 From 30e405f7575590979f9a6c65c6510f4b7e6ff35e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 4 Aug 2025 18:29:14 -0500 Subject: use an array to store compiled search request filters --- src/slskd/Application.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index e1f8d762..57e5bcf2 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -135,7 +135,7 @@ namespace slskd regexOptions |= RegexOptions.IgnoreCase; } - CompiledSearchResponseFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, regexOptions)); + CompiledSearchRequestFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, regexOptions)).ToArray(); State = state; State.OnChange(state => State_OnChange(state)); @@ -228,7 +228,7 @@ namespace slskd private ISearchService Search { get; set; } private IRelayService Relay { get; set; } private IMemoryCache Cache { get; set; } = new MemoryCache(new MemoryCacheOptions()); - private IEnumerable CompiledSearchResponseFilters { get; set; } + private Regex[] CompiledSearchRequestFilters { get; set; } private IEnumerable ActiveDownloadIdsAtPreviousShutdown { get; set; } = Enumerable.Empty(); private Options.FlagsOptions Flags { get; set; } private IReadOnlyCollection ExcludedSearchPhrases { get; set; } = Enumerable.Empty().ToList(); @@ -1319,7 +1319,7 @@ namespace slskd if (PreviousOptions.Filters.Search.Request.Except(newOptions.Filters.Search.Request).Any() || newOptions.Filters.Search.Request.Except(PreviousOptions.Filters.Search.Request).Any()) { - CompiledSearchResponseFilters = newOptions.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled)); + CompiledSearchRequestFilters = newOptions.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled)).ToArray(); Log.Information("Updated and re-compiled search response filters"); } @@ -1445,7 +1445,7 @@ namespace slskd return null; } - if (CompiledSearchResponseFilters.Any(filter => filter.IsMatch(query.SearchText))) + if (CompiledSearchRequestFilters.Any(filter => filter.IsMatch(query.SearchText))) { return null; } -- cgit v1.2.3 From 29c1ee192a64a56171a7d3955e3f0a64b56f0255 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 10 Aug 2025 15:29:08 -0500 Subject: use a readonlycollection for repositories --- src/slskd/Shares/ShareService.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 19579458..1fd683cc 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -116,7 +116,7 @@ namespace slskd.Shares private StorageMode CacheStorageMode { get; } private ILogger Log { get; } = Serilog.Log.ForContext(); private (Host Host, IShareRepository Repository) Local { get; set; } - private IEnumerable AllRepositories { get; set; } + private IReadOnlyCollection AllRepositories { get; set; } /// /// Adds a new, or updates an existing, share host. @@ -133,7 +133,9 @@ namespace slskd.Shares AllRepositories = HostDictionary.Values .Select(value => value.Repository) - .Prepend(Local.Repository); + .Prepend(Local.Repository) + .ToList() + .AsReadOnly(); State.SetValue(state => state with { @@ -239,7 +241,9 @@ namespace slskd.Shares AllRepositories = HostDictionary.Values .Select(value => value.Repository) - .Prepend(Local.Repository); + .Prepend(Local.Repository) + .ToList() + .AsReadOnly(); State.SetValue(state => state with { -- cgit v1.2.3 From 515440c62cb08943f629dc2f75dcb2201e140465 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 10 Aug 2025 15:29:41 -0500 Subject: snapshot the list of repositories before generating a browse response --- src/slskd/Shares/ShareService.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 1fd683cc..f2d07305 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -160,17 +160,20 @@ namespace slskd.Shares prefix = share.RemotePath + (share.RemotePath.EndsWith('\\') ? string.Empty : '\\'); } + // snapshot the current list of repositories + var repositories = AllRepositories.ToList(); + // Soulseek requires that each directory in the tree have an entry in the list returned in a browse response. if // missing, files that are nested within directories which contain only directories (no files) are displayed as being // in the root. to get around this, prime a dictionary with all known directories, and an empty Soulseek.Directory. if // there are any files in the directory, this entry will be overwritten with a new Soulseek.Directory containing the // files. if not they'll be left as is. - foreach (var directory in AllRepositories.SelectMany(r => r.ListDirectories(prefix))) + foreach (var directory in repositories.SelectMany(r => r.ListDirectories(prefix))) { directories.TryAdd(directory, new Directory(directory)); } - var files = AllRepositories.SelectMany(r => r.ListFiles(prefix, includeFullPath: true)); + var files = repositories.SelectMany(r => r.ListFiles(prefix, includeFullPath: true)); var groups = files .GroupBy(file => file.Filename.GetNormalizedDirectoryName()) -- cgit v1.2.3 From b5cabb6f79b403d9fa6b9cfb43fd30d4fe739410 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 10 Aug 2025 15:33:11 -0500 Subject: docs --- src/slskd/Shares/ShareService.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index f2d07305..7b3e949b 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -322,6 +322,9 @@ namespace slskd.Shares /// Returns the list of all started at or after the specified /// unix timestamp. /// + /// + /// Note that this returns the scan history for local shares only. + /// /// A unix timestamp that serves as the lower bound of the time-based listing. /// The operation context, including the list of found scans. public Task> ListScansAsync(long startedAtOrAfter = 0) -- cgit v1.2.3 From 9353755d0ee0f2764dcf6e5574758ee57ff73cd6 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 10 Aug 2025 16:55:11 -0500 Subject: use readonlylist in a few places --- src/slskd/Application.cs | 23 +++++++++++++++-------- src/slskd/Events/EventService.cs | 5 +++-- src/slskd/Shares/ShareScanner.cs | 9 +++++++-- src/slskd/Shares/ShareService.cs | 4 ++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 57e5bcf2..56d26276 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -135,7 +135,10 @@ namespace slskd regexOptions |= RegexOptions.IgnoreCase; } - CompiledSearchRequestFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, regexOptions)).ToArray(); + CompiledSearchRequestFilters = OptionsAtStartup.Filters.Search.Request + .Select(f => new Regex(f, regexOptions)) + .ToList() + .AsReadOnly(); State = state; State.OnChange(state => State_OnChange(state)); @@ -228,10 +231,10 @@ namespace slskd private ISearchService Search { get; set; } private IRelayService Relay { get; set; } private IMemoryCache Cache { get; set; } = new MemoryCache(new MemoryCacheOptions()); - private Regex[] CompiledSearchRequestFilters { get; set; } - private IEnumerable ActiveDownloadIdsAtPreviousShutdown { get; set; } = Enumerable.Empty(); + private IReadOnlyList CompiledSearchRequestFilters { get; set; } = []; + private IReadOnlyList ActiveDownloadIdsAtPreviousShutdown { get; set; } = []; private Options.FlagsOptions Flags { get; set; } - private IReadOnlyCollection ExcludedSearchPhrases { get; set; } = Enumerable.Empty().ToList(); + private IReadOnlyList ExcludedSearchPhrases { get; set; } = []; public void CollectGarbage() { @@ -352,7 +355,7 @@ namespace slskd // save the ids of any downloads that were active, so we can re-enqueue them after we've connected and logged in. // we need to check the database before we re-request to make sure the user didn't remove them from the UI while // the application was running, but before it was logged in. so just save the ids. - ActiveDownloadIdsAtPreviousShutdown = activeDownloads.Select(d => d.Id); + ActiveDownloadIdsAtPreviousShutdown = activeDownloads.Select(d => d.Id).ToList().AsReadOnly(); Log.Debug("Downloads to resume upon connection: {Ids}", ActiveDownloadIdsAtPreviousShutdown.ToJson()); Log.Debug("Configuring client"); @@ -924,7 +927,7 @@ namespace slskd } // clear the ids we saved at startup; we don't want to re-request these again if the connection is cycled - ActiveDownloadIdsAtPreviousShutdown = Enumerable.Empty(); + ActiveDownloadIdsAtPreviousShutdown = []; } catch (Exception ex) { @@ -1178,7 +1181,7 @@ namespace slskd private void Client_ExcludedSearchPhrasesReceived(object sender, IReadOnlyCollection e) { Log.Debug("Excluded search phrases: {Phrases}", string.Join(", ", e)); - ExcludedSearchPhrases = e; + ExcludedSearchPhrases = e.ToList(); } private void Client_TransferProgressUpdated(object sender, TransferProgressUpdatedEventArgs args) @@ -1319,7 +1322,11 @@ namespace slskd if (PreviousOptions.Filters.Search.Request.Except(newOptions.Filters.Search.Request).Any() || newOptions.Filters.Search.Request.Except(PreviousOptions.Filters.Search.Request).Any()) { - CompiledSearchRequestFilters = newOptions.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled)).ToArray(); + CompiledSearchRequestFilters = newOptions.Filters.Search.Request + .Select(f => new Regex(f, RegexOptions.Compiled)) + .ToList() + .AsReadOnly(); + Log.Information("Updated and re-compiled search response filters"); } diff --git a/src/slskd/Events/EventService.cs b/src/slskd/Events/EventService.cs index d6f1a3f5..6dc61c13 100644 --- a/src/slskd/Events/EventService.cs +++ b/src/slskd/Events/EventService.cs @@ -48,7 +48,7 @@ public class EventService /// The retrieved list. /// Thrown when the specified is less than zero. /// Thrown when the specified is zero. - public virtual IReadOnlyCollection Get(int offset = 0, int limit = int.MaxValue) + public virtual IReadOnlyList Get(int offset = 0, int limit = int.MaxValue) { if (offset < 0) { @@ -68,7 +68,8 @@ public class EventService .OrderByDescending(e => e.Timestamp) .Skip(offset) .Take(limit) - .ToList(); + .ToList() + .AsReadOnly(); return events; } diff --git a/src/slskd/Shares/ShareScanner.cs b/src/slskd/Shares/ShareScanner.cs index bf069991..6e32f81e 100644 --- a/src/slskd/Shares/ShareScanner.cs +++ b/src/slskd/Shares/ShareScanner.cs @@ -88,7 +88,7 @@ namespace slskd.Shares private FileService Files { get; } private int WorkerCount { get; } private ILogger Log { get; } = Serilog.Log.ForContext(); - private List Shares { get; set; } + private IReadOnlyList Shares { get; set; } private ISoulseekFileFactory SoulseekFileFactory { get; } private IManagedState State { get; } = new ManagedState(); private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1); @@ -161,6 +161,8 @@ namespace slskd.Shares var swSnapshot = 0L; sw.Start(); + // note: this should be the only place where we are assigning Shares, so that this is 1) synchronized by SyncRoot + // and 2) stable throughout the scan. if this ever changes we'll have to snapshot the value and use it instead Shares = shares.ToList(); if (!Shares.Any()) @@ -168,7 +170,10 @@ namespace slskd.Shares Log.Warning("Aborting shared file scan; no shares configured."); } - Shares.ForEach(s => Log.Debug(s.ToJson())); + foreach (var share in Shares) + { + Log.Debug(share.ToJson()); + } Shares.Where(s => !s.IsExcluded).ToList() .ForEach(s => Log.Information("Sharing {Local} as {Remote}", s.LocalPath, s.RemotePath)); diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 7b3e949b..6068a744 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -59,7 +59,7 @@ namespace slskd.Shares Local = (host, repository); - AllRepositories = new List(new[] { repository }); + AllRepositories = [repository]; Scanner = scanner ?? new ShareScanner( workerCount: options.Shares.Cache.Workers, @@ -116,7 +116,7 @@ namespace slskd.Shares private StorageMode CacheStorageMode { get; } private ILogger Log { get; } = Serilog.Log.ForContext(); private (Host Host, IShareRepository Repository) Local { get; set; } - private IReadOnlyCollection AllRepositories { get; set; } + private IReadOnlyList AllRepositories { get; set; } /// /// Adds a new, or updates an existing, share host. -- cgit v1.2.3 From 0aecb39d0965ec013f6a2293165a6944869c963a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 10 Aug 2025 16:58:14 -0500 Subject: bump Soulseek.NET to 7.1.2 --- src/slskd/slskd.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj index 94770f16..465ac16f 100644 --- a/src/slskd/slskd.csproj +++ b/src/slskd/slskd.csproj @@ -68,7 +68,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- cgit v1.2.3 From fa43c322af04457d47cba9bf0fd0007252dce8a1 Mon Sep 17 00:00:00 2001 From: Audrey Drake <6566104+RalphORama@users.noreply.github.com> Date: Thu, 14 Aug 2025 04:08:54 +0000 Subject: fix(docs): add missing prefixes to env names --- docs/config.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/config.md b/docs/config.md index 6f01c2af..053deea3 100644 --- a/docs/config.md +++ b/docs/config.md @@ -78,9 +78,9 @@ remote_configuration: false Users that want extra security and don't intend to use the application's web UI can disable it. This setting is ideal in situations where slskd will be controlled by another application via the API (like when run as a Relay agent). -| Command-Line | Environment Variable | Description | -| ------------------------ | -----------------------------| ------------------------------------------------------------- | -| `--headless` | `SLSKD_HEADLESS` | Determines whether the application should run in headless (no web UI) mode | +| Command-Line | Environment Variable | Description | +| ------------------------ | -----------------------------| -------------------------------------------------------------------------- | +| `--headless` | `SLSKD_HEADLESS` | Determines whether the application should run in headless (no web UI) mode | #### **YAML** ```yaml @@ -556,10 +556,10 @@ When enabled, the specified file is validated by reading the first few lines of Note that the contents of the blacklist are stored in memory to ensure performance, and this will increase the amount of memory used, potentially significantly if the blacklist is large. -| Command-Line | Environment Variable | Description | -| -------------------- | -------------------- | ------------------------------ | -| `--enable-blacklist` | `BLACKLIST` | Enable the managed blacklist | -| `--blacklist-file` | `BLACKLIST_FILE` | The path to the blacklist file | +| Command-Line | Environment Variable | Description | +| -------------------- | -------------------------- | ------------------------------ | +| `--enable-blacklist` | `SLSKD_BLACKLIST` | Enable the managed blacklist | +| `--blacklist-file` | `SLSKD_BLACKLIST_FILE` | The path to the blacklist file | ```yaml blacklist: @@ -579,7 +579,7 @@ Additionally, when the client is disconnected, any rooms that were joined at the | Command-Line | Environment Variable | Description | | ------------- | ---------------------| ----------------------------------------| -| `--rooms` | `ROOMS` | A list of chat rooms to join on startup | +| `--rooms` | `SLSKD_ROOMS` | A list of chat rooms to join on startup | #### **YAML** ```yaml @@ -897,9 +897,9 @@ Search filters can be used to prevent certain types of search requests from bein Filter expressions are case insensitive by default. -| Command Line | Environment Variable | Description | -| ------------------------- | ----------------------- | --------------------------------------------------------------------- | -| `--search-request-filter` | `SEARCH_REQUEST_FILTER` | A list of regular expressions used to filter incoming search requests | +| Command Line | Environment Variable | Description | +| ------------------------- | ----------------------------- | --------------------------------------------------------------------- | +| `--search-request-filter` | `SLSKD_SEARCH_REQUEST_FILTER` | A list of regular expressions used to filter incoming search requests | #### **YAML** ```yaml -- cgit v1.2.3