aboutsummaryrefslogtreecommitdiff
path: root/src/p2p/net_peerlist.h
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2021-07-27 10:02:26 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2021-08-05 17:29:25 +0000
commit7354ffb8a7ccdfab0c7be186423634ac571ba1cb (patch)
treedac627b8257bda98c2cdcd59c5d8e8068a2845a4 /src/p2p/net_peerlist.h
parentMerge pull request #7764 (diff)
downloadmonero-7354ffb8a7ccdfab0c7be186423634ac571ba1cb.tar.xz
p2p: remove blocked addresses/hosts from peerlist
Diffstat (limited to 'src/p2p/net_peerlist.h')
-rw-r--r--src/p2p/net_peerlist.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index d8de6abe9..0662789b9 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -109,7 +109,7 @@ namespace nodetool
bool get_white_peer_by_index(peerlist_entry& p, size_t i);
bool get_gray_peer_by_index(peerlist_entry& p, size_t i);
template<typename F> bool foreach(bool white, const F &f);
- void evict_host_from_white_peerlist(const peerlist_entry& pr);
+ void evict_host_from_peerlist(bool white, const peerlist_entry& pr);
bool append_with_peer_white(const peerlist_entry& pr, bool trust_last_seen = false);
bool append_with_peer_gray(const peerlist_entry& pr);
bool append_with_peer_anchor(const anchor_peerlist_entry& ple);
@@ -120,6 +120,7 @@ namespace nodetool
bool get_and_empty_anchor_peerlist(std::vector<anchor_peerlist_entry>& apl);
bool remove_from_peer_anchor(const epee::net_utils::network_address& addr);
bool remove_from_peer_white(const peerlist_entry& pe);
+ template<typename F> size_t filter(bool white, const F &f); // f returns true: drop, false: keep
private:
struct by_time{};
@@ -346,7 +347,7 @@ namespace nodetool
if(by_addr_it_wt == m_peers_white.get<by_addr>().end())
{
//put new record into white list
- evict_host_from_white_peerlist(ple);
+ evict_host_from_peerlist(true, ple);
m_peers_white.insert(ple);
trim_white_peerlist();
}else
@@ -520,5 +521,26 @@ namespace nodetool
CATCH_ENTRY_L0("peerlist_manager::remove_from_peer_anchor()", false);
}
//--------------------------------------------------------------------------------------------------
+ template<typename F> size_t peerlist_manager::filter(bool white, const F &f)
+ {
+ size_t filtered = 0;
+ TRY_ENTRY();
+ CRITICAL_REGION_LOCAL(m_peerlist_lock);
+ peers_indexed::index<by_addr>::type& sorted_index = white ? m_peers_gray.get<by_addr>() : m_peers_white.get<by_addr>();
+ auto i = sorted_index.begin();
+ while (i != sorted_index.end())
+ {
+ if (f(*i))
+ {
+ i = sorted_index.erase(i);
+ ++filtered;
+ }
+ else
+ ++i;
+ }
+ CATCH_ENTRY_L0("peerlist_manager::filter()", filtered);
+ return filtered;
+ }
+ //--------------------------------------------------------------------------------------------------
}