Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Initializes receive and completion times to always hold a valid value… #3594

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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