aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-11-21 18:58:25 -0600
committerGitHub <noreply@github.com>2022-11-21 18:58:25 -0600
commit8dc6e65a3d18f6a8ad4f0569694b4eef5f023afb (patch)
tree545929a7463c4e6a8b89dc3582f91e6a244d70cc /src
parent6798f34362f59be57040cbd03b6e09386ef3b7dd (diff)
parent8f77abce8504e8bc345a3c89945173c18746a345 (diff)
downloadslskd-8dc6e65a3d18f6a8ad4f0569694b4eef5f023afb.tar.gz
Merge pull request #776 from slskd/relay
Relay tweaks and bug fixes
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application.cs1
-rw-r--r--src/slskd/Relay/API/Controllers/RelayController.cs4
-rw-r--r--src/slskd/Relay/API/Hubs/RelayHub.cs2
-rw-r--r--src/slskd/Relay/RelayClient.cs17
-rw-r--r--src/slskd/Shares/ShareService.cs9
5 files changed, 22 insertions, 11 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index aeb18201..71fb140d 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -1052,7 +1052,6 @@ namespace slskd
// ...but if it completed successfully, immediately update again to lower the pending flag
State.SetValue(state => state with { Shares = state.Shares with { ScanPending = false } });
Log.Information("Shares scanned successfully. Found {Directories} directories and {Files} files in {Duration}ms", current.Directories, current.Files, (DateTime.UtcNow - SharesRefreshStarted).TotalMilliseconds);
- rebuildBrowseCache = true;
SharesRefreshStarted = default;
diff --git a/src/slskd/Relay/API/Controllers/RelayController.cs b/src/slskd/Relay/API/Controllers/RelayController.cs
index c11c33bc..d6f4f840 100644
--- a/src/slskd/Relay/API/Controllers/RelayController.cs
+++ b/src/slskd/Relay/API/Controllers/RelayController.cs
@@ -150,7 +150,7 @@ namespace slskd.Relay
// caller is the same caller that received the request, and that the caller knows the shared secret.
if (!Relay.TryValidateFileStreamResponseCredential(token: guid, agentName, filename, credential))
{
- Log.Warning("Failed to authenticate file upload token {Token} from a caller claiming to be agent {Agent}", agentName);
+ Log.Warning("Failed to authenticate file upload token {Token} from a caller claiming to be agent {Agent}", guid, agentName);
return Unauthorized();
}
@@ -220,7 +220,7 @@ namespace slskd.Relay
if (!Relay.TryValidateShareUploadCredential(token: guid, agentName, credential))
{
- Log.Warning("Failed to authenticate share upload from caller claiming to be agent {Agent}");
+ Log.Warning("Failed to authenticate share upload from caller claiming to be agent {Agent} using token {Token}", agentName, guid);
return Unauthorized();
}
diff --git a/src/slskd/Relay/API/Hubs/RelayHub.cs b/src/slskd/Relay/API/Hubs/RelayHub.cs
index 6b091a39..885ba453 100644
--- a/src/slskd/Relay/API/Hubs/RelayHub.cs
+++ b/src/slskd/Relay/API/Hubs/RelayHub.cs
@@ -169,7 +169,7 @@ namespace slskd.Relay
throw new UnauthorizedAccessException();
}
- Log.Warning("Agent {Agent} (connection {ConnectionId}) from {IP} reported upload failure for {Id}: {Message}", id, exception.Message, RemoteIpAddress);
+ Log.Warning("Agent {Agent} (connection {ConnectionId}) from {IP} reported upload failure for {Id}: {Message}", record.Agent, Context.ConnectionId, RemoteIpAddress, id, exception.Message);
Relay.NotifyFileStreamException(id, exception);
}
diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs
index 693a7017..515d30ca 100644
--- a/src/slskd/Relay/RelayClient.cs
+++ b/src/slskd/Relay/RelayClient.cs
@@ -20,6 +20,7 @@ using Microsoft.Extensions.Options;
namespace slskd.Relay
{
using System;
+ using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading;
@@ -207,7 +208,7 @@ namespace slskd.Relay
/// <returns>The operation context.</returns>
public Task SynchronizeAsync(CancellationToken cancellationToken = default)
{
- return UploadSharesAsync();
+ return UploadSharesAsync(cancellationToken);
}
private RelayClientState TranslateState(HubConnectionState hub) => hub switch
@@ -254,7 +255,12 @@ namespace slskd.Relay
request.Headers.Add("X-API-Key", OptionsMonitor.CurrentValue.Relay.Controller.ApiKey);
request.Content = content;
- Log.Information("Beginning upload of shares");
+ var size = ((double)stream.Length).SizeSuffix();
+ var sw = new Stopwatch();
+ sw.Start();
+
+ Log.Information("Beginning upload of shares ({Size})", size);
+ Log.Debug("Shares: {Shares}", Shares.LocalHost.Shares.ToJson());
var response = await CreateHttpClient().SendAsync(request, cancellationToken);
if (!response.IsSuccessStatusCode)
@@ -262,7 +268,8 @@ namespace slskd.Relay
throw new RelayException($"Failed to upload shares to relay controller: {response.StatusCode}");
}
- Log.Information("Upload shares succeeded");
+ sw.Stop();
+ Log.Information("Upload of shares succeeded ({Size} in {Duration}ms)", size, sw.ElapsedMilliseconds);
}
finally
{
@@ -317,11 +324,11 @@ namespace slskd.Relay
if (!response.IsSuccessStatusCode)
{
- Log.Error("Upload of file {Filename} with ID {Id} failed: {StatusCode}", response.StatusCode);
+ Log.Error("Upload of file {Filename} with ID {Id} failed: {StatusCode}", filename, token, response.StatusCode);
}
else
{
- Log.Information("Upload of file {Filename} with ID {Id} succeeded.", filename);
+ Log.Information("Upload of file {Filename} with ID {Id} succeeded.", filename, token);
}
}
catch (Exception ex)
diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs
index 3101cede..7051fda3 100644
--- a/src/slskd/Shares/ShareService.cs
+++ b/src/slskd/Shares/ShareService.cs
@@ -70,7 +70,6 @@ namespace slskd.Shares
Scanning = current.Filling,
Faulted = current.Faulted,
Cancelled = current.Cancelled,
- Ready = current.Filled,
ScanProgress = current.FillProgress,
Directories = current.Directories,
Files = current.Files,
@@ -319,6 +318,8 @@ namespace slskd.Shares
/// <exception cref="ShareScanInProgressException">Thrown when a scan is already in progress.</exception>
public async Task ScanAsync()
{
+ State.SetValue(state => state with { Ready = false });
+
await Scanner.ScanAsync(Local.Host.Shares, OptionsMonitor.CurrentValue.Shares, Local.Repository);
Log.Debug("Backing up shared file cache database...");
@@ -327,12 +328,13 @@ namespace slskd.Shares
Log.Debug("Recomputing share statistics...");
ComputeShareStatistics();
- Log.Debug("Share statistics updated");
+ Log.Debug("Share statistics updated: {Shares}", Local.Host.Shares.ToJson());
State.SetValue(state => state with
{
Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories),
Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files),
+ Ready = true,
});
}
@@ -354,6 +356,9 @@ namespace slskd.Shares
{
Log.Information("Initializing shares");
+ // _probably_ redundant, but to be safe
+ State.SetValue(state => state with { Ready = false });
+
try
{
if (forceRescan)