From b6f7a3725b2d62e541a482e76b0836e7ea9c5076 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 9 Jan 2022 16:31:11 -0600 Subject: add QueueStrategy --- src/slskd/Common/QueueStrategy.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/slskd/Common/QueueStrategy.cs (limited to 'src') 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 (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/. +// + +namespace slskd +{ + /// + /// Queue strategies. + /// + public enum QueueStrategy + { + /// + /// Uploads are prioritized based on the time they became ready. + /// + RoundRobin = 0, + + /// + /// Uploads are prioritized based on the time they were enqueued. + /// + FirstInFirstOut = 1, + } +} -- cgit v1.2.3 From e58183c31c08707e1945b1bca1e57a60eda5cb76 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 9 Jan 2022 17:04:24 -0600 Subject: rough in queue options --- src/slskd/Options.cs | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 8ddc4c7f..ffe62146 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -227,6 +227,12 @@ namespace slskd [RequiresRestart] public DirectoriesOptions Directories { get; init; } = new DirectoriesOptions(); + /// + /// Gets queue options. + /// + [Validate] + public QueuesOptions Queues { get; init; } = new QueuesOptions(); + /// /// Gets filter options. /// @@ -378,6 +384,61 @@ namespace slskd } } + public class QueuesOptions : IValidatableObject + { + [Validate] + public QueueOptions Default { get; init; } = new QueueOptions(); + + [Validate] + public Dictionary Custom { get; init; } = new Dictionary(); + + /// + /// Extended validation. + /// + /// + /// + public IEnumerable Validate(ValidationContext validationContext) + { + var validationResults = new List(); + + var customResults = new CompositeValidationResult("Custom"); + + foreach (var (key, value) in Custom) + { + var results = new List(); + var context = new ValidationContext(value, null, null); + + Validator.TryValidateObject(value, context, results, true); + + if (results.Count != 0) + { + var keyResults = new CompositeValidationResult(key); + results.ForEach(keyResults.AddResult); + + customResults.AddResult(keyResults); + } + } + + if (customResults.Results.Any()) + { + validationResults.Add(customResults); + } + + return validationResults; + } + + public class QueueOptions + { + [Enum(typeof(QueueStrategy))] + public string Strategy { get; init; } = "roundrobin"; + + [Range(1, int.MaxValue)] + public int Slots { get; init; } = 10; + + public bool Priority { get; init; } = true; + } + } + /// /// Feature options. /// -- cgit v1.2.3 From 6d12d62ec3bae84dfc4854699911eef042797794 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 9 Jan 2022 22:25:23 -0600 Subject: treat dictionaries like arrays when diffing --- src/slskd/Common/Extensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') 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()) { -- cgit v1.2.3 From 8e3414a8f9567c336c86ce124be94a19bfb1cc5e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 9 Jan 2022 22:26:06 -0600 Subject: require restart if changing custom queues or number of slots --- src/slskd/Options.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index ffe62146..fb746984 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -390,6 +390,7 @@ namespace slskd public QueueOptions Default { get; init; } = new QueueOptions(); [Validate] + [RequiresRestart] public Dictionary Custom { get; init; } = new Dictionary(); /// @@ -432,6 +433,7 @@ namespace slskd [Enum(typeof(QueueStrategy))] public string Strategy { get; init; } = "roundrobin"; + [RequiresRestart] [Range(1, int.MaxValue)] public int Slots { get; init; } = 10; -- cgit v1.2.3 From 03952c1a9f959b3f87b0a627baad635018c0f39e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 9 Jan 2022 23:05:40 -0600 Subject: clear yaml provider dictionary before loading --- src/slskd/Common/Configuration/YamlConfigurationSource.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/slskd/Common/Configuration/YamlConfigurationSource.cs b/src/slskd/Common/Configuration/YamlConfigurationSource.cs index cd388f46..191e49ab 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" + Data.Clear(); + using var reader = new StreamReader(stream); var yaml = new YamlStream(); -- cgit v1.2.3 From 4495f4176f9f4be435d8fe8604b71471476eba5f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 9 Jan 2022 23:21:19 -0600 Subject: add args for default queue --- src/slskd/Options.cs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index fb746984..0d7fb4fe 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -387,11 +387,11 @@ namespace slskd public class QueuesOptions : IValidatableObject { [Validate] - public QueueOptions Default { get; init; } = new QueueOptions(); + public DefaultQueueOptions Default { get; init; } = new DefaultQueueOptions(); [Validate] [RequiresRestart] - public Dictionary Custom { get; init; } = new Dictionary(); + public Dictionary Custom { get; init; } = new Dictionary(); /// /// Extended validation. @@ -428,16 +428,31 @@ namespace slskd return validationResults; } - public class QueueOptions + public class DefaultQueueOptions { + [Argument(default, "queue-strategy")] [Enum(typeof(QueueStrategy))] public string Strategy { get; init; } = "roundrobin"; + [Argument(default, "queue-slots")] [RequiresRestart] [Range(1, int.MaxValue)] public int Slots { get; init; } = 10; - public bool Priority { get; init; } = true; + [Argument(default, "disable-queue-priorty")] + public bool DisablePriority { get; init; } = false; + } + + public class CustomQueueOptions + { + [Enum(typeof(QueueStrategy))] + public string Strategy { get; init; } = "roundrobin"; + + [RequiresRestart] + [Range(1, int.MaxValue)] + public int Slots { get; init; } = 10; + + public bool DisablePriority { get; init; } = false; } } -- cgit v1.2.3 From d5e3a4776716a1348e8603c1054bf0f33967fa1e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 10 Jan 2022 09:09:03 -0600 Subject: don't require a restart if slots change --- src/slskd/Common/Configuration/YamlConfigurationSource.cs | 2 +- src/slskd/Options.cs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/Configuration/YamlConfigurationSource.cs b/src/slskd/Common/Configuration/YamlConfigurationSource.cs index 191e49ab..7f2c548d 100644 --- a/src/slskd/Common/Configuration/YamlConfigurationSource.cs +++ b/src/slskd/Common/Configuration/YamlConfigurationSource.cs @@ -111,7 +111,7 @@ namespace slskd.Configuration { // clear the data collection before we populate // not doing this will cause array and dictionary keys - // to get "stuck" + // to get "stuck" when the config is reloaded Data.Clear(); using var reader = new StreamReader(stream); diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 0d7fb4fe..bffc1be9 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -435,7 +435,6 @@ namespace slskd public string Strategy { get; init; } = "roundrobin"; [Argument(default, "queue-slots")] - [RequiresRestart] [Range(1, int.MaxValue)] public int Slots { get; init; } = 10; @@ -448,7 +447,6 @@ namespace slskd [Enum(typeof(QueueStrategy))] public string Strategy { get; init; } = "roundrobin"; - [RequiresRestart] [Range(1, int.MaxValue)] public int Slots { get; init; } = 10; -- cgit v1.2.3 From 363aa639671923ee3efea8d1802a6d3572dae9b9 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 10 Jan 2022 09:47:47 -0600 Subject: don't require a restart on any custom change --- src/slskd/Application.cs | 2 ++ src/slskd/Options.cs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 34610018..3f0490dc 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -615,6 +615,8 @@ namespace slskd _ = RoomService.TryJoinAsync(newOptions.Rooms); } + // todo: determine if any custom queues were deleted, and require a restart if so + // determine whether any Soulseek options changed. if so, we need to construct a patch and invoke ReconfigureOptionsAsync(). var slskDiff = PreviousOptions.Soulseek.DiffWith(newOptions.Soulseek); diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index bffc1be9..ccdd97c5 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -390,7 +390,6 @@ namespace slskd public DefaultQueueOptions Default { get; init; } = new DefaultQueueOptions(); [Validate] - [RequiresRestart] public Dictionary Custom { get; init; } = new Dictionary(); /// -- cgit v1.2.3 From 76a3b624daf37cb2f4f4f8cb5e0065097c259ef8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 10 Jan 2022 21:13:28 -0600 Subject: require restart if queues are removed --- src/slskd/Application.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 3f0490dc..63ac2cc0 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -588,7 +588,7 @@ namespace slskd var requiresRestart = HasAttribute(property); var requiresReconnect = HasAttribute(property); - Log.Debug($"{fqn} changed from '{left.ToJson() ?? ""}' to '{right.ToJson() ?? ""}'{(requiresRestart ? "; Restart required to take effect." : string.Empty)}{(requiresReconnect ? "; Reconnect required to take effect." : string.Empty)}"); + Log.Debug($"{fqn} changed from '{left.ToJson() ?? ""}' to '{right.ToJson() ?? ""}'{(requiresRestart ? ". Restart required to take effect." : string.Empty)}{(requiresReconnect ? "; Reconnect required to take effect." : string.Empty)}"); pendingRestart |= requiresRestart; pendingReconnect |= requiresReconnect; @@ -601,6 +601,13 @@ namespace slskd Log.Information("Shared directory configuration changed. Shares must be re-scanned for changes to take effect."); } + var removedQueues = PreviousOptions.Queues.Custom.Keys.Where(key => !newOptions.Queues.Custom.ContainsKey(key)); + if (removedQueues.Any()) + { + Log.Information("Custom queue(s) {Queues} removed or renamed. Restart required to take effect.", string.Join(", ", removedQueues)); + pendingRestart = true; + } + if (PreviousOptions.Filters.Share.Except(newOptions.Filters.Share).Any() || newOptions.Filters.Share.Except(PreviousOptions.Filters.Share).Any()) { @@ -615,8 +622,6 @@ namespace slskd _ = RoomService.TryJoinAsync(newOptions.Rooms); } - // todo: determine if any custom queues were deleted, and require a restart if so - // determine whether any Soulseek options changed. if so, we need to construct a patch and invoke ReconfigureOptionsAsync(). var slskDiff = PreviousOptions.Soulseek.DiffWith(newOptions.Soulseek); -- cgit v1.2.3 From 0e06dc2acac4461beb27daa4e2c83ca5a0d23152 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 11 Jan 2022 22:18:21 -0600 Subject: set slot limit --- src/slskd/Startup.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') 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(_ => - 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 -- cgit v1.2.3 From 87b86d3b76dd7568001ce16532cc1c732347d841 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 11 Jan 2022 22:18:58 -0600 Subject: remove queues, add limits --- src/slskd/Options.cs | 81 +++++++++++++--------------------------------------- 1 file changed, 20 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index ccdd97c5..375f5ac8 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -228,10 +228,10 @@ namespace slskd public DirectoriesOptions Directories { get; init; } = new DirectoriesOptions(); /// - /// Gets queue options. + /// Gets limits. /// [Validate] - public QueuesOptions Queues { get; init; } = new QueuesOptions(); + public LimitsOptions Limits { get; init; } = new LimitsOptions(); /// /// Gets filter options. @@ -384,72 +384,31 @@ namespace slskd } } - public class QueuesOptions : IValidatableObject + /// + /// Limits. + /// + public class LimitsOptions { + /// + /// Gets queue limits. + /// [Validate] - public DefaultQueueOptions Default { get; init; } = new DefaultQueueOptions(); - - [Validate] - public Dictionary Custom { get; init; } = new Dictionary(); + public LimitsQueueOptions Queue { get; init; } = new LimitsQueueOptions(); /// - /// Extended validation. + /// Queue limits. /// - /// - /// - public IEnumerable Validate(ValidationContext validationContext) - { - var validationResults = new List(); - - var customResults = new CompositeValidationResult("Custom"); - - foreach (var (key, value) in Custom) - { - var results = new List(); - var context = new ValidationContext(value, null, null); - - Validator.TryValidateObject(value, context, results, true); - - if (results.Count != 0) - { - var keyResults = new CompositeValidationResult(key); - results.ForEach(keyResults.AddResult); - - customResults.AddResult(keyResults); - } - } - - if (customResults.Results.Any()) - { - validationResults.Add(customResults); - } - - return validationResults; - } - - public class DefaultQueueOptions + public class LimitsQueueOptions { - [Argument(default, "queue-strategy")] - [Enum(typeof(QueueStrategy))] - public string Strategy { get; init; } = "roundrobin"; - - [Argument(default, "queue-slots")] - [Range(1, int.MaxValue)] - public int Slots { get; init; } = 10; - - [Argument(default, "disable-queue-priorty")] - public bool DisablePriority { get; init; } = false; - } - - public class CustomQueueOptions - { - [Enum(typeof(QueueStrategy))] - public string Strategy { get; init; } = "roundrobin"; - + /// + /// Gets the limit for the total number of queue slots. + /// + [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; - - public bool DisablePriority { get; init; } = false; + public int Slots { get; init; } = 20; } } -- cgit v1.2.3 From 057d4b8f16ae8758aa47793b1cc94e72f29ff452 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 11 Jan 2022 22:20:30 -0600 Subject: default slots to 10 --- src/slskd/Options.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 375f5ac8..900f2cd4 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -408,7 +408,7 @@ namespace slskd [Description("the limit for the total number of queue slots")] [RequiresRestart] [Range(1, int.MaxValue)] - public int Slots { get; init; } = 20; + public int Slots { get; init; } = 10; } } -- cgit v1.2.3 From 91e7136c8cc0c6e5b36956082421c1380b328271 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 11 Jan 2022 22:21:31 -0600 Subject: remove queue diff --- src/slskd/Application.cs | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 63ac2cc0..ffd76fc5 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -601,13 +601,6 @@ namespace slskd Log.Information("Shared directory configuration changed. Shares must be re-scanned for changes to take effect."); } - var removedQueues = PreviousOptions.Queues.Custom.Keys.Where(key => !newOptions.Queues.Custom.ContainsKey(key)); - if (removedQueues.Any()) - { - Log.Information("Custom queue(s) {Queues} removed or renamed. Restart required to take effect.", string.Join(", ", removedQueues)); - pendingRestart = true; - } - if (PreviousOptions.Filters.Share.Except(newOptions.Filters.Share).Any() || newOptions.Filters.Share.Except(PreviousOptions.Filters.Share).Any()) { -- cgit v1.2.3 From c97d2428e880ff1cebb6850a67c947e024ba18ec Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 11 Jan 2022 23:00:51 -0600 Subject: don't try to validate null values --- src/slskd/Common/Validation/ValidateAttribute.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') 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(); var context = new ValidationContext(value, null, null); -- cgit v1.2.3