mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	* 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>
		
			
				
	
	
		
			151 lines
		
	
	
	
		
			6.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			151 lines
		
	
	
	
		
			6.9 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/>.
 | 
						|
 | 
						|
    Copyright 2017-2020 Telegram Systems LLP
 | 
						|
*/
 | 
						|
#pragma once
 | 
						|
 | 
						|
#include <map>
 | 
						|
 | 
						|
#include "td/actor/actor.h"
 | 
						|
#include "td/db/KeyValueAsync.h"
 | 
						|
 | 
						|
#include "adnl/adnl.h"
 | 
						|
#include "dht/dht.h"
 | 
						|
 | 
						|
#include "overlays.h"
 | 
						|
#include "overlay-id.hpp"
 | 
						|
 | 
						|
namespace ton {
 | 
						|
 | 
						|
namespace overlay {
 | 
						|
 | 
						|
constexpr int VERBOSITY_NAME(OVERLAY_WARNING) = verbosity_WARNING;
 | 
						|
constexpr int VERBOSITY_NAME(OVERLAY_NOTICE) = verbosity_DEBUG;
 | 
						|
constexpr int VERBOSITY_NAME(OVERLAY_INFO) = verbosity_DEBUG;
 | 
						|
constexpr int VERBOSITY_NAME(OVERLAY_DEBUG) = verbosity_DEBUG + 1;
 | 
						|
constexpr int VERBOSITY_NAME(OVERLAY_EXTRA_DEBUG) = verbosity_DEBUG + 10;
 | 
						|
 | 
						|
class Overlay;
 | 
						|
 | 
						|
class OverlayManager : public Overlays {
 | 
						|
 public:
 | 
						|
  OverlayManager(std::string db_root, td::actor::ActorId<keyring::Keyring> keyring, td::actor::ActorId<adnl::Adnl> adnl,
 | 
						|
                 td::actor::ActorId<dht::Dht> dht);
 | 
						|
  void start_up() override;
 | 
						|
  void save_to_db(adnl::AdnlNodeIdShort local_id, OverlayIdShort overlay_id, std::vector<OverlayNode> nodes);
 | 
						|
 | 
						|
  void update_dht_node(td::actor::ActorId<dht::Dht> dht) override;
 | 
						|
 | 
						|
  void create_public_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id,
 | 
						|
                             std::unique_ptr<Callback> callback, OverlayPrivacyRules rules, td::string scope) override;
 | 
						|
  void create_public_overlay_ex(adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id,
 | 
						|
                                 std::unique_ptr<Callback> callback, OverlayPrivacyRules rules, td::string scope,
 | 
						|
                                 bool announce_self) override;
 | 
						|
  void create_private_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id,
 | 
						|
                              std::vector<adnl::AdnlNodeIdShort> nodes, std::unique_ptr<Callback> callback,
 | 
						|
                              OverlayPrivacyRules rules) override;
 | 
						|
  void delete_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdShort overlay_id) override;
 | 
						|
  void send_query(adnl::AdnlNodeIdShort dst, adnl::AdnlNodeIdShort src, OverlayIdShort overlay_id, std::string name,
 | 
						|
                  td::Promise<td::BufferSlice> promise, td::Timestamp timeout, td::BufferSlice query) override {
 | 
						|
    send_query_via(dst, src, overlay_id, std::move(name), std::move(promise), timeout, std::move(query),
 | 
						|
                   adnl::Adnl::huge_packet_max_size(), adnl_);
 | 
						|
  }
 | 
						|
  void send_query_via(adnl::AdnlNodeIdShort dst, adnl::AdnlNodeIdShort src, OverlayIdShort overlay_id, std::string name,
 | 
						|
                      td::Promise<td::BufferSlice> promise, td::Timestamp timeout, td::BufferSlice query,
 | 
						|
                      td::uint64 max_answer_size, td::actor::ActorId<adnl::AdnlSenderInterface> via) override;
 | 
						|
  void send_message(adnl::AdnlNodeIdShort dst, adnl::AdnlNodeIdShort src, OverlayIdShort overlay_id,
 | 
						|
                    td::BufferSlice object) override {
 | 
						|
    send_message_via(dst, src, overlay_id, std::move(object), adnl_);
 | 
						|
  }
 | 
						|
  void send_message_via(adnl::AdnlNodeIdShort dst, adnl::AdnlNodeIdShort src, OverlayIdShort overlay_id,
 | 
						|
                        td::BufferSlice object, td::actor::ActorId<adnl::AdnlSenderInterface> via) override;
 | 
						|
 | 
						|
  void send_broadcast(adnl::AdnlNodeIdShort src, OverlayIdShort overlay_id, td::BufferSlice object) override;
 | 
						|
  void send_broadcast_ex(adnl::AdnlNodeIdShort src, OverlayIdShort overlay_id, PublicKeyHash send_as, td::uint32 flags,
 | 
						|
                         td::BufferSlice object) override;
 | 
						|
  void send_broadcast_fec(adnl::AdnlNodeIdShort src, OverlayIdShort overlay_id, td::BufferSlice object) override;
 | 
						|
  void send_broadcast_fec_ex(adnl::AdnlNodeIdShort src, OverlayIdShort overlay_id, PublicKeyHash send_as,
 | 
						|
                             td::uint32 flags, td::BufferSlice object) override;
 | 
						|
 | 
						|
  void set_privacy_rules(adnl::AdnlNodeIdShort local_id, OverlayIdShort overlay_id, OverlayPrivacyRules rules) override;
 | 
						|
  void update_certificate(adnl::AdnlNodeIdShort local_id, OverlayIdShort overlay_id, PublicKeyHash key,
 | 
						|
                          std::shared_ptr<Certificate> cert) override;
 | 
						|
 | 
						|
  void get_overlay_random_peers(adnl::AdnlNodeIdShort local_id, OverlayIdShort overlay, td::uint32 max_peers,
 | 
						|
                                td::Promise<std::vector<adnl::AdnlNodeIdShort>> promise) override;
 | 
						|
 | 
						|
  void receive_query(adnl::AdnlNodeIdShort src, adnl::AdnlNodeIdShort dst, td::BufferSlice data,
 | 
						|
                     td::Promise<td::BufferSlice> promise);
 | 
						|
  void receive_message(adnl::AdnlNodeIdShort src, adnl::AdnlNodeIdShort dst, td::BufferSlice data);
 | 
						|
 | 
						|
  void register_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdShort overlay_id,
 | 
						|
                        td::actor::ActorOwn<Overlay> overlay);
 | 
						|
  void get_stats(td::Promise<tl_object_ptr<ton_api::engine_validator_overlaysStats>> promise) override;
 | 
						|
 | 
						|
  struct PrintId {};
 | 
						|
 | 
						|
  PrintId print_id() const {
 | 
						|
    return PrintId{};
 | 
						|
  }
 | 
						|
 | 
						|
 private:
 | 
						|
  std::map<adnl::AdnlNodeIdShort, std::map<OverlayIdShort, td::actor::ActorOwn<Overlay>>> overlays_;
 | 
						|
 | 
						|
  std::string db_root_;
 | 
						|
 | 
						|
  td::actor::ActorId<keyring::Keyring> keyring_;
 | 
						|
  td::actor::ActorId<adnl::Adnl> adnl_;
 | 
						|
  td::actor::ActorId<dht::Dht> dht_node_;
 | 
						|
 | 
						|
  using DbType = td::KeyValueAsync<td::Bits256, td::BufferSlice>;
 | 
						|
  DbType db_;
 | 
						|
 | 
						|
  class AdnlCallback : public adnl::Adnl::Callback {
 | 
						|
   public:
 | 
						|
    void receive_message(adnl::AdnlNodeIdShort src, adnl::AdnlNodeIdShort dst, td::BufferSlice data) override {
 | 
						|
      td::actor::send_closure(id_, &OverlayManager::receive_message, src, dst, std::move(data));
 | 
						|
    }
 | 
						|
    void receive_query(adnl::AdnlNodeIdShort src, adnl::AdnlNodeIdShort dst, td::BufferSlice data,
 | 
						|
                       td::Promise<td::BufferSlice> promise) override {
 | 
						|
      td::actor::send_closure(id_, &OverlayManager::receive_query, src, dst, std::move(data), std::move(promise));
 | 
						|
    }
 | 
						|
    AdnlCallback(td::actor::ActorId<OverlayManager> id) : id_(id) {
 | 
						|
    }
 | 
						|
 | 
						|
   private:
 | 
						|
    td::actor::ActorId<OverlayManager> id_;
 | 
						|
  };
 | 
						|
};
 | 
						|
 | 
						|
inline td::StringBuilder &operator<<(td::StringBuilder &sb, const OverlayManager::PrintId &id) {
 | 
						|
  sb << "[overlaymanager]";
 | 
						|
  return sb;
 | 
						|
}
 | 
						|
 | 
						|
inline td::StringBuilder &operator<<(td::StringBuilder &sb, const OverlayManager &manager) {
 | 
						|
  sb << manager.print_id();
 | 
						|
  return sb;
 | 
						|
}
 | 
						|
 | 
						|
inline td::StringBuilder &operator<<(td::StringBuilder &sb, const OverlayManager *manager) {
 | 
						|
  sb << manager->print_id();
 | 
						|
  return sb;
 | 
						|
}
 | 
						|
 | 
						|
}  // namespace overlay
 | 
						|
 | 
						|
}  // namespace ton
 |