aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-08-07 15:57:13 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-08-07 15:57:13 -0500
commit80ecb0d03cf1da83e33dde6326365713b3d605e0 (patch)
treedd8ea1392c4f61defc67b6436ee58be689b3991b
parent9a51c7fcc0f7a0394b7c3e5cdc01322652743470 (diff)
parent25c4abfc9428272eed0936d17c8a310653b21111 (diff)
downloadslskd-80ecb0d03cf1da83e33dde6326365713b3d605e0.tar.gz
Merge remote-tracking branch 'origin/master' into transfers
-rw-r--r--Dockerfile3
-rw-r--r--config/slskd.example.yml3
-rw-r--r--docs/config.md14
-rw-r--r--src/slskd/Application.cs16
-rw-r--r--src/slskd/Core/Options.cs40
-rw-r--r--src/slskd/slskd.csproj25
6 files changed, 81 insertions, 20 deletions
diff --git a/Dockerfile b/Dockerfile
index 6e5aabf9..e705e515 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -50,6 +50,9 @@ VOLUME /app
HEALTHCHECK --interval=60s --timeout=3s --start-period=5s --retries=3 CMD wget -q -O - http://localhost:${SLSKD_HTTP_PORT}/health
ENV DOTNET_BUNDLE_EXTRACT_BASE_DIR=/var/tmp/.net \
+ DOTNET_gcServer=0 \
+ DOTNET_gcConcurrent=1 \
+ DOTNET_GCHeapHardLimit=1F400000 \
DOTNET_GCConserveMemory=9 \
SLSKD_HTTP_PORT=5000 \
SLSKD_HTTPS_PORT=5001 \
diff --git a/config/slskd.example.yml b/config/slskd.example.yml
index c2c11668..16dabb22 100644
--- a/config/slskd.example.yml
+++ b/config/slskd.example.yml
@@ -49,6 +49,9 @@
# - \.ini$
# - Thumbs.db$
# - \.DS_Store$
+# search:
+# request:
+# - ^.{1,2}$
# web:
# port: 5000
# https:
diff --git a/docs/config.md b/docs/config.md
index 74d7b24d..2254c9e2 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -542,11 +542,14 @@ web:
A number of filters can be configured to control various aspects of how the application interacts with the Soulseek network.
-The share filters can be used to prevent certain types of files from being shared. This option is an array that can take any number of filters. Filters must be a valid regular expression; a few examples are included below and in the example configuration included with the application, but the list is empty by default.
+Share filters can be used to prevent certain types of files from being shared. This option is an array that can take any number of filters. Filters must be a valid regular expression; a few examples are included below and in the example configuration included with the application, but the list is empty by default.
-| Command Line | Environment Variable | Description |
-| ---------------- | -------------------- | -------------------------------------------------------------- |
-| `--share-filter` | `SHARE_FILTER` | A list of regular expressions used to filter files from shares |
+Search request filters can be used to discard incoming search requests that match one or more filters. Like share filters, this option is an array of regular expressions, and it defaults to an empty array (no request filtering is applied).
+
+| Command Line | Environment Variable | Description |
+| ------------------------- | ----------------------- | --------------------------------------------------------------------- |
+| `--share-filter` | `SHARE_FILTER` | A list of regular expressions used to filter files from shares |
+| `--search-request-filter` | `SEARCH_REQUEST_FILTER` | A list of regular expressions used to filter incoming search requests |
#### **YAML**
```yaml
@@ -555,6 +558,9 @@ filters:
- \.ini$
- Thumbs.db$
- \.DS_Store$
+ search:
+ request:
+ - ^.{1,2}$
```
# Integrations
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 3e501cdc..44723aba 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -29,6 +29,7 @@ namespace slskd
using System.Net.Sockets;
using System.Reflection;
using System.Runtime;
+ using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@@ -112,6 +113,8 @@ namespace slskd
PreviousOptions = OptionsMonitor.CurrentValue;
+ CompiledSearchResponseFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled));
+
State = state;
State.OnChange(state => State_OnChange(state));
@@ -187,6 +190,7 @@ namespace slskd
private IUserService Users { get; set; }
private IShareService Shares { 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>();
public void CollectGarbage()
@@ -199,7 +203,7 @@ namespace slskd
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
#pragma warning disable S1215 // "GC.Collect" should not be called
- GC.Collect(2, GCCollectionMode.Forced, blocking: false, compacting: true);
+ GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true);
#pragma warning restore S1215 // "GC.Collect" should not be called
sw.Stop();
@@ -740,6 +744,13 @@ namespace slskd
Log.Information("File filter configuration changed. Shares must be re-scanned for changes to take effect.");
}
+ 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));
+ Log.Information("Updated and re-compiled search response filters");
+ }
+
if (PreviousOptions.Rooms.Except(newOptions.Rooms).Any()
|| newOptions.Rooms.Except(PreviousOptions.Rooms).Any())
{
@@ -861,8 +872,7 @@ namespace slskd
/// <returns>A Task resolving a SearchResponse, or null.</returns>
private async Task<SearchResponse> SearchResponseResolver(string username, int token, SearchQuery query)
{
- // some bots and perhaps users search for very short terms. only respond to queries >= 3 characters. sorry, U2 fans.
- if (query.Query.Length < 3)
+ if (CompiledSearchResponseFilters.Any(filter => filter.IsMatch(query.SearchText)))
{
return null;
}
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 9deababa..197c3412 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -625,6 +625,12 @@ namespace slskd
public string[] Share { get; init; } = Array.Empty<string>();
/// <summary>
+ /// Gets search filter options.
+ /// </summary>
+ [Validate]
+ public SearchOptions Search { get; init; } = new SearchOptions();
+
+ /// <summary>
/// Extended validation.
/// </summary>
/// <param name="validationContext"></param>
@@ -643,6 +649,40 @@ namespace slskd
return results;
}
+
+ /// <summary>
+ /// Search filter options.
+ /// </summary>
+ public class SearchOptions : IValidatableObject
+ {
+ /// <summary>
+ /// Gets the list of search request filters.
+ /// </summary>
+ [Argument(default, "search-request-filter")]
+ [EnvironmentVariable("SEARCH_REQUEST_FILTER")]
+ [Description("regular expressions to filter incoming search requests")]
+ public string[] Request { get; init; } = Array.Empty<string>();
+
+ /// <summary>
+ /// Extended validation.
+ /// </summary>
+ /// <param name="validationContext"></param>
+ /// <returns></returns>
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var results = new List<ValidationResult>();
+
+ foreach (var filter in Request)
+ {
+ if (!filter.IsValidRegex())
+ {
+ results.Add(new ValidationResult($"Search request filter '{filter}' is not a valid regular expression"));
+ }
+ }
+
+ return results;
+ }
+ }
}
/// <summary>
diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj
index 2f5ec67c..d2f0a9b7 100644
--- a/src/slskd/slskd.csproj
+++ b/src/slskd/slskd.csproj
@@ -12,7 +12,6 @@
<LangVersion>9.0</LangVersion>
<CodeAnalysisRuleSet>Properties\analysis.ruleset</CodeAnalysisRuleSet>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
- <ServerGarbageCollection>false</ServerGarbageCollection>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
@@ -43,42 +42,42 @@
</Target>
<ItemGroup>
- <PackageReference Include="FluentFTP" Version="37.0.5" />
- <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.6" />
+ <PackageReference Include="FluentFTP" Version="39.0.1" />
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.6" />
- <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
- <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="6.0.6" />
+ <PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.7" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="6.0.7" />
<PackageReference Include="prometheus-net" Version="6.0.0" />
<PackageReference Include="prometheus-net.AspNetCore" Version="6.0.0" />
<PackageReference Include="prometheus-net.AspNetCore.HealthChecks" Version="6.0.0" />
<PackageReference Include="prometheus-net.DotNetRuntime" Version="4.2.4" />
<PackageReference Include="prometheus-net.SystemMetrics" Version="2.0.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
- <PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
+ <PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<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="SonarAnalyzer.CSharp" Version="8.41.0.50478">
+ <PackageReference Include="SonarAnalyzer.CSharp" Version="8.43.0.51858">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="Soulseek" Version="5.0.0" />
+ <PackageReference Include="Soulseek" Version="5.1.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
- <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.21.0" />
- <PackageReference Include="TagLibSharp" Version="2.2.0" />
+ <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
+ <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.22.0" />
+ <PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="Utility.CommandLine.Arguments" Version="6.0.0" />
<PackageReference Include="Utility.EnvironmentVariables" Version="1.0.5" />
- <PackageReference Include="YamlDotNet" Version="11.2.1" />
+ <PackageReference Include="YamlDotNet" Version="12.0.0" />
</ItemGroup>
</Project>