mirror of
https://github.com/monero-project/monero.git
synced 2024-12-13 11:56:31 +02:00
p2p: use vector instead of list for peer lists
This commit is contained in:
parent
7e957c162a
commit
570dd3690e
@ -197,12 +197,12 @@ namespace nodetool
|
||||
const boost::program_options::variables_map& vm
|
||||
);
|
||||
bool idle_worker();
|
||||
bool handle_remote_peerlist(const std::list<peerlist_entry>& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context);
|
||||
bool handle_remote_peerlist(const std::vector<peerlist_entry>& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context);
|
||||
bool get_local_node_data(basic_node_data& node_data);
|
||||
//bool get_local_handshake_data(handshake_data& hshd);
|
||||
|
||||
bool merge_peerlist_with_local(const std::list<peerlist_entry>& bs);
|
||||
bool fix_time_delta(std::list<peerlist_entry>& local_peerlist, time_t local_time, int64_t& delta);
|
||||
bool merge_peerlist_with_local(const std::vector<peerlist_entry>& bs);
|
||||
bool fix_time_delta(std::vector<peerlist_entry>& local_peerlist, time_t local_time, int64_t& delta);
|
||||
|
||||
bool connections_maker();
|
||||
bool peer_sync_idle_maker();
|
||||
|
@ -1374,7 +1374,7 @@ namespace nodetool
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::fix_time_delta(std::list<peerlist_entry>& local_peerlist, time_t local_time, int64_t& delta)
|
||||
bool node_server<t_payload_net_handler>::fix_time_delta(std::vector<peerlist_entry>& local_peerlist, time_t local_time, int64_t& delta)
|
||||
{
|
||||
//fix time delta
|
||||
time_t now = 0;
|
||||
@ -1394,10 +1394,10 @@ namespace nodetool
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::handle_remote_peerlist(const std::list<peerlist_entry>& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context)
|
||||
bool node_server<t_payload_net_handler>::handle_remote_peerlist(const std::vector<peerlist_entry>& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context)
|
||||
{
|
||||
int64_t delta = 0;
|
||||
std::list<peerlist_entry> peerlist_ = peerlist;
|
||||
std::vector<peerlist_entry> peerlist_ = peerlist;
|
||||
if(!fix_time_delta(peerlist_, local_time, delta))
|
||||
return false;
|
||||
LOG_DEBUG_CC(context, "REMOTE PEERLIST: TIME_DELTA: " << delta << ", remote peerlist size=" << peerlist_.size());
|
||||
@ -1779,8 +1779,8 @@ namespace nodetool
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::log_peerlist()
|
||||
{
|
||||
std::list<peerlist_entry> pl_white;
|
||||
std::list<peerlist_entry> pl_gray;
|
||||
std::vector<peerlist_entry> pl_white;
|
||||
std::vector<peerlist_entry> pl_gray;
|
||||
m_peerlist.get_peerlist_full(pl_gray, pl_white);
|
||||
MINFO(ENDL << "Peerlist white:" << ENDL << print_peerlist_to_string(pl_white) << ENDL << "Peerlist gray:" << ENDL << print_peerlist_to_string(pl_gray) );
|
||||
return true;
|
||||
|
@ -68,9 +68,9 @@ namespace nodetool
|
||||
bool deinit();
|
||||
size_t get_white_peers_count(){CRITICAL_REGION_LOCAL(m_peerlist_lock); return m_peers_white.size();}
|
||||
size_t get_gray_peers_count(){CRITICAL_REGION_LOCAL(m_peerlist_lock); return m_peers_gray.size();}
|
||||
bool merge_peerlist(const std::list<peerlist_entry>& outer_bs);
|
||||
bool get_peerlist_head(std::list<peerlist_entry>& bs_head, uint32_t depth = P2P_DEFAULT_PEERS_IN_HANDSHAKE);
|
||||
bool get_peerlist_full(std::list<peerlist_entry>& pl_gray, std::list<peerlist_entry>& pl_white);
|
||||
bool merge_peerlist(const std::vector<peerlist_entry>& outer_bs);
|
||||
bool get_peerlist_head(std::vector<peerlist_entry>& bs_head, uint32_t depth = P2P_DEFAULT_PEERS_IN_HANDSHAKE);
|
||||
bool get_peerlist_full(std::vector<peerlist_entry>& pl_gray, std::vector<peerlist_entry>& pl_white);
|
||||
bool get_white_peer_by_index(peerlist_entry& p, size_t i);
|
||||
bool get_gray_peer_by_index(peerlist_entry& p, size_t i);
|
||||
bool append_with_peer_white(const peerlist_entry& pr);
|
||||
@ -265,7 +265,7 @@ namespace nodetool
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
bool peerlist_manager::merge_peerlist(const std::list<peerlist_entry>& outer_bs)
|
||||
bool peerlist_manager::merge_peerlist(const std::vector<peerlist_entry>& outer_bs)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_peerlist_lock);
|
||||
for(const peerlist_entry& be: outer_bs)
|
||||
@ -315,12 +315,13 @@ namespace nodetool
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
bool peerlist_manager::get_peerlist_head(std::list<peerlist_entry>& bs_head, uint32_t depth)
|
||||
bool peerlist_manager::get_peerlist_head(std::vector<peerlist_entry>& bs_head, uint32_t depth)
|
||||
{
|
||||
|
||||
CRITICAL_REGION_LOCAL(m_peerlist_lock);
|
||||
peers_indexed::index<by_time>::type& by_time_index=m_peers_white.get<by_time>();
|
||||
uint32_t cnt = 0;
|
||||
bs_head.reserve(depth);
|
||||
for(const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index))
|
||||
{
|
||||
if(!vl.last_seen)
|
||||
@ -335,16 +336,18 @@ namespace nodetool
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
bool peerlist_manager::get_peerlist_full(std::list<peerlist_entry>& pl_gray, std::list<peerlist_entry>& pl_white)
|
||||
bool peerlist_manager::get_peerlist_full(std::vector<peerlist_entry>& pl_gray, std::vector<peerlist_entry>& pl_white)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_peerlist_lock);
|
||||
peers_indexed::index<by_time>::type& by_time_index_gr=m_peers_gray.get<by_time>();
|
||||
pl_gray.resize(pl_gray.size() + by_time_index_gr.size());
|
||||
for(const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index_gr))
|
||||
{
|
||||
pl_gray.push_back(vl);
|
||||
}
|
||||
|
||||
peers_indexed::index<by_time>::type& by_time_index_wt=m_peers_white.get<by_time>();
|
||||
pl_white.resize(pl_white.size() + by_time_index_wt.size());
|
||||
for(const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index_wt))
|
||||
{
|
||||
pl_white.push_back(vl);
|
||||
|
@ -114,7 +114,7 @@ namespace nodetool
|
||||
#pragma pack(pop)
|
||||
|
||||
inline
|
||||
std::string print_peerlist_to_string(const std::list<peerlist_entry>& pl)
|
||||
std::string print_peerlist_to_string(const std::vector<peerlist_entry>& pl)
|
||||
{
|
||||
time_t now_time = 0;
|
||||
time(&now_time);
|
||||
@ -189,7 +189,7 @@ namespace nodetool
|
||||
{
|
||||
basic_node_data node_data;
|
||||
t_playload_type payload_data;
|
||||
std::list<peerlist_entry> local_peerlist_new;
|
||||
std::vector<peerlist_entry> local_peerlist_new;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(node_data)
|
||||
@ -198,7 +198,7 @@ namespace nodetool
|
||||
{
|
||||
// saving: save both, so old and new peers can understand it
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
std::list<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
std::vector<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
for (const auto &p: this_ref.local_peerlist_new)
|
||||
{
|
||||
if (p.adr.get_type_id() == epee::net_utils::ipv4_network_address::ID)
|
||||
@ -217,7 +217,7 @@ namespace nodetool
|
||||
// loading: load old list only if there is no new one
|
||||
if (!epee::serialization::selector<is_store>::serialize(this_ref.local_peerlist_new, stg, hparent_section, "local_peerlist_new"))
|
||||
{
|
||||
std::list<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
std::vector<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(local_peerlist, stg, hparent_section, "local_peerlist");
|
||||
for (const auto &p: local_peerlist)
|
||||
((response&)this_ref).local_peerlist_new.push_back(peerlist_entry({epee::net_utils::ipv4_network_address(p.adr.ip, p.adr.port), p.id, p.last_seen}));
|
||||
@ -248,7 +248,7 @@ namespace nodetool
|
||||
{
|
||||
uint64_t local_time;
|
||||
t_playload_type payload_data;
|
||||
std::list<peerlist_entry> local_peerlist_new;
|
||||
std::vector<peerlist_entry> local_peerlist_new;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(local_time)
|
||||
@ -257,7 +257,7 @@ namespace nodetool
|
||||
{
|
||||
// saving: save both, so old and new peers can understand it
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
std::list<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
std::vector<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
for (const auto &p: this_ref.local_peerlist_new)
|
||||
{
|
||||
if (p.adr.get_type_id() == epee::net_utils::ipv4_network_address::ID)
|
||||
@ -276,7 +276,7 @@ namespace nodetool
|
||||
// loading: load old list only if there is no new one
|
||||
if (!epee::serialization::selector<is_store>::serialize(this_ref.local_peerlist_new, stg, hparent_section, "local_peerlist_new"))
|
||||
{
|
||||
std::list<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
std::vector<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(local_peerlist, stg, hparent_section, "local_peerlist");
|
||||
for (const auto &p: local_peerlist)
|
||||
((response&)this_ref).local_peerlist_new.push_back(peerlist_entry({epee::net_utils::ipv4_network_address(p.adr.ip, p.adr.port), p.id, p.last_seen}));
|
||||
@ -389,9 +389,9 @@ namespace nodetool
|
||||
|
||||
struct response
|
||||
{
|
||||
std::list<peerlist_entry> local_peerlist_white;
|
||||
std::list<peerlist_entry> local_peerlist_gray;
|
||||
std::list<connection_entry> connections_list;
|
||||
std::vector<peerlist_entry> local_peerlist_white;
|
||||
std::vector<peerlist_entry> local_peerlist_gray;
|
||||
std::vector<connection_entry> connections_list;
|
||||
peerid_type my_id;
|
||||
uint64_t local_time;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
|
@ -857,11 +857,11 @@ namespace cryptonote
|
||||
bool core_rpc_server::on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request& req, COMMAND_RPC_GET_PEER_LIST::response& res)
|
||||
{
|
||||
PERF_TIMER(on_get_peer_list);
|
||||
std::list<nodetool::peerlist_entry> white_list;
|
||||
std::list<nodetool::peerlist_entry> gray_list;
|
||||
std::vector<nodetool::peerlist_entry> white_list;
|
||||
std::vector<nodetool::peerlist_entry> gray_list;
|
||||
m_p2p.get_peerlist_manager().get_peerlist_full(gray_list, white_list);
|
||||
|
||||
|
||||
res.white_list.reserve(white_list.size());
|
||||
for (auto & entry : white_list)
|
||||
{
|
||||
if (entry.adr.get_type_id() == epee::net_utils::ipv4_network_address::ID)
|
||||
@ -871,6 +871,7 @@ namespace cryptonote
|
||||
res.white_list.emplace_back(entry.id, entry.adr.str(), entry.last_seen);
|
||||
}
|
||||
|
||||
res.gray_list.reserve(gray_list.size());
|
||||
for (auto & entry : gray_list)
|
||||
{
|
||||
if (entry.adr.get_type_id() == epee::net_utils::ipv4_network_address::ID)
|
||||
|
@ -42,7 +42,7 @@ TEST(peer_list, peer_list_general)
|
||||
#define ADD_GRAY_NODE(addr_, id_, last_seen_) { nodetool::peerlist_entry ple; ple.last_seen=last_seen_;ple.adr = addr_; ple.id = id_;plm.append_with_peer_gray(ple);}
|
||||
#define ADD_WHITE_NODE(addr_, id_, last_seen_) { nodetool::peerlist_entry ple;ple.last_seen=last_seen_; ple.adr = addr_; ple.id = id_;plm.append_with_peer_white(ple);}
|
||||
|
||||
#define PRINT_HEAD(step) {std::list<nodetool::peerlist_entry> bs_head; bool r = plm.get_peerlist_head(bs_head, 100);std::cout << "step " << step << ": " << bs_head.size() << std::endl;}
|
||||
#define PRINT_HEAD(step) {std::vector<nodetool::peerlist_entry> bs_head; bool r = plm.get_peerlist_head(bs_head, 100);std::cout << "step " << step << ": " << bs_head.size() << std::endl;}
|
||||
|
||||
ADD_GRAY_NODE(MAKE_IPV4_ADDRESS(123,43,12,1, 8080), 121241, 34345);
|
||||
ADD_GRAY_NODE(MAKE_IPV4_ADDRESS(123,43,12,2, 8080), 121241, 34345);
|
||||
@ -58,7 +58,7 @@ TEST(peer_list, peer_list_general)
|
||||
size_t gray_list_size = plm.get_gray_peers_count();
|
||||
ASSERT_EQ(gray_list_size, 1);
|
||||
|
||||
std::list<nodetool::peerlist_entry> bs_head;
|
||||
std::vector<nodetool::peerlist_entry> bs_head;
|
||||
bool r = plm.get_peerlist_head(bs_head, 100);
|
||||
std::cout << bs_head.size() << std::endl;
|
||||
ASSERT_TRUE(r);
|
||||
@ -78,7 +78,7 @@ TEST(peer_list, merge_peer_lists)
|
||||
//ADD_NODE_TO_PL("\2", \3, 0x\1, (1353346618 -(\4*60*60*24+\5*60*60+\6*60+\7 )));\n
|
||||
nodetool::peerlist_manager plm;
|
||||
plm.init(false);
|
||||
std::list<nodetool::peerlist_entry> outer_bs;
|
||||
std::vector<nodetool::peerlist_entry> outer_bs;
|
||||
#define ADD_NODE_TO_PL(ip_, port_, id_, timestamp_) { nodetool::peerlist_entry ple; epee::string_tools::get_ip_int32_from_string(ple.adr.ip, ip_); ple.last_seen = timestamp_; ple.adr.port = port_; ple.id = id_;outer_bs.push_back(ple);}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user