Initializes receive and completion times to always hold a valid value (#3587) (#3594)

This commit is contained in:
Dimitrios Siganos 2021-12-09 00:44:18 +02:00 committed by GitHub
commit d9594fcdc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View file

@ -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 }
{
@ -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 ()
@ -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;

View file

@ -115,8 +115,8 @@ protected:
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;