aboutsummaryrefslogtreecommitdiff
path: root/src/p2p/net_peerlist.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/p2p/net_peerlist.h')
-rw-r--r--src/p2p/net_peerlist.h83
1 files changed, 80 insertions, 3 deletions
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index 11d995995..de0f51cc3 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -54,7 +54,7 @@
#include "net_peerlist_boost_serialization.h"
-#define CURRENT_PEERLIST_STORAGE_ARCHIVE_VER 4
+#define CURRENT_PEERLIST_STORAGE_ARCHIVE_VER 5
namespace nodetool
{
@@ -77,13 +77,15 @@ namespace nodetool
bool get_gray_peer_by_index(peerlist_entry& p, size_t i);
bool append_with_peer_white(const peerlist_entry& pr);
bool append_with_peer_gray(const peerlist_entry& pr);
+ bool append_with_peer_anchor(const anchor_peerlist_entry& ple);
bool set_peer_just_seen(peerid_type peer, uint32_t ip, uint32_t port);
bool set_peer_just_seen(peerid_type peer, const net_address& addr);
bool set_peer_unreachable(const peerlist_entry& pr);
bool is_ip_allowed(uint32_t ip);
bool get_random_gray_peer(peerlist_entry& pe);
bool remove_from_peer_gray(const peerlist_entry& pe);
-
+ bool get_and_empty_anchor_peerlist(std::vector<anchor_peerlist_entry>& apl);
+ bool remove_from_peer_anchor(const net_address& addr);
private:
struct by_time{};
@@ -145,6 +147,16 @@ namespace nodetool
boost::multi_index::ordered_non_unique<boost::multi_index::tag<by_time>, boost::multi_index::member<peerlist_entry,int64_t,&peerlist_entry::last_seen> >
>
> peers_indexed_old;
+
+ typedef boost::multi_index_container<
+ anchor_peerlist_entry,
+ boost::multi_index::indexed_by<
+ // access by anchor_peerlist_entry::net_adress
+ boost::multi_index::ordered_unique<boost::multi_index::tag<by_addr>, boost::multi_index::member<anchor_peerlist_entry,net_address,&anchor_peerlist_entry::adr> >,
+ // sort by anchor_peerlist_entry::first_seen
+ boost::multi_index::ordered_non_unique<boost::multi_index::tag<by_time>, boost::multi_index::member<anchor_peerlist_entry,int64_t,&anchor_peerlist_entry::first_seen> >
+ >
+ > anchor_peers_indexed;
public:
template <class Archive, class t_version_type>
@@ -161,8 +173,15 @@ namespace nodetool
peers_indexed_from_old(pio, m_peers_white);
return;
}
+
a & m_peers_white;
a & m_peers_gray;
+
+ if(ver < 5) {
+ return;
+ }
+
+ a & m_peers_anchor;
}
private:
@@ -178,6 +197,7 @@ namespace nodetool
peers_indexed m_peers_gray;
peers_indexed m_peers_white;
+ anchor_peers_indexed m_peers_anchor;
};
//--------------------------------------------------------------------------------------------------
inline
@@ -398,6 +418,24 @@ namespace nodetool
}
//--------------------------------------------------------------------------------------------------
inline
+ bool peerlist_manager::append_with_peer_anchor(const anchor_peerlist_entry& ple)
+ {
+ TRY_ENTRY();
+
+ CRITICAL_REGION_LOCAL(m_peerlist_lock);
+
+ auto by_addr_it_anchor = m_peers_anchor.get<by_addr>().find(ple.adr);
+
+ if(by_addr_it_anchor == m_peers_anchor.get<by_addr>().end()) {
+ m_peers_anchor.insert(ple);
+ }
+
+ return true;
+
+ CATCH_ENTRY_L0("peerlist_manager::append_with_peer_anchor()", false);
+ }
+ //--------------------------------------------------------------------------------------------------
+ inline
bool peerlist_manager::get_random_gray_peer(peerlist_entry& pe)
{
TRY_ENTRY();
@@ -435,7 +473,46 @@ namespace nodetool
CATCH_ENTRY_L0("peerlist_manager::remove_from_peer_gray()", false);
}
- //--------------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------------------
+ inline
+ bool peerlist_manager::get_and_empty_anchor_peerlist(std::vector<anchor_peerlist_entry>& apl)
+ {
+ TRY_ENTRY();
+
+ CRITICAL_REGION_LOCAL(m_peerlist_lock);
+
+ auto begin = m_peers_anchor.get<by_time>().begin();
+ auto end = m_peers_anchor.get<by_time>().end();
+
+ std::for_each(begin, end, [&apl](const anchor_peerlist_entry &a) {
+ apl.push_back(a);
+ });
+
+ m_peers_anchor.get<by_time>().clear();
+
+ return true;
+
+ CATCH_ENTRY_L0("peerlist_manager::get_and_empty_anchor_peerlist()", false);
+ }
+ //--------------------------------------------------------------------------------------------------
+ inline
+ bool peerlist_manager::remove_from_peer_anchor(const net_address& addr)
+ {
+ TRY_ENTRY();
+
+ CRITICAL_REGION_LOCAL(m_peerlist_lock);
+
+ anchor_peers_indexed::index_iterator<by_addr>::type iterator = m_peers_anchor.get<by_addr>().find(addr);
+
+ if (iterator != m_peers_anchor.get<by_addr>().end()) {
+ m_peers_anchor.erase(iterator);
+ }
+
+ return true;
+
+ CATCH_ENTRY_L0("peerlist_manager::remove_from_peer_anchor()", false);
+ }
+ //--------------------------------------------------------------------------------------------------
}
BOOST_CLASS_VERSION(nodetool::peerlist_manager, CURRENT_PEERLIST_STORAGE_ARCHIVE_VER)