aboutsummaryrefslogtreecommitdiff
path: root/src/p2p/net_peerlist.h
diff options
context:
space:
mode:
authorMiguel Herranz <miguel@ipglider.org>2017-02-09 01:11:58 +0100
committerMiguel Herranz <miguel@ipglider.org>2017-02-10 23:28:54 +0100
commit8277e67f112fcf066b4530616560efec87f0b20e (patch)
tree3e842ce521cf06ab9e3b20fa52be2fbe72ccf4df /src/p2p/net_peerlist.h
parentMerge pull request #1679 (diff)
downloadmonero-8277e67f112fcf066b4530616560efec87f0b20e.tar.xz
Add anchor connections
Based on https://eprint.iacr.org/2015/263.pdf 4. Anchor connections. Peer list serialisation version bumped to 5.
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 c73d6615d..9af3694b6 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();
@@ -438,7 +476,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)