Only getting endpoint out of peer list instead of all information.

This commit is contained in:
clemahieu 2017-04-01 17:08:59 -05:00
commit 1c6c379032
3 changed files with 12 additions and 27 deletions

View file

@ -168,6 +168,7 @@ bool confirm_broadcast (rai::node & node_a, T & list_a, std::unique_ptr <rai::bl
rai::transaction transaction (node_a.store.environment, nullptr, true); rai::transaction transaction (node_a.store.environment, nullptr, true);
node_a.wallets.foreach_representative (transaction, [&result, &block_a, &list_a, &node_a, &transaction] (rai::public_key const & pub_a, rai::raw_key const & prv_a) node_a.wallets.foreach_representative (transaction, [&result, &block_a, &list_a, &node_a, &transaction] (rai::public_key const & pub_a, rai::raw_key const & prv_a)
{ {
result = true;
auto sequence (node_a.store.sequence_atomic_inc (transaction, pub_a)); auto sequence (node_a.store.sequence_atomic_inc (transaction, pub_a));
rai::vote vote (pub_a, prv_a, sequence, block_a->clone ()); rai::vote vote (pub_a, prv_a, sequence, block_a->clone ());
rai::confirm_ack confirm (vote); rai::confirm_ack confirm (vote);
@ -178,8 +179,7 @@ bool confirm_broadcast (rai::node & node_a, T & list_a, std::unique_ptr <rai::bl
} }
for (auto j (list_a.begin ()), m (list_a.end ()); j != m; ++j) for (auto j (list_a.begin ()), m (list_a.end ()); j != m; ++j)
{ {
node_a.network.confirm_block (confirm, bytes, j->endpoint); node_a.network.confirm_block (confirm, bytes, *j);
result = true;
} }
}); });
} }
@ -189,25 +189,10 @@ bool confirm_broadcast (rai::node & node_a, T & list_a, std::unique_ptr <rai::bl
template <> template <>
bool confirm_broadcast (rai::node & node_a, rai::endpoint & peer_a, std::unique_ptr <rai::block> block_a) bool confirm_broadcast (rai::node & node_a, rai::endpoint & peer_a, std::unique_ptr <rai::block> block_a)
{ {
bool result (false); std::array <rai::endpoint, 1> endpoints;
if (node_a.config.enable_voting) endpoints [0] = peer_a;
{ auto result (confirm_broadcast (node_a, endpoints, std::move (block_a)));
rai::transaction transaction (node_a.store.environment, nullptr, true); return result;
node_a.wallets.foreach_representative (transaction, [&result, &block_a, &peer_a, &node_a, &transaction] (rai::public_key const & pub_a, rai::raw_key const & prv_a)
{
auto sequence (node_a.store.sequence_atomic_inc (transaction, pub_a));
rai::vote vote (pub_a, prv_a, sequence, block_a->clone ());
rai::confirm_ack confirm (vote);
std::shared_ptr <std::vector <uint8_t>> bytes (new std::vector <uint8_t>);
{
rai::vectorstream stream (*bytes);
confirm.serialize (stream);
}
node_a.network.confirm_block (confirm, bytes, peer_a);
result = true;
});
}
return result;
} }
void rai::network::republish_block (rai::block & block) void rai::network::republish_block (rai::block & block)
@ -249,7 +234,7 @@ void rai::network::broadcast_confirm_req (rai::block const & block_a)
auto list (node.peers.list ()); auto list (node.peers.list ());
for (auto i (list.begin ()), j (list.end ()); i != j; ++i) for (auto i (list.begin ()), j (list.end ()); i != j; ++i)
{ {
node.network.send_confirm_req (i->endpoint, block_a); node.network.send_confirm_req (*i, block_a);
} }
if (node.config.logging.network_logging ()) if (node.config.logging.network_logging ())
{ {
@ -1419,14 +1404,14 @@ std::vector <rai::endpoint> rai::peer_container::list_sqrt ()
return result; return result;
} }
std::vector <rai::peer_information> rai::peer_container::list () std::vector <rai::endpoint> rai::peer_container::list ()
{ {
std::vector <rai::peer_information> result; std::vector <rai::endpoint> result;
std::lock_guard <std::mutex> lock (mutex); std::lock_guard <std::mutex> lock (mutex);
result.reserve (peers.size ()); result.reserve (peers.size ());
for (auto i (peers.begin ()), j (peers.end ()); i != j; ++i) for (auto i (peers.begin ()), j (peers.end ()); i != j; ++i)
{ {
result.push_back (*i); result.push_back (i->endpoint);
} }
std::random_shuffle (result.begin (), result.end ()); std::random_shuffle (result.begin (), result.end ());
return result; return result;

View file

@ -182,7 +182,7 @@ public:
// Request a list of the top known representatives // Request a list of the top known representatives
std::vector <peer_information> representatives (size_t); std::vector <peer_information> representatives (size_t);
// List of all peers // List of all peers
std::vector <peer_information> list (); std::vector <rai::endpoint> list ();
// A list of random peers with size the square root of total peer count // A list of random peers with size the square root of total peer count
std::vector <rai::endpoint> list_sqrt (); std::vector <rai::endpoint> list_sqrt ();
// Get the next peer for attempting bootstrap // Get the next peer for attempting bootstrap

View file

@ -893,7 +893,7 @@ void rai::rpc_handler::peers ()
{ {
boost::property_tree::ptree entry; boost::property_tree::ptree entry;
std::stringstream text; std::stringstream text;
text << i->endpoint; text << *i;
entry.put ("", text.str ()); entry.put ("", text.str ());
peers_l.push_back (std::make_pair ("", entry)); peers_l.push_back (std::make_pair ("", entry));
} }