aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-11-02 09:38:46 -0500
committerGitHub <noreply@github.com>2022-11-02 09:38:46 -0500
commit8238ccee6c1b10353f42b1f435ced652d2867dd3 (patch)
treec7c02b48c12c61b5c7d7243b5878cb9d1ae7edad /src
parent69d663c55ae5ad60a3e5120806e2054497eb40e8 (diff)
parentf8af26a3c6726b65e0b38d5fc86271c93a5b340b (diff)
downloadslskd-8238ccee6c1b10353f42b1f435ced652d2867dd3.tar.gz
Merge pull request #727 from slskd/paths
Fix a couple of bugs handling agent responses
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Network/API/Hubs/NetworkHub.cs32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/slskd/Network/API/Hubs/NetworkHub.cs b/src/slskd/Network/API/Hubs/NetworkHub.cs
index fe187909..5fd4aacb 100644
--- a/src/slskd/Network/API/Hubs/NetworkHub.cs
+++ b/src/slskd/Network/API/Hubs/NetworkHub.cs
@@ -130,14 +130,14 @@ namespace slskd.Network
{
if (Network.TryGetAgentRegistration(Context.ConnectionId, out var record))
{
- var token = Network.GenerateShareUploadToken(record.Agent.Name);
- Log.Information("Agent {Agent} (connection {Id}) requested share upload token {Token}", record.Agent.Name, record.ConnectionId, token);
- return token;
+ // this can happen if the agent attempts to upload before logging in
+ Log.Information("Agent connection {Id} requested a share upload token, but is not registered.", Context.ConnectionId);
+ throw new UnauthorizedAccessException();
}
- // this can happen if the agent attempts to upload before logging in
- Log.Information("Agent connection {Id} requested a share upload token, but is not registered.", Context.ConnectionId);
- throw new UnauthorizedAccessException();
+ var token = Network.GenerateShareUploadToken(record.Agent.Name);
+ Log.Information("Agent {Agent} (connection {Id}) requested share upload token {Token}", record.Agent.Name, record.ConnectionId, token);
+ return token;
}
/// <summary>
@@ -150,11 +150,13 @@ namespace slskd.Network
{
if (Network.TryGetAgentRegistration(Context.ConnectionId, out var record))
{
- Network.NotifyFileStreamException(id, exception);
+ Log.Warning("Agent connection {Id} attempted to report a failed upload, but is not registered.", Context.ConnectionId);
+ throw new UnauthorizedAccessException();
}
- Log.Warning("Agent connection {Id} attempted to report a failed upload, but is not registered.", Context.ConnectionId);
- throw new UnauthorizedAccessException();
+ Log.Warning("Agent {Agent} (connection {ConnectionId}) reported upload failure for {Id}: {Message}", id, exception.Message);
+
+ Network.NotifyFileStreamException(id, exception);
}
/// <summary>
@@ -166,15 +168,15 @@ namespace slskd.Network
/// <exception cref="UnauthorizedAccessException">Thrown when the agent is not fully authenticated.</exception>
public void ReturnFileInfo(Guid id, bool exists, long length)
{
- if (Network.TryGetAgentRegistration(Context.ConnectionId, out var record))
+ if (!Network.TryGetAgentRegistration(Context.ConnectionId, out var record))
{
- Log.Information("Agent {Agent} (connection {ConnectionId}) returned file info for {Id}; exists: {Exists}, length: {Length}", record.Agent.Name, Context.ConnectionId, id, exists, length);
-
- Network.HandleFileInfoResponse(record.Agent.Name, id, (exists, length));
+ Log.Warning("Agent connection {Id} attempted to return file information, but is not registered.", Context.ConnectionId);
+ throw new UnauthorizedAccessException();
}
- Log.Warning("Agent connection {Id} attempted to return file information, but is not registered.", Context.ConnectionId);
- throw new UnauthorizedAccessException();
+ Log.Information("Agent {Agent} (connection {ConnectionId}) returned file info for {Id}; exists: {Exists}, length: {Length}", record.Agent.Name, Context.ConnectionId, id, exists, length);
+
+ Network.HandleFileInfoResponse(record.Agent.Name, id, (exists, length));
}
}
} \ No newline at end of file