1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

TON Storage utilities (#564)

* Rename chunk to piece in MerkleTree for consistency

* Refactor PeerManager

* Make PeerState thread-safe

* Download torrent by hash

* First version of storage daemon

* Download torrents partially

* Improve storing and loading torrent state in DB

* Rewrite MerkleTree

* "Remove torrent" in storage daemon

* Process errors, fix bugs in storage

* Move TonlibClientWrapper from rldp-http-proxy to tonlib

* Initial version of storage provider

* Move interaction with contracts to smc-util

* Improve TonlibClientWrapper interface

* Various improvements in storage provider

* Fix TorrentCreator.cpp

* Improve interface for partial download

* Client mode in storage-daemon

* Improve interface of storage-daemon-cli

* Fix calculating speed, show peers in storage-daemon

* Use permanent adnl id in storage daemon

* Fix sending large "storage.addUpdate" messages

* Improve printing torrents in cli

* Update tlo

* Fix RldpSender::on_ack

* Update storage provider

* Add "address" parameter to get-provider-params

* Allow client to close storage contract

* Limit torrent description

* Add more logs to storage provider

* smc.forget tonlib method

* Use smc.forget in storage daemon

* Optimize sending messages in smc-util.cpp

* Fix verbosity, remove excessive logs

* Json output in storage-daemon-cli

* Update storage provider contracts

* Fix rldp2 acks

* Change verbosity of logs in rldp2

* Update help and output of commands and in storage-daemon-cli

Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
EmelyanenkoK 2022-12-22 12:24:13 +03:00 committed by GitHub
parent 434dc487a4
commit 360ef54e6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
75 changed files with 8872 additions and 1148 deletions

View file

@ -21,7 +21,6 @@
#include "Bitset.h"
#include "PeerState.h"
#include "SharedState.h"
#include "td/utils/optional.h"
@ -38,14 +37,14 @@ class PeerActor : public td::actor::Actor {
virtual void send_query(td::uint64 query_id, td::BufferSlice query) = 0;
};
PeerActor(td::unique_ptr<Callback> callback, td::SharedState<PeerState> state);
PeerActor(td::unique_ptr<Callback> callback, std::shared_ptr<PeerState> state);
void execute_query(td::BufferSlice query, td::Promise<td::BufferSlice> promise);
void on_query_result(td::uint64 query_id, td::Result<td::BufferSlice> r_answer);
private:
td::unique_ptr<Callback> callback_;
td::SharedState<PeerState> state_;
std::shared_ptr<PeerState> state_;
bool need_notify_node_{false};
td::uint64 next_query_id_{0};
@ -53,7 +52,9 @@ class PeerActor : public td::actor::Actor {
// ping
td::Timestamp next_ping_at_;
td::optional<td::uint64> ping_query_id_;
td::optional<td::uint64> get_info_query_id_;
td::Timestamp wait_pong_till_;
td::Timestamp next_get_info_at_;
// startSession
td::uint64 node_session_id_;
@ -63,15 +64,17 @@ class PeerActor : public td::actor::Actor {
td::optional<td::uint64> peer_session_id_;
td::optional<td::uint64> update_query_id_;
bool peer_is_inited_{false};
size_t peer_init_offset_{0};
td::uint32 node_seqno_{0};
td::Bitset have_pieces_;
std::vector<PartId> have_pieces_list_;
std::vector<PartId> sent_have_pieces_list_;
td::uint32 peer_seqno_{0};
// update state
struct UpdateState {
td::optional<td::uint64> query_id;
PeerState::State state;
PeerState::State state{false, false};
};
UpdateState update_state_query_;
@ -102,6 +105,7 @@ class PeerActor : public td::actor::Actor {
void loop_update_init();
void loop_update_pieces();
void update_have_pieces();
void loop_get_torrent_info();
void loop_update_state();
@ -112,14 +116,14 @@ class PeerActor : public td::actor::Actor {
void loop_peer_get_piece();
void execute_add_update(ton::ton_api::storage_addUpdate &add_update, td::Promise<td::BufferSlice> promise);
void execute_get_piece(ton::ton_api::storage_getPiece &get_piece, td::Promise<td::BufferSlice> promise);
void execute_get_torrent_info(td::Promise<td::BufferSlice> promise);
void on_update_result(td::Result<td::BufferSlice> r_answer);
void on_get_piece_result(PartId piece_id, td::Result<td::BufferSlice> r_answer);
void on_update_state_result(td::Result<td::BufferSlice> r_answer);
void on_get_info_result(td::Result<td::BufferSlice> r_answer);
template <class T, class... ArgsT>
td::uint64 create_and_send_query(ArgsT &&... args);
@ -127,5 +131,7 @@ class PeerActor : public td::actor::Actor {
void schedule_loop();
void notify_node();
static const size_t UPDATE_INIT_BLOCK_SIZE = 6000;
};
} // namespace ton