Skip to content

Commit

Permalink
Initializes receive and completion times to always hold a valid value (
Browse files Browse the repository at this point in the history
  • Loading branch information
dsiganos authored Dec 8, 2021
1 parent d0b21c1 commit d9594fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions nano/node/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ nano::socket::socket (nano::node & node_a) :
tcp_socket{ node_a.io_ctx },
node{ node_a },
next_deadline{ std::numeric_limits<uint64_t>::max () },
last_completion_time{ 0 },
last_receive_time{ 0 },
last_completion_time_or_init{ nano::seconds_since_epoch () },
last_receive_time_or_init{ nano::seconds_since_epoch () },
io_timeout{ node_a.config.tcp_io_timeout },
silent_connection_tolerance_time{ node_a.network_params.network.silent_connection_tolerance_time }
{
Expand Down Expand Up @@ -124,12 +124,12 @@ void nano::socket::start_timer (std::chrono::seconds deadline_a)

void nano::socket::stop_timer ()
{
last_completion_time = nano::seconds_since_epoch ();
last_completion_time_or_init = nano::seconds_since_epoch ();
}

void nano::socket::update_last_receive_time ()
{
last_receive_time = nano::seconds_since_epoch ();
last_receive_time_or_init = nano::seconds_since_epoch ();
}

void nano::socket::checkup ()
Expand All @@ -140,12 +140,12 @@ void nano::socket::checkup ()
{
uint64_t now (nano::seconds_since_epoch ());
auto condition_to_disconnect{ false };
if (this_l->is_realtime_connection () && now - this_l->last_receive_time > this_l->silent_connection_tolerance_time.count ())
if (this_l->is_realtime_connection () && (now - this_l->last_receive_time_or_init) > this_l->silent_connection_tolerance_time.count ())
{
this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_silent_connection_drop, nano::stat::dir::in);
condition_to_disconnect = true;
}
if (this_l->next_deadline != std::numeric_limits<uint64_t>::max () && now - this_l->last_completion_time > this_l->next_deadline)
if (this_l->next_deadline != std::numeric_limits<uint64_t>::max () && (now - this_l->last_completion_time_or_init) > this_l->next_deadline)
{
this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_io_timeout_drop, nano::stat::dir::in);
condition_to_disconnect = true;
Expand Down
4 changes: 2 additions & 2 deletions nano/node/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ class socket : public std::enable_shared_from_this<nano::socket>
boost::asio::ip::tcp::endpoint remote;

std::atomic<uint64_t> next_deadline;
std::atomic<uint64_t> last_completion_time;
std::atomic<uint64_t> last_receive_time;
std::atomic<uint64_t> last_completion_time_or_init;
std::atomic<uint64_t> last_receive_time_or_init;
std::atomic<bool> timed_out{ false };
std::atomic<std::chrono::seconds> io_timeout;
std::chrono::seconds silent_connection_tolerance_time;
Expand Down

0 comments on commit d9594fc

Please sign in to comment.