From 2d1b24164357af9f15ee0629979035d7c365e94a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 5 Jan 2023 19:22:48 -0600 Subject: add agent CIDR --- src/slskd/Core/Options.cs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index bc6f14a6..063da9e6 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -513,15 +513,46 @@ namespace slskd /// /// Relay agent configuration options. /// - public class RelayAgentConfigurationOptions + public class RelayAgentConfigurationOptions : IValidatableObject { /// /// Gets the agent secret. /// + [Description("shared secret for this agent")] [StringLength(255, MinimumLength = 16)] [NotNullOrWhiteSpace] [Secret] public string Secret { get; init; } + + /// + /// Gets the comma separated list of CIDRs that are authorized to connect as this agent. + /// + [Description("optional; comma separated list of CIDRs that are authorized to connect as this agent")] + public string Cidr { get; init; } = "0.0.0.0/0,::/0"; + + /// + /// Extended validation. + /// + /// + /// + public IEnumerable Validate(ValidationContext validationContext) + { + var results = new List(); + + foreach (var cidr in Cidr.Split(',')) + { + try + { + _ = IPAddressRange.Parse(cidr); + } + catch (Exception ex) + { + results.Add(new ValidationResult($"CIDR {cidr} is invalid: {ex.Message}")); + } + } + + return results; + } } } @@ -1476,7 +1507,7 @@ namespace slskd /// /// Gets the comma separated list of CIDRs that are authorized to use the key. /// - [Description("An optional comma separated list of CIDRs that are authorized to use the key")] + [Description("optional; comma separated list of CIDRs that are authorized to use the key")] public string Cidr { get; init; } = "0.0.0.0/0,::/0"; /// -- cgit v1.2.3