Tracking node versions in peer_container.
This commit is contained in:
parent
b3a8e89f9e
commit
32b84a3ccb
7 changed files with 42 additions and 40 deletions
|
@ -84,8 +84,8 @@ TEST (network, send_keepalive)
|
|||
auto peers2 (node1->peers.list ());
|
||||
ASSERT_EQ (1, peers1.size ());
|
||||
ASSERT_EQ (1, peers2.size ());
|
||||
ASSERT_NE (peers1.end (), std::find_if (peers1.begin (), peers1.end (), [&node1] (rai::peer_information const & information_a) {return information_a.endpoint == node1->network.endpoint ();}));
|
||||
ASSERT_NE (peers2.end (), std::find_if (peers2.begin (), peers2.end (), [&system] (rai::peer_information const & information_a) {return information_a.endpoint == system.nodes [0]->network.endpoint ();}));
|
||||
ASSERT_NE (peers1.end (), std::find_if (peers1.begin (), peers1.end (), [&node1] (rai::endpoint const & information_a) {return information_a == node1->network.endpoint ();}));
|
||||
ASSERT_NE (peers2.end (), std::find_if (peers2.begin (), peers2.end (), [&system] (rai::endpoint const & information_a) {return information_a == system.nodes [0]->network.endpoint ();}));
|
||||
node1->stop ();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,9 @@ TEST (peer_container, no_recontact)
|
|||
ASSERT_EQ (0, peers.size ());
|
||||
peers.peer_observer = [&observed_peer] (rai::endpoint const &) {++observed_peer;};
|
||||
peers.disconnect_observer = [&observed_disconnect] () {observed_disconnect = true;};
|
||||
ASSERT_FALSE (peers.insert (endpoint1));
|
||||
ASSERT_FALSE (peers.insert (endpoint1, 0));
|
||||
ASSERT_EQ (1, peers.size ());
|
||||
ASSERT_TRUE (peers.insert (endpoint1));
|
||||
ASSERT_TRUE (peers.insert (endpoint1, 0));
|
||||
auto remaining (peers.purge_list (std::chrono::system_clock::now () + std::chrono::seconds (5)));
|
||||
ASSERT_TRUE (remaining.empty ());
|
||||
ASSERT_EQ (1, observed_peer);
|
||||
|
@ -30,7 +30,7 @@ TEST (peer_container, no_self_incoming)
|
|||
{
|
||||
rai::endpoint self (boost::asio::ip::address_v6::loopback (), 10000);
|
||||
rai::peer_container peers (self);
|
||||
peers.insert (self);
|
||||
peers.insert (self, 0);
|
||||
ASSERT_TRUE (peers.peers.empty ());
|
||||
}
|
||||
|
||||
|
@ -38,20 +38,20 @@ TEST (peer_container, no_self_contacting)
|
|||
{
|
||||
rai::endpoint self (boost::asio::ip::address_v6::loopback (), 10000);
|
||||
rai::peer_container peers (self);
|
||||
peers.insert (self);
|
||||
peers.insert (self, 0);
|
||||
ASSERT_TRUE (peers.peers.empty ());
|
||||
}
|
||||
|
||||
TEST (peer_container, reserved_peers_no_contact)
|
||||
{
|
||||
rai::peer_container peers (rai::endpoint {});
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0x00000001)), 10000)));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xc0000201)), 10000)));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xc6336401)), 10000)));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xcb007101)), 10000)));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xe9fc0001)), 10000)));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xf0000001)), 10000)));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xffffffff)), 10000)));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0x00000001)), 10000), 0));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xc0000201)), 10000), 0));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xc6336401)), 10000), 0));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xcb007101)), 10000), 0));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xe9fc0001)), 10000), 0));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xf0000001)), 10000), 0));
|
||||
ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xffffffff)), 10000), 0));
|
||||
ASSERT_EQ (0, peers.size ());
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ TEST (peer_container, fill_random_full)
|
|||
rai::peer_container peers (rai::endpoint {});
|
||||
for (auto i (0); i < 100; ++i)
|
||||
{
|
||||
peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), i));
|
||||
peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), i), 0);
|
||||
}
|
||||
std::array <rai::endpoint, 8> target;
|
||||
std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000));
|
||||
|
@ -99,7 +99,7 @@ TEST (peer_container, fill_random_part)
|
|||
auto half (target.size () / 2);
|
||||
for (auto i (0); i < half; ++i)
|
||||
{
|
||||
peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), i + 1));
|
||||
peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), i + 1), 0);
|
||||
}
|
||||
std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000));
|
||||
peers.random_fill (target);
|
||||
|
@ -115,7 +115,7 @@ TEST (peer_container, list_sqrt)
|
|||
ASSERT_TRUE (list1.empty ());
|
||||
for (auto i (0); i < 1000; ++i)
|
||||
{
|
||||
ASSERT_FALSE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000 + i)));
|
||||
ASSERT_FALSE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000 + i), 0));
|
||||
}
|
||||
auto list2 (peers.list_sqrt ());
|
||||
ASSERT_EQ (64, list2.size ());
|
||||
|
@ -124,15 +124,15 @@ TEST (peer_container, list_sqrt)
|
|||
TEST (peer_container, rep_weight)
|
||||
{
|
||||
rai::peer_container peers (rai::endpoint {});
|
||||
peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 24001));
|
||||
peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 24001), 0);
|
||||
ASSERT_TRUE (peers.representatives (1).empty ());
|
||||
rai::endpoint endpoint0 (boost::asio::ip::address_v6::loopback (), 24000);
|
||||
rai::endpoint endpoint1 (boost::asio::ip::address_v6::loopback (), 24002);
|
||||
rai::endpoint endpoint2 (boost::asio::ip::address_v6::loopback (), 24003);
|
||||
rai::amount amount (100);
|
||||
peers.insert (endpoint2);
|
||||
peers.insert (endpoint0);
|
||||
peers.insert (endpoint1);
|
||||
peers.insert (endpoint2, 0);
|
||||
peers.insert (endpoint0, 0);
|
||||
peers.insert (endpoint1, 0);
|
||||
peers.rep_response (endpoint0, amount);
|
||||
auto reps (peers.representatives (1));
|
||||
ASSERT_EQ (1, reps.size ());
|
||||
|
|
|
@ -348,7 +348,7 @@ public:
|
|||
BOOST_LOG (node.log) << boost::str (boost::format ("Received keepalive message from %1%") % sender);
|
||||
}
|
||||
++node.network.incoming.keepalive;
|
||||
node.peers.contacted (sender);
|
||||
node.peers.contacted (sender, message_a.version_using);
|
||||
node.network.merge_peers (message_a.peers);
|
||||
}
|
||||
void publish (rai::publish const & message_a) override
|
||||
|
@ -358,8 +358,8 @@ public:
|
|||
BOOST_LOG (node.log) << boost::str (boost::format ("Publish message from %1% for %2%") % sender % message_a.block->hash ().to_string ());
|
||||
}
|
||||
++node.network.incoming.publish;
|
||||
node.peers.contacted (sender);
|
||||
node.peers.insert (sender);
|
||||
node.peers.contacted (sender, message_a.version_using);
|
||||
node.peers.insert (sender, message_a.version_using);
|
||||
node.process_receive_republish (message_a.block);
|
||||
}
|
||||
void confirm_req (rai::confirm_req const & message_a) override
|
||||
|
@ -369,8 +369,8 @@ public:
|
|||
BOOST_LOG (node.log) << boost::str (boost::format ("Confirm_req message from %1% for %2%") % sender % message_a.block->hash ().to_string ());
|
||||
}
|
||||
++node.network.incoming.confirm_req;
|
||||
node.peers.contacted (sender);
|
||||
node.peers.insert (sender);
|
||||
node.peers.contacted (sender, message_a.version_using);
|
||||
node.peers.insert (sender, message_a.version_using);
|
||||
node.process_receive_republish (message_a.block);
|
||||
if (node.ledger.block_exists (message_a.block->hash ()))
|
||||
{
|
||||
|
@ -384,8 +384,8 @@ public:
|
|||
BOOST_LOG (node.log) << boost::str (boost::format ("Received confirm_ack message from %1% for %2%") % sender % message_a.vote.block->hash ().to_string ());
|
||||
}
|
||||
++node.network.incoming.confirm_ack;
|
||||
node.peers.contacted (sender);
|
||||
node.peers.insert (sender);
|
||||
node.peers.contacted (sender, message_a.version_using);
|
||||
node.peers.insert (sender, message_a.version_using);
|
||||
node.process_receive_republish (message_a.vote.block);
|
||||
node.vote_processor.vote (message_a.vote, sender);
|
||||
}
|
||||
|
@ -2306,7 +2306,7 @@ void rai::peer_container::rep_request (rai::endpoint const & endpoint_a)
|
|||
}
|
||||
}
|
||||
|
||||
bool rai::peer_container::insert (rai::endpoint const & endpoint_a)
|
||||
bool rai::peer_container::insert (rai::endpoint const & endpoint_a, unsigned version_a)
|
||||
{
|
||||
auto unknown (false);
|
||||
auto result (not_a_peer (endpoint_a));
|
||||
|
@ -2324,7 +2324,7 @@ bool rai::peer_container::insert (rai::endpoint const & endpoint_a)
|
|||
}
|
||||
else
|
||||
{
|
||||
peers.insert (rai::peer_information (endpoint_a));
|
||||
peers.insert (rai::peer_information (endpoint_a, version_a));
|
||||
unknown = true;
|
||||
}
|
||||
}
|
||||
|
@ -2404,14 +2404,15 @@ bool rai::reserved_address (rai::endpoint const & endpoint_a)
|
|||
return result;
|
||||
}
|
||||
|
||||
rai::peer_information::peer_information (rai::endpoint const & endpoint_a) :
|
||||
rai::peer_information::peer_information (rai::endpoint const & endpoint_a, unsigned network_version_a) :
|
||||
endpoint (endpoint_a),
|
||||
last_contact (std::chrono::system_clock::now ()),
|
||||
last_attempt (last_contact),
|
||||
last_bootstrap_attempt (std::chrono::system_clock::time_point ()),
|
||||
last_rep_request (std::chrono::system_clock::time_point ()),
|
||||
last_rep_response (std::chrono::system_clock::time_point ()),
|
||||
rep_weight (0)
|
||||
rep_weight (0),
|
||||
network_version (network_version_a)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2433,7 +2434,7 @@ disconnect_observer ([] () {})
|
|||
{
|
||||
}
|
||||
|
||||
void rai::peer_container::contacted (rai::endpoint const & endpoint_a)
|
||||
void rai::peer_container::contacted (rai::endpoint const & endpoint_a, unsigned version_a)
|
||||
{
|
||||
auto endpoint_l (endpoint_a);
|
||||
if (endpoint_l.address ().is_v4 ())
|
||||
|
@ -2441,7 +2442,7 @@ void rai::peer_container::contacted (rai::endpoint const & endpoint_a)
|
|||
endpoint_l = rai::endpoint (boost::asio::ip::address_v6::v4_mapped (endpoint_l.address ().to_v4 ()), endpoint_l.port ());
|
||||
}
|
||||
assert (endpoint_l.address ().is_v6 ());
|
||||
insert (endpoint_l);
|
||||
insert (endpoint_l, version_a);
|
||||
}
|
||||
|
||||
std::ostream & operator << (std::ostream & stream_a, std::chrono::system_clock::time_point const & time_a)
|
||||
|
|
|
@ -151,7 +151,7 @@ class work_pool;
|
|||
class peer_information
|
||||
{
|
||||
public:
|
||||
peer_information (rai::endpoint const &);
|
||||
peer_information (rai::endpoint const &, unsigned);
|
||||
peer_information (rai::endpoint const &, std::chrono::system_clock::time_point const &, std::chrono::system_clock::time_point const &);
|
||||
rai::endpoint endpoint;
|
||||
std::chrono::system_clock::time_point last_contact;
|
||||
|
@ -160,19 +160,20 @@ public:
|
|||
std::chrono::system_clock::time_point last_rep_request;
|
||||
std::chrono::system_clock::time_point last_rep_response;
|
||||
rai::amount rep_weight;
|
||||
unsigned network_version;
|
||||
};
|
||||
class peer_container
|
||||
{
|
||||
public:
|
||||
peer_container (rai::endpoint const &);
|
||||
// We were contacted by endpoint, update peers
|
||||
void contacted (rai::endpoint const &);
|
||||
void contacted (rai::endpoint const &, unsigned);
|
||||
// Unassigned, reserved, self
|
||||
bool not_a_peer (rai::endpoint const &);
|
||||
// Returns true if peer was already known
|
||||
bool known_peer (rai::endpoint const &);
|
||||
// Notify of peer we received from
|
||||
bool insert (rai::endpoint const &);
|
||||
bool insert (rai::endpoint const &, unsigned);
|
||||
std::unordered_set <rai::endpoint> random_set (size_t);
|
||||
void random_fill (std::array <rai::endpoint, 8> &);
|
||||
// Request a list of the top known representatives
|
||||
|
|
|
@ -1608,9 +1608,9 @@ wallet (wallet_a)
|
|||
void rai_qt::advanced_actions::refresh_peers ()
|
||||
{
|
||||
auto list (wallet.node.peers.list ());
|
||||
std::sort (list.begin (), list.end (), [] (rai::peer_information const & lhs, rai::peer_information const & rhs)
|
||||
std::sort (list.begin (), list.end (), [] (rai::endpoint const & lhs, rai::endpoint const & rhs)
|
||||
{
|
||||
return lhs.endpoint < rhs.endpoint;
|
||||
return lhs < rhs;
|
||||
});
|
||||
QStringList peers;
|
||||
for (auto i: list)
|
||||
|
|
|
@ -33,7 +33,7 @@ TEST (wallet, status)
|
|||
auto wallet (std::make_shared <rai_qt::wallet> (*test_application, processor, *system.nodes [0], wallet_l, key.pub));
|
||||
wallet->start ();
|
||||
ASSERT_EQ ("Status: Disconnected", wallet->status->text ().toStdString ());
|
||||
system.nodes [0]->peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000));
|
||||
system.nodes [0]->peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000), 0);
|
||||
ASSERT_NE ("Status: Synchronizing", wallet->status->text ().toStdString ());
|
||||
auto iterations (0);
|
||||
while (wallet->status->text ().toStdString () != "Status: Synchronizing")
|
||||
|
|
|
@ -363,7 +363,7 @@ TEST (peer_container, random_set)
|
|||
rai::peer_container container (rai::endpoint (loopback, 24000));
|
||||
for (auto i (0); i < 200; ++i)
|
||||
{
|
||||
container.contacted (rai::endpoint (loopback, 24001 + i));
|
||||
container.contacted (rai::endpoint (loopback, 24001 + i), 0);
|
||||
}
|
||||
auto old (std::chrono::system_clock::now ());
|
||||
for (auto i (0); i < 10000; ++i)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue