Skip to content

Commit

Permalink
Reinstate preconfigured keepalives (nanocurrency#1854)
Browse files Browse the repository at this point in the history
* Reinstate preconfigured keepalives

* Remove unused constants

* No need to insert preconfigured peers into container

* Remove unused param
  • Loading branch information
cryptocode authored and Guilherme Lawless committed Apr 15, 2019
1 parent c8863b3 commit e9a6e2a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ void nano::network::send_keepalive (nano::transport::channel const & channel_a)
channel_a.send (message);
}

void nano::node::keepalive (std::string const & address_a, uint16_t port_a, bool preconfigured_peer_a)
void nano::node::keepalive (std::string const & address_a, uint16_t port_a)
{
auto node_l (shared_from_this ());
network.resolver.async_resolve (boost::asio::ip::udp::resolver::query (address_a, std::to_string (port_a)), [node_l, address_a, port_a, preconfigured_peer_a](boost::system::error_code const & ec, boost::asio::ip::udp::resolver::iterator i_a) {
network.resolver.async_resolve (boost::asio::ip::udp::resolver::query (address_a, std::to_string (port_a)), [node_l, address_a, port_a](boost::system::error_code const & ec, boost::asio::ip::udp::resolver::iterator i_a) {
if (!ec)
{
for (auto i (i_a), n (boost::asio::ip::udp::resolver::iterator{}); i != n; ++i)
Expand Down Expand Up @@ -1597,7 +1597,7 @@ void nano::node::keepalive_preconfigured (std::vector<std::string> const & peers
{
for (auto i (peers_a.begin ()), n (peers_a.end ()); i != n; ++i)
{
keepalive (*i, network_params.default_node_port, true);
keepalive (*i, network_params.default_node_port);
}
}

Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class node : public std::enable_shared_from_this<nano::node>
alarm.io_ctx.post (action_a);
}
bool copy_with_compaction (boost::filesystem::path const &);
void keepalive (std::string const &, uint16_t, bool = false);
void keepalive (std::string const &, uint16_t);
void start ();
void stop ();
std::shared_ptr<nano::node> shared ();
Expand Down
8 changes: 7 additions & 1 deletion nano/node/repcrawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ void nano::rep_crawler::ongoing_crawl ()
{
auto now (std::chrono::steady_clock::now ());
query (get_crawl_targets ());
auto sufficient_weight (total_weight_internal () > node.config.online_weight_minimum.number ());
// If online weight drops below minimum, reach out to preconfigured peers
if (!sufficient_weight)
{
node.keepalive_preconfigured (node.config.preconfigured_peers);
}
// Reduce crawl frequency when there's enough total peer weight
unsigned next_run_seconds = (total_weight_internal () > node.config.online_weight_minimum.number ()) ? 7 : 3;
unsigned next_run_seconds = sufficient_weight ? 7 : 3;
std::weak_ptr<nano::node> node_w (node.shared ());
node.alarm.add (now + std::chrono::seconds (next_run_seconds), [node_w, this]() {
if (auto node_l = node_w.lock ())
Expand Down

0 comments on commit e9a6e2a

Please sign in to comment.