aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-01-12 06:48:50 -0600
committerGitHub <noreply@github.com>2022-01-12 06:48:50 -0600
commitc68e8b1dfca0059b7495a303a7ac506fe21ed64f (patch)
treea81bccbe0a2e2601076eb79d69bc54c6f7454c94 /src/slskd/Common
parent1398847c27cbcab2af0c7e7890e1cbe3a774fb95 (diff)
parentc97d2428e880ff1cebb6850a67c947e024ba18ec (diff)
downloadslskd-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/slskd/Common')
-rw-r--r--src/slskd/Common/Configuration/YamlConfigurationSource.cs5
-rw-r--r--src/slskd/Common/Extensions.cs2
-rw-r--r--src/slskd/Common/QueueStrategy.cs35
-rw-r--r--src/slskd/Common/Validation/ValidateAttribute.cs5
4 files changed, 46 insertions, 1 deletions
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);