From 1fb7b1d85d04546dda66616030f427badff48ebd Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 1 Mar 2026 13:44:22 -0600 Subject: move transfer options into the same type, move limits under upload --- src/slskd/Core/Options.cs | 380 +++++++++++++++++++++++----------------------- 1 file changed, 186 insertions(+), 194 deletions(-) (limited to 'src') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 1464cf99..c68b6131 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -239,16 +239,9 @@ namespace slskd public SharesOptions Shares { get; init; } = new SharesOptions(); /// - /// Gets global options. + /// Gets transfer options. /// - [Validate] - public GlobalOptions Global { get; init; } = new GlobalOptions(); - - /// - /// Gets user groups. - /// - [Validate] - public GroupsOptions Groups { get; init; } = new GroupsOptions(); + public TransfersOptions Transfers { get; init; } = new TransfersOptions(); /// /// Gets blacklist options. @@ -904,9 +897,9 @@ namespace slskd } /// - /// Global options. + /// Transfer options. /// - public class GlobalOptions + public class TransfersOptions { /// /// Gets global upload options. @@ -915,16 +908,16 @@ namespace slskd public GlobalUploadOptions Upload { get; init; } = new GlobalUploadOptions(); /// - /// Gets global limits. + /// Gets global download options. /// [Validate] - public LimitsOptions Limits { get; init; } = new LimitsOptions(); + public GlobalDownloadOptions Download { get; init; } = new GlobalDownloadOptions(); /// - /// Gets global download options. + /// Gets user groups. /// [Validate] - public GlobalDownloadOptions Download { get; init; } = new GlobalDownloadOptions(); + public GroupsOptions Groups { get; init; } = new GroupsOptions(); /// /// Global upload options. @@ -949,6 +942,12 @@ namespace slskd [Description("the total upload speed limit")] [Range(1, int.MaxValue)] public int SpeedLimit { get; init; } = int.MaxValue; + + /// + /// Gets global limits. + /// + [Validate] + public LimitsOptions Limits { get; init; } = new LimitsOptions(); } /// @@ -975,244 +974,237 @@ namespace slskd [Range(1, int.MaxValue)] public int SpeedLimit { get; init; } = int.MaxValue; } - } - - /// - /// Limit options. - /// - public class LimitsOptions - { - /// - /// Gets limits for queued transfers. - /// - [Validate] - public Limits Queued { get; init; } = new Limits(); - - /// - /// Gets daily limits for transfers. - /// - [Validate] - public Limits Daily { get; init; } = new Limits(); - - /// - /// Gets weekly limits for transfers. - /// - [Validate] - public Limits Weekly { get; init; } = new Limits(); /// - /// Limits. + /// User groups. /// - public class Limits + public class GroupsOptions : IValidatableObject { /// - /// Gets the limit for number of files. + /// Gets options for the default user group. /// - [Range(1, int.MaxValue)] - public int? Files { get; init; } = null; + /// + /// These options apply to users that are not privileged, have not been identified as leechers, + /// and have not been added as a member of any group. + /// + [Validate] + public GroupOptions Default { get; init; } = new GroupOptions(); /// - /// Gets the limit for number of megabytes. + /// Gets options for the leecher user group. /// - [Range(1, int.MaxValue)] - public int? Megabytes { get; init; } = null; + /// + /// These options apply to users that have been identified as leechers, and have not been added as a member of any group. + /// + [Validate] + public LeecherOptions Leechers { get; init; } = new LeecherOptions(); /// - /// Gets the limit for number of failures. + /// Gets options for the blacklisted user group. /// - [Range(1, int.MaxValue)] - public int? Failures { get; init; } = null; - } - } - - /// - /// User groups. - /// - public class GroupsOptions : IValidatableObject - { - /// - /// Gets options for the default user group. - /// - /// - /// These options apply to users that are not privileged, have not been identified as leechers, - /// and have not been added as a member of any group. - /// - [Validate] - public BuiltInOptions Default { get; init; } = new BuiltInOptions(); - - /// - /// Gets options for the leecher user group. - /// - /// - /// These options apply to users that have been identified as leechers, and have not been added as a member of any group. - /// - [Validate] - public LeecherOptions Leechers { get; init; } = new LeecherOptions(); - - /// - /// Gets options for the blacklisted user group. - /// - [Validate] - public BlacklistedOptions Blacklisted { get; init; } = new BlacklistedOptions(); - - /// - /// Gets user defined groups and options. - /// - [Validate] - public Dictionary UserDefined { get; init; } = new Dictionary(); - - /// - /// Extended validation. - /// - /// - /// - public IEnumerable Validate(ValidationContext validationContext) - { - var builtInGroups = new[] { Application.PrivilegedGroup, 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.")); - } + [Validate] + public BlacklistedOptions Blacklisted { get; init; } = new BlacklistedOptions(); - /// - /// Options that are common to all groups. - /// - public class GroupOptions - { /// - /// Gets upload options. + /// Gets user defined groups and options. /// [Validate] - public UploadOptions Upload { get; init; } = new UploadOptions(); + public Dictionary UserDefined { get; init; } = new Dictionary(); /// - /// Gets limit options. + /// Extended validation. /// - [Validate] - public LimitsOptions Limits { get; init; } = new LimitsOptions(); - } + /// + /// + public IEnumerable Validate(ValidationContext validationContext) + { + var builtInGroups = new[] { Application.PrivilegedGroup, Application.DefaultGroup, Application.LeecherGroup }; + var intersection = UserDefined.Keys.Intersect(builtInGroups); - /// - /// Built in user group options. - /// - public class BuiltInOptions : GroupOptions - { - } + return intersection.Select(group => new ValidationResult($"User defined group '{group}' collides with a built in group. Choose a different name.")); + } - /// - /// Built in blacklisted group options. - /// - public class BlacklistedOptions : IValidatableObject - { /// - /// Gets the list of group member usernames. + /// Options that are common to all groups. /// - public string[] Members { get; init; } = Array.Empty(); + public class GroupOptions + { + /// + /// Gets upload options. + /// + [Validate] + public GroupUploadOptions Upload { get; init; } = new GroupUploadOptions(); + + /// + /// User group upload options. + /// + public class GroupUploadOptions + { + /// + /// Gets the priority of the group. + /// + [Range(1, int.MaxValue)] + public int Priority { get; init; } = 1; + + /// + /// Gets the queue strategy for the group. + /// + [Enum(typeof(Transfers.QueueStrategy))] + public string Strategy { get; init; } = slskd.Transfers.QueueStrategy.RoundRobin.ToString().ToLowerInvariant(); + + /// + /// Gets the limit for the total number of upload slots for the group. + /// + [Range(1, int.MaxValue)] + public int Slots { get; init; } = int.MaxValue; + + /// + /// Gets the total upload speed limit for the group, in kibibytes. + /// + [Range(1, int.MaxValue)] + public int SpeedLimit { get; init; } = int.MaxValue; + + /// + /// Gets limit options. + /// + [Validate] + public LimitsOptions Limits { get; init; } = new LimitsOptions(); + } + } /// - /// Gets the list of group CIDRs. + /// Built in leecher group options. /// - public string[] Cidrs { get; init; } = Array.Empty(); + public class LeecherOptions : GroupOptions + { + /// + /// Gets leecher threshold options. + /// + [Validate] + public ThresholdOptions Thresholds { get; init; } = new ThresholdOptions(); + + /// + /// Leecher threshold options. + /// + public class ThresholdOptions + { + /// + /// Gets the minimum number of shared files required to avoid being classified as a leecher. + /// + [Range(1, int.MaxValue)] + public int Files { get; init; } = 1; + + /// + /// Gets the minimum number of shared directories required to avoid being classified as a leecher. + /// + [Range(1, int.MaxValue)] + public int Directories { get; init; } = 1; + } + } /// - /// Extended validation. + /// Built in blacklisted group options. /// - /// - /// - public IEnumerable Validate(ValidationContext validationContext) + public class BlacklistedOptions : IValidatableObject { - var results = new List(); + /// + /// Gets the list of group member usernames. + /// + public string[] Members { get; init; } = Array.Empty(); + + /// + /// Gets the list of group CIDRs. + /// + public string[] Cidrs { get; init; } = Array.Empty(); - foreach (var cidr in Cidrs ?? Array.Empty()) + /// + /// Extended validation. + /// + /// + /// + public IEnumerable Validate(ValidationContext validationContext) { - try + var results = new List(); + + foreach (var cidr in Cidrs ?? Array.Empty()) { - if (cidr.StartsWith("::ffff", StringComparison.OrdinalIgnoreCase)) + try { - throw new Exception("IPv4 mapped IPv6 addresses are not allowed"); - } + if (cidr.StartsWith("::ffff", StringComparison.OrdinalIgnoreCase)) + { + throw new Exception("IPv4 mapped IPv6 addresses are not allowed"); + } - _ = IPAddressRange.Parse(cidr); - } - catch (Exception ex) - { - results.Add(new ValidationResult($"CIDR {cidr} is invalid: {ex.Message}")); + _ = IPAddressRange.Parse(cidr); + } + catch (Exception ex) + { + results.Add(new ValidationResult($"CIDR {cidr} is invalid: {ex.Message}")); + } } - } - return results; + return results; + } } - } - /// - /// Built in leecher group options. - /// - public class LeecherOptions : GroupOptions - { /// - /// Gets leecher threshold options. + /// User defined user group options. /// - [Validate] - public ThresholdOptions Thresholds { get; init; } = new ThresholdOptions(); + public class UserDefinedOptions : GroupOptions + { + /// + /// Gets the list of group member usernames. + /// + public string[] Members { get; init; } = Array.Empty(); + } } /// - /// Leecher threshold options. + /// Limit options. /// - public class ThresholdOptions + public class LimitsOptions { /// - /// Gets the minimum number of shared files required to avoid being classified as a leecher. - /// - [Range(1, int.MaxValue)] - public int Files { get; init; } = 1; - - /// - /// Gets the minimum number of shared directories required to avoid being classified as a leecher. + /// Gets limits for queued transfers. /// - [Range(1, int.MaxValue)] - public int Directories { get; init; } = 1; - } + [Validate] + public Limits Queued { get; init; } = new Limits(); - /// - /// User defined user group options. - /// - public class UserDefinedOptions : GroupOptions - { /// - /// Gets the list of group member usernames. + /// Gets daily limits for transfers. /// - public string[] Members { get; init; } = Array.Empty(); - } + [Validate] + public Limits Daily { get; init; } = new Limits(); - /// - /// User group upload options. - /// - public class UploadOptions - { /// - /// Gets the priority of the group. + /// Gets weekly limits for transfers. /// - [Range(1, int.MaxValue)] - public int Priority { get; init; } = 1; + [Validate] + public Limits Weekly { get; init; } = new Limits(); /// - /// Gets the queue strategy for the group. + /// Limits. /// - [Enum(typeof(Transfers.QueueStrategy))] - public string Strategy { get; init; } = Transfers.QueueStrategy.RoundRobin.ToString().ToLowerInvariant(); + public class Limits + { + /// + /// Gets the limit for number of files. + /// + [Range(1, int.MaxValue)] + public int? Files { get; init; } = null; - /// - /// Gets the limit for the total number of upload slots for the group. - /// - [Range(1, int.MaxValue)] - public int Slots { get; init; } = int.MaxValue; + /// + /// Gets the limit for number of megabytes. + /// + [Range(1, int.MaxValue)] + public int? Megabytes { get; init; } = null; - /// - /// Gets the total upload speed limit for the group, in kibibytes. - /// - [Range(1, int.MaxValue)] - public int SpeedLimit { get; init; } = int.MaxValue; + /// + /// Gets the limit for number of failures. + /// + [Range(1, int.MaxValue)] + public int? Failures { get; init; } = null; + } } } -- cgit v1.2.3