aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-01-07 16:14:00 -0600
committerJP Dillingham <jp@dillingham.me>2023-01-07 16:14:00 -0600
commit87f72f7f482953c90ed50eca647f36827cdd64cd (patch)
tree51424a5495a9a4181d4391472b9fe3e70e7fe080 /src
parent8e73db196759307c89a7e5da1f87d49be9ba56c5 (diff)
downloadslskd-87f72f7f482953c90ed50eca647f36827cdd64cd.tar.gz
polish logging
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Relay/API/Controllers/RelayController.cs22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/slskd/Relay/API/Controllers/RelayController.cs b/src/slskd/Relay/API/Controllers/RelayController.cs
index a36e643d..f6c6d778 100644
--- a/src/slskd/Relay/API/Controllers/RelayController.cs
+++ b/src/slskd/Relay/API/Controllers/RelayController.cs
@@ -21,6 +21,7 @@ namespace slskd.Relay
{
using System;
using System.Collections.Generic;
+ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -115,7 +116,7 @@ namespace slskd.Relay
return BadRequest();
}
- Log.Information("Handling file download for token {Token} from a caller claiming to be agent {Agent}", token, agentName);
+ Log.Information("Handling file download of {Filename} ({Token}) from a caller claiming to be agent {Agent}", filename, token, agentName);
// note: the token remains valid after the validation attempt, unlike most other endpoints.
// this is done to support retries
@@ -127,9 +128,9 @@ namespace slskd.Relay
var sourceFile = Path.Combine(OptionsMonitor.CurrentValue.Directories.Downloads, filename);
- Log.Information("Agent {Agent} authenticated. Sending file {File}", agentName, filename);
+ Log.Information("Agent {Agent} authenticated for token {Token}. Sending file {Filename}", agentName, guid, filename);
- var stream = new FileStream(Path.Combine(OptionsMonitor.CurrentValue.Directories.Downloads, filename), FileMode.Open);
+ var stream = new FileStream(sourceFile, FileMode.Open);
return File(stream, "application/octet-stream");
}
@@ -204,7 +205,7 @@ namespace slskd.Relay
return BadRequest();
}
- Log.Information("Handling file upload for token {Token} from a caller claiming to be agent {Agent}", token, agentName);
+ Log.Information("Handling file upload of {Filename} ({Token}) from a caller claiming to be agent {Agent}", filename, token, agentName);
// agents must encrypt the Id they were given in the request with the secret they share with the controller, and
// provide the encrypted value as the credential with the request. the validation below verifies a bunch of
@@ -216,7 +217,7 @@ namespace slskd.Relay
return Unauthorized();
}
- Log.Information("File upload of {Filename} ({Token}) from agent {Agent} validated and authenticated. Forwarding file stream.", filename, token, agentName);
+ Log.Information("Agent {Agent} authenticated for token {Token}. Forwarding file stream for {Filename}", agentName, guid, filename);
// pass the stream back to the relay service, which will in turn pass it to the upload service, and use it to
// feed data into the remote upload. await this call, it will complete when the upload is complete, one way or the other.
@@ -279,6 +280,8 @@ namespace slskd.Relay
return BadRequest();
}
+ Log.Information("Handling share upload ({Token}) from a caller claiming to be agent {Agent}", token, agentName);
+
if (!Relay.TryValidateShareUploadCredential(token: guid, agentName, credential))
{
Log.Warning("Failed to authenticate share upload from caller claiming to be agent {Agent} using token {Token}", agentName, guid);
@@ -290,14 +293,19 @@ namespace slskd.Relay
try
{
- Log.Debug("Uploading share from {Agent} to {Filename}", agentName, temp);
+ Log.Information("Agent {Agent} authenticated for token {Token}. Beginning download of shares to {Filename}", agentName, guid, temp);
+
+ var sw = new Stopwatch();
+ sw.Start();
using var outputStream = new FileStream(temp, FileMode.CreateNew, FileAccess.Write);
using var inputStream = database.OpenReadStream();
await inputStream.CopyToAsync(outputStream);
- Log.Debug("Upload of share from {Agent} to {Filename} complete", agentName, temp);
+ sw.Stop();
+
+ Log.Information("Download of shares from {Agent} ({Token}) complete ({Size} in {Duration}ms)", agentName, guid, ((double)inputStream.Length).SizeSuffix(), sw.ElapsedMilliseconds);
await Relay.HandleShareUpload(agentName, id: guid, shares, temp);