/* 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 . Copyright 2017-2019 Telegram Systems LLP */ #pragma once #include "dht-remote-node.hpp" #include "dht.hpp" #include namespace ton { namespace dht { class DhtMember; class DhtBucket { private: double ping_timeout_ = 60; td::uint32 max_missed_pings_ = 3; std::vector> active_nodes_; std::vector> backup_nodes_; //std::map> pending_nodes_; td::uint32 k_; bool check_one(td::actor::ActorId adnl, td::actor::ActorId node, adnl::AdnlNodeIdShort src, const DhtMember::PrintId &print_id); void demote_node(size_t idx); void promote_node(size_t idx); public: DhtBucket(td::uint32 k) : k_(k) { active_nodes_.resize(k); backup_nodes_.resize(k); } td::uint32 active_cnt(); td::Status add_full_node(DhtKeyId id, DhtNode node, td::actor::ActorId adnl, adnl::AdnlNodeIdShort self_id); void check(td::actor::ActorId adnl, td::actor::ActorId node, adnl::AdnlNodeIdShort src); void receive_ping(DhtKeyId id, DhtNode result, td::actor::ActorId adnl, adnl::AdnlNodeIdShort self_id); void get_nearest_nodes(DhtKeyId id, td::uint32 bit, DhtNodesList &vec, td::uint32 k); void dump(td::StringBuilder &sb) const; DhtNodesList export_nodes() const; }; } // namespace dht } // namespace ton