aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-03-01 13:44:22 -0600
committerJP Dillingham <jp@dillingham.me>2026-03-15 11:23:37 -0500
commit1fb7b1d85d04546dda66616030f427badff48ebd (patch)
tree34a5a241589e7be463112d4296d7ddf44a35bf80 /src/slskd/Core
parent032d9a3513642b85379c6b33a479cb7e0a5adc22 (diff)
downloadslskd-1fb7b1d85d04546dda66616030f427badff48ebd.tar.gz
move transfer options into the same type, move limits under upload
Diffstat (limited to 'src/slskd/Core')
-rw-r--r--src/slskd/Core/Options.cs380
1 files changed, 186 insertions, 194 deletions
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();
/// <summary>
- /// Gets global options.
+ /// Gets transfer options.
/// </summary>
- [Validate]
- public GlobalOptions Global { get; init; } = new GlobalOptions();
-
- /// <summary>
- /// Gets user groups.
- /// </summary>
- [Validate]
- public GroupsOptions Groups { get; init; } = new GroupsOptions();
+ public TransfersOptions Transfers { get; init; } = new TransfersOptions();
/// <summary>
/// Gets blacklist options.
@@ -904,9 +897,9 @@ namespace slskd
}
/// <summary>
- /// Global options.
+ /// Transfer options.
/// </summary>
- public class GlobalOptions
+ public class TransfersOptions
{
/// <summary>
/// Gets global upload options.
@@ -915,16 +908,16 @@ namespace slskd
public GlobalUploadOptions Upload { get; init; } = new GlobalUploadOptions();
/// <summary>
- /// Gets global limits.
+ /// Gets global download options.
/// </summary>
[Validate]
- public LimitsOptions Limits { get; init; } = new LimitsOptions();
+ public GlobalDownloadOptions Download { get; init; } = new GlobalDownloadOptions();
/// <summary>
- /// Gets global download options.
+ /// Gets user groups.
/// </summary>
[Validate]
- public GlobalDownloadOptions Download { get; init; } = new GlobalDownloadOptions();
+ public GroupsOptions Groups { get; init; } = new GroupsOptions();
/// <summary>
/// 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;
+
+ /// <summary>
+ /// Gets global limits.
+ /// </summary>
+ [Validate]
+ public LimitsOptions Limits { get; init; } = new LimitsOptions();
}
/// <summary>
@@ -975,244 +974,237 @@ namespace slskd
[Range(1, int.MaxValue)]
public int SpeedLimit { get; init; } = int.MaxValue;
}
- }
-
- /// <summary>
- /// Limit options.
- /// </summary>
- public class LimitsOptions
- {
- /// <summary>
- /// Gets limits for queued transfers.
- /// </summary>
- [Validate]
- public Limits Queued { get; init; } = new Limits();
-
- /// <summary>
- /// Gets daily limits for transfers.
- /// </summary>
- [Validate]
- public Limits Daily { get; init; } = new Limits();
-
- /// <summary>
- /// Gets weekly limits for transfers.
- /// </summary>
- [Validate]
- public Limits Weekly { get; init; } = new Limits();
/// <summary>
- /// Limits.
+ /// User groups.
/// </summary>
- public class Limits
+ public class GroupsOptions : IValidatableObject
{
/// <summary>
- /// Gets the limit for number of files.
+ /// Gets options for the default user group.
/// </summary>
- [Range(1, int.MaxValue)]
- public int? Files { get; init; } = null;
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ [Validate]
+ public GroupOptions Default { get; init; } = new GroupOptions();
/// <summary>
- /// Gets the limit for number of megabytes.
+ /// Gets options for the leecher user group.
/// </summary>
- [Range(1, int.MaxValue)]
- public int? Megabytes { get; init; } = null;
+ /// <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 LeecherOptions Leechers { get; init; } = new LeecherOptions();
/// <summary>
- /// Gets the limit for number of failures.
+ /// Gets options for the blacklisted user group.
/// </summary>
- [Range(1, int.MaxValue)]
- public int? Failures { get; init; } = null;
- }
- }
-
- /// <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 privileged, 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 LeecherOptions Leechers { get; init; } = new LeecherOptions();
-
- /// <summary>
- /// Gets options for the blacklisted user group.
- /// </summary>
- [Validate]
- public BlacklistedOptions Blacklisted { get; init; } = new BlacklistedOptions();
-
- /// <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.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();
- /// <summary>
- /// Options that are common to all groups.
- /// </summary>
- public class GroupOptions
- {
/// <summary>
- /// Gets upload options.
+ /// Gets user defined groups and options.
/// </summary>
[Validate]
- public UploadOptions Upload { get; init; } = new UploadOptions();
+ public Dictionary<string, UserDefinedOptions> UserDefined { get; init; } = new Dictionary<string, UserDefinedOptions>();
/// <summary>
- /// Gets limit options.
+ /// Extended validation.
/// </summary>
- [Validate]
- public LimitsOptions Limits { get; init; } = new LimitsOptions();
- }
+ /// <param name="validationContext"></param>
+ /// <returns></returns>
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var builtInGroups = new[] { Application.PrivilegedGroup, Application.DefaultGroup, Application.LeecherGroup };
+ var intersection = UserDefined.Keys.Intersect(builtInGroups);
- /// <summary>
- /// Built in user group options.
- /// </summary>
- public class BuiltInOptions : GroupOptions
- {
- }
+ return intersection.Select(group => new ValidationResult($"User defined group '{group}' collides with a built in group. Choose a different name."));
+ }
- /// <summary>
- /// Built in blacklisted group options.
- /// </summary>
- public class BlacklistedOptions : IValidatableObject
- {
/// <summary>
- /// Gets the list of group member usernames.
+ /// Options that are common to all groups.
/// </summary>
- public string[] Members { get; init; } = Array.Empty<string>();
+ public class GroupOptions
+ {
+ /// <summary>
+ /// Gets upload options.
+ /// </summary>
+ [Validate]
+ public GroupUploadOptions Upload { get; init; } = new GroupUploadOptions();
+
+ /// <summary>
+ /// User group upload options.
+ /// </summary>
+ public class GroupUploadOptions
+ {
+ /// <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(Transfers.QueueStrategy))]
+ public string Strategy { get; init; } = slskd.Transfers.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, in kibibytes.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int SpeedLimit { get; init; } = int.MaxValue;
+
+ /// <summary>
+ /// Gets limit options.
+ /// </summary>
+ [Validate]
+ public LimitsOptions Limits { get; init; } = new LimitsOptions();
+ }
+ }
/// <summary>
- /// Gets the list of group CIDRs.
+ /// Built in leecher group options.
/// </summary>
- public string[] Cidrs { get; init; } = Array.Empty<string>();
+ public class LeecherOptions : GroupOptions
+ {
+ /// <summary>
+ /// Gets leecher threshold options.
+ /// </summary>
+ [Validate]
+ public ThresholdOptions Thresholds { get; init; } = new ThresholdOptions();
+
+ /// <summary>
+ /// Leecher threshold options.
+ /// </summary>
+ public class ThresholdOptions
+ {
+ /// <summary>
+ /// Gets the minimum number of shared files required to avoid being classified as a leecher.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int Files { get; init; } = 1;
+
+ /// <summary>
+ /// Gets the minimum number of shared directories required to avoid being classified as a leecher.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int Directories { get; init; } = 1;
+ }
+ }
/// <summary>
- /// Extended validation.
+ /// Built in blacklisted group options.
/// </summary>
- /// <param name="validationContext"></param>
- /// <returns></returns>
- public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ public class BlacklistedOptions : IValidatableObject
{
- var results = new List<ValidationResult>();
+ /// <summary>
+ /// Gets the list of group member usernames.
+ /// </summary>
+ public string[] Members { get; init; } = Array.Empty<string>();
+
+ /// <summary>
+ /// Gets the list of group CIDRs.
+ /// </summary>
+ public string[] Cidrs { get; init; } = Array.Empty<string>();
- foreach (var cidr in Cidrs ?? Array.Empty<string>())
+ /// <summary>
+ /// Extended validation.
+ /// </summary>
+ /// <param name="validationContext"></param>
+ /// <returns></returns>
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
- try
+ var results = new List<ValidationResult>();
+
+ foreach (var cidr in Cidrs ?? Array.Empty<string>())
{
- 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;
+ }
}
- }
- /// <summary>
- /// Built in leecher group options.
- /// </summary>
- public class LeecherOptions : GroupOptions
- {
/// <summary>
- /// Gets leecher threshold options.
+ /// User defined user group options.
/// </summary>
- [Validate]
- public ThresholdOptions Thresholds { get; init; } = new ThresholdOptions();
+ public class UserDefinedOptions : GroupOptions
+ {
+ /// <summary>
+ /// Gets the list of group member usernames.
+ /// </summary>
+ public string[] Members { get; init; } = Array.Empty<string>();
+ }
}
/// <summary>
- /// Leecher threshold options.
+ /// Limit options.
/// </summary>
- public class ThresholdOptions
+ public class LimitsOptions
{
/// <summary>
- /// Gets the minimum number of shared files required to avoid being classified as a leecher.
- /// </summary>
- [Range(1, int.MaxValue)]
- public int Files { get; init; } = 1;
-
- /// <summary>
- /// Gets the minimum number of shared directories required to avoid being classified as a leecher.
+ /// Gets limits for queued transfers.
/// </summary>
- [Range(1, int.MaxValue)]
- public int Directories { get; init; } = 1;
- }
+ [Validate]
+ public Limits Queued { get; init; } = new Limits();
- /// <summary>
- /// User defined user group options.
- /// </summary>
- public class UserDefinedOptions : GroupOptions
- {
/// <summary>
- /// Gets the list of group member usernames.
+ /// Gets daily limits for transfers.
/// </summary>
- public string[] Members { get; init; } = Array.Empty<string>();
- }
+ [Validate]
+ public Limits Daily { get; init; } = new Limits();
- /// <summary>
- /// User group upload options.
- /// </summary>
- public class UploadOptions
- {
/// <summary>
- /// Gets the priority of the group.
+ /// Gets weekly limits for transfers.
/// </summary>
- [Range(1, int.MaxValue)]
- public int Priority { get; init; } = 1;
+ [Validate]
+ public Limits Weekly { get; init; } = new Limits();
/// <summary>
- /// Gets the queue strategy for the group.
+ /// Limits.
/// </summary>
- [Enum(typeof(Transfers.QueueStrategy))]
- public string Strategy { get; init; } = Transfers.QueueStrategy.RoundRobin.ToString().ToLowerInvariant();
+ public class Limits
+ {
+ /// <summary>
+ /// Gets the limit for number of files.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int? Files { get; init; } = null;
- /// <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 limit for number of megabytes.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int? Megabytes { get; init; } = null;
- /// <summary>
- /// Gets the total upload speed limit for the group, in kibibytes.
- /// </summary>
- [Range(1, int.MaxValue)]
- public int SpeedLimit { get; init; } = int.MaxValue;
+ /// <summary>
+ /// Gets the limit for number of failures.
+ /// </summary>
+ [Range(1, int.MaxValue)]
+ public int? Failures { get; init; } = null;
+ }
}
}