diff --git a/rai/core/core.cpp b/rai/core/core.cpp index 66903b6c..a8f8d176 100644 --- a/rai/core/core.cpp +++ b/rai/core/core.cpp @@ -367,8 +367,15 @@ void rai::network::receive_action (boost::system::error_code const & error, size } } -void rai::network::merge_peers (std::shared_ptr > const & bytes_a, std::array const & peers_a) +void rai::network::merge_peers (std::array const & peers_a) { + rai::keepalive_req req_message; + client.peers.random_fill (req_message.peers); + std::shared_ptr > req_bytes (new std::vector ); + { + rai::vectorstream stream (*req_bytes); + req_message.serialize (stream); + } for (auto i (peers_a.begin ()), j (peers_a.end ()); i != j; ++i) // Amplify attack, send to the same IP many times { if (!client.peers.contacting_peer (*i) && *i != endpoint ()) @@ -379,7 +386,7 @@ void rai::network::merge_peers (std::shared_ptr > const & } auto & client_l (client); auto endpoint (*i); - send_buffer (bytes_a->data (), bytes_a->size (), endpoint, [bytes_a, &client_l] (boost::system::error_code const & error, size_t size_a) + send_buffer (req_bytes->data (), req_bytes->size (), endpoint, [req_bytes, &client_l] (boost::system::error_code const & error, size_t size_a) { if (network_logging ()) { @@ -3635,14 +3642,7 @@ public: } } }); - rai::keepalive_req req_message; - req_message.peers = ack_message.peers; - std::shared_ptr > req_bytes (new std::vector ); - { - rai::vectorstream stream (*req_bytes); - req_message.serialize (stream); - } - client.network.merge_peers (req_bytes, message_a.peers); + client.network.merge_peers (message_a.peers); if (network_keepalive_logging ()) { client.log.add (boost::str (boost::format ("Sending keepalive ack to %1%") % sender)); @@ -3654,14 +3654,7 @@ public: { client.log.add (boost::str (boost::format ("Received keepalive ack from %1%") % sender)); } - rai::keepalive_req req_message; - client.peers.random_fill (req_message.peers); - std::shared_ptr > req_bytes (new std::vector ); - { - rai::vectorstream stream (*req_bytes); - req_message.serialize (stream); - } - client.network.merge_peers (req_bytes, message_a.peers); + client.network.merge_peers (message_a.peers); client.peers.incoming_from_peer (sender); if (!known_peer && message_a.checksum != client.ledger.checksum (0, std::numeric_limits ::max ())) { diff --git a/rai/core/core.hpp b/rai/core/core.hpp index 3876bcc6..bc937796 100644 --- a/rai/core/core.hpp +++ b/rai/core/core.hpp @@ -442,7 +442,7 @@ namespace rai { void rpc_action (boost::system::error_code const &, size_t); void publish_block (rai::endpoint const &, std::unique_ptr ); void confirm_block (std::unique_ptr , uint64_t); - void merge_peers (std::shared_ptr > const &, std::array const &); + void merge_peers (std::array const &); void send_keepalive (rai::endpoint const &); void send_confirm_req (rai::endpoint const &, rai::block const &); void send_buffer (uint8_t const *, size_t, rai::endpoint const &, std::function );