mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Recent updates in storage (#667)
* Fix error handling in Torrent.cpp, improve choosing peers for upload * Various improvements in storage daemon "get-pieces-info" Store "added at" Improve calculating up/down speed Improve TL protocol for future compatibility Remove empty directories on "--remove-files" Better windows support Debug logs in PeerActor More restrictions on TorrentInfo Bugfixes * Global speed limits for download and upload +bugfix * Reset download/upload speed on changing settings or completion * Exclude some system files in TorrentCreator
This commit is contained in:
parent
e3af63e6c0
commit
bb21f732fd
21 changed files with 974 additions and 213 deletions
|
@ -180,6 +180,9 @@ class StorageDaemon : public td::actor::Actor {
|
|||
dht_id_ = dht_id_full.compute_short_id();
|
||||
td::actor::send_closure(adnl_, &adnl::Adnl::add_id, dht_id_full, addr_list, static_cast<td::uint8>(0));
|
||||
|
||||
LOG(INFO) << "Storage daemon ADNL id is " << local_id_;
|
||||
LOG(INFO) << "DHT id is " << dht_id_;
|
||||
|
||||
if (client_mode_) {
|
||||
auto D = dht::Dht::create_client(dht_id_, db_root_, dht_config_, keyring_.get(), adnl_.get());
|
||||
D.ensure();
|
||||
|
@ -431,6 +434,52 @@ class StorageDaemon : public td::actor::Actor {
|
|||
}));
|
||||
}
|
||||
|
||||
void run_control_query(ton_api::storage_daemon_getTorrentPiecesInfo &query, td::Promise<td::BufferSlice> promise) {
|
||||
td::Bits256 hash = query.hash_;
|
||||
td::actor::send_closure(
|
||||
manager_, &StorageManager::with_torrent, hash,
|
||||
promise.wrap([query = std::move(query)](NodeActor::NodeState state) -> td::Result<td::BufferSlice> {
|
||||
Torrent &torrent = state.torrent;
|
||||
if (!torrent.inited_info()) {
|
||||
return td::Status::Error("Torrent info is not available");
|
||||
}
|
||||
td::uint64 total_pieces = torrent.get_info().pieces_count();
|
||||
td::uint64 range_l = std::min<td::uint64>(total_pieces, query.offset_);
|
||||
td::uint64 size = query.max_pieces_ != -1 ? std::min<td::uint64>(total_pieces - range_l, query.max_pieces_)
|
||||
: total_pieces - range_l;
|
||||
td::BufferSlice piece_ready((size + 7) / 8);
|
||||
std::fill(piece_ready.data(), piece_ready.data() + piece_ready.size(), 0);
|
||||
for (td::uint64 i = range_l; i < range_l + size; ++i) {
|
||||
if (torrent.is_piece_ready(i)) {
|
||||
piece_ready.data()[(i - range_l) / 8] |= (1 << ((i - range_l) % 8));
|
||||
}
|
||||
}
|
||||
|
||||
auto result = create_tl_object<ton_api::storage_daemon_torrentPiecesInfo>();
|
||||
result->total_pieces_ = total_pieces;
|
||||
result->piece_size_ = torrent.get_info().piece_size;
|
||||
result->range_l_ = range_l;
|
||||
result->range_r_ = range_l + size;
|
||||
result->piece_ready_bitset_ = std::move(piece_ready);
|
||||
|
||||
if ((query.flags_ & 1) && torrent.inited_header()) {
|
||||
result->flags_ = 1;
|
||||
auto range = torrent.get_header_parts_range();
|
||||
result->files_.push_back(
|
||||
create_tl_object<ton_api::storage_daemon_filePiecesInfo>("", range.begin, range.end));
|
||||
for (size_t i = 0; i < torrent.get_files_count().value(); ++i) {
|
||||
auto range = torrent.get_file_parts_range(i);
|
||||
result->files_.push_back(create_tl_object<ton_api::storage_daemon_filePiecesInfo>(
|
||||
torrent.get_file_name(i).str(), range.begin, range.end));
|
||||
}
|
||||
} else {
|
||||
result->flags_ = 0;
|
||||
}
|
||||
|
||||
return serialize_tl_object(result, true);
|
||||
}));
|
||||
}
|
||||
|
||||
void run_control_query(ton_api::storage_daemon_setFilePriorityAll &query, td::Promise<td::BufferSlice> promise) {
|
||||
TRY_RESULT_PROMISE(promise, priority, td::narrow_cast_safe<td::uint8>(query.priority_));
|
||||
td::actor::send_closure(manager_, &StorageManager::set_all_files_priority, query.hash_, priority,
|
||||
|
@ -491,6 +540,24 @@ class StorageDaemon : public td::actor::Actor {
|
|||
});
|
||||
}
|
||||
|
||||
void run_control_query(ton_api::storage_daemon_getSpeedLimits &query, td::Promise<td::BufferSlice> promise) {
|
||||
td::actor::send_closure(manager_, &StorageManager::get_speed_limits,
|
||||
promise.wrap([](std::pair<double, double> limits) -> td::BufferSlice {
|
||||
return create_serialize_tl_object<ton_api::storage_daemon_speedLimits>(limits.first,
|
||||
limits.second);
|
||||
}));
|
||||
}
|
||||
|
||||
void run_control_query(ton_api::storage_daemon_setSpeedLimits &query, td::Promise<td::BufferSlice> promise) {
|
||||
if (query.flags_ & 1) {
|
||||
td::actor::send_closure(manager_, &StorageManager::set_download_speed_limit, query.download_);
|
||||
}
|
||||
if (query.flags_ & 2) {
|
||||
td::actor::send_closure(manager_, &StorageManager::set_upload_speed_limit, query.upload_);
|
||||
}
|
||||
promise.set_result(create_serialize_tl_object<ton_api::storage_daemon_success>());
|
||||
}
|
||||
|
||||
void run_control_query(ton_api::storage_daemon_getNewContractMessage &query, td::Promise<td::BufferSlice> promise) {
|
||||
td::Promise<std::pair<td::RefInt256, td::uint32>> P =
|
||||
[promise = std::move(promise), hash = query.hash_, query_id = query.query_id_,
|
||||
|
@ -779,6 +846,7 @@ class StorageDaemon : public td::actor::Actor {
|
|||
file->name_ = torrent.get_file_name(i).str();
|
||||
file->size_ = torrent.get_file_size(i);
|
||||
file->downloaded_size_ = torrent.get_file_ready_size(i);
|
||||
file->flags_ = 0;
|
||||
obj.files_.push_back(std::move(file));
|
||||
}
|
||||
}
|
||||
|
@ -798,6 +866,7 @@ class StorageDaemon : public td::actor::Actor {
|
|||
obj->active_upload_ = state.active_upload;
|
||||
obj->download_speed_ = state.download_speed;
|
||||
obj->upload_speed_ = state.upload_speed;
|
||||
obj->added_at_ = state.added_at;
|
||||
promise.set_result(std::move(obj));
|
||||
});
|
||||
}
|
||||
|
@ -816,6 +885,7 @@ class StorageDaemon : public td::actor::Actor {
|
|||
obj->torrent_->active_upload_ = state.active_upload;
|
||||
obj->torrent_->download_speed_ = state.download_speed;
|
||||
obj->torrent_->upload_speed_ = state.upload_speed;
|
||||
obj->torrent_->added_at_ = state.added_at;
|
||||
for (size_t i = 0; i < obj->files_.size(); ++i) {
|
||||
obj->files_[i]->priority_ =
|
||||
(i < state.file_priority.size() ? state.file_priority[i] : 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue