diff options
Diffstat (limited to 'src/slskd/Network/API')
| -rw-r--r-- | src/slskd/Network/API/Controllers/NetworkController.cs | 18 | ||||
| -rw-r--r-- | src/slskd/Network/API/Hubs/NetworkHub.cs | 17 |
2 files changed, 22 insertions, 13 deletions
diff --git a/src/slskd/Network/API/Controllers/NetworkController.cs b/src/slskd/Network/API/Controllers/NetworkController.cs index 4cd6437a..624d7a2c 100644 --- a/src/slskd/Network/API/Controllers/NetworkController.cs +++ b/src/slskd/Network/API/Controllers/NetworkController.cs @@ -121,7 +121,7 @@ namespace slskd.Network // pass the stream back to the network 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. - await Network.HandleFileStreamResponse(id: guid, stream); + await Network.HandleFileStreamResponse(agentName, id: guid, stream); Log.Information("File upload of {Filename} ({Token}) from agent {Agent} complete", filename, token, agentName); return Ok(); @@ -174,18 +174,14 @@ namespace slskd.Network Log.Debug("Upload of share from {Agent} to {Filename} complete", agentName, temp); - var repository = ShareRepositoryFactory.CreateFromFile(temp); - - if (!repository.TryValidate(out var problems)) + try { - return BadRequest("Invalid database: " + string.Join(", ", problems)); + await Network.HandleShareUpload(agentName, id: guid, shares, temp); + } + catch (ShareValidationException ex) + { + return BadRequest(ex.Message); } - - var destinationRepository = ShareRepositoryFactory.CreateFromHost(agentName); - - destinationRepository.RestoreFrom(repository); - - Shares.AddOrUpdateHost(new Host(agentName, shares)); return Ok(); } diff --git a/src/slskd/Network/API/Hubs/NetworkHub.cs b/src/slskd/Network/API/Hubs/NetworkHub.cs index 298dd9ec..0ee80f9a 100644 --- a/src/slskd/Network/API/Hubs/NetworkHub.cs +++ b/src/slskd/Network/API/Hubs/NetworkHub.cs @@ -79,6 +79,7 @@ namespace slskd.Network Log.Information("Agent connection {Id} authentication failed", Context.ConnectionId); Network.TryDeregisterAgent(Context.ConnectionId, out var _); // just in case! return false; + // todo: throw UnauthorizedAccessException()? } public Guid GetShareUploadToken() @@ -97,12 +98,24 @@ namespace slskd.Network public void NotifyUploadFailed(Guid id, Exception exception) { - Network.NotifyFileStreamException(id, exception); + 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(); } public void ReturnFileInfo(Guid id, bool exists, long length) { - Network.HandleFileInfoResponse(id, (exists, length)); + if (Network.TryGetAgentRegistration(Context.ConnectionId, out var record)) + { + 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(); } } }
\ No newline at end of file |
