Transition asio::deadline_timer to asio::steady_timer
What changed, and why it matters
This commit replaces older Boost timer types with newer, more robust standard-library-based timers throughout Monero's networking code. It is primarily a modernization and maintainability change. There is no direct evidence in the commit that it fixes an active security vulnerability, though using the newer timer API can help avoid subtle timing bugs in the long run.
Treat as routine maintenance. Review that all timeout values remain behaviorally equivalent after unit conversion, and verify with existing network/timing tests. No urgent security action is warranted based on this commit alone.
Security signals we found
Timer API modernization from deadline_timer to steady_timer
Use of monotonic std::chrono-based timers reduces system clock dependency
No explicit security bug or CVE referenced in commit or diff
No bounds, memory, cryptographic, or authentication changes present
Evidence from the diff
The patch transitions boost::asio::deadline_timer to boost::asio::steady_timer and replaces boost::posix_time durations with std::chrono durations across 19 files. steady_timer is monotonic and not subject to system clock changes, which can make timeout handling more reliable. The changes are mechanical: header swaps, expires_from_now/expires_at → expires_after, posix_time::milliseconds → std::chrono::milliseconds, and boost::shared_ptr → std::shared_ptr in some timer contexts. No logic changes or vulnerability fixes are described in the commit message or diff.
Changed components
contrib/epee/include/net/abstract_tcp_server2.hcontrib/epee/include/net/abstract_tcp_server2.inlcontrib/epee/include/net/levin_base.hcontrib/epee/include/net/levin_protocol_handler_async.hcontrib/epee/include/net/network_throttle.hppcontrib/epee/include/storages/levin_abstract_invoke2.hsrc/debug_utilities/object_sizes.cppsrc/device_trezor/trezor/transport.cppsrc/device_trezor/trezor/transport.hppsrc/p2p/net_node.hsrc/p2p/net_node.inlsrc/p2p/p2p_protocol_defs.hsrc/rpc/core_rpc_server.cppsrc/wallet/wallet_rpc_server.cpptests/net_load_tests/clt.cpptests/net_load_tests/srv.cpptests/unit_tests/epee_boosted_tcp_server.cpptests/unit_tests/epee_levin_protocol_handler_async.cpptests/unit_tests/node_server.cppInspect captured patch +67 / −67
diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h
index 33e50cd..925a465 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.h
+++ b/contrib/epee/include/net/abstract_tcp_server2.h
@@ -404,7 +404,7 @@ namespace net_utils
try_connect_result_t try_connect(connection_ptr new_connection_l, const std::string& adr, const std::string& port, boost::asio::ip::tcp::socket &sock_, const boost::asio::ip::tcp::endpoint &remote_endpoint, const std::string &bind_ip, uint32_t conn_timeout, epee::net_utils::ssl_support_t ssl_support);
bool connect(const std::string& adr, const std::string& port, uint32_t conn_timeot, t_connection_context& cn, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
template<class t_callback>
- bool connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeot, const t_callback &cb, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, t_connection_context&& initial = t_connection_context{});
+ bool connect_async(const std::string& adr, const std::string& port, std::chrono::milliseconds conn_timeout, const t_callback &cb, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, t_connection_context&& initial = t_connection_context{});
boost::asio::ssl::context& get_ssl_context() noexcept
{
@@ -445,42 +445,43 @@ namespace net_utils
idle_callback_conext_base(boost::asio::io_context& io_serice):
m_timer(io_serice)
{}
- boost::asio::deadline_timer m_timer;
+ boost::asio::steady_timer m_timer;
};
template <class t_handler>
struct idle_callback_conext: public idle_callback_conext_base
{
- idle_callback_conext(boost::asio::io_context& io_serice, t_handler& h, uint64_t period):
+ idle_callback_conext(boost::asio::io_context& io_serice, t_handler& h, std::chrono::milliseconds period):
idle_callback_conext_base(io_serice),
- m_handler(h)
- {this->m_period = period;}
+ m_handler(h),
+ m_period(period)
+ {}
t_handler m_handler;
virtual bool call_handler()
{
return m_handler();
}
- uint64_t m_period;
+ const std::chrono::milliseconds m_period;
};
template<class t_handler>
- bool add_idle_handler(t_handler t_callback, uint64_t timeout_ms)
+ bool add_idle_handler(t_handler t_callback, const std::chrono::milliseconds timeout)
{
- boost::shared_ptr<idle_callback_conext<t_handler>> ptr(new idle_callback_conext<t_handler>(io_context_, t_callback, timeout_ms));
+ std::shared_ptr<idle_callback_conext<t_handler>> ptr(std::make_shared<idle_callback_conext<t_handler>>(io_context_, t_callback, timeout));
//needed call handler here ?...
- ptr->m_timer.expires_from_now(boost::posix_time::milliseconds(ptr->m_period));
+ ptr->m_timer.expires_after(ptr->m_period);
ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler<t_handler>, this, ptr));
return true;
}
template<class t_handler>
- bool global_timer_handler(/*const boost::system::error_code& err, */boost::shared_ptr<idle_callback_conext<t_handler>> ptr)
+ bool global_timer_handler(/*const boost::system::error_code& err, */std::shared_ptr<idle_callback_conext<t_handler>> ptr)
{
//if handler return false - he don't want to be called anymore
if(!ptr->call_handler())
return true;
- ptr->m_timer.expires_from_now(boost::posix_time::milliseconds(ptr->m_period));
+ ptr->m_timer.expires_after(ptr->m_period);
ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler<t_handler>, this, ptr));
return true;
}
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 83f0c08..d344119 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -38,7 +38,7 @@
#include <boost/chrono.hpp>
#include <boost/utility/value_init.hpp>
#include <boost/asio/bind_executor.hpp>
-#include <boost/asio/deadline_timer.hpp>
+#include <boost/asio/steady_timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp> // TODO
#include <boost/thread/condition_variable.hpp> // TODO
#include <boost/make_shared.hpp>
@@ -1894,7 +1894,7 @@ namespace net_utils
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler> template<class t_callback>
- bool boosted_tcp_server<t_protocol_handler>::connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeout, const t_callback &cb, const std::string& bind_ip, epee::net_utils::ssl_support_t ssl_support, t_connection_context&& initial)
+ bool boosted_tcp_server<t_protocol_handler>::connect_async(const std::string& adr, const std::string& port, const std::chrono::milliseconds conn_timeout, const t_callback &cb, const std::string& bind_ip, epee::net_utils::ssl_support_t ssl_support, t_connection_context&& initial)
{
TRY_ENTRY();
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_context_, m_state, m_connection_type, ssl_support, std::move(initial)) );
@@ -1975,14 +1975,14 @@ namespace net_utils
}
}
- boost::shared_ptr<boost::asio::deadline_timer> sh_deadline(new boost::asio::deadline_timer(io_context_));
+ std::shared_ptr<boost::asio::steady_timer> sh_deadline(std::make_shared<boost::asio::steady_timer>(io_context_));
//start deadline
- sh_deadline->expires_from_now(boost::posix_time::milliseconds(conn_timeout));
+ sh_deadline->expires_after(conn_timeout);
sh_deadline->async_wait([=](const boost::system::error_code& error)
{
if(error != boost::asio::error::operation_aborted)
{
- _dbg3("Failed to connect to " << adr << ':' << port << ", because of timeout (" << conn_timeout << ")");
+ _dbg3("Failed to connect to " << adr << ':' << port << ", because of timeout (" << conn_timeout.count() << ")");
new_connection_l->socket().close();
}
});
diff --git a/contrib/epee/include/net/levin_base.h b/contrib/epee/include/net/levin_base.h
index b680691..9dc1035 100644
--- a/contrib/epee/include/net/levin_base.h
+++ b/contrib/epee/include/net/levin_base.h
@@ -29,6 +29,7 @@
#ifndef _LEVIN_BASE_H_
#define _LEVIN_BASE_H_
+#include <chrono>
#include <cstdint>
#include "byte_stream.h"
@@ -72,7 +73,7 @@ namespace levin
#pragma pack(pop)
-#define LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED 0
+constexpr const std::chrono::milliseconds LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED{0};
#define LEVIN_INITIAL_MAX_PACKET_SIZE 256*1024 // 256 KiB before handshake
#define LEVIN_DEFAULT_MAX_PACKET_SIZE 100000000 //100MB by default after handshake
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h
index 341522b..9d80cb2 100644
--- a/contrib/epee/include/net/levin_protocol_handler_async.h
+++ b/contrib/epee/include/net/levin_protocol_handler_async.h
@@ -25,7 +25,7 @@
//
#pragma once
-#include <boost/asio/deadline_timer.hpp>
+#include <boost/asio/steady_timer.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/unordered_map.hpp>
#include <boost/smart_ptr/make_shared.hpp>
@@ -100,10 +100,10 @@ public:
typedef t_connection_context connection_context;
uint64_t m_initial_max_packet_size;
uint64_t m_max_packet_size;
- uint64_t m_invoke_timeout;
+ std::chrono::milliseconds m_invoke_timeout;
template<class callback_t>
- int invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED);
+ int invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, std::chrono::milliseconds timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED);
int send(epee::byte_slice message, const boost::uuids::uuid& connection_id);
bool close(boost::uuids::uuid connection_id);
@@ -190,19 +190,19 @@ public:
template <class callback_t>
struct anvoke_handler: invoke_response_handler_base
{
- anvoke_handler(const callback_t& cb, uint64_t timeout, async_protocol_handler& con, int command)
+ anvoke_handler(const callback_t& cb, const std::chrono::milliseconds timeout, async_protocol_handler& con, int command)
:m_cb(cb), m_timeout(timeout), m_con(con), m_timer(con.m_pservice_endpoint->get_io_context()), m_timer_started(false),
m_cancel_timer_called(false), m_timer_cancelled(false), m_command(command)
{
if(m_con.start_outer_call())
{
- MDEBUG(con.get_context_ref() << "anvoke_handler, timeout: " << timeout);
- m_timer.expires_from_now(boost::posix_time::milliseconds(timeout));
+ MDEBUG(con.get_context_ref() << "anvoke_handler, timeout: " << timeout.count());
+ m_timer.expires_after(timeout);
m_timer.async_wait([&con, command, cb, timeout](const boost::system::error_code& ec)
{
if(ec == boost::asio::error::operation_aborted)
return;
- MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout);
+ MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout.count());
epee::span<const uint8_t> fake;
cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref());
con.close();
@@ -215,11 +215,11 @@ public:
{}
callback_t m_cb;
async_protocol_handler& m_con;
- boost::asio::deadline_timer m_timer;
+ boost::asio::steady_timer m_timer;
bool m_timer_started;
bool m_cancel_timer_called;
bool m_timer_cancelled;
- uint64_t m_timeout;
+ const std::chrono::milliseconds m_timeout;
int m_command;
virtual bool handle(int res, const epee::span<const uint8_t> buff, typename async_protocol_handler::connection_context& context)
{
@@ -247,26 +247,24 @@ public:
if(!m_cancel_timer_called)
{
m_cancel_timer_called = true;
- boost::system::error_code ignored_ec;
- m_timer_cancelled = 1 == m_timer.cancel(ignored_ec);
+ m_timer_cancelled = 1 == m_timer.cancel();
}
return m_timer_cancelled;
}
virtual void reset_timer()
{
- boost::system::error_code ignored_ec;
- if (!m_cancel_timer_called && m_timer.cancel(ignored_ec) > 0)
+ if (!m_cancel_timer_called && m_timer.cancel() > 0)
{
callback_t& cb = m_cb;
- uint64_t timeout = m_timeout;
+ const auto timeout = m_timeout;
async_protocol_handler& con = m_con;
int command = m_command;
- m_timer.expires_from_now(boost::posix_time::milliseconds(m_timeout));
+ m_timer.expires_after(m_timeout);
m_timer.async_wait([&con, cb, command, timeout](const boost::system::error_code& ec)
{
if(ec == boost::asio::error::operation_aborted)
return;
- MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout);
+ MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout.count());
epee::span<const uint8_t> fake;
cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref());
con.close();
@@ -279,7 +277,7 @@ public:
std::list<boost::shared_ptr<invoke_response_handler_base> > m_invoke_response_handlers;
template<class callback_t>
- bool add_invoke_response_handler(const callback_t &cb, uint64_t timeout, async_protocol_handler& con, int command)
+ bool add_invoke_response_handler(const callback_t &cb, const std::chrono::milliseconds timeout, async_protocol_handler& con, int command)
{
CRITICAL_REGION_LOCAL(m_invoke_response_handlers_lock);
if (m_protocol_released)
@@ -604,7 +602,7 @@ public:
}
template<class callback_t>
- bool async_invoke(int command, message_writer in_msg, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
+ bool async_invoke(int command, message_writer in_msg, const callback_t &cb, std::chrono::milliseconds timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
{
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler(
boost::bind(&async_protocol_handler::finish_outer_call, this));
@@ -752,7 +750,7 @@ int async_protocol_handler_config<t_connection_context>::find_and_lock_connectio
}
//------------------------------------------------------------------------------------------
template<class t_connection_context> template<class callback_t>
-int async_protocol_handler_config<t_connection_context>::invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout)
+int async_protocol_handler_config<t_connection_context>::invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, const std::chrono::milliseconds timeout)
{
async_protocol_handler<t_connection_context>* aph;
int r = find_and_lock_connection(connection_id, aph);
diff --git a/contrib/epee/include/net/network_throttle.hpp b/contrib/epee/include/net/network_throttle.hpp
index fb39f69..46361e5 100644
--- a/contrib/epee/include/net/network_throttle.hpp
+++ b/contrib/epee/include/net/network_throttle.hpp
@@ -56,7 +56,6 @@
#include <boost/uuid/random_generator.hpp>
#include <boost/chrono.hpp>
#include <boost/utility/value_init.hpp>
-#include <boost/asio/deadline_timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "misc_language.h"
#include <sstream>
diff --git a/contrib/epee/include/storages/levin_abstract_invoke2.h b/contrib/epee/include/storages/levin_abstract_invoke2.h
index 9d3dda0..0f5c358 100644
--- a/contrib/epee/include/storages/levin_abstract_invoke2.h
+++ b/contrib/epee/include/storages/levin_abstract_invoke2.h
@@ -57,7 +57,7 @@ namespace epee
namespace net_utils
{
template<class t_result, class t_arg, class callback_t, class t_transport>
- bool async_invoke_remote_command2(const epee::net_utils::connection_context_base &context, int command, const t_arg& out_struct, t_transport& transport, const callback_t &cb, size_t inv_timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
+ bool async_invoke_remote_command2(const epee::net_utils::connection_context_base &context, int command, const t_arg& out_struct, t_transport& transport, const callback_t &cb, const std::chrono::milliseconds inv_timeout = levin::LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
{
const boost::uuids::uuid &conn_id = context.m_connection_id;
typename serialization::portable_storage stg;
diff --git a/src/debug_utilities/object_sizes.cpp b/src/debug_utilities/object_sizes.cpp
index 4b5ff81..789968b 100644
--- a/src/debug_utilities/object_sizes.cpp
+++ b/src/debug_utilities/object_sizes.cpp
@@ -72,7 +72,7 @@ int main(int argc, char* argv[])
SL(boost::thread);
SL(boost::asio::io_context);
SL(boost::asio::executor_work_guard<boost::asio::io_context::executor_type>);
- SL(boost::asio::deadline_timer);
+ SL(boost::asio::steady_timer);
SL(cryptonote::DB_ERROR);
SL(cryptonote::mdb_txn_safe);
diff --git a/src/device_trezor/trezor/transport.cpp b/src/device_trezor/trezor/transport.cpp
index 48fd9c7..ec39dc3 100644
--- a/src/device_trezor/trezor/transport.cpp
+++ b/src/device_trezor/trezor/transport.cpp
@@ -571,7 +571,7 @@ namespace trezor{
return ping_int();
}
- bool UdpTransport::ping_int(boost::posix_time::time_duration timeout){
+ bool UdpTransport::ping_int(boost::asio::steady_timer::duration timeout){
require_socket();
try {
std::string req = "PINGPING";
@@ -619,7 +619,7 @@ namespace trezor{
m_socket.reset(new udp::socket(m_io_service));
m_socket->open(udp::v4());
- m_deadline.expires_at(boost::posix_time::pos_infin);
+ m_deadline.expires_after(boost::asio::steady_timer::duration::max());
check_deadline();
m_proto->session_begin(*this);
@@ -701,14 +701,14 @@ namespace trezor{
return static_cast<size_t>(len);
}
- ssize_t UdpTransport::receive(void * buff, size_t size, boost::system::error_code * error_code, bool no_throw, boost::posix_time::time_duration timeout){
+ ssize_t UdpTransport::receive(void * buff, size_t size, boost::system::error_code * error_code, bool no_throw, const boost::asio::steady_timer::duration timeout){
boost::system::error_code ec;
boost::asio::mutable_buffer buffer = boost::asio::buffer(buff, size);
require_socket();
// Set a deadline for the asynchronous operation.
- m_deadline.expires_from_now(timeout);
+ m_deadline.expires_after(timeout);
// Set up the variables that receive the result of the asynchronous
// operation. The error code is set to would_block to signal that the
@@ -766,7 +766,7 @@ namespace trezor{
// Check whether the deadline has passed. We compare the deadline against
// the current time since a new asynchronous operation may have moved the
// deadline before this actor had a chance to run.
- if (m_deadline.expires_at() <= boost::asio::deadline_timer::traits_type::now())
+ if (m_deadline.expiry() <= boost::asio::steady_timer::clock_type::now())
{
// The deadline has passed. The outstanding asynchronous operation needs
// to be cancelled so that the blocked receive() function will return.
@@ -778,7 +778,7 @@ namespace trezor{
// There is no longer an active deadline. The expiry is set to positive
// infinity so that the actor takes no action until a new deadline is set.
- m_deadline.expires_at(boost::posix_time::pos_infin);
+ m_deadline.expires_after(boost::asio::steady_timer::duration::max());
}
// Put the actor back to sleep.
diff --git a/src/device_trezor/trezor/transport.hpp b/src/device_trezor/trezor/transport.hpp
index 91cb017..9ac95f3 100644
--- a/src/device_trezor/trezor/transport.hpp
+++ b/src/device_trezor/trezor/transport.hpp
@@ -32,7 +32,7 @@
#include <boost/asio.hpp>
-#include <boost/asio/deadline_timer.hpp>
+#include <boost/asio/steady_timer.hpp>
#include <boost/array.hpp>
#include <boost/utility/string_ref.hpp>
@@ -233,11 +233,11 @@ namespace trezor {
private:
void require_socket();
- ssize_t receive(void * buff, size_t size, boost::system::error_code * error_code=nullptr, bool no_throw=false, boost::posix_time::time_duration timeout=boost::posix_time::seconds(10));
+ ssize_t receive(void * buff, size_t size, boost::system::error_code * error_code=nullptr, bool no_throw=false, boost::asio::steady_timer::duration timeout = std::chrono::seconds(10));
void check_deadline();
static void handle_receive(const boost::system::error_code& ec, std::size_t length,
boost::system::error_code* out_ec, std::size_t* out_length);
- bool ping_int(boost::posix_time::time_duration timeout=boost::posix_time::milliseconds(1500));
+ bool ping_int(boost::asio::steady_timer::duration = std::chrono::milliseconds(1500));
std::shared_ptr<Protocol> m_proto;
std::string m_device_host;
@@ -245,7 +245,7 @@ namespace trezor {
std::unique_ptr<udp::socket> m_socket;
boost::asio::io_context m_io_service;
- boost::asio::deadline_timer m_deadline;
+ boost::asio::steady_timer m_deadline;
udp::endpoint m_endpoint;
};
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 08db076..187e671 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -230,7 +230,7 @@ namespace nodetool
m_config.m_net_config.packet_max_size = P2P_DEFAULT_PACKET_MAX_SIZE;
m_config.m_net_config.config_id = 0;
m_config.m_net_config.connection_timeout = P2P_DEFAULT_CONNECTION_TIMEOUT;
- m_config.m_net_config.ping_connection_timeout = P2P_DEFAULT_PING_CONNECTION_TIMEOUT;
+ m_config.m_net_config.ping_connection_timeout = std::chrono::milliseconds{P2P_DEFAULT_PING_CONNECTION_TIMEOUT};
m_config.m_net_config.send_peerlist_sz = P2P_DEFAULT_PEERS_IN_HANDSHAKE;
m_config.m_support_flags = 0; // only set in public zone
}
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 1be3fc4..c33220c 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -988,7 +988,7 @@ namespace nodetool
for (auto& zone : m_network_zones)
{
zone.second.m_net_server.get_config_object().set_handler(this);
- zone.second.m_net_server.get_config_object().m_invoke_timeout = P2P_DEFAULT_INVOKE_TIMEOUT;
+ zone.second.m_net_server.get_config_object().m_invoke_timeout = std::chrono::milliseconds{P2P_DEFAULT_INVOKE_TIMEOUT};
if (!zone.second.m_bind_ip.empty())
{
@@ -1073,8 +1073,8 @@ namespace nodetool
})); // lambda
network_zone& public_zone = m_network_zones.at(epee::net_utils::zone::public_);
- public_zone.m_net_server.add_idle_handler(boost::bind(&node_server<t_payload_net_handler>::idle_worker, this), 1000);
- public_zone.m_net_server.add_idle_handler(boost::bind(&t_payload_net_handler::on_idle, &m_payload_handler), 1000);
+ public_zone.m_net_server.add_idle_handler(boost::bind(&node_server<t_payload_net_handler>::idle_worker, this), std::chrono::seconds{1});
+ public_zone.m_net_server.add_idle_handler(boost::bind(&t_payload_net_handler::on_idle, &m_payload_handler), std::chrono::seconds{1});
//here you can set worker threads count
int thrds_count = 10;
@@ -1234,7 +1234,7 @@ namespace nodetool
LOG_DEBUG_CC(context, " COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK");
}
context_ = context;
- }, P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT);
+ }, std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT});
if(r)
{
@@ -2564,7 +2564,7 @@ namespace nodetool
f(context_, rsp.support_flags);
},
- P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT
+ std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT}
);
return r;
diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h
index 43cc6b0..cc0c6cf 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -136,10 +136,10 @@ namespace nodetool
KV_SERIALIZE(config_id)
END_KV_SERIALIZE_MAP()
+ std::chrono::milliseconds ping_connection_timeout;
uint32_t max_out_connection_count;
uint32_t max_in_connection_count;
uint32_t connection_timeout;
- uint32_t ping_connection_timeout;
uint32_t handshake_interval;
uint32_t packet_max_size;
uint32_t config_id;
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 5b680b5..bf4cdb4 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -350,7 +350,7 @@ namespace cryptonote
http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password());
if (m_rpc_payment)
- m_net_server.add_idle_handler([this](){ return m_rpc_payment->on_idle(); }, 60 * 1000);
+ m_net_server.add_idle_handler([this](){ return m_rpc_payment->on_idle(); }, std::chrono::minutes{1});
bool store_ssl_key = !restricted && rpc_config->ssl_options && rpc_config->ssl_options.auth.certificate_path.empty();
const auto ssl_base_path = (boost::filesystem::path{data_dir} / "rpc_ssl").string();
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index f4a1b0d..c64e45c 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -267,7 +267,7 @@ namespace tools
}
}
return true;
- }, auto_refresh_evaluation_ms.count());
+ }, auto_refresh_evaluation_ms);
m_net_server.add_idle_handler([this](){
if (m_stop.load(std::memory_order_relaxed))
{
@@ -275,7 +275,7 @@ namespace tools
return false;
}
return true;
- }, 500);
+ }, std::chrono::milliseconds{500});
//DO NOT START THIS SERVER IN MORE THEN 1 THREADS WITHOUT REFACTORING
return epee::http_server_impl_base<wallet_rpc_server, connection_context>::run(1, true);
diff --git a/tests/net_load_tests/clt.cpp b/tests/net_load_tests/clt.cpp
index ab5de97..d10089d 100644
--- a/tests/net_load_tests/clt.cpp
+++ b/tests/net_load_tests/clt.cpp
@@ -50,7 +50,7 @@ using namespace net_load_tests;
namespace
{
const size_t CONNECTION_COUNT = 100000;
- const size_t CONNECTION_TIMEOUT = 10000;
+ constexpr const std::chrono::seconds CONNECTION_TIMEOUT{10};
const size_t DEFAULT_OPERATION_TIMEOUT = 30000;
const size_t RESERVED_CONN_CNT = 1;
diff --git a/tests/net_load_tests/srv.cpp b/tests/net_load_tests/srv.cpp
index dd22b1b..844f2a3 100644
--- a/tests/net_load_tests/srv.cpp
+++ b/tests/net_load_tests/srv.cpp
@@ -28,6 +28,7 @@
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+#include <boost/asio/steady_timer.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
@@ -189,10 +190,10 @@ namespace
if (0 < count)
{
// Perhaps not all connections were closed, try to close it after 7 seconds
- boost::shared_ptr<boost::asio::deadline_timer> sh_deadline(new boost::asio::deadline_timer(m_tcp_server.get_io_context(), boost::posix_time::seconds(7)));
+ std::shared_ptr<boost::asio::steady_timer> sh_deadline(std::make_shared<boost::asio::steady_timer>(m_tcp_server.get_io_context(), std::chrono::seconds(7)));
sh_deadline->async_wait([=](const boost::system::error_code& ec)
{
- boost::shared_ptr<boost::asio::deadline_timer> t = sh_deadline; // Capture sh_deadline
+ std::shared_ptr<boost::asio::steady_timer> t = sh_deadline; // Capture sh_deadline
if (!ec)
{
close_connections(cmd_conn_id);
@@ -229,7 +230,7 @@ int main(int argc, char** argv)
srv_levin_commands_handler *commands_handler = new srv_levin_commands_handler(tcp_server);
tcp_server.get_config_object().set_handler(commands_handler, [](epee::levin::levin_commands_handler<test_connection_context> *handler) { delete handler; });
- tcp_server.get_config_object().m_invoke_timeout = 10000;
+ tcp_server.get_config_object().m_invoke_timeout = std::chrono::seconds{10};
//tcp_server.get_config_object().m_max_packet_size = max_packet_size;
if (!tcp_server.run_server(thread_count, true))
diff --git a/tests/unit_tests/epee_boosted_tcp_server.cpp b/tests/unit_tests/epee_boosted_tcp_server.cpp
index 4b06302..d48818f 100644
--- a/tests/unit_tests/epee_boosted_tcp_server.cpp
+++ b/tests/unit_tests/epee_boosted_tcp_server.cpp
@@ -282,7 +282,7 @@ TEST(test_epee_connection, test_lifetime)
while (shared_state->sock_count);
ASSERT_TRUE(shared_state->get_connections_count() == 0);
constexpr auto DELAY = 30;
- constexpr auto TIMEOUT = 1;
+ constexpr std::chrono::milliseconds TIMEOUT{1};
while (server.get_connections_count()) {
server.get_config_shared()->del_in_connections(
server.get_config_shared()->get_in_connections_count()
diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
index 9677081..3e1d65d 100644
--- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp
+++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
@@ -185,7 +185,7 @@ namespace
class async_protocol_handler_test : public ::testing::Test
{
public:
- const static uint64_t invoke_timeout = 5 * 1000;
+ constexpr const static std::chrono::seconds invoke_timeout{5};
const static size_t max_packet_size = 10 * 1024 * 1024;
typedef std::unique_ptr<test_connection> test_connection_ptr;
diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp
index 96d74e9..b5c0fa1 100644
--- a/tests/unit_tests/node_server.cpp
+++ b/tests/unit_tests/node_server.cpp
@@ -690,7 +690,7 @@ TEST(cryptonote_protocol_handler, race_condition)
net_node.core_protocol->process_payload_sync_data(msg.payload_data, context, true);
handshaked.raise();
},
- P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT
+ std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT}
);
return true;
}
@@ -1202,7 +1202,7 @@ TEST(node_server, race_condition)
EXPECT_TRUE(code >= 0);
handshaked.raise();
},
- P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT
+ std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT}
);
handshaked.wait();
boost::asio::post(conn->strand_, [conn]{
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.