diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-11-02 08:53:01 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-11-02 08:53:01 -0500 |
| commit | 891b8b7b5015f14d95ce88553b52ff436089e6ff (patch) | |
| tree | c7c02b48c12c61b5c7d7243b5878cb9d1ae7edad /src | |
| parent | 4d45a5fe303c27869db80015c2e540453d073b27 (diff) | |
| download | slskd-891b8b7b5015f14d95ce88553b52ff436089e6ff.tar.gz | |
fix bug handling file info
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Network/API/Hubs/NetworkHub.cs | 32 |
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 |
