diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index 636294a9..53cffa92 100644 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -162,7 +162,8 @@ std::unique_ptr rai::push_synchronization::retrieve (rai::transacti rai::bootstrap_client::bootstrap_client (std::shared_ptr node_a, std::shared_ptr attempt_a) : node (node_a), attempt (attempt_a), -socket (node_a->network.service) +socket (node_a->network.service), +connected (false) { } @@ -185,6 +186,7 @@ void rai::bootstrap_client::run (boost::asio::ip::tcp::endpoint const & endpoint { if (!ec) { + this_l->connected = true; if (!this_l->attempt->connected.exchange (true)) { this_l->connect_action (); @@ -203,6 +205,18 @@ void rai::bootstrap_client::run (boost::asio::ip::tcp::endpoint const & endpoint this_l->node->peers.bootstrap_failed (rai::endpoint (endpoint_a.address (), endpoint_a.port ())); } }); + std::weak_ptr this_w (this_l); + node->alarm.add (std::chrono::system_clock::now () + std::chrono::seconds(5), [this_w] () + { + auto this_l (this_w.lock ()); + if (this_l != nullptr) + { + if (!this_l->connected) + { + this_l->socket.close (); + } + } + }); } void rai::bootstrap_client::connect_action () diff --git a/rai/node/bootstrap.hpp b/rai/node/bootstrap.hpp index f0d774d0..2b054fc6 100644 --- a/rai/node/bootstrap.hpp +++ b/rai/node/bootstrap.hpp @@ -69,6 +69,7 @@ public: std::shared_ptr node; std::shared_ptr attempt; boost::asio::ip::tcp::socket socket; + bool connected; }; class frontier_req_client : public std::enable_shared_from_this { @@ -219,4 +220,4 @@ public: std::vector send_buffer; size_t count; }; -} \ No newline at end of file +}