Skip to content

Commit

Permalink
Feature: don't disconnect peer if still needed (#2138)
Browse files Browse the repository at this point in the history
* feature: don't disconnect peer if still needed 

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
  • Loading branch information
xDimon authored Jun 26, 2024
1 parent 1ef9521 commit 81c606e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
17 changes: 6 additions & 11 deletions core/network/impl/peer_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <libp2p/protocol/kademlia/impl/peer_routing_table.hpp>
#include <libp2p/protocol/ping.hpp>

#include "authority_discovery/query/query.hpp"
#include "common/main_thread_pool.hpp"
#include "network/impl/protocols/beefy_protocol_impl.hpp"
#include "network/impl/protocols/grandpa_protocol.hpp"
Expand Down Expand Up @@ -88,8 +87,7 @@ namespace kagome::network {
std::shared_ptr<storage::SpacedStorage> storage,
std::shared_ptr<crypto::Hasher> hasher,
std::shared_ptr<ReputationRepository> reputation_repository,
std::shared_ptr<PeerView> peer_view,
std::shared_ptr<authority_discovery::Query> authority_discovery)
std::shared_ptr<PeerView> peer_view)
: log_{log::createLogger("PeerManager", "network")},
host_(host),
main_pool_handler_{poolHandlerReadyMake(
Expand All @@ -106,8 +104,7 @@ namespace kagome::network {
storage_{storage->getSpace(storage::Space::kDefault)},
hasher_{std::move(hasher)},
reputation_repository_{std::move(reputation_repository)},
peer_view_{std::move(peer_view)},
authority_discovery_{std::move(authority_discovery)} {
peer_view_{std::move(peer_view)} {
BOOST_ASSERT(identify_ != nullptr);
BOOST_ASSERT(kademlia_ != nullptr);
BOOST_ASSERT(scheduler_ != nullptr);
Expand All @@ -118,7 +115,6 @@ namespace kagome::network {
BOOST_ASSERT(peer_view_);
BOOST_ASSERT(reputation_repository_ != nullptr);
BOOST_ASSERT(peer_view_ != nullptr);
BOOST_ASSERT(authority_discovery_ != nullptr);

// Register metrics
registry_->registerGaugeFamily(syncPeerMetricName,
Expand Down Expand Up @@ -328,11 +324,10 @@ namespace kagome::network {

for (const auto &[peer_id, desc] : active_peers_) {
// Skip peer having immunity
// TODO(xDimon): it's validators now.
// Probably is needed to limit them by common core
auto authority_id_opt = authority_discovery_->get(peer_id);
if (authority_id_opt.has_value()) {
continue;
if (auto it = peer_states_.find(peer_id); it != peer_states_.end()) {
if (not it->second.can_be_disconnected()) {
continue;
}
}

const uint64_t last_activity_ms =
Expand Down
8 changes: 1 addition & 7 deletions core/network/impl/peer_manager_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@

namespace kagome {
class PoolHandlerReady;
} // namespace kagome

namespace kagome::authority_discovery {
class Query;
}

namespace kagome::network {
Expand Down Expand Up @@ -80,8 +76,7 @@ namespace kagome::network {
std::shared_ptr<storage::SpacedStorage> storage,
std::shared_ptr<crypto::Hasher> hasher,
std::shared_ptr<ReputationRepository> reputation_repository,
std::shared_ptr<PeerView> peer_view,
std::shared_ptr<authority_discovery::Query> authority_discovery);
std::shared_ptr<PeerView> peer_view);

/** @see poolHandlerReadyMake */
bool tryStart();
Expand Down Expand Up @@ -210,7 +205,6 @@ namespace kagome::network {
std::shared_ptr<crypto::Hasher> hasher_;
std::shared_ptr<ReputationRepository> reputation_repository_;
std::shared_ptr<network::PeerView> peer_view_;
std::shared_ptr<authority_discovery::Query> authority_discovery_;

libp2p::event::Handle add_peer_handle_;
libp2p::event::Handle peer_disconnected_handler_;
Expand Down

0 comments on commit 81c606e

Please sign in to comment.