diff --git a/file/include/files/FileServer.h b/file/include/files/FileServer.h index da63a13..8f815b7 100644 --- a/file/include/files/FileServer.h +++ b/file/include/files/FileServer.h @@ -273,7 +273,9 @@ namespace ts::server::file { NETWORK_IO_ERROR, UNEXPECTED_CLIENT_DISCONNECT, - UNEXPECTED_DISK_EOF + UNEXPECTED_DISK_EOF, + + USER_REQUEST } error_type{UNKNOWN}; std::string error_message{}; }; diff --git a/file/local_server/LocalFileTransfer.cpp b/file/local_server/LocalFileTransfer.cpp index 3ab049f..8633a94 100644 --- a/file/local_server/LocalFileTransfer.cpp +++ b/file/local_server/LocalFileTransfer.cpp @@ -248,6 +248,15 @@ std::shared_ptr>> L response->emplace_fail(TransferInitError::IO_ERROR, "file_size"); return response; } + + if(info.download_client_quota_limit > 0 && info.download_client_quota_limit <= transfer->expected_file_size) { + response->emplace_fail(TransferInitError::CLIENT_QUOTA_EXCEEDED, ""); + return response; + } + if(info.download_server_quota_limit > 0 && info.download_server_quota_limit <= transfer->expected_file_size) { + response->emplace_fail(TransferInitError::SERVER_QUOTA_EXCEEDED, ""); + return response; + } } { @@ -297,11 +306,13 @@ std::shared_ptr> LocalFileTransfer::stop_tr } if(connected_transfer) { + this->invoke_aborted_callback(connected_transfer, { TransferError::USER_REQUEST, "" }); logMessage(LOG_FT, "{} Stopping transfer due to an user request.", connected_transfer->log_prefix()); std::unique_lock slock{connected_transfer->state_mutex}; this->disconnect_client(connected_transfer, slock, flush); } else { + this->invoke_aborted_callback(transfer, { TransferError::USER_REQUEST, "" }); logMessage(LOG_FT, "Removing pending file transfer for id {}", id); } diff --git a/server/src/FileServerHandler.cpp b/server/src/FileServerHandler.cpp index d863d31..7b92e92 100644 --- a/server/src/FileServerHandler.cpp +++ b/server/src/FileServerHandler.cpp @@ -123,6 +123,10 @@ void FileServerHandler::callback_transfer_aborted(const std::shared_ptr>> transfer_response{}; info.max_bandwidth = -1; + { + auto max_quota = this->calculate_permission(permission::i_ft_max_bandwidth_upload, this->getClientId()); + if(max_quota.has_value) + info.max_bandwidth = max_quota.value; + } info.file_offset = 0; info.expected_file_size = cmd["size"].as(); info.override_exiting = cmd["overwrite"].as(); @@ -721,6 +726,12 @@ command_result ConnectedClient::handleCommandFTInitDownload(ts::Command &cmd) { } info.max_bandwidth = -1; + { + auto max_quota = this->calculate_permission(permission::i_ft_max_bandwidth_download, this->getClientId()); + if(max_quota.has_value) + info.max_bandwidth = max_quota.value; + } + info.file_offset = cmd["seekpos"].as(); info.override_exiting = false; info.file_path = cmd["name"].string(); diff --git a/shared b/shared index a4febf7..f404d5e 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit a4febf7b5af191d41c566292958c55155128f16f +Subproject commit f404d5e1fa5ed1cfbe3ef9a97c0e81c1fba943ff