From 45df497064a1dbfd6db2bf731a5875490ce58ff5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 21 Nov 2022 17:13:21 -0600 Subject: fix logging issues --- src/slskd/Relay/API/Controllers/RelayController.cs | 4 ++-- src/slskd/Relay/API/Hubs/RelayHub.cs | 2 +- src/slskd/Relay/RelayClient.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/slskd/Relay') 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..406101c6 100644 --- a/src/slskd/Relay/RelayClient.cs +++ b/src/slskd/Relay/RelayClient.cs @@ -317,11 +317,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) -- cgit v1.2.3 From eea25af2573f5404c091112db29f1d0594e12b5e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 21 Nov 2022 18:49:59 -0600 Subject: pass cancellation token --- src/slskd/Relay/RelayClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Relay') diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs index 406101c6..bc0d5d48 100644 --- a/src/slskd/Relay/RelayClient.cs +++ b/src/slskd/Relay/RelayClient.cs @@ -207,7 +207,7 @@ namespace slskd.Relay /// The operation context. public Task SynchronizeAsync(CancellationToken cancellationToken = default) { - return UploadSharesAsync(); + return UploadSharesAsync(cancellationToken); } private RelayClientState TranslateState(HubConnectionState hub) => hub switch -- cgit v1.2.3 From aaea2f91c1fbef91a0fe6c5350c79b9bac3175c3 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 21 Nov 2022 18:50:22 -0600 Subject: log share information around uploads --- src/slskd/Relay/RelayClient.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/slskd/Relay') diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs index bc0d5d48..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; @@ -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 { -- cgit v1.2.3