diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index 5a0def46..62da3855 100755 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -223,6 +223,13 @@ void rai::bootstrap_client::run () } void rai::bootstrap_client::frontier_request () +{ + auto this_l (shared_from_this ()); + auto client_l (std::make_shared (this_l)); + client_l->run (); +} + +void rai::frontier_req_client::run () { std::unique_ptr request (new rai::frontier_req); request->start.clear (); @@ -234,31 +241,24 @@ void rai::bootstrap_client::frontier_request () request->serialize (stream); } auto this_l (shared_from_this ()); - start_timeout (); - boost::asio::async_write (socket, boost::asio::buffer (send_buffer->data (), send_buffer->size ()), [this_l, send_buffer] (boost::system::error_code const & ec, size_t size_a) + connection->start_timeout (); + boost::asio::async_write (connection->socket, boost::asio::buffer (send_buffer->data (), send_buffer->size ()), [this_l, send_buffer] (boost::system::error_code const & ec, size_t size_a) { - this_l->stop_timeout (); - this_l->sent_request (ec, size_a); + this_l->connection->stop_timeout (); + if (!ec) + { + this_l->receive_frontier (); + } + else + { + if (this_l->connection->node->config.logging.network_logging ()) + { + BOOST_LOG (this_l->connection->node->log) << boost::str (boost::format ("Error while sending bootstrap request %1%") % ec.message ()); + } + } }); } -void rai::bootstrap_client::sent_request (boost::system::error_code const & ec, size_t size_a) -{ - if (!ec) - { - auto this_l (shared_from_this ()); - auto client_l (std::make_shared (this_l)); - client_l->receive_frontier (); - } - else - { - if (node->config.logging.network_logging ()) - { - BOOST_LOG (node->log) << boost::str (boost::format ("Error while sending bootstrap request %1%") % ec.message ()); - } - } -} - std::shared_ptr rai::bootstrap_client::shared () { return shared_from_this (); @@ -283,6 +283,7 @@ rai::frontier_req_client::~frontier_req_client () BOOST_LOG (connection->node->log) << "frontier_req failed, reattempting"; } connection->attempt->state = rai::attempt_state::starting; + connection->attempt->pulls.clear (); } else { diff --git a/rai/node/bootstrap.hpp b/rai/node/bootstrap.hpp index 7d895d62..d8ee56f8 100644 --- a/rai/node/bootstrap.hpp +++ b/rai/node/bootstrap.hpp @@ -88,6 +88,7 @@ class frontier_req_client : public std::enable_shared_from_this const &); ~frontier_req_client (); + void run (); void receive_frontier (); void received_frontier (boost::system::error_code const &, size_t); void request_account (rai::account const &, rai::block_hash const &);