aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Options.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-02-18 07:05:03 -0600
committerGitHub <noreply@github.com>2022-02-18 07:05:03 -0600
commitfccc9c6440af11fd400f3d1dee243d2d18ea1651 (patch)
tree0ba68479205c192e630c985f5025c67d2ca4c715 /src/slskd/Options.cs
parentdee1b7315ff56194f7868803b876cabe4ab165d7 (diff)
parent58e865993eb507e31dca3771fac0ea3829880d02 (diff)
downloadslskd-fccc9c6440af11fd400f3d1dee243d2d18ea1651.tar.gz
Merge pull request #346 from slskd/groups
Add upload slot and bandwidth limiting for user groups
Diffstat (limited to 'src/slskd/Options.cs')
-rw-r--r--src/slskd/Options.cs175
1 files changed, 162 insertions, 13 deletions
diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs
index 900f2cd4..2313ce69 100644
--- a/src/slskd/Options.cs
+++ b/src/slskd/Options.cs
@@ -228,10 +228,16 @@ namespace slskd
public DirectoriesOptions Directories { get; init; } = new DirectoriesOptions();
/// <summary>
- /// Gets limits.
+ /// Gets global options.
/// </summary>
[Validate]
- public LimitsOptions Limits { get; init; } = new LimitsOptions();
+ public GlobalOptions Global { get; init; } = new GlobalOptions();
+
+ /// <summary>
+ /// Gets user groups.
+ /// </summary>
+ [Validate]
+ public GroupsOptions Groups { get; init; } = new GroupsOptions();
/// <summary>
/// Gets filter options.
@@ -385,30 +391,173 @@ namespace slskd
}
/// <summary>
- /// Limits.
+ /// Global options.
/// </summary>
- public class LimitsOptions
+ public class GlobalOptions
{
/// <summary>
- /// Gets queue limits.
+ /// Gets global upload options.
+ /// </summary>
+ [Validate]
+ public GlobalUploadOptions Upload { get; init; } = new GlobalUploadOptions();
+
+ /// <summary>
+ /// Gets global download options.
/// </summary>
[Validate]
- public LimitsQueueOptions Queue { get; init; } = new LimitsQueueOptions();
+ public GlobalDownloadOptions Download { get; init; } = new GlobalDownloadOptions();
/// <summary>
- /// Queue limits.
+ /// Global upload options.
/// </summary>
- public class LimitsQueueOptions
+ public class GlobalUploadOptions
{
/// <summary>
- /// Gets the limit for the total number of queue slots.
+ /// Gets the limit for the total number of upload slots.
/// </summary>
- [Argument(default, "queue-slot-limit")]
- [EnvironmentVariable("QUEUE_SLOT_LIMIT")]
- [Description("the limit for the total number of queue slots")]
+ [Argument(default, "upload-slots")]
+ [EnvironmentVariable("UPLOAD_SLOTS")]
+ [Description("the total number of upload slots")]
[RequiresRestart]
[Range(1, int.MaxValue)]
public int Slots { get; init; } = 10;
+
+ /// <summary>
+ /// Gets the total upload speed limit.
+ /// </summary>
+ [Argument(default, "upload-speed-limit")]
+ [EnvironmentVariable("UPLOAD_SPEED_LIMIT")]
+ [Description("the total upload speed limit")]
+ [Range(1, int.MaxValue)]
+ public int SpeedLimit { get; init; } = int.MaxValue;
+ }
+
+ /// <summary>
+ /// Gets global download options.
+ /// </summary>
+ public class GlobalDownloadOptions
+ {
+ /// <summary>
+ /// Gets the limit for the total number of download slots.
+ /// </summary>
+ [Argument(default, "download-slots")]
+ [EnvironmentVariable("DOWNLOAD_SLOTS")]
+ [Description("the total number of download slots")]
+ [RequiresRestart]
+ [Range(1, int.MaxValue)]
+ public int Slots { get; init; } = int.MaxValue;
+
+ /// <summary>
+ /// Gets the total download speed limit.
+ /// </summary>
+ [Argument(default, "download-speed-limit")]
+ [EnvironmentVariable("DOWNLOAD_SPEED_LIMIT")]
+ [Description("the total download speed limit")]
+ [Range(1, int.MaxValue)]
+ public int SpeedLimit { get; init; } = int.MaxValue;
+ }
+ }
+
+ /// <summary>
+ /// User groups.
+ /// </summary>
+ public class GroupsOptions : IValidatableObject
+ {
+ /// <summary>
+ /// Gets options for the default user group.
+ /// </summary>
+ /// <remarks>
+ /// These options apply to users that are not priviledged, have not been identified as leechers,
+ /// and have not been added as a member of any group.
+ /// </remarks>
+ [Validate]
+ public BuiltInOptions Default { get; init; } = new BuiltInOptions();
+
+ /// <summary>
+ /// Gets options for the leecher user group.
+ /// </summary>
+ /// <remarks>
+ /// These options apply to users that have been identified as leechers, and have not been added as a member of any group.
+ /// </remarks>
+ [Validate]
+ public BuiltInOptions Leechers { get; init; } = new BuiltInOptions();
+
+ /// <summary>
+ /// Gets user defined groups and options.
+ /// </summary>
+ [Validate]
+ public Dictionary<string, UserDefinedOptions> UserDefined { get; init; } = new Dictionary<string, UserDefinedOptions>();
+
+ /// <summary>
+ /// Extended validation.
+ /// </summary>
+ /// <param name="validationContext"></param>
+ /// <returns></returns>
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var builtInGroups = new[] { Application.PriviledgedGroup, Application.DefaultGroup, Application.LeecherGroup };
+ var intersection = UserDefined.Keys.Intersect(builtInGroups);
+
+ return intersection.Select(group => new ValidationResult($"User defined group '{group}' collides with a built in group. Choose a different name."));
+ }
+
+ /// <summary>
+ /// Built in user group options.
+ /// </summary>
+ public class BuiltInOptions
+ {
+ /// <summary>
+ /// Gets upload options.
+ /// </summary>
+ [Validate]
+ public UploadOptions Upload { get; init; } = new UploadOptions();
+ }
+
+ /// <summary>
+ /// User defined user group options.
+ /// </summary>
+ public class UserDefinedOptions
+ {
+ /// <summary>
+ /// Gets upload options.
+ /// </summary>
+ [Validate]
+ public UploadOptions Upload { get; init; } = new UploadOptions();
+
+ /// <summary>
+ /// Gets the list of group member usernames.
+ /// </summary>
+ public string[] Members { get; init; } = Array.Empty<string>();
+ }
+
+ /// <summary>
+ /// User group upload options.
+ /// </summary>
+ public class UploadOptions
+ {
+ /// <summary>
+ /// Gets the priority of the group.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int Priority { get; init; } = 1;
+
+ /// <summary>
+ /// Gets the queue strategy for the group.
+ /// </summary>
+ [Enum(typeof(QueueStrategy))]
+ public string Strategy { get; init; } = QueueStrategy.RoundRobin.ToString().ToLowerInvariant();
+
+ /// <summary>
+ /// Gets the limit for the total number of upload slots for the group.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int Slots { get; init; } = int.MaxValue;
+
+ /// <summary>
+ /// Gets the total upload speed limit for the group.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int SpeedLimit { get; init; } = int.MaxValue;
}
}
@@ -972,7 +1121,7 @@ namespace slskd
[EnvironmentVariable("FTP_ENCRYPTION_MODE")]
[Description("FTP encryption mode; none, implicit, explicit, auto")]
[Enum(typeof(FtpEncryptionMode))]
- public string EncryptionMode { get; init; } = "auto";
+ public string EncryptionMode { get; init; } = FtpEncryptionMode.Auto.ToString().ToLowerInvariant();
/// <summary>
/// Gets a value indicating whether FTP certificate errors should be ignored.