diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-07-12 14:58:53 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-12 14:58:53 -0500 |
| commit | 367b2cee4d475277fb278e6537f1014436d5a09f (patch) | |
| tree | 2bcdd9f727ebfbb57787ee203e6760a3e0f1e910 /src/slskd/Core/API | |
| parent | eed42e9c4916e2ba653e40147de546e7af3af563 (diff) | |
| parent | 11456386b8c3dcd6d054b2ceff5861a972fbe3cd (diff) | |
| download | slskd-367b2cee4d475277fb278e6537f1014436d5a09f.tar.gz | |
Merge pull request #1385 from slskd/dns
Adjust auto-reconnect logic
Diffstat (limited to 'src/slskd/Core/API')
| -rw-r--r-- | src/slskd/Core/API/Controllers/ServerController.cs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/slskd/Core/API/Controllers/ServerController.cs b/src/slskd/Core/API/Controllers/ServerController.cs index 9b8e2764..da777b02 100644 --- a/src/slskd/Core/API/Controllers/ServerController.cs +++ b/src/slskd/Core/API/Controllers/ServerController.cs @@ -19,9 +19,9 @@ using Microsoft.Extensions.Options; namespace slskd.Core.API { - using System.Threading.Tasks; using Asp.Versioning; using Microsoft.AspNetCore.Authorization; + using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Soulseek; @@ -37,15 +37,18 @@ namespace slskd.Core.API { public ServerController( ISoulseekClient soulseekClient, + ConnectionWatchdog connectionWatchdog, IOptionsSnapshot<Options> optionsSnapshot, IStateSnapshot<State> stateSnapshot) { Client = soulseekClient; + ConnectionWatchdog = connectionWatchdog; OptionsSnapshot = optionsSnapshot; StateSnapshot = stateSnapshot; } private ISoulseekClient Client { get; } + private ConnectionWatchdog ConnectionWatchdog { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } private IStateSnapshot<State> StateSnapshot { get; } @@ -57,23 +60,28 @@ namespace slskd.Core.API [Route("")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(200)] + [ProducesResponseType(StatusCodes.Status205ResetContent)] [ProducesResponseType(403)] - public async Task<IActionResult> Connect() + public IActionResult Connect() { if (Program.IsRelayAgent) { return Forbid(); } - if (!Client.State.HasFlag(SoulseekClientStates.Connected)) + // if the watchdog is already enabled, we're already attempting to connect. the user might have changed something + // or perhaps is just being impatient; either way, restart the retry loop so they can see results faster + // remember, we may be in a ~5 minute delay at this moment + if (ConnectionWatchdog.IsEnabled) { - var opt = OptionsSnapshot.Value.Soulseek; + ConnectionWatchdog.Restart(); + return StatusCode(StatusCodes.Status205ResetContent); + } - await Client.ConnectAsync( - address: opt.Address, - port: opt.Port, - username: opt.Username, - password: opt.Password); + if (!ConnectionWatchdog.IsEnabled) + { + ConnectionWatchdog.Start(); + return Ok(); } return Ok(); @@ -96,8 +104,13 @@ namespace slskd.Core.API return Forbid(); } + // stop the watchdog so that it will exit any retry logic + ConnectionWatchdog.Stop(abortReconnect: true); + if (Client.State.HasFlag(SoulseekClientStates.Connected)) { + // the IntentionalDisconnectException is used to indicate that the disconnect was intentional, which + // prevents the watchdog from trying to reconnect Client.Disconnect(message, new IntentionalDisconnectException(message)); } |
