From d234ec10d08262cc6896cb7dd2793bc45a048293 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 11 Dec 2023 21:49:49 -0600 Subject: add IPAddress validator --- src/slskd/Common/Validation/IPAddressAttribute.cs | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/slskd/Common/Validation/IPAddressAttribute.cs (limited to 'src') diff --git a/src/slskd/Common/Validation/IPAddressAttribute.cs b/src/slskd/Common/Validation/IPAddressAttribute.cs new file mode 100644 index 00000000..6e53df57 --- /dev/null +++ b/src/slskd/Common/Validation/IPAddressAttribute.cs @@ -0,0 +1,48 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Validation +{ + using System.ComponentModel.DataAnnotations; + using System.Net; + + /// + /// Validates that the string is a valid IPv4 or IPv6 IP address. + /// + public class IPAddressAttribute : ValidationAttribute + { + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + if (value != null) + { + var fail = new ValidationResult($"The {validationContext.DisplayName} field specifies an invalid IPv4 or IPv6 IP address."); + + if (value is not string valueAsString) + { + return fail; + } + + if (!IPAddress.TryParse(valueAsString, out _)) + { + return fail; + } + } + + return ValidationResult.Success; + } + } +} \ No newline at end of file -- cgit v1.2.3 From 7c6d8c2a71f2eea94af851b227f4da7c26e49d68 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 11 Dec 2023 21:50:40 -0600 Subject: add a ListenAddress option --- src/slskd/Core/Options.cs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 1d4742da..49f20ea4 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1294,6 +1294,15 @@ namespace slskd [Description("user description for the Soulseek network")] public string Description { get; init; } = "A slskd user. https://github.com/slskd/slskd"; + /// + /// Gets the local IP address on which to listen for incoming connections. + /// + [Argument(default, "slsk-listen-address")] + [EnvironmentVariable("SLSK_LISTEN_ADDRESS")] + [Description("local IP address on which to listen for incoming connections")] + [IPAddress] + public string ListenAddress { get; init; } = "0.0.0.0"; + /// /// Gets the port on which to listen for incoming connections. /// -- cgit v1.2.3 From 87dec303d339647059550c23318b8c33e6b05d27 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 12 Dec 2023 09:13:31 -0600 Subject: tweak name --- src/slskd/Core/Options.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 49f20ea4..2dd8d141 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1297,11 +1297,11 @@ namespace slskd /// /// Gets the local IP address on which to listen for incoming connections. /// - [Argument(default, "slsk-listen-address")] - [EnvironmentVariable("SLSK_LISTEN_ADDRESS")] + [Argument(default, "slsk-listen-ip-address")] + [EnvironmentVariable("SLSK_LISTEN_IP_ADDRESS")] [Description("local IP address on which to listen for incoming connections")] [IPAddress] - public string ListenAddress { get; init; } = "0.0.0.0"; + public string ListenIPAddress { get; init; } = "0.0.0.0"; /// /// Gets the port on which to listen for incoming connections. -- cgit v1.2.3 From 8f820e01591d0197945a13b1c1e1543613c56a2c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 12 Dec 2023 09:14:13 -0600 Subject: include listen ip when configuring/reconfiguring --- src/slskd/Application.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index b6d11914..04c6b7d6 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -361,6 +361,7 @@ namespace slskd writeBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Transfer); var patch = new SoulseekClientOptionsPatch( + listenIPAddress: IPAddress.Parse(OptionsAtStartup.Soulseek.ListenIPAddress), listenPort: OptionsAtStartup.Soulseek.ListenPort, enableListener: true, userEndPointCache: new UserEndPointCache(), @@ -386,7 +387,7 @@ namespace slskd await Client.ReconfigureOptionsAsync(patch); Log.Debug("Client configured"); - Log.Information("Listening for incoming connections on port {Port}", OptionsAtStartup.Soulseek.ListenPort); + Log.Information("Listening for incoming connections on {IP:Port}", OptionsAtStartup.Soulseek.ListenIPAddress, OptionsAtStartup.Soulseek.ListenPort); if (OptionsAtStartup.Soulseek.Connection.Proxy.Enabled) { @@ -1049,6 +1050,7 @@ namespace slskd } var patch = new SoulseekClientOptionsPatch( + listenIPAddress: old.ListenIPAddress == update.ListenIPAddress ? null : IPAddress.Parse(update.ListenIPAddress), listenPort: old.ListenPort == update.ListenPort ? null : update.ListenPort, enableDistributedNetwork: old.DistributedNetwork.Disabled == update.DistributedNetwork.Disabled ? null : !update.DistributedNetwork.Disabled, distributedChildLimit: old.DistributedNetwork.ChildLimit == update.DistributedNetwork.ChildLimit ? null : update.DistributedNetwork.ChildLimit, -- cgit v1.2.3 From 617523ab4d93910240029493b4d5105f56fefb97 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 16 Dec 2023 20:28:54 -0600 Subject: fix case on IPAddress for YAML compatibility --- src/slskd/Application.cs | 6 +++--- src/slskd/Core/Options.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 04c6b7d6..a7483105 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -361,7 +361,7 @@ namespace slskd writeBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Transfer); var patch = new SoulseekClientOptionsPatch( - listenIPAddress: IPAddress.Parse(OptionsAtStartup.Soulseek.ListenIPAddress), + listenIPAddress: IPAddress.Parse(OptionsAtStartup.Soulseek.ListenIpAddress), listenPort: OptionsAtStartup.Soulseek.ListenPort, enableListener: true, userEndPointCache: new UserEndPointCache(), @@ -387,7 +387,7 @@ namespace slskd await Client.ReconfigureOptionsAsync(patch); Log.Debug("Client configured"); - Log.Information("Listening for incoming connections on {IP:Port}", OptionsAtStartup.Soulseek.ListenIPAddress, OptionsAtStartup.Soulseek.ListenPort); + Log.Information("Listening for incoming connections son {IP}:{Port}", OptionsAtStartup.Soulseek.ListenIpAddress, OptionsAtStartup.Soulseek.ListenPort); if (OptionsAtStartup.Soulseek.Connection.Proxy.Enabled) { @@ -1050,7 +1050,7 @@ namespace slskd } var patch = new SoulseekClientOptionsPatch( - listenIPAddress: old.ListenIPAddress == update.ListenIPAddress ? null : IPAddress.Parse(update.ListenIPAddress), + listenIPAddress: old.ListenIpAddress == update.ListenIpAddress ? null : IPAddress.Parse(update.ListenIpAddress), listenPort: old.ListenPort == update.ListenPort ? null : update.ListenPort, enableDistributedNetwork: old.DistributedNetwork.Disabled == update.DistributedNetwork.Disabled ? null : !update.DistributedNetwork.Disabled, distributedChildLimit: old.DistributedNetwork.ChildLimit == update.DistributedNetwork.ChildLimit ? null : update.DistributedNetwork.ChildLimit, diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 2dd8d141..1eb92449 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1301,7 +1301,7 @@ namespace slskd [EnvironmentVariable("SLSK_LISTEN_IP_ADDRESS")] [Description("local IP address on which to listen for incoming connections")] [IPAddress] - public string ListenIPAddress { get; init; } = "0.0.0.0"; + public string ListenIpAddress { get; init; } = "0.0.0.0"; /// /// Gets the port on which to listen for incoming connections. -- cgit v1.2.3