From 0862cca295535ec4777cccee00d63a10acb3598e Mon Sep 17 00:00:00 2001 From: SpyCheese Date: Thu, 24 Oct 2024 17:12:22 +0300 Subject: [PATCH] Fix updating neighbors in private overlays (#1314) --- overlay/overlay-peers.cpp | 12 ++++-------- overlay/overlay.h | 2 +- overlay/overlay.hpp | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/overlay/overlay-peers.cpp b/overlay/overlay-peers.cpp index aba62eb15..00b508fd4 100644 --- a/overlay/overlay-peers.cpp +++ b/overlay/overlay-peers.cpp @@ -407,7 +407,8 @@ void OverlayImpl::update_neighbours(td::uint32 nodes_to_change) { continue; } - if (X->get_version() <= td::Clocks::system() - Overlays::overlay_peer_ttl()) { + if (overlay_type_ != OverlayType::FixedMemberList && X->get_version() <= td::Clocks::system() - + Overlays::overlay_peer_ttl()) { if (X->is_permanent_member()) { del_from_neighbour_list(X); } else { @@ -656,14 +657,9 @@ size_t OverlayImpl::neighbours_cnt() const { void OverlayImpl::update_root_member_list(std::vector ids, std::vector root_public_keys, OverlayMemberCertificate cert) { - td::uint32 expectd_size = + auto expected_size = (td::uint32)(ids.size() + root_public_keys.size() * opts_.max_slaves_in_semiprivate_overlay_); - if (expectd_size > opts_.max_peers_) { - opts_.max_peers_ = expectd_size; - } - if (expectd_size > opts_.max_neighbours_) { - opts_.max_neighbours_ = expectd_size; - } + opts_.max_peers_ = std::max(opts_.max_peers_, expected_size); std::sort(ids.begin(), ids.end()); auto old_root_public_keys = std::move(peer_list_.root_public_keys_); for (const auto &pub_key : root_public_keys) { diff --git a/overlay/overlay.h b/overlay/overlay.h index ce9f40d3f..bfab49877 100644 --- a/overlay/overlay.h +++ b/overlay/overlay.h @@ -78,7 +78,7 @@ class Overlay : public td::actor::Actor { bool is_response) = 0; virtual void update_peer_ip_str(adnl::AdnlNodeIdShort peer_id, td::string ip_str) = 0; virtual void update_member_certificate(OverlayMemberCertificate cert) = 0; - virtual void update_root_member_list(std::vector nodes, + virtual void update_root_member_list(std::vector ids, std::vector root_public_keys, OverlayMemberCertificate cert) = 0; //virtual void receive_broadcast(td::BufferSlice data) = 0; //virtual void subscribe(std::unique_ptr callback) = 0; diff --git a/overlay/overlay.hpp b/overlay/overlay.hpp index 43822c5a1..6476779ba 100644 --- a/overlay/overlay.hpp +++ b/overlay/overlay.hpp @@ -280,7 +280,7 @@ class OverlayImpl : public Overlay { void update_peer_ip_str(adnl::AdnlNodeIdShort peer_id, td::string ip_str) override; - void update_root_member_list(std::vector nodes, std::vector root_public_keys, + void update_root_member_list(std::vector ids, std::vector root_public_keys, OverlayMemberCertificate cert) override; bool is_valid_peer(const adnl::AdnlNodeIdShort &id, const ton_api::overlay_MemberCertificate *certificate);