Permalink
Browse files

[skip ci] Improve wallet shutdown speed when internet is off

  • Loading branch information...
nopara73 committed Oct 26, 2018
1 parent f6a3f39 commit c38d4c79d8f8fc2494fef54a603558565c605a4c
Showing with 13 additions and 10 deletions.
  1. +9 −6 WalletWasabi/Services/UpdateChecker.cs
  2. +4 −4 WalletWasabi/WebClients/Wasabi/WasabiClient.cs
@@ -43,7 +43,7 @@ public void Start(TimeSpan period, Func<Task> executeIfBackendIncompatible, Func
// If stop was requested return.
if (IsRunning == false) return;
(bool backendCompatible, bool clientUpToDate) updates = await WasabiClient.CheckUpdatesAsync();
(bool backendCompatible, bool clientUpToDate) updates = await WasabiClient.CheckUpdatesAsync(Stop.Token);
if (!updates.backendCompatible)
{
@@ -57,10 +57,6 @@ public void Start(TimeSpan period, Func<Task> executeIfBackendIncompatible, Func
await Task.Delay(period, Stop.Token);
}
catch (TaskCanceledException ex)
{
Logger.LogTrace<UpdateChecker>(ex);
}
catch (ConnectionException ex)
{
Logger.LogError<UpdateChecker>(ex);
@@ -75,7 +71,14 @@ public void Start(TimeSpan period, Func<Task> executeIfBackendIncompatible, Func
}
catch (Exception ex)
{
Logger.LogDebug<UpdateChecker>(ex);
if (ex is TaskCanceledException || ex is OperationCanceledException || ex is TimeoutException)
{
Logger.LogTrace<UpdateChecker>(ex);
}
else
{
Logger.LogDebug<UpdateChecker>(ex);
}
}
}
}
@@ -119,9 +119,9 @@ public async Task<IEnumerable<ExchangeRate>> GetExchangeRatesAsync()
#region software
public async Task<(Version ClientVersion, int BackendMajorVersion)> GetVersionsAsync()
public async Task<(Version ClientVersion, int BackendMajorVersion)> GetVersionsAsync(CancellationToken cancel)
{
using (var response = await TorClient.SendAndRetryAsync(HttpMethod.Get, HttpStatusCode.OK, "/api/software/versions"))
using (var response = await TorClient.SendAndRetryAsync(HttpMethod.Get, HttpStatusCode.OK, "/api/software/versions", cancel: cancel))
{
if (response.StatusCode == HttpStatusCode.NotFound)
{
@@ -142,9 +142,9 @@ public async Task<(Version ClientVersion, int BackendMajorVersion)> GetVersionsA
}
}
public async Task<(bool backendCompatible, bool clientUpToDate)> CheckUpdatesAsync()
public async Task<(bool backendCompatible, bool clientUpToDate)> CheckUpdatesAsync(CancellationToken cancel)
{
var versions = await GetVersionsAsync();
var versions = await GetVersionsAsync(cancel);
var clientUpToDate = Helpers.Constants.ClientVersion >= versions.ClientVersion; // If the client version locally is greater or equal to the backend's reported client version, then good.
var backendCompatible = int.Parse(Helpers.Constants.BackendMajorVersion) == versions.BackendMajorVersion; // If the backend major and the client major equals, then our softwares are compatible.

0 comments on commit c38d4c7

Please sign in to comment.