mirror of
https://github.com/ton-blockchain/ton
synced 2025-02-13 03:32:22 +00:00
* 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
127 lines
5.1 KiB
C++
127 lines
5.1 KiB
C++
/*
|
|
This file is part of TON Blockchain Library.
|
|
|
|
TON Blockchain Library is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
TON Blockchain Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
#include "td/actor/actor.h"
|
|
#include "adnl/adnl.h"
|
|
#include "rldp2/rldp.h"
|
|
#include "overlay/overlays.h"
|
|
#include "storage/PeerManager.h"
|
|
#include "storage/db.h"
|
|
#include "SpeedLimiter.h"
|
|
|
|
namespace ton {
|
|
|
|
class StorageManager : public td::actor::Actor {
|
|
public:
|
|
class Callback {
|
|
public:
|
|
virtual ~Callback() = default;
|
|
virtual void on_ready() = 0;
|
|
};
|
|
|
|
StorageManager(adnl::AdnlNodeIdShort local_id, std::string db_root, td::unique_ptr<Callback> callback,
|
|
bool client_mode, td::actor::ActorId<adnl::Adnl> adnl, td::actor::ActorId<ton_rldp::Rldp> rldp,
|
|
td::actor::ActorId<overlay::Overlays> overlays);
|
|
|
|
void start_up() override;
|
|
|
|
void add_torrent(Torrent torrent, bool start_download, bool allow_upload, bool copy_inside,
|
|
td::Promise<td::Unit> promise);
|
|
void add_torrent_by_meta(TorrentMeta meta, std::string root_dir, bool start_download, bool allow_upload,
|
|
td::Promise<td::Unit> promise);
|
|
void add_torrent_by_hash(td::Bits256 hash, std::string root_dir, bool start_download, bool allow_upload,
|
|
td::Promise<td::Unit> promise);
|
|
|
|
void set_active_download(td::Bits256 hash, bool active, td::Promise<td::Unit> promise);
|
|
void set_active_upload(td::Bits256 hash, bool active, td::Promise<td::Unit> promise);
|
|
|
|
void with_torrent(td::Bits256 hash, td::Promise<NodeActor::NodeState> promise);
|
|
void get_all_torrents(td::Promise<std::vector<td::Bits256>> promise);
|
|
|
|
void set_all_files_priority(td::Bits256 hash, td::uint8 priority, td::Promise<bool> promise);
|
|
void set_file_priority_by_idx(td::Bits256 hash, size_t idx, td::uint8 priority, td::Promise<bool> promise);
|
|
void set_file_priority_by_name(td::Bits256 hash, std::string name, td::uint8 priority, td::Promise<bool> promise);
|
|
|
|
void remove_torrent(td::Bits256 hash, bool remove_files, td::Promise<td::Unit> promise);
|
|
void load_from(td::Bits256 hash, td::optional<TorrentMeta> meta, std::string files_path,
|
|
td::Promise<td::Unit> promise);
|
|
|
|
void wait_for_completion(td::Bits256 hash, td::Promise<td::Unit> promise);
|
|
void get_peers_info(td::Bits256 hash, td::Promise<tl_object_ptr<ton_api::storage_daemon_peerList>> promise);
|
|
|
|
void get_speed_limits(td::Promise<std::pair<double, double>> promise); // Download, upload
|
|
void set_download_speed_limit(double max_speed);
|
|
void set_upload_speed_limit(double max_speed);
|
|
|
|
private:
|
|
adnl::AdnlNodeIdShort local_id_;
|
|
std::string db_root_;
|
|
td::unique_ptr<Callback> callback_;
|
|
bool client_mode_ = false;
|
|
td::actor::ActorId<adnl::Adnl> adnl_;
|
|
td::actor::ActorId<ton_rldp::Rldp> rldp_;
|
|
td::actor::ActorId<overlay::Overlays> overlays_;
|
|
|
|
std::shared_ptr<db::DbType> db_;
|
|
|
|
struct TorrentEntry {
|
|
td::Bits256 hash;
|
|
td::actor::ActorOwn<NodeActor> actor;
|
|
td::actor::ActorOwn<PeerManager> peer_manager;
|
|
|
|
struct ClosingState {
|
|
bool removing = false;
|
|
td::Promise<td::Unit> promise;
|
|
bool remove_files = false;
|
|
};
|
|
std::shared_ptr<ClosingState> closing_state = std::make_shared<ClosingState>();
|
|
};
|
|
|
|
std::map<td::Bits256, TorrentEntry> torrents_;
|
|
|
|
double download_speed_limit_ = -1.0;
|
|
double upload_speed_limit_ = -1.0;
|
|
td::actor::ActorOwn<SpeedLimiter> download_speed_limiter_ =
|
|
td::actor::create_actor<SpeedLimiter>("DownloadRateLimitrer", -1.0);
|
|
td::actor::ActorOwn<SpeedLimiter> upload_speed_limiter_ =
|
|
td::actor::create_actor<SpeedLimiter>("DownloadRateLimitrer", -1.0);
|
|
|
|
td::Status add_torrent_impl(Torrent torrent, bool start_download, bool allow_upload);
|
|
|
|
td::Result<TorrentEntry*> get_torrent(td::Bits256 hash) {
|
|
auto it = torrents_.find(hash);
|
|
if (it == torrents_.end()) {
|
|
return td::Status::Error("No such torrent");
|
|
}
|
|
return &it->second;
|
|
}
|
|
|
|
td::unique_ptr<NodeActor::Callback> create_callback(td::Bits256 hash,
|
|
std::shared_ptr<TorrentEntry::ClosingState> closing_state);
|
|
|
|
void loaded_config_from_db(tl_object_ptr<ton_api::storage_db_config> config);
|
|
void load_torrents_from_db(std::vector<td::Bits256> torrents);
|
|
void loaded_torrent_from_db(td::Bits256 hash, td::Result<td::actor::ActorOwn<NodeActor>> R);
|
|
void after_load_torrents_from_db();
|
|
void db_store_config();
|
|
void db_store_torrent_list();
|
|
|
|
void on_torrent_closed(Torrent torrent, std::shared_ptr<TorrentEntry::ClosingState> closing_state);
|
|
};
|
|
|
|
} // namespace ton
|