diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-11-05 14:05:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-05 14:05:31 -0500 |
| commit | 2c6c42b03ba0254d92d176bad2f283be0a746969 (patch) | |
| tree | 6de8a7834af99dae47ebef97d08d429da83fa816 /src/slskd/Network/NetworkClient.cs | |
| parent | accfdb85cac9ec5098297d45796f239f1a712c50 (diff) | |
| parent | a94f07ab844c074f4fcd931e3aacbbd888ca87aa (diff) | |
| download | slskd-2c6c42b03ba0254d92d176bad2f283be0a746969.tar.gz | |
Merge pull request #735 from slskd/client
Reconnect network client indefinitely, improvements to share state management
Diffstat (limited to 'src/slskd/Network/NetworkClient.cs')
| -rw-r--r-- | src/slskd/Network/NetworkClient.cs | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/slskd/Network/NetworkClient.cs b/src/slskd/Network/NetworkClient.cs index 30cc6971..bf79a790 100644 --- a/src/slskd/Network/NetworkClient.cs +++ b/src/slskd/Network/NetworkClient.cs @@ -196,12 +196,12 @@ namespace slskd.Network using var request = new HttpRequestMessage(HttpMethod.Post, $"api/v0/network/shares/{token}"); using var content = new MultipartFormDataContent - { - { new StringContent(OptionsMonitor.CurrentValue.InstanceName), "name" }, - { new StringContent(ComputeCredential(token)), "credential" }, - { new StringContent(Shares.LocalHost.Shares.ToJson()), "shares" }, - { new StreamContent(stream), "database", "shares" }, - }; + { + { new StringContent(OptionsMonitor.CurrentValue.InstanceName), "name" }, + { new StringContent(ComputeCredential(token)), "credential" }, + { new StringContent(Shares.LocalHost.Shares.ToJson()), "shares" }, + { new StreamContent(stream), "database", "shares" }, + }; request.Headers.Add("X-API-Key", OptionsMonitor.CurrentValue.Network.Controller.ApiKey); request.Content = content; @@ -418,14 +418,7 @@ namespace slskd.Network return message; }; }) - .WithAutomaticReconnect(new[] - { - TimeSpan.FromSeconds(0), - TimeSpan.FromSeconds(1), - TimeSpan.FromSeconds(3), - TimeSpan.FromSeconds(10), - TimeSpan.FromSeconds(30), - }) + .WithAutomaticReconnect(new ControllerRetryPolicy(0, 1, 3, 10, 30, 60)) .Build(); HubConnection.Reconnected += HubConnection_Reconnected; @@ -453,5 +446,20 @@ namespace slskd.Network SyncRoot.Release(); } } + + private class ControllerRetryPolicy : IRetryPolicy + { + public ControllerRetryPolicy(params int[] intervals) + { + Intervals = intervals; + } + + private int[] Intervals { get; set; } + + public TimeSpan? NextRetryDelay(RetryContext retryContext) + { + return TimeSpan.FromSeconds(Intervals[Math.Min(retryContext.PreviousRetryCount, Intervals.Length - 1)]); + } + } } } |
