aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-01-06 07:50:03 -0600
committerJP Dillingham <jp@dillingham.me>2023-01-06 07:50:03 -0600
commit622718b5ed5c9f8aa6b2f324a1fa4648b481d73c (patch)
tree593e2f98cb604d458a86b436ac8da6f0d0ef169c /src/slskd/Core
parent6acd4b59a303a41b685d6b75a684c718ac80897c (diff)
parent9251a1be5f004f022a7e197112d89dd1972571fd (diff)
downloadslskd-622718b5ed5c9f8aa6b2f324a1fa4648b481d73c.tar.gz
Merge remote-tracking branch 'origin/master' into relay-docs
Diffstat (limited to 'src/slskd/Core')
-rw-r--r--src/slskd/Core/Options.cs35
1 files changed, 33 insertions, 2 deletions
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
/// <summary>
/// Relay agent configuration options.
/// </summary>
- public class RelayAgentConfigurationOptions
+ public class RelayAgentConfigurationOptions : IValidatableObject
{
/// <summary>
/// Gets the agent secret.
/// </summary>
+ [Description("shared secret for this agent")]
[StringLength(255, MinimumLength = 16)]
[NotNullOrWhiteSpace]
[Secret]
public string Secret { get; init; }
+
+ /// <summary>
+ /// Gets the comma separated list of CIDRs that are authorized to connect as this agent.
+ /// </summary>
+ [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";
+
+ /// <summary>
+ /// Extended validation.
+ /// </summary>
+ /// <param name="validationContext"></param>
+ /// <returns></returns>
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var results = new List<ValidationResult>();
+
+ 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
/// <summary>
/// Gets the comma separated list of CIDRs that are authorized to use the key.
/// </summary>
- [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";
/// <summary>