diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-11-21 15:10:07 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-21 15:10:07 -0600 |
| commit | 6798f34362f59be57040cbd03b6e09386ef3b7dd (patch) | |
| tree | 7acac646bec5a0d1ee0382a8c62a0d76576fe31f | |
| parent | ca7476025c3e63b3e2d78ecc601ef3001c3cff84 (diff) | |
| parent | 41f818ee64fb677bb9756b9ff78b38864e05f69a (diff) | |
| download | slskd-6798f34362f59be57040cbd03b6e09386ef3b7dd.tar.gz | |
Merge pull request #774 from slskd/relay
Add docs for Relay
| -rw-r--r-- | docs/config.md | 59 | ||||
| -rw-r--r-- | src/slskd/Application.cs | 4 | ||||
| -rw-r--r-- | src/slskd/Core/API/Controllers/ServerController.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 18 | ||||
| -rw-r--r-- | src/slskd/Core/State.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Messaging/API/Controllers/ConversationsController.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Messaging/API/Controllers/PublicChatController.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Messaging/API/Controllers/RoomsController.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Relay/API/Controllers/RelayController.cs | 10 | ||||
| -rw-r--r-- | src/slskd/Relay/API/Hubs/RelayHub.cs | 4 | ||||
| -rw-r--r-- | src/slskd/Relay/RelayClient.cs | 10 | ||||
| -rw-r--r-- | src/slskd/Relay/RelayService.cs | 4 | ||||
| -rw-r--r-- | src/slskd/Relay/Types/RelayMode.cs (renamed from src/slskd/Relay/Types/OperationMode.cs) | 10 | ||||
| -rw-r--r-- | src/slskd/Search/API/Controllers/SearchesController.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Transfers/API/Controllers/TransfersController.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Users/API/Controllers/UsersController.cs | 2 |
16 files changed, 97 insertions, 38 deletions
diff --git a/docs/config.md b/docs/config.md index bde38889..6d311826 100644 --- a/docs/config.md +++ b/docs/config.md @@ -184,6 +184,65 @@ shares: storage_mode: memory ``` +# Relay + +Two (or more) instances of the application can be connected, allowing files shared by one instance to be "relayed" to another while only one of the instances is connected to the Soulseek network. This allows users to share files from several different systems as the same Soulseek user, or to run an instance in the cloud and avoid needing to expose their home network to internet traffic. + +The Relay consists of two operation modes: 'Controller', which is the copy that connects to the Soulseek network, and 'Agent', which relays files to the controller. Only one controller can be configured, while any number of agents can be connected. + +## Controller + +Controllers must have at least one API key configured. For increased security it is a good idea to use a different API key for each agent, and to specify a CIDR for each key that limits access to the known IP address range the agent will be connecting from. + +The relay mode for the controller must be set to `controller`, and the relay must be enabled. + +For each agent, the agent's name (corresponding to the configured instance name of the agent) must be specified in the agent map, and a different secret value between 16-255 characters should be specified for each agent. + +It is strongly suggested that controllers be configured to force HTTPS. This makes the traffic between the controller and agents completely private, and prevents API keys and agent secrets from being exposed. + +```yaml +relay: + enabled: true + mode: controller + agents: + some_instance: + secret: <a secret value between 16 and 255 characters> + a_different_instance: + secret: <a different secret value between 16 and 255 characters> +``` + +| Command-Line | Environment Variable | Description | +| ------------------ | ---------------------| ------------------------------------------| +| `-r\|--relay` | `SLSKD_RELAY` | Enable the Relay feature | +| `-m\|--relay-mode` | `SLSKD_RELAY_MODE` | The Relay mode (Controller, Agent, Debug) | + +## Agents + +The relay mode for agents must be set to `agent`, the relay must be enabled, and each agent must have a unique instance name that corresponds to an agent configured in the controller. + +Agents need to specify the HTTP or HTTPS address of their controller, the API key for the controller, and the secret that corresponds to the value configured in the controller for the agent. + +If using HTTPS; most users won't have a valid certificate (the self-signed certificates that slskd generates at startup are not 'valid' because they are self-signed), and in those cases the `ignore_certificate_errors` option should be set to `true`. + +| Command-Line | Environment Variable | Description | +| ---------------------------------------- | -------------------------------------------- | ---------------------------------| +| `--controller-address` | `SLSKD_CONTROLLER_ADDRESS` | Enable the Relay feature | +| `--controller-ignore-certificate-errors` | `SLSKD_CONTROLLER_IGNORE_CERTIFICATE_ERRORS` | Ignore certificate errors | +| `--controller-api-key` | `SLSKD_CONTROLLER_API_KEY` | An API key for the controller | +| `--controller-secret` | `SLSKD_CONTROLLER_SECRET` | The shared secret for this agent | + +```yaml +instance_name: some_instance +relay: + enabled: true + mode: agent + controller: + address: https://my_cloud_server.example.com:5001 + ignore_certificate_errors: true + api_key: <a valid API key for the controller instance> + secret: <a secret value that matches the controller for this instance> +``` + # Limits and User Groups ## Global diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 0c7815e5..aeb18201 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -398,14 +398,14 @@ namespace slskd { Log.Warning($"Not connecting to the Soulseek server; username and/or password invalid. Specify valid credentials and manually connect, or update config and restart."); } - else if (OptionsAtStartup.Relay.Enabled && OptionsAtStartup.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent) + else if (OptionsAtStartup.Relay.Enabled && OptionsAtStartup.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent) { Log.Information("Running in Agent relay mode; not connecting to the Soulseek server."); await Relay.Client.StartAsync(cancellationToken); } else { - if (OptionsAtStartup.Relay.Enabled && OptionsAtStartup.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Debug) + if (OptionsAtStartup.Relay.Enabled && OptionsAtStartup.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Debug) { Log.Warning("Running in Debug relay mode; connecting to controller"); _ = Relay.Client.StartAsync(cancellationToken); diff --git a/src/slskd/Core/API/Controllers/ServerController.cs b/src/slskd/Core/API/Controllers/ServerController.cs index b1e36b1a..d9823a23 100644 --- a/src/slskd/Core/API/Controllers/ServerController.cs +++ b/src/slskd/Core/API/Controllers/ServerController.cs @@ -48,7 +48,7 @@ namespace slskd.Core.API private ISoulseekClient Client { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } private IStateSnapshot<State> StateSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent; + private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Connects the client. diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 368b5ca0..95ecfb6a 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -288,7 +288,7 @@ namespace slskd { var results = new List<ValidationResult>(); - if (InstanceName == "local" && Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent) + if (InstanceName == "local" && Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent) { results.Add(new ValidationResult("Instance name must be something other than 'local' when operating in Relay Agent mode")); } @@ -398,14 +398,14 @@ namespace slskd public bool Enabled { get; init; } = false; /// <summary> - /// Gets the relay operation mode. + /// Gets the relay mode. /// </summary> - [Argument('m', "relay-operation-mode")] - [EnvironmentVariable("RELAY_OPERATION_MODE")] - [Description("relay operation mode; controller, agent")] + [Argument('m', "relay-mode")] + [EnvironmentVariable("RELAY_MODE")] + [Description("relay mode; controller, agent")] [RequiresRestart] - [Enum(typeof(OperationMode))] - public string Mode { get; init; } = OperationMode.Controller.ToString().ToLowerInvariant(); + [Enum(typeof(RelayMode))] + public string Mode { get; init; } = RelayMode.Controller.ToString().ToLowerInvariant(); /// <summary> /// Gets the controller configuration. @@ -419,11 +419,11 @@ namespace slskd public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { - var mode = Mode.ToEnum<OperationMode>(); + var mode = Mode.ToEnum<RelayMode>(); var results = new List<ValidationResult>(); var modeResults = new List<ValidationResult>(); - if (mode == OperationMode.Agent && !Validator.TryValidateObject(Controller, new ValidationContext(Controller), modeResults, validateAllProperties: true)) + if (mode == RelayMode.Agent && !Validator.TryValidateObject(Controller, new ValidationContext(Controller), modeResults, validateAllProperties: true)) { results.Add(new CompositeValidationResult("Controller", modeResults)); } diff --git a/src/slskd/Core/State.cs b/src/slskd/Core/State.cs index 76253501..9ae6df6b 100644 --- a/src/slskd/Core/State.cs +++ b/src/slskd/Core/State.cs @@ -67,7 +67,7 @@ namespace slskd public record RelayState { - public OperationMode Mode { get; init; } + public RelayMode Mode { get; init; } public RelayControllerState Controller { get; init; } = new RelayControllerState(); public IReadOnlyCollection<Agent> Agents { get; init; } = Enumerable.Empty<Agent>().ToList().AsReadOnly(); } diff --git a/src/slskd/Messaging/API/Controllers/ConversationsController.cs b/src/slskd/Messaging/API/Controllers/ConversationsController.cs index 65608ae3..90e7f380 100644 --- a/src/slskd/Messaging/API/Controllers/ConversationsController.cs +++ b/src/slskd/Messaging/API/Controllers/ConversationsController.cs @@ -60,7 +60,7 @@ namespace slskd.Messaging.API private IStateMonitor<State> ApplicationStateMonitor { get; } private IConversationTracker Tracker { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent; + private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Acknowledges the given message id for the given username. diff --git a/src/slskd/Messaging/API/Controllers/PublicChatController.cs b/src/slskd/Messaging/API/Controllers/PublicChatController.cs index 66f0951d..8b6ce4f8 100644 --- a/src/slskd/Messaging/API/Controllers/PublicChatController.cs +++ b/src/slskd/Messaging/API/Controllers/PublicChatController.cs @@ -44,7 +44,7 @@ namespace slskd.Messaging.API private ISoulseekClient Client { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent; + private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Starts public chat. diff --git a/src/slskd/Messaging/API/Controllers/RoomsController.cs b/src/slskd/Messaging/API/Controllers/RoomsController.cs index c5651554..1036e10e 100644 --- a/src/slskd/Messaging/API/Controllers/RoomsController.cs +++ b/src/slskd/Messaging/API/Controllers/RoomsController.cs @@ -58,7 +58,7 @@ namespace slskd.Messaging.API private IStateMonitor<State> ApplicationStateMonitor { get; } private IRoomTracker Tracker { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent; + private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Gets all rooms. diff --git a/src/slskd/Relay/API/Controllers/RelayController.cs b/src/slskd/Relay/API/Controllers/RelayController.cs index cd688306..c11c33bc 100644 --- a/src/slskd/Relay/API/Controllers/RelayController.cs +++ b/src/slskd/Relay/API/Controllers/RelayController.cs @@ -49,13 +49,13 @@ namespace slskd.Relay private ILogger Log { get; } = Serilog.Log.ForContext<RelayController>(); private IRelayService Relay { get; } private OptionsAtStartup OptionsAtStartup { get; } - private OperationMode OperationMode => OptionsAtStartup.Relay.Mode.ToEnum<OperationMode>(); + private RelayMode OperationMode => OptionsAtStartup.Relay.Mode.ToEnum<RelayMode>(); [HttpPut("")] [Authorize(Policy = AuthPolicy.Any)] public async Task<IActionResult> Connect() { - if (!OptionsAtStartup.Relay.Enabled || !new[] { OperationMode.Agent, OperationMode.Debug }.Contains(OperationMode)) + if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Agent, RelayMode.Debug }.Contains(OperationMode)) { return Forbid(); } @@ -68,7 +68,7 @@ namespace slskd.Relay [Authorize(Policy = AuthPolicy.Any)] public async Task<IActionResult> Disconnect() { - if (!OptionsAtStartup.Relay.Enabled || !new[] { OperationMode.Agent, OperationMode.Debug }.Contains(OperationMode)) + if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Agent, RelayMode.Debug }.Contains(OperationMode)) { return Forbid(); } @@ -89,7 +89,7 @@ namespace slskd.Relay [Authorize(Policy = AuthPolicy.Any)] public async Task<IActionResult> UploadFile(string token) { - if (!OptionsAtStartup.Relay.Enabled || !new[] { OperationMode.Controller, OperationMode.Debug }.Contains(OperationMode)) + if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Controller, RelayMode.Debug }.Contains(OperationMode)) { return Forbid(); } @@ -178,7 +178,7 @@ namespace slskd.Relay [Authorize(Policy = AuthPolicy.Any)] public async Task<IActionResult> UploadShares(string token) { - if (!OptionsAtStartup.Relay.Enabled || !new[] { OperationMode.Controller, OperationMode.Debug }.Contains(OperationMode)) + if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Controller, RelayMode.Debug }.Contains(OperationMode)) { return Forbid(); } diff --git a/src/slskd/Relay/API/Hubs/RelayHub.cs b/src/slskd/Relay/API/Hubs/RelayHub.cs index 99cd3839..6b091a39 100644 --- a/src/slskd/Relay/API/Hubs/RelayHub.cs +++ b/src/slskd/Relay/API/Hubs/RelayHub.cs @@ -77,7 +77,7 @@ namespace slskd.Relay private ILogger Log { get; } = Serilog.Log.ForContext<RelayService>(); private IRelayService Relay { get; } private OptionsAtStartup OptionsAtStartup { get; } - private OperationMode OperationMode => OptionsAtStartup.Relay.Mode.ToEnum<OperationMode>(); + private RelayMode OperationMode => OptionsAtStartup.Relay.Mode.ToEnum<RelayMode>(); private IPAddress RemoteIpAddress => Context.Features.Get<IHttpConnectionFeature>().RemoteIpAddress; /// <summary> @@ -86,7 +86,7 @@ namespace slskd.Relay /// <returns></returns> public override async Task OnConnectedAsync() { - if (!OptionsAtStartup.Relay.Enabled || !new[] { OperationMode.Controller, OperationMode.Debug }.Contains(OperationMode)) + if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Controller, RelayMode.Debug }.Contains(OperationMode)) { Log.Debug("Agent connection {Id} from {IP} aborted; Relay is not enabled, or is not in Controller mode", Context.ConnectionId, RemoteIpAddress); Context.Abort(); diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs index df4a3e89..693a7017 100644 --- a/src/slskd/Relay/RelayClient.cs +++ b/src/slskd/Relay/RelayClient.cs @@ -123,11 +123,11 @@ namespace slskd.Relay try { - var mode = OptionsMonitor.CurrentValue.Relay.Mode.ToEnum<OperationMode>(); + var mode = OptionsMonitor.CurrentValue.Relay.Mode.ToEnum<RelayMode>(); - if (mode != OperationMode.Agent && mode != OperationMode.Debug) + if (mode != RelayMode.Agent && mode != RelayMode.Debug) { - throw new InvalidOperationException($"Relay client can only be started when operation mode is {OperationMode.Agent}"); + throw new InvalidOperationException($"Relay client can only be started when operation mode is {RelayMode.Agent}"); } StartCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); @@ -432,9 +432,9 @@ namespace slskd.Relay private void Configure(Options options) { - var mode = options.Relay.Mode.ToEnum<OperationMode>(); + var mode = options.Relay.Mode.ToEnum<RelayMode>(); - if (mode != OperationMode.Agent && mode != OperationMode.Debug) + if (mode != RelayMode.Agent && mode != RelayMode.Debug) { return; } diff --git a/src/slskd/Relay/RelayService.cs b/src/slskd/Relay/RelayService.cs index 79f9f143..3b872816 100644 --- a/src/slskd/Relay/RelayService.cs +++ b/src/slskd/Relay/RelayService.cs @@ -718,9 +718,9 @@ namespace slskd.Relay if (options.Relay.Enabled) { - var mode = options.Relay.Mode.ToEnum<OperationMode>(); + var mode = options.Relay.Mode.ToEnum<RelayMode>(); - if (mode == OperationMode.Controller) + if (mode == RelayMode.Controller) { State.SetValue(state => state with { diff --git a/src/slskd/Relay/Types/OperationMode.cs b/src/slskd/Relay/Types/RelayMode.cs index c572f0da..d45a8933 100644 --- a/src/slskd/Relay/Types/OperationMode.cs +++ b/src/slskd/Relay/Types/RelayMode.cs @@ -1,4 +1,4 @@ -// <copyright file="OperationMode.cs" company="slskd Team"> +// <copyright file="RelayMode.cs" company="slskd Team"> // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -18,17 +18,17 @@ namespace slskd.Relay { /// <summary> - /// The relay operation mode. + /// The relay mode. /// </summary> - public enum OperationMode + public enum RelayMode { /// <summary> - /// Controller operation mode. + /// Controller mode. /// </summary> Controller = 0, /// <summary> - /// Agent operation mode. + /// Agent mode. /// </summary> Agent = 1, diff --git a/src/slskd/Search/API/Controllers/SearchesController.cs b/src/slskd/Search/API/Controllers/SearchesController.cs index ae7f42db..507de5d6 100644 --- a/src/slskd/Search/API/Controllers/SearchesController.cs +++ b/src/slskd/Search/API/Controllers/SearchesController.cs @@ -50,7 +50,7 @@ namespace slskd.Search.API private ISearchService Searches { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent; + private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Performs a search for the specified <paramref name="request"/>. diff --git a/src/slskd/Transfers/API/Controllers/TransfersController.cs b/src/slskd/Transfers/API/Controllers/TransfersController.cs index 80613586..6918888d 100644 --- a/src/slskd/Transfers/API/Controllers/TransfersController.cs +++ b/src/slskd/Transfers/API/Controllers/TransfersController.cs @@ -52,7 +52,7 @@ namespace slskd.Transfers.API private ITransferService Transfers { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent; + private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Cancels the specified download. diff --git a/src/slskd/Users/API/Controllers/UsersController.cs b/src/slskd/Users/API/Controllers/UsersController.cs index f35051a2..852d15a8 100644 --- a/src/slskd/Users/API/Controllers/UsersController.cs +++ b/src/slskd/Users/API/Controllers/UsersController.cs @@ -56,7 +56,7 @@ namespace slskd.Users.API private ISoulseekClient Client { get; } private IUserService Users { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent; + private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Retrieves the address of the specified <paramref name="username"/>. |
