From b5770249d4a51617aebf2f4cdcb7d20159b842d0 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Sat, 1 Apr 2017 17:18:31 -0500 Subject: [PATCH] Refactoring confirm functions to be able to operate on a vote instead of a block. --- rai/core_test/node.cpp | 2 +- rai/node/node.cpp | 38 ++++++++++++++++++++++---------------- rai/node/node.hpp | 2 +- rai/qt/qt.cpp | 8 ++------ 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/rai/core_test/node.cpp b/rai/core_test/node.cpp index ab3b55e6..61eb39a5 100644 --- a/rai/core_test/node.cpp +++ b/rai/core_test/node.cpp @@ -1024,7 +1024,7 @@ TEST (node, fork_no_vote_quorum) rai::vectorstream stream (*bytes); confirm.serialize (stream); } - node2.network.confirm_block (confirm, bytes, node3.network.endpoint ()); + node2.network.confirm_send (confirm, bytes, node3.network.endpoint ()); while (node3.network.confirm_ack_count < 3) { system.poll (); diff --git a/rai/node/node.cpp b/rai/node/node.cpp index 05b23cc3..2a38ba9d 100755 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -160,7 +160,22 @@ void rai::network::rebroadcast_reps (rai::block & block_a) } template -bool confirm_broadcast (rai::node & node_a, T & list_a, std::unique_ptr block_a) +void confirm_broadcast (rai::node & node_a, T & list_a, rai::vote & vote_a) +{ + rai::confirm_ack confirm (vote_a); + std::shared_ptr > bytes (new std::vector ); + { + rai::vectorstream stream (*bytes); + confirm.serialize (stream); + } + for (auto j (list_a.begin ()), m (list_a.end ()); j != m; ++j) + { + node_a.network.confirm_send (confirm, bytes, *j); + } +} + +template +bool confirm_block (rai::node & node_a, T & list_a, std::unique_ptr block_a) { bool result (false); if (node_a.config.enable_voting) @@ -171,27 +186,18 @@ bool confirm_broadcast (rai::node & node_a, T & list_a, std::unique_ptr clone ()); - rai::confirm_ack confirm (vote); - std::shared_ptr > bytes (new std::vector ); - { - rai::vectorstream stream (*bytes); - confirm.serialize (stream); - } - for (auto j (list_a.begin ()), m (list_a.end ()); j != m; ++j) - { - node_a.network.confirm_block (confirm, bytes, *j); - } + confirm_broadcast (node_a, list_a, vote); }); } return result; } template <> -bool confirm_broadcast (rai::node & node_a, rai::endpoint & peer_a, std::unique_ptr block_a) +bool confirm_block (rai::node & node_a, rai::endpoint & peer_a, std::unique_ptr block_a) { std::array endpoints; endpoints [0] = peer_a; - auto result (confirm_broadcast (node_a, endpoints, std::move (block_a))); + auto result (confirm_block (node_a, endpoints, std::move (block_a))); return result; } @@ -201,7 +207,7 @@ void rai::network::republish_block (rai::block & block) auto hash (block.hash ()); auto list (node.peers.list ()); // If we're a representative, broadcast a signed confirm, otherwise an unsigned publish - if (!confirm_broadcast (node, list, block.clone ())) + if (!confirm_block (node, list, block.clone ())) { rai::publish message (block.clone ()); std::shared_ptr > bytes (new std::vector ); @@ -343,7 +349,7 @@ public: node.process_receive_republish (message_a.block->clone ()); if (node.ledger.block_exists (message_a.block->hash ())) { - confirm_broadcast (node, sender, message_a.block->clone ()); + confirm_block (node, sender, message_a.block->clone ()); } } void confirm_ack (rai::confirm_ack const & message_a) override @@ -1194,7 +1200,7 @@ void rai::gap_cache::purge_old () } } -void rai::network::confirm_block (rai::confirm_ack const & confirm_a, std::shared_ptr > bytes_a, rai::endpoint const & endpoint_a) +void rai::network::confirm_send (rai::confirm_ack const & confirm_a, std::shared_ptr > bytes_a, rai::endpoint const & endpoint_a) { if (node.config.logging.network_publish_logging ()) { diff --git a/rai/node/node.hpp b/rai/node/node.hpp index c0952ea9..ba0646ef 100644 --- a/rai/node/node.hpp +++ b/rai/node/node.hpp @@ -271,7 +271,7 @@ public: void republish_block (rai::block &); void republish (rai::block_hash const &, std::shared_ptr >, rai::endpoint); void publish_broadcast (std::vector &, std::unique_ptr ); - void confirm_block (rai::confirm_ack const &, std::shared_ptr >, rai::endpoint const &); + void confirm_send (rai::confirm_ack const &, std::shared_ptr >, rai::endpoint const &); void merge_peers (std::array const &); void send_keepalive (rai::endpoint const &); void broadcast_confirm_req (rai::block const &); diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index 82f65fc9..3d2c0886 100644 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -1343,13 +1343,9 @@ void rai_qt::advanced_actions::refresh_peers () for (auto i: list) { std::stringstream endpoint; - endpoint << i.endpoint.address ().to_string (); + endpoint << i.address ().to_string (); endpoint << ':'; - endpoint << i.endpoint.port (); - endpoint << ' '; - endpoint << i.last_contact; - endpoint << ' '; - endpoint << i.last_attempt; + endpoint << i.port (); QString qendpoint (endpoint.str().c_str ()); peers << qendpoint; }