aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-08-16 15:06:25 -0500
committerGitHub <noreply@github.com>2025-08-16 15:06:25 -0500
commitb08c877124a29fbdc34ae5fea8839006e307810b (patch)
treef058d1cdb7821aec539cf3c11f67812627108293 /src
parent52a7fa8141e5f11b95175f68dbd8fc3070636e3c (diff)
parent5b0c4b7a42c22164635efa2558131075e725dcf4 (diff)
downloadslskd-b08c877124a29fbdc34ae5fea8839006e307810b.tar.gz
Merge branch 'master' into metrics
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application.cs30
-rw-r--r--src/slskd/Common/CommonExtensions.cs2
-rw-r--r--src/slskd/Core/Options.cs5
-rw-r--r--src/slskd/Events/EventService.cs5
-rw-r--r--src/slskd/Program.cs2
-rw-r--r--src/slskd/Shares/ShareScanner.cs9
-rw-r--r--src/slskd/Shares/ShareService.cs22
-rw-r--r--src/slskd/slskd.csproj2
8 files changed, 53 insertions, 24 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 41597396..d8dab87c 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -135,7 +135,10 @@ 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))
+ .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 IEnumerable<Regex> CompiledSearchResponseFilters { get; set; }
- private IEnumerable<Guid> ActiveDownloadIdsAtPreviousShutdown { get; set; } = Enumerable.Empty<Guid>();
+ private IReadOnlyList<Regex> CompiledSearchRequestFilters { get; set; } = [];
+ private IReadOnlyList<Guid> ActiveDownloadIdsAtPreviousShutdown { get; set; } = [];
private Options.FlagsOptions Flags { get; set; }
- private IReadOnlyCollection<string> ExcludedSearchPhrases { get; set; } = Enumerable.Empty<string>().ToList();
+ private IReadOnlyList<string> 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<Guid>();
+ ActiveDownloadIdsAtPreviousShutdown = [];
}
catch (Exception ex)
{
@@ -1178,7 +1181,7 @@ namespace slskd
private void Client_ExcludedSearchPhrasesReceived(object sender, IReadOnlyCollection<string> e)
{
Log.Debug("Excluded search phrases: {Phrases}", string.Join(", ", e));
- ExcludedSearchPhrases = e;
+ ExcludedSearchPhrases = e.ToList();
}
private void Client_TransferProgressUpdated(object sender, TransferProgressUpdatedEventArgs args)
@@ -1270,6 +1273,8 @@ namespace slskd
// shenanigans here could lead to missed updates.
await OptionsSyncRoot.WaitAsync();
+ Log.Debug("OptionsMonitor OnChange Invoked");
+
try
{
var pendingRestart = false;
@@ -1281,9 +1286,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<T>(PropertyInfo property) => property.CustomAttributes.Any(a => a.AttributeType == typeof(T));
@@ -1314,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())
{
- CompiledSearchResponseFilters = newOptions.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled));
+ CompiledSearchRequestFilters = newOptions.Filters.Search.Request
+ .Select(f => new Regex(f, RegexOptions.Compiled))
+ .ToList()
+ .AsReadOnly();
+
Log.Information("Updated and re-compiled search response filters");
}
@@ -1440,7 +1452,7 @@ namespace slskd
return null;
}
- if (CompiledSearchResponseFilters.Any(filter => filter.IsMatch(query.SearchText)))
+ if (CompiledSearchRequestFilters.Any(filter => filter.IsMatch(query.SearchText)))
{
return null;
}
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))
{
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;
/// <summary>
/// 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();
/// <summary>
/// Gets options for the distributed network.
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
/// <returns>The retrieved list.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the specified <paramref name="offset"/> is less than zero.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the specified <paramref name="limit"/> is zero.</exception>
- public virtual IReadOnlyCollection<EventRecord> Get(int offset = 0, int limit = int.MaxValue)
+ public virtual IReadOnlyList<EventRecord> 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/Program.cs b/src/slskd/Program.cs
index cfcf315b..613ff054 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<Soulseek.Diagnostics.DiagnosticLevel>())));
// add the core application service to DI as well as a hosted service so that other services can
// access instance methods
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<ShareScanner>();
- private List<Share> Shares { get; set; }
+ private IReadOnlyList<Share> Shares { get; set; }
private ISoulseekFileFactory SoulseekFileFactory { get; }
private IManagedState<SharedFileCacheState> State { get; } = new ManagedState<SharedFileCacheState>();
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 19579458..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<IShareRepository>(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<ShareService>();
private (Host Host, IShareRepository Repository) Local { get; set; }
- private IEnumerable<IShareRepository> AllRepositories { get; set; }
+ private IReadOnlyList<IShareRepository> AllRepositories { get; set; }
/// <summary>
/// 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
{
@@ -158,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())
@@ -239,7 +244,9 @@ namespace slskd.Shares
AllRepositories = HostDictionary.Values
.Select(value => value.Repository)
- .Prepend(Local.Repository);
+ .Prepend(Local.Repository)
+ .ToList()
+ .AsReadOnly();
State.SetValue(state => state with
{
@@ -315,6 +322,9 @@ namespace slskd.Shares
/// Returns the list of all <see cref="Scan"/> started at or after the specified <paramref name="startedAtOrAfter"/>
/// unix timestamp.
/// </summary>
+ /// <remarks>
+ /// Note that this returns the scan history for local shares only.
+ /// </remarks>
/// <param name="startedAtOrAfter">A unix timestamp that serves as the lower bound of the time-based listing.</param>
/// <returns>The operation context, including the list of found scans.</returns>
public Task<IEnumerable<Scan>> ListScansAsync(long startedAtOrAfter = 0)
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 @@
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="7.1.1" />
<PackageReference Include="Serilog.Sinks.Http" Version="8.0.0" />
- <PackageReference Include="Soulseek" Version="7.1.1" />
+ <PackageReference Include="Soulseek" Version="7.1.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>