mirror of
https://github.com/ton-blockchain/ton
synced 2025-02-12 11:12:16 +00:00
A few improvements in storage-daemon-cli interface (#570)
* Pause and resume upload in storage-daemon * Update help * Update LoadSpeed.cpp * Fix json output, prohibit torrents without files Co-authored-by: SpyCheese <mikle98@yandex.ru> Co-authored-by: Andrey Pfau <andreypfau@ton.org>
This commit is contained in:
parent
1a07edfed4
commit
b88eda83fe
4 changed files with 17 additions and 1 deletions
|
@ -22,7 +22,7 @@
|
|||
#include "td/utils/format.h"
|
||||
|
||||
namespace ton {
|
||||
void LoadSpeed::add(std::size_t size, td::Timestamp now) {
|
||||
void LoadSpeed::add(td::uint64 size, td::Timestamp now) {
|
||||
total_size_ += size;
|
||||
events_.push(Event{size, now});
|
||||
update(now);
|
||||
|
|
|
@ -98,6 +98,9 @@ TD_WARN_UNUSED_RESULT td::Status Torrent::Creator::add_file(td::Slice name, td::
|
|||
}
|
||||
|
||||
td::Result<Torrent> Torrent::Creator::finalize() {
|
||||
if (files_.empty()) {
|
||||
return td::Status::Error("No files");
|
||||
}
|
||||
TorrentHeader header;
|
||||
TRY_RESULT(files_count, td::narrow_cast_safe<td::uint32>(files_.size()));
|
||||
header.files_count = files_count;
|
||||
|
|
|
@ -100,6 +100,9 @@ td::Status TorrentHeader::validate(td::uint64 total_size, td::uint64 header_size
|
|||
if (serialization_size() != header_size) {
|
||||
return td::Status::Error("Invalid size");
|
||||
}
|
||||
if (files_count == 0) {
|
||||
return td::Status::Error("No files");
|
||||
}
|
||||
for (size_t i = 0; i + 1 < files_count; ++i) {
|
||||
if (name_index[i] > name_index[i + 1]) {
|
||||
return td::Status::Error("Invalid name offset");
|
||||
|
|
|
@ -774,6 +774,8 @@ class StorageDaemonCli : public td::actor::Actor {
|
|||
td::TerminalIO::out() << "\t--json\tOutput in json\n";
|
||||
td::TerminalIO::out() << "download-pause <bag>\tPause download of <bag>\n";
|
||||
td::TerminalIO::out() << "download-resume <bag>\tResume download of <bag>\n";
|
||||
td::TerminalIO::out() << "upload-pause <bag>\tPause upload of <bag>\n";
|
||||
td::TerminalIO::out() << "upload-resume <bag>\tResume upload of <bag>\n";
|
||||
td::TerminalIO::out() << "priority-all <bag> <p>\tSet priority of all files in <bag> to <p>\n";
|
||||
td::TerminalIO::out() << "\tPriority is in [0..255], 0 - don't download\n";
|
||||
td::TerminalIO::out() << "priority-idx <bag> <idx> <p>\tSet priority of file #<idx> in <bag> to <p>\n";
|
||||
|
@ -856,6 +858,7 @@ class StorageDaemonCli : public td::actor::Actor {
|
|||
}
|
||||
if (json) {
|
||||
print_json(R.ok());
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK());
|
||||
return;
|
||||
}
|
||||
td::TerminalIO::out() << "Bag created\n";
|
||||
|
@ -888,6 +891,7 @@ class StorageDaemonCli : public td::actor::Actor {
|
|||
}
|
||||
if (json) {
|
||||
print_json(R.ok());
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK());
|
||||
return;
|
||||
}
|
||||
td::TerminalIO::out() << "Bag added\n";
|
||||
|
@ -921,6 +925,7 @@ class StorageDaemonCli : public td::actor::Actor {
|
|||
}
|
||||
if (json) {
|
||||
print_json(R.ok());
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK());
|
||||
return;
|
||||
}
|
||||
td::TerminalIO::out() << "Bag added\n";
|
||||
|
@ -939,6 +944,7 @@ class StorageDaemonCli : public td::actor::Actor {
|
|||
}
|
||||
if (json) {
|
||||
print_json(R.ok());
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK());
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::print_torrent_list, R.move_as_ok(), with_hashes);
|
||||
|
@ -956,6 +962,7 @@ class StorageDaemonCli : public td::actor::Actor {
|
|||
}
|
||||
if (json) {
|
||||
print_json(R.ok());
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK());
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::print_torrent_full, R.move_as_ok());
|
||||
|
@ -994,6 +1001,7 @@ class StorageDaemonCli : public td::actor::Actor {
|
|||
}
|
||||
if (json) {
|
||||
print_json(R.ok());
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK());
|
||||
return;
|
||||
}
|
||||
auto obj = R.move_as_ok();
|
||||
|
@ -1260,6 +1268,7 @@ class StorageDaemonCli : public td::actor::Actor {
|
|||
}
|
||||
if (json) {
|
||||
print_json(R.ok());
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK());
|
||||
return;
|
||||
}
|
||||
auto params = R.move_as_ok();
|
||||
|
@ -1325,6 +1334,7 @@ class StorageDaemonCli : public td::actor::Actor {
|
|||
}
|
||||
if (json) {
|
||||
print_json(R.ok());
|
||||
td::actor::send_closure(SelfId, &StorageDaemonCli::command_finished, td::Status::OK());
|
||||
return;
|
||||
}
|
||||
auto info = R.move_as_ok();
|
||||
|
|
Loading…
Reference in a new issue