summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Taaki <genjix@riseup.net>2014-03-23 12:16:19 (GMT)
committer Amir Taaki <genjix@riseup.net>2014-03-23 12:17:01 (GMT)
commit16c81b855475105d616b30542104d8ee6a1acf30 (patch)
tree94ba4e613f749a1fad97e14711e7469ed193ee44
parent199b846795920f727c854d2cd4fddba0939dba2e (diff)
looping start. keeps retrying every 30 secs.
-rw-r--r--src/worker/node_impl.cpp36
-rw-r--r--src/worker/node_impl.hpp5
2 files changed, 28 insertions, 13 deletions
diff --git a/src/worker/node_impl.cpp b/src/worker/node_impl.cpp
index 5670348..5b61b05 100644
--- a/src/worker/node_impl.cpp
+++ b/src/worker/node_impl.cpp
@@ -6,12 +6,15 @@
namespace obelisk {
+using namespace boost::posix_time;
using namespace bc;
using std::placeholders::_1;
using std::placeholders::_2;
using std::placeholders::_3;
using std::placeholders::_4;
+const time_duration retry_start_duration = seconds(30);
+
void log_to_file(std::ofstream& file, log_level level,
const std::string& domain, const std::string& body, bool log_requests)
{
@@ -73,7 +76,8 @@ node_impl::node_impl()
txpool_(mem_pool_, chain_),
indexer_(mem_pool_),
session_(mem_pool_, {
- handshake_, protocol_, chain_, poller_, txpool_})
+ handshake_, protocol_, chain_, poller_, txpool_}),
+ retry_start_timer_(mem_pool_.service())
{
}
@@ -131,22 +135,28 @@ bool node_impl::start(config_type& config)
log_info() << "Adding node: " << node.hostname << " " << node.port;
protocol_.maintain_connection(node.hostname, node.port);
}
+ start_session();
+ return true;
+}
+void node_impl::start_session()
+{
// Start session
- std::promise<std::error_code> ec_session;
- auto session_started =
- [&](const std::error_code& ec)
+ auto session_started = [this](const std::error_code& ec)
{
- ec_session.set_value(ec);
+ if (ec)
+ wait_and_retry_start(ec);
};
session_.start(session_started);
- // Query the error_code and wait for startup completion.
- ec = ec_session.get_future().get();
- if (ec)
- {
- log_error() << "Unable to start session: " << ec.message();
- return false;
- }
- return true;
+}
+void node_impl::wait_and_retry_start(const std::error_code& ec)
+{
+ BITCOIN_ASSERT(ec);
+ log_error() << "Unable to start session: " << ec.message();
+ log_error() << "Retrying in "
+ << retry_start_duration.seconds() << " seconds.";
+ retry_start_timer_.expires_from_now(retry_start_duration);
+ retry_start_timer_.async_wait(
+ std::bind(&node_impl::start_session, this));
}
bool node_impl::stop()
diff --git a/src/worker/node_impl.hpp b/src/worker/node_impl.hpp
index 9231281..d3bed3b 100644
--- a/src/worker/node_impl.hpp
+++ b/src/worker/node_impl.hpp
@@ -35,6 +35,9 @@ private:
typedef std::vector<block_notify_callback> block_notify_list;
typedef std::vector<transaction_notify_callback> transaction_notify_list;
+ void start_session();
+ void wait_and_retry_start(const std::error_code& ec);
+
void monitor_tx(const std::error_code& ec, bc::channel_ptr node);
void recv_transaction(const std::error_code& ec,
const bc::transaction_type& tx, bc::channel_ptr node);
@@ -62,6 +65,8 @@ private:
block_notify_list notify_blocks_;
transaction_notify_list notify_txs_;
+
+ boost::asio::deadline_timer retry_start_timer_;
};
} // namespace obelisk