diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-01-12 06:48:50 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-12 06:48:50 -0600 |
| commit | c68e8b1dfca0059b7495a303a7ac506fe21ed64f (patch) | |
| tree | a81bccbe0a2e2601076eb79d69bc54c6f7454c94 /src | |
| parent | 1398847c27cbcab2af0c7e7890e1cbe3a774fb95 (diff) | |
| parent | c97d2428e880ff1cebb6850a67c947e024ba18ec (diff) | |
| download | slskd-c68e8b1dfca0059b7495a303a7ac506fe21ed64f.tar.gz | |
Merge pull request #323 from slskd/slots
Add option to set a limit for total number of upload slots
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Common/Configuration/YamlConfigurationSource.cs | 5 | ||||
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Common/QueueStrategy.cs | 35 | ||||
| -rw-r--r-- | src/slskd/Common/Validation/ValidateAttribute.cs | 5 | ||||
| -rw-r--r-- | src/slskd/Options.cs | 34 | ||||
| -rw-r--r-- | src/slskd/Startup.cs | 4 |
7 files changed, 84 insertions, 3 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 34610018..ffd76fc5 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -588,7 +588,7 @@ namespace slskd var requiresRestart = HasAttribute<RequiresRestartAttribute>(property); var requiresReconnect = HasAttribute<RequiresReconnectAttribute>(property); - Log.Debug($"{fqn} changed from '{left.ToJson() ?? "<null>"}' to '{right.ToJson() ?? "<null>"}'{(requiresRestart ? "; Restart required to take effect." : string.Empty)}{(requiresReconnect ? "; Reconnect required to take effect." : string.Empty)}"); + Log.Debug($"{fqn} changed from '{left.ToJson() ?? "<null>"}' to '{right.ToJson() ?? "<null>"}'{(requiresRestart ? ". Restart required to take effect." : string.Empty)}{(requiresReconnect ? "; Reconnect required to take effect." : string.Empty)}"); pendingRestart |= requiresRestart; pendingReconnect |= requiresReconnect; diff --git a/src/slskd/Common/Configuration/YamlConfigurationSource.cs b/src/slskd/Common/Configuration/YamlConfigurationSource.cs index cd388f46..7f2c548d 100644 --- a/src/slskd/Common/Configuration/YamlConfigurationSource.cs +++ b/src/slskd/Common/Configuration/YamlConfigurationSource.cs @@ -109,6 +109,11 @@ namespace slskd.Configuration { try { + // clear the data collection before we populate + // not doing this will cause array and dictionary keys + // to get "stuck" when the config is reloaded + Data.Clear(); + using var reader = new StreamReader(stream); var yaml = new YamlStream(); diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 5c95f8d1..90f0b659 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -60,7 +60,7 @@ namespace slskd var propType = prop.PropertyType; var fqn = string.IsNullOrEmpty(parentFqn) ? prop.Name : string.Join(".", parentFqn, prop.Name); - if (propType.IsArray) + if (propType.IsArray || (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Dictionary<,>))) { if (leftVal.ToJson() != rightVal.ToJson()) { diff --git a/src/slskd/Common/QueueStrategy.cs b/src/slskd/Common/QueueStrategy.cs new file mode 100644 index 00000000..50f6cce1 --- /dev/null +++ b/src/slskd/Common/QueueStrategy.cs @@ -0,0 +1,35 @@ +// <copyright file="QueueStrategy.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd +{ + /// <summary> + /// Queue strategies. + /// </summary> + public enum QueueStrategy + { + /// <summary> + /// Uploads are prioritized based on the time they became ready. + /// </summary> + RoundRobin = 0, + + /// <summary> + /// Uploads are prioritized based on the time they were enqueued. + /// </summary> + FirstInFirstOut = 1, + } +} diff --git a/src/slskd/Common/Validation/ValidateAttribute.cs b/src/slskd/Common/Validation/ValidateAttribute.cs index 72ef25e1..d731eb0e 100644 --- a/src/slskd/Common/Validation/ValidateAttribute.cs +++ b/src/slskd/Common/Validation/ValidateAttribute.cs @@ -27,6 +27,11 @@ namespace slskd.Validation { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { + if (value == null) + { + return ValidationResult.Success; + } + var results = new List<ValidationResult>(); var context = new ValidationContext(value, null, null); diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 8ddc4c7f..900f2cd4 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -228,6 +228,12 @@ namespace slskd public DirectoriesOptions Directories { get; init; } = new DirectoriesOptions(); /// <summary> + /// Gets limits. + /// </summary> + [Validate] + public LimitsOptions Limits { get; init; } = new LimitsOptions(); + + /// <summary> /// Gets filter options. /// </summary> [Validate] @@ -379,6 +385,34 @@ namespace slskd } /// <summary> + /// Limits. + /// </summary> + public class LimitsOptions + { + /// <summary> + /// Gets queue limits. + /// </summary> + [Validate] + public LimitsQueueOptions Queue { get; init; } = new LimitsQueueOptions(); + + /// <summary> + /// Queue limits. + /// </summary> + public class LimitsQueueOptions + { + /// <summary> + /// Gets the limit for the total number of queue slots. + /// </summary> + [Argument(default, "queue-slot-limit")] + [EnvironmentVariable("QUEUE_SLOT_LIMIT")] + [Description("the limit for the total number of queue slots")] + [RequiresRestart] + [Range(1, int.MaxValue)] + public int Slots { get; init; } = 10; + } + } + + /// <summary> /// Feature options. /// </summary> public class FeatureOptions diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index f069c818..200a23fc 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -234,7 +234,9 @@ namespace slskd // add a partially configured instance of SoulseekClient. the Application instance will // complete configuration at startup. services.AddSingleton<ISoulseekClient, SoulseekClient>(_ => - new SoulseekClient(options: new SoulseekClientOptions(minimumDiagnosticLevel: OptionsAtStartup.Soulseek.DiagnosticLevel))); + new SoulseekClient(options: new SoulseekClientOptions( + maximumConcurrentUploads: OptionsAtStartup.Limits.Queue.Slots, + minimumDiagnosticLevel: OptionsAtStartup.Soulseek.DiagnosticLevel))); // add the core application service to DI as well as a hosted service so that other services can // access instance methods |
