aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-17 08:59:57 -0500
committerGitHub <noreply@github.com>2022-10-17 08:59:57 -0500
commit352def9012790ab97252715697291ba4c0ebec01 (patch)
tree0b8d6e2340ce40818ddbbea2de0db4019b5e45a3 /src/slskd/Core
parent593308d4e786cd569e3a683f5b02b8f13aa39b23 (diff)
parent9379a1fa3af07bab44b81752fe808cb9ca94be7a (diff)
downloadslskd-352def9012790ab97252715697291ba4c0ebec01.tar.gz
Merge pull request #697 from slskd/agent
Add the ability to 'network' multiple copies of slskd together (enable remote shares)
Diffstat (limited to 'src/slskd/Core')
-rw-r--r--src/slskd/Core/Options.cs114
-rw-r--r--src/slskd/Core/Types/NetworkOperationMode.cs35
2 files changed, 146 insertions, 3 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 484a514b..b75f9356 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -30,6 +30,7 @@ namespace slskd
using FluentFTP;
using NetTools;
using slskd.Configuration;
+ using slskd.Cryptography;
using slskd.Validation;
using Soulseek.Diagnostics;
using Utility.CommandLine;
@@ -132,12 +133,22 @@ namespace slskd
/// </summary>
[Argument('k', "generate-api-key")]
[Description("generate random API key for HTTP/S")]
- [Obsolete("USed only for documentation; see Program for actual implementation")]
+ [Obsolete("Used only for documentation; see Program for actual implementation")]
[JsonIgnore]
[YamlIgnore]
public bool GenerateApiKey { get; init; } = false;
/// <summary>
+ /// Gets a value indicating whether to generate a random agent secret.
+ /// </summary>
+ [Argument('t', "generate-agent-secret")]
+ [Description("generate random agent secret")]
+ [Obsolete("Used only for documentation; see Program for actual implementation")]
+ [JsonIgnore]
+ [YamlIgnore]
+ public bool GenerateAgentSecret { get; init; } = false;
+
+ /// <summary>
/// Gets a value indicating whether the application should run in debug mode.
/// </summary>
[Argument('d', "debug")]
@@ -181,7 +192,7 @@ namespace slskd
/// <summary>
/// Gets the path where application data is saved.
/// </summary>
- [Argument(default, "app")]
+ [Argument('a', "app-dir")]
[EnvironmentVariable("APP_DIR")]
[Description("path where application data is saved")]
[Obsolete("Used only for documentation; see Program for actual implementation")]
@@ -201,6 +212,12 @@ namespace slskd
public string ConfigurationFile { get; init; } = Program.DefaultConfigurationFile;
/// <summary>
+ /// Gets network options.
+ /// </summary>
+ [Validate]
+ public NetworkOptions Network { get; init; } = new NetworkOptions();
+
+ /// <summary>
/// Gets directory options.
/// </summary>
[Validate]
@@ -345,6 +362,97 @@ namespace slskd
[Description("log SQL queries generated by Entity Framework")]
[RequiresRestart]
public bool LogSQL { get; init; } = false;
+
+ /// <summary>
+ /// Gets a value indicating whether to run in both controller and agent network modes.
+ /// </summary>
+ [Argument(default, "dual-network-mode")]
+ [EnvironmentVariable("DUAL_NETWORK_MODE")]
+ [Description("run in both controller and agent network modes")]
+ [RequiresRestart]
+ public bool DualNetworkMode { get; init; } = false;
+ }
+
+ /// <summary>
+ /// Network options.
+ /// </summary>
+ public class NetworkOptions : IValidatableObject
+ {
+ /// <summary>
+ /// Gets the application operation mode.
+ /// </summary>
+ [Argument('m', "network-operation-mode")]
+ [EnvironmentVariable("NETWORK_OPERATION_MODE")]
+ [Description("network operation mode; controller, agent")]
+ [RequiresRestart]
+ [Enum(typeof(NetworkOperationMode))]
+ public string OperationMode { get; init; } = NetworkOperationMode.Controller.ToString().ToLowerInvariant();
+
+ /// <summary>
+ /// Gets the controller configuration.
+ /// </summary>
+ public NetworkControllerConfigurationOptions Controller { get; init; } = new NetworkControllerConfigurationOptions();
+
+ /// <summary>
+ /// Gets the agent configuration.
+ /// </summary>
+ public Dictionary<string, NetworkAgentConfigurationOptions> Agents { get; init; } = new();
+
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var results = new List<ValidationResult>();
+
+ // todo: can't run in agent mode if instancename is default
+
+ //var controllerResults = new List<ValidationResult>();
+ //var agentResults = new List<ValidationResult>();
+
+ //if (OperationMode.ToEnum<NetworkOperationMode>() == NetworkOperationMode.Agent && !Validator.TryValidateObject(Controller, validationContext, controllerResults))
+ //{
+ // results.AddRange(controllerResults);
+ //}
+ //else if (!Validator.TryValidateObject(Agents, validationContext, results))
+ //{
+ // results.AddRange(agentResults);
+ //}
+
+ return results;
+ }
+
+ /// <summary>
+ /// Network controller configuration options.
+ /// </summary>
+ public class NetworkControllerConfigurationOptions
+ {
+ /// <summary>
+ /// Gets the controller address.
+ /// </summary>
+ [Argument(default, "controller-address")]
+ [EnvironmentVariable("CONTROLLER_ADDRESS")]
+ public string Address { get; init; }
+
+ /// <summary>
+ /// Gets the controller secret.
+ /// </summary>
+ [Argument(default, "controller-secret")]
+ [EnvironmentVariable("CONTROLLER_SECRET")]
+ [StringLength(48, MinimumLength = 48)]
+ [Secret]
+ public string Secret { get; init; }
+ }
+
+ /// <summary>
+ /// Network agent configuration options.
+ /// </summary>
+ public class NetworkAgentConfigurationOptions
+ {
+ /// <summary>
+ /// Gets the agent secret.
+ /// </summary>
+ [StringLength(48, MinimumLength = 48)]
+ [Secret]
+ public string Secret { get; init; }
+ }
}
/// <summary>
@@ -1246,7 +1354,7 @@ namespace slskd
[StringLength(255, MinimumLength = 16)]
[Secret]
[RequiresRestart]
- public string Key { get; init; } = Cryptography.Random.GetBytes(16).ToBase62String();
+ public string Key { get; init; } = Cryptography.Random.GetBytes(16).ToBase62();
/// <summary>
/// Gets the TTL for JWTs, in milliseconds.
diff --git a/src/slskd/Core/Types/NetworkOperationMode.cs b/src/slskd/Core/Types/NetworkOperationMode.cs
new file mode 100644
index 00000000..4b190275
--- /dev/null
+++ b/src/slskd/Core/Types/NetworkOperationMode.cs
@@ -0,0 +1,35 @@
+// <copyright file="NetworkOperationMode.cs" company="slskd Team">
+// 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/.
+// </copyright>
+
+namespace slskd
+{
+ /// <summary>
+ /// The network operation mode.
+ /// </summary>
+ public enum NetworkOperationMode
+ {
+ /// <summary>
+ /// Controller operation mode.
+ /// </summary>
+ Controller = 0,
+
+ /// <summary>
+ /// Agent operation mode.
+ /// </summary>
+ Agent = 1,
+ }
+}