Replace boost chrono & posix_time with stl chrono

This commit is contained in:
Jason Rhinelander 2020-06-03 00:04:55 -03:00
parent 515b96e20b
commit 718a9496fb
44 changed files with 262 additions and 378 deletions

View File

@ -790,9 +790,9 @@ set(Boost_USE_MULTITHREADED TRUE) # Needed for macOS, at least, and won't hurt e
if(BUILD_STATIC_DEPS)
# StaticBuild.cmake sets Boost targets up for us
elseif (WIN32)
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS system filesystem thread date_time chrono serialization program_options locale)
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS system filesystem thread date_time serialization program_options locale)
else()
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS system filesystem thread date_time chrono serialization program_options)
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS system filesystem thread date_time serialization program_options)
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_LIB_SUFFIXES})

View File

@ -280,7 +280,7 @@ build_external(boost
CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env ${boost_bootstrap_cxx}
./bootstrap.sh --without-icu --prefix=${DEPS_DESTDIR} --with-toolset=${boost_toolset}
--with-libraries=chrono,filesystem,program_options,system,thread,date_time,serialization,locale,atomic
--with-libraries=filesystem,program_options,system,thread,date_time,serialization,locale,atomic
BUILD_COMMAND true
INSTALL_COMMAND
./b2 -d0 variant=release link=static runtime-link=static optimization=speed ${boost_extra}
@ -289,7 +289,6 @@ build_external(boost
install
BUILD_BYPRODUCTS
${DEPS_DESTDIR}/lib/libboost_atomic.a
${DEPS_DESTDIR}/lib/libboost_chrono.a
${DEPS_DESTDIR}/lib/libboost_date_time.a
${DEPS_DESTDIR}/lib/libboost_filesystem.a
${DEPS_DESTDIR}/lib/libboost_locale.a
@ -303,7 +302,7 @@ add_library(boost_core INTERFACE)
add_dependencies(boost_core INTERFACE boost_external)
target_include_directories(boost_core SYSTEM INTERFACE ${DEPS_DESTDIR}/include)
add_library(Boost::boost ALIAS boost_core)
foreach(boostlib atomic chrono date_time filesystem locale program_options serialization system thread)
foreach(boostlib atomic date_time filesystem locale program_options serialization system thread)
add_static_target(Boost::${boostlib} boost_external libboost_${boostlib}.a)
target_link_libraries(Boost::${boostlib} INTERFACE boost_core)
endforeach()

View File

@ -154,9 +154,9 @@ namespace net_utils
void handle_write(const boost::system::error_code& e, size_t cb);
/// reset connection timeout timer and callback
void reset_timer(boost::posix_time::milliseconds ms, bool add);
boost::posix_time::milliseconds get_default_timeout();
boost::posix_time::milliseconds get_timeout_from_bytes_read(size_t bytes);
void reset_timer(std::chrono::milliseconds ms, bool add);
std::chrono::milliseconds get_default_timeout();
std::chrono::milliseconds get_timeout_from_bytes_read(size_t bytes);
/// host connection count tracking
unsigned int host_count(const std::string &host, int delta = 0);
@ -185,7 +185,7 @@ namespace net_utils
std::mutex m_throttle_speed_in_mutex;
std::mutex m_throttle_speed_out_mutex;
boost::asio::deadline_timer m_timer;
boost::asio::steady_timer m_timer;
bool m_local;
bool m_ready_to_close;
std::string m_host;
@ -287,59 +287,47 @@ namespace net_utils
boost::asio::io_service& get_io_service(){return io_service_;}
struct idle_callback_conext_base
template <class Callback>
struct idle_callback_conext
{
virtual ~idle_callback_conext_base(){}
virtual bool call_handler(){return true;}
idle_callback_conext_base(boost::asio::io_service& io_serice):
m_timer(io_serice)
idle_callback_conext(boost::asio::io_service& io_service, Callback h, std::chrono::milliseconds period)
: m_timer{io_service}, m_handler{std::move(h)}, m_period{period}
{}
boost::asio::deadline_timer m_timer;
};
template <class t_handler>
struct idle_callback_conext: public idle_callback_conext_base
{
idle_callback_conext(boost::asio::io_service& io_serice, t_handler& h, uint64_t period):
idle_callback_conext_base(io_serice),
m_handler(h)
{this->m_period = period;}
t_handler m_handler;
virtual bool call_handler()
bool call_handler()
{
return m_handler();
}
uint64_t m_period;
Callback m_handler;
std::chrono::milliseconds m_period;
boost::asio::steady_timer m_timer;
};
template<class t_handler>
bool add_idle_handler(t_handler t_callback, uint64_t timeout_ms)
bool add_idle_handler(t_handler callback, std::chrono::milliseconds timeout)
{
auto ptr = std::make_shared<idle_callback_conext<t_handler>>(io_service_, t_callback, timeout_ms);
auto ptr = std::make_shared<idle_callback_conext<t_handler>>(io_service_, std::move(callback), timeout);
//needed call handler here ?...
ptr->m_timer.expires_from_now(boost::posix_time::milliseconds(ptr->m_period));
ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler<t_handler>, this, ptr));
ptr->m_timer.expires_after(ptr->m_period);
ptr->m_timer.async_wait([this, ptr] (const boost::system::error_code&) { global_timer_handler<t_handler>(ptr); });
return true;
}
template<class t_handler>
bool global_timer_handler(/*const boost::system::error_code& err, */std::shared_ptr<idle_callback_conext<t_handler>> ptr)
void 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.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler<t_handler>, this, ptr));
return true;
return;
ptr->m_timer.expires_after(ptr->m_period);
ptr->m_timer.async_wait([this, ptr] (const boost::system::error_code&) { global_timer_handler<t_handler>(ptr); });
}
template<class t_handler>
bool async_call(t_handler t_callback)
{
io_service_.post(t_callback);
io_service_.post(std::move(t_callback));
return true;
}

View File

@ -34,15 +34,14 @@
#include <boost/bind.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/chrono.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp> // TODO
#include <boost/asio/steady_timer.hpp>
#include "warnings.h"
#include "string_tools.h"
#include "misc_language.h"
#include "net/local_ip.h"
#include "pragma_comp_defs.h"
#include <chrono>
#include <thread>
#include <mutex>
#include <condition_variable>
@ -201,7 +200,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
m_protocol_handler.after_init_connection();
reset_timer(boost::posix_time::milliseconds(m_local ? NEW_CONNECTION_TIMEOUT_LOCAL : NEW_CONNECTION_TIMEOUT_REMOTE), false);
reset_timer(std::chrono::milliseconds(m_local ? NEW_CONNECTION_TIMEOUT_LOCAL : NEW_CONNECTION_TIMEOUT_REMOTE), false);
// first read on the raw socket to detect SSL for the server
buffer_ssl_init_fill = 0;
@ -364,7 +363,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
delay *= 0.5;
long int ms = (long int)(delay * 100);
if (ms > 0) {
reset_timer(boost::posix_time::milliseconds(ms + 1), true);
reset_timer(std::chrono::milliseconds(ms + 1), true);
std::this_thread::sleep_for(std::chrono::milliseconds{ms});
}
} while(delay > 0);
@ -372,7 +371,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
//MINFO("[sock " << socket().native_handle() << "] RECV " << bytes_transferred);
logger_handle_net_read(bytes_transferred);
context.m_last_recv = time(NULL);
context.m_last_recv = std::chrono::steady_clock::now();
context.m_recv_cnt += bytes_transferred;
m_ready_to_close = false;
bool recv_res = m_protocol_handler.handle_recv(buffer_.data(), bytes_transferred);
@ -614,7 +613,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
context.m_max_speed_up = std::max(context.m_max_speed_up, current_speed_up);
//MINFO("[sock " << socket().native_handle() << "] SEND " << cb);
context.m_last_send = time(NULL);
context.m_last_send = std::chrono::steady_clock::now();
context.m_send_cnt += chunk.size();
//some data should be wrote to stream
//request complete
@ -706,26 +705,24 @@ PRAGMA_WARNING_DISABLE_VS(4355)
} // do_send_chunk
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
boost::posix_time::milliseconds connection<t_protocol_handler>::get_default_timeout()
std::chrono::milliseconds connection<t_protocol_handler>::get_default_timeout()
{
unsigned count;
try { count = host_count(m_host); } catch (...) { count = 0; }
const unsigned shift = get_state().sock_count > AGGRESSIVE_TIMEOUT_THRESHOLD ? std::min(std::max(count, 1u) - 1, 8u) : 0;
boost::posix_time::milliseconds timeout(0);
if (m_local)
timeout = boost::posix_time::milliseconds(DEFAULT_TIMEOUT_MS_LOCAL >> shift);
return std::chrono::milliseconds{DEFAULT_TIMEOUT_MS_LOCAL >> shift};
else
timeout = boost::posix_time::milliseconds(DEFAULT_TIMEOUT_MS_REMOTE >> shift);
return timeout;
return std::chrono::milliseconds{DEFAULT_TIMEOUT_MS_REMOTE >> shift};
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
boost::posix_time::milliseconds connection<t_protocol_handler>::get_timeout_from_bytes_read(size_t bytes)
std::chrono::milliseconds connection<t_protocol_handler>::get_timeout_from_bytes_read(size_t bytes)
{
boost::posix_time::milliseconds ms = (boost::posix_time::milliseconds)(unsigned)(bytes * TIMEOUT_EXTRA_MS_PER_BYTE);
const auto cur = m_timer.expires_from_now().total_milliseconds();
if (cur > 0)
ms += (boost::posix_time::milliseconds)cur;
std::chrono::milliseconds ms{(unsigned)(bytes * TIMEOUT_EXTRA_MS_PER_BYTE)};
if (auto remaining = std::chrono::duration_cast<std::chrono::milliseconds>(m_timer.expiry() - std::chrono::steady_clock::now());
remaining > 0ms)
ms += remaining;
if (ms > get_default_timeout())
ms = get_default_timeout();
return ms;
@ -749,14 +746,14 @@ PRAGMA_WARNING_DISABLE_VS(4355)
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
void connection<t_protocol_handler>::reset_timer(boost::posix_time::milliseconds ms, bool add)
void connection<t_protocol_handler>::reset_timer(std::chrono::milliseconds ms, bool add)
{
if (ms.total_milliseconds() < 0)
if (ms < 0s)
{
MWARNING("Ignoring negative timeout " << ms);
MWARNING("Ignoring negative timeout " << ms.count());
return;
}
MTRACE((add ? "Adding" : "Setting") << " " << ms << " expiry");
MTRACE((add ? "Adding" : "Setting") << " " << ms.count() << "ms expiry");
auto self = safe_shared_from_this();
if(!self)
{
@ -770,11 +767,11 @@ PRAGMA_WARNING_DISABLE_VS(4355)
}
if (add)
{
const auto cur = m_timer.expires_from_now().total_milliseconds();
if (cur > 0)
ms += (boost::posix_time::milliseconds)cur;
if (const auto cur = std::chrono::duration_cast<std::chrono::milliseconds>(m_timer.expiry() - std::chrono::steady_clock::now());
cur > 0)
ms += cur;
}
m_timer.expires_from_now(ms);
m_timer.expires_after(ms);
m_timer.async_wait([=](const boost::system::error_code& ec)
{
if(ec == boost::asio::error::operation_aborted)
@ -1658,9 +1655,9 @@ POP_WARNINGS
}
}
std::shared_ptr<boost::asio::deadline_timer> sh_deadline(new boost::asio::deadline_timer(io_service_));
std::shared_ptr<boost::asio::steady_timer> sh_deadline(new boost::asio::steady_timer(io_service_));
//start deadline
sh_deadline->expires_from_now(boost::posix_time::milliseconds(conn_timeout));
sh_deadline->expires_from_now(std::chrono::milliseconds(conn_timeout));
sh_deadline->async_wait([=](const boost::system::error_code& error)
{
if(error != boost::asio::error::operation_aborted)

View File

@ -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>
@ -185,7 +185,7 @@ public:
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));
m_timer.expires_after(std::chrono::milliseconds(timeout));
m_timer.async_wait([&con, command, cb, timeout](const boost::system::error_code& ec)
{
if(ec == boost::asio::error::operation_aborted)
@ -203,7 +203,7 @@ 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;
@ -249,7 +249,7 @@ public:
uint64_t 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(std::chrono::milliseconds(m_timeout));
m_timer.async_wait([&con, cb, command, timeout](const boost::system::error_code& ec)
{
if(ec == boost::asio::error::operation_aborted)

View File

@ -156,7 +156,7 @@ namespace net_utils
inline
try_connect_result_t try_connect(const std::string& addr, const std::string& port, std::chrono::milliseconds timeout)
{
m_deadline.expires_from_now(timeout);
m_deadline.expires_after(timeout);
auto connection = m_connector(addr, port, m_deadline);
do {
m_io_service.reset();
@ -279,7 +279,7 @@ namespace net_utils
try
{
m_deadline.expires_from_now(timeout);
m_deadline.expires_after(timeout);
// Set up the variable that receives the result of the asynchronous
// operation. The error code is set to would_block to signal that the
@ -288,10 +288,6 @@ namespace net_utils
// ec indicates completion.
boost::system::error_code ec = boost::asio::error::would_block;
// Start the asynchronous operation itself. The boost::lambda function
// object is used as a callback and will update the ec variable when the
// operation completes. The blocking_udp_client.cpp example shows how you
// can use boost::bind rather than boost::lambda.
async_write(buff.c_str(), buff.size(), ec);
// Block until the asynchronous operation has completed.
@ -332,28 +328,6 @@ namespace net_utils
{
try
{
/*
m_deadline.expires_from_now(boost::posix_time::milliseconds(m_reciev_timeout));
// Set up the variable that receives the result of the asynchronous
// operation. The error code is set to would_block to signal that the
// operation is incomplete. Asio guarantees that its asynchronous
// operations will never fail with would_block, so any other value in
// ec indicates completion.
boost::system::error_code ec = boost::asio::error::would_block;
// Start the asynchronous operation itself. The boost::lambda function
// object is used as a callback and will update the ec variable when the
// operation completes. The blocking_udp_client.cpp example shows how you
// can use boost::bind rather than boost::lambda.
boost::asio::async_write(m_socket, boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
// Block until the asynchronous operation has completed.
while (ec == boost::asio::error::would_block)
{
m_io_service.run_one();
}
*/
boost::system::error_code ec;
size_t writen = write(data, sz, ec);
@ -403,7 +377,7 @@ namespace net_utils
// Set a deadline for the asynchronous operation. Since this function uses
// a composed operation (async_read_until), the deadline applies to the
// entire operation, rather than individual reads from the socket.
m_deadline.expires_from_now(timeout);
m_deadline.expires_after(timeout);
// Set up the variable that receives the result of the asynchronous
// operation. The error code is set to would_block to signal that the
@ -412,11 +386,6 @@ namespace net_utils
// ec indicates completion.
//boost::system::error_code ec = boost::asio::error::would_block;
// Start the asynchronous operation itself. The boost::lambda function
// object is used as a callback and will update the ec variable when the
// operation completes. The blocking_udp_client.cpp example shows how you
// can use boost::bind rather than boost::lambda.
boost::system::error_code ec = boost::asio::error::would_block;
size_t bytes_transfered = 0;
@ -489,19 +458,7 @@ namespace net_utils
// Set a deadline for the asynchronous operation. Since this function uses
// a composed operation (async_read_until), the deadline applies to the
// entire operation, rather than individual reads from the socket.
m_deadline.expires_from_now(timeout);
// Set up the variable that receives the result of the asynchronous
// operation. The error code is set to would_block to signal that the
// operation is incomplete. Asio guarantees that its asynchronous
// operations will never fail with would_block, so any other value in
// ec indicates completion.
//boost::system::error_code ec = boost::asio::error::would_block;
// Start the asynchronous operation itself. The boost::lambda function
// object is used as a callback and will update the ec variable when the
// operation completes. The blocking_udp_client.cpp example shows how you
// can use boost::bind rather than boost::lambda.
m_deadline.expires_after(timeout);
buff.resize(static_cast<size_t>(sz));
boost::system::error_code ec = boost::asio::error::would_block;
@ -616,14 +573,14 @@ namespace net_utils
}
// Put the actor back to sleep.
m_deadline.async_wait(boost::bind(&blocked_mode_client::check_deadline, this));
m_deadline.async_wait([this] (const boost::system::error_code&) { check_deadline(); });
}
void shutdown_ssl() {
// ssl socket shutdown blocks if server doesn't respond. We close after 2 secs
boost::system::error_code ec = boost::asio::error::would_block;
m_deadline.expires_from_now(std::chrono::milliseconds(2000));
m_ssl_socket->async_shutdown(boost::lambda::var(ec) = boost::lambda::_1);
m_deadline.expires_after(2s);
m_ssl_socket->async_shutdown([&ec](const boost::system::error_code& e) { ec = e; });
while (ec == boost::asio::error::would_block)
{
m_io_service.reset();
@ -632,11 +589,7 @@ namespace net_utils
// Ignore "short read" error
if (ec.category() == boost::asio::error::get_ssl_category() &&
ec.value() !=
#if BOOST_VERSION >= 106200
boost::asio::ssl::error::stream_truncated
#else // older Boost supports only OpenSSL 1.0, so 1.0-only macros are appropriate
ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)
#endif
)
MDEBUG("Problems at ssl shutdown: " << ec.message());
}
@ -654,10 +607,11 @@ namespace net_utils
void async_write(const void* data, size_t sz, boost::system::error_code& ec)
{
auto handler = [&ec](const boost::system::error_code& e, size_t) { ec = e; };
if(m_ssl_options.support != ssl_support_t::e_ssl_support_disabled)
boost::asio::async_write(*m_ssl_socket, boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
boost::asio::async_write(*m_ssl_socket, boost::asio::buffer(data, sz), std::move(handler));
else
boost::asio::async_write(m_ssl_socket->next_layer(), boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
boost::asio::async_write(m_ssl_socket->next_layer(), boost::asio::buffer(data, sz), std::move(handler));
}
void async_read(char* buff, size_t sz, boost::asio::detail::transfer_at_least_t transfer_at_least, handler_obj& hndlr)
@ -673,7 +627,7 @@ namespace net_utils
boost::asio::io_service m_io_service;
boost::asio::ssl::context m_ctx;
std::shared_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> m_ssl_socket;
std::function<connect_func> m_connector;
connect_func m_connector;
ssl_options_t m_ssl_options;
bool m_initialized;
bool m_connected;
@ -696,7 +650,7 @@ namespace net_utils
// No deadline is required until the first socket operation is started. We
// set the deadline to positive infinity so that the actor takes no action
// until a specific deadline is set.
m_send_deadline.expires_at(boost::posix_time::pos_infin);
m_send_deadline.expires_at(std::chrono::steady_clock::time_point::max());
// Start the persistent actor that checks for deadline expiry.
check_send_deadline();
@ -718,28 +672,6 @@ namespace net_utils
{
try
{
/*
m_send_deadline.expires_from_now(boost::posix_time::milliseconds(m_reciev_timeout));
// Set up the variable that receives the result of the asynchronous
// operation. The error code is set to would_block to signal that the
// operation is incomplete. Asio guarantees that its asynchronous
// operations will never fail with would_block, so any other value in
// ec indicates completion.
boost::system::error_code ec = boost::asio::error::would_block;
// Start the asynchronous operation itself. The boost::lambda function
// object is used as a callback and will update the ec variable when the
// operation completes. The blocking_udp_client.cpp example shows how you
// can use boost::bind rather than boost::lambda.
boost::asio::async_write(m_socket, boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
// Block until the asynchronous operation has completed.
while(ec == boost::asio::error::would_block)
{
m_io_service.run_one();
}*/
boost::system::error_code ec;
size_t writen = write(data, sz, ec);
@ -750,7 +682,7 @@ namespace net_utils
return false;
}else
{
m_send_deadline.expires_at(boost::posix_time::pos_infin);
m_send_deadline.expires_at(std::chrono::steady_clock::time_point::max());
}
}
@ -771,14 +703,14 @@ namespace net_utils
private:
boost::asio::deadline_timer m_send_deadline;
boost::asio::steady_timer m_send_deadline;
void check_send_deadline()
{
// 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_send_deadline.expires_at() <= boost::asio::deadline_timer::traits_type::now())
if (m_send_deadline.expiry() <= std::chrono::steady_clock::now())
{
// The deadline has passed. The socket is closed so that any outstanding
// asynchronous operations are cancelled. This allows the blocked
@ -788,11 +720,11 @@ namespace net_utils
// 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_send_deadline.expires_at(boost::posix_time::pos_infin);
m_send_deadline.expires_at(std::chrono::steady_clock::time_point::max());
}
// Put the actor back to sleep.
m_send_deadline.async_wait(boost::bind(&async_blocked_mode_client::check_send_deadline, this));
m_send_deadline.async_wait([this] (const boost::system::error_code&) { check_send_deadline(); });
}
};
}

View File

@ -349,10 +349,10 @@ namespace net_utils
const boost::uuids::uuid m_connection_id;
const network_address m_remote_address;
const bool m_is_income;
const time_t m_started;
std::chrono::steady_clock::time_point m_started;
const bool m_ssl;
time_t m_last_recv;
time_t m_last_send;
std::chrono::steady_clock::time_point m_last_recv;
std::chrono::steady_clock::time_point m_last_send;
uint64_t m_recv_cnt;
uint64_t m_send_cnt;
double m_current_speed_down;
@ -362,12 +362,13 @@ namespace net_utils
connection_context_base(boost::uuids::uuid connection_id,
const network_address &remote_address, bool is_income, bool ssl,
time_t last_recv = 0, time_t last_send = 0,
std::chrono::steady_clock::time_point last_recv = std::chrono::steady_clock::time_point::min(),
std::chrono::steady_clock::time_point last_send = std::chrono::steady_clock::time_point::min(),
uint64_t recv_cnt = 0, uint64_t send_cnt = 0):
m_connection_id(connection_id),
m_remote_address(remote_address),
m_is_income(is_income),
m_started(time(NULL)),
m_started(std::chrono::steady_clock::now()),
m_ssl(ssl),
m_last_recv(last_recv),
m_last_send(last_send),
@ -382,10 +383,10 @@ namespace net_utils
connection_context_base(): m_connection_id(),
m_remote_address(),
m_is_income(false),
m_started(time(NULL)),
m_started(std::chrono::steady_clock::now()),
m_ssl(false),
m_last_recv(0),
m_last_send(0),
m_last_recv(std::chrono::steady_clock::time_point::min()),
m_last_send(std::chrono::steady_clock::time_point::min()),
m_recv_cnt(0),
m_send_cnt(0),
m_current_speed_down(0),

View File

@ -36,8 +36,8 @@
#include "net/net_utils_base.h"
#include "misc_log_ex.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <thread>
#include <chrono>
#include "misc_language.h"
#include "pragma_comp_defs.h"
#include <iomanip>

View File

@ -6,7 +6,7 @@ set(Boost_USE_MULTITHREADED ON)
include_directories(.)
include_directories(../../include)
find_package(Boost COMPONENTS system filesystem thread date_time chrono)
find_package(Boost COMPONENTS system filesystem thread)
include_directories( ${Boost_INCLUDE_DIRS} )
IF (MSVC)

View File

@ -59,7 +59,6 @@ target_link_libraries(cncrypto
randomx
Boost::system
Boost::thread
Boost::chrono
sodium
PRIVATE
extra)

View File

@ -31,7 +31,7 @@
#pragma once
#include <unordered_set>
#include <atomic>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <chrono>
#include "net/net_utils_base.h"
#include "copyable_atomic.h"
#include "crypto/hash.h"
@ -58,7 +58,7 @@ namespace cryptonote
uint32_t m_drop_count{0}; // How many times we've wanted to drop
uint64_t m_remote_blockchain_height{0};
uint64_t m_last_response_height{0};
boost::posix_time::ptime m_last_request_time{boost::date_time::not_a_date_time};
std::optional<std::chrono::steady_clock::time_point> m_last_request_time;
epee::copyable_atomic m_callback_request_count{0}; //in debug purpose: problem with double callback rise
crypto::hash m_last_known_hash{crypto::null_hash};
uint32_t m_pruning_seed{0};

View File

@ -53,7 +53,6 @@ target_link_libraries(cryptonote_core
sqlite3
PRIVATE
Boost::program_options
Boost::chrono
systemd
extra)

View File

@ -1,5 +1,5 @@
// Copyright (c) 2018-2020, The Loki Project
// Copyright (c) 2017-2019, The Monero Project
// Copyright (c) 2018, The Loki Project
//
// All rights reserved.
//
@ -70,7 +70,7 @@ void block_queue::add_blocks(uint64_t height, std::vector<cryptonote::block_comp
}
}
void block_queue::add_blocks(uint64_t height, uint64_t nblocks, const boost::uuids::uuid &connection_id, boost::posix_time::ptime time)
void block_queue::add_blocks(uint64_t height, uint64_t nblocks, const boost::uuids::uuid &connection_id, std::chrono::steady_clock::time_point time)
{
CHECK_AND_ASSERT_THROW_MES(nblocks > 0, "Empty span");
std::unique_lock lock{mutex};
@ -229,7 +229,14 @@ bool block_queue::have(const crypto::hash &hash) const
return have_blocks.find(hash) != have_blocks.end();
}
std::pair<uint64_t, uint64_t> block_queue::reserve_span(uint64_t first_block_height, uint64_t last_block_height, uint64_t max_blocks, const boost::uuids::uuid &connection_id, uint32_t pruning_seed, uint64_t blockchain_height, const std::vector<crypto::hash> &block_hashes, boost::posix_time::ptime time)
std::pair<uint64_t, uint64_t> block_queue::reserve_span(
uint64_t first_block_height,
uint64_t last_block_height,
uint64_t max_blocks,
const boost::uuids::uuid &connection_id,
uint32_t pruning_seed,
uint64_t blockchain_height,
const std::vector<crypto::hash> &block_hashes)
{
std::unique_lock lock{mutex};
@ -295,12 +302,12 @@ std::pair<uint64_t, uint64_t> block_queue::reserve_span(uint64_t first_block_hei
return std::make_pair(0, 0);
}
MDEBUG("Reserving span " << span_start_height << " - " << (span_start_height + span_length - 1) << " for " << connection_id);
add_blocks(span_start_height, span_length, connection_id, time);
add_blocks(span_start_height, span_length, connection_id, std::chrono::steady_clock::now());
set_span_hashes(span_start_height, connection_id, hashes);
return std::make_pair(span_start_height, span_length);
}
std::pair<uint64_t, uint64_t> block_queue::get_next_span_if_scheduled(std::vector<crypto::hash> &hashes, boost::uuids::uuid &connection_id, boost::posix_time::ptime &time) const
std::pair<uint64_t, uint64_t> block_queue::get_next_span_if_scheduled(std::vector<crypto::hash> &hashes, boost::uuids::uuid &connection_id) const
{
std::unique_lock lock{mutex};
if (blocks.empty())
@ -312,20 +319,21 @@ std::pair<uint64_t, uint64_t> block_queue::get_next_span_if_scheduled(std::vecto
return std::make_pair(0, 0);
hashes = i->hashes;
connection_id = i->connection_id;
time = i->time;
return std::make_pair(i->start_block_height, i->nblocks);
}
void block_queue::reset_next_span_time(boost::posix_time::ptime t)
void block_queue::reset_next_span_time()
{
std::unique_lock lock{mutex};
CHECK_AND_ASSERT_THROW_MES(!blocks.empty(), "No next span to reset time");
block_map::iterator i = blocks.begin();
CHECK_AND_ASSERT_THROW_MES(i != blocks.end(), "No next span to reset time");
CHECK_AND_ASSERT_THROW_MES(i->blocks.empty(), "Next span is not empty");
(boost::posix_time::ptime&)i->time = t; // sod off, time doesn't influence sorting
const_cast<std::chrono::steady_clock::time_point&>(i->time) // time doesn't influence sorting
= std::chrono::steady_clock::now();
}
void block_queue::set_span_hashes(uint64_t start_height, const boost::uuids::uuid &connection_id, std::vector<crypto::hash> hashes)
{
std::unique_lock lock{mutex};
@ -363,22 +371,7 @@ bool block_queue::get_next_span(uint64_t &height, std::vector<cryptonote::block_
return false;
}
bool block_queue::has_next_span(const boost::uuids::uuid &connection_id, bool &filled, boost::posix_time::ptime &time) const
{
std::unique_lock lock{mutex};
if (blocks.empty())
return false;
block_map::const_iterator i = blocks.begin();
if (i == blocks.end())
return false;
if (i->connection_id != connection_id)
return false;
filled = !i->blocks.empty();
time = i->time;
return true;
}
bool block_queue::has_next_span(uint64_t height, bool &filled, boost::posix_time::ptime &time, boost::uuids::uuid &connection_id) const
bool block_queue::has_next_span(uint64_t height, bool &filled, std::chrono::steady_clock::time_point& time, boost::uuids::uuid &connection_id) const
{
std::unique_lock lock{mutex};
if (blocks.empty())
@ -403,22 +396,6 @@ size_t block_queue::get_data_size() const
return size;
}
size_t block_queue::get_num_filled_spans_prefix() const
{
std::unique_lock lock{mutex};
if (blocks.empty())
return 0;
block_map::const_iterator i = blocks.begin();
size_t size = 0;
while (i != blocks.end() && !i->blocks.empty())
{
++i;
++size;
}
return size;
}
size_t block_queue::get_num_filled_spans() const
{
std::unique_lock lock{mutex};

View File

@ -1,5 +1,5 @@
// Copyright (c) 2018-2020, The Loki Project
// Copyright (c) 2017-2019, The Monero Project
// Copyright (c) 2018, The Loki Project
//
// All rights reserved.
//
@ -37,7 +37,7 @@
#include <unordered_set>
#include <mutex>
#include <boost/uuid/uuid.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include "crypto/hash.h"
#undef LOKI_DEFAULT_LOG_CATEGORY
#define LOKI_DEFAULT_LOG_CATEGORY "cn.block_queue"
@ -58,11 +58,12 @@ namespace cryptonote
uint64_t nblocks;
float rate;
size_t size;
boost::posix_time::ptime time;
std::chrono::steady_clock::time_point time;
span(uint64_t start_block_height, std::vector<cryptonote::block_complete_entry> blocks, const boost::uuids::uuid &connection_id, float rate, size_t size):
start_block_height(start_block_height), blocks(std::move(blocks)), connection_id(connection_id), nblocks(this->blocks.size()), rate(rate), size(size), time() {}
span(uint64_t start_block_height, uint64_t nblocks, const boost::uuids::uuid &connection_id, boost::posix_time::ptime time):
start_block_height(start_block_height), blocks(std::move(blocks)), connection_id(connection_id), nblocks(this->blocks.size()), rate(rate), size(size),
time{std::chrono::steady_clock::now()} {}
span(uint64_t start_block_height, uint64_t nblocks, const boost::uuids::uuid &connection_id, std::chrono::steady_clock::time_point time):
start_block_height(start_block_height), connection_id(connection_id), nblocks(nblocks), rate(0.0f), size(0), time(time) {}
bool operator<(const span &s) const { return start_block_height < s.start_block_height; }
@ -71,25 +72,23 @@ namespace cryptonote
public:
void add_blocks(uint64_t height, std::vector<cryptonote::block_complete_entry> bcel, const boost::uuids::uuid &connection_id, float rate, size_t size);
void add_blocks(uint64_t height, uint64_t nblocks, const boost::uuids::uuid &connection_id, boost::posix_time::ptime time = boost::date_time::min_date_time);
void add_blocks(uint64_t height, uint64_t nblocks, const boost::uuids::uuid &connection_id, std::chrono::steady_clock::time_point time);
void flush_spans(const boost::uuids::uuid &connection_id, bool all = false);
void flush_stale_spans(const std::set<boost::uuids::uuid> &live_connections);
bool remove_span(uint64_t start_block_height, std::vector<crypto::hash> *hashes = NULL);
bool remove_span(uint64_t start_block_height, std::vector<crypto::hash> *hashes = nullptr);
void remove_spans(const boost::uuids::uuid &connection_id, uint64_t start_block_height);
uint64_t get_max_block_height() const;
void print() const;
std::string get_overview(uint64_t blockchain_height) const;
bool has_unpruned_height(uint64_t block_height, uint64_t blockchain_height, uint32_t pruning_seed) const;
std::pair<uint64_t, uint64_t> reserve_span(uint64_t first_block_height, uint64_t last_block_height, uint64_t max_blocks, const boost::uuids::uuid &connection_id, uint32_t pruning_seed, uint64_t blockchain_height, const std::vector<crypto::hash> &block_hashes, boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time());
std::pair<uint64_t, uint64_t> reserve_span(uint64_t first_block_height, uint64_t last_block_height, uint64_t max_blocks, const boost::uuids::uuid &connection_id, uint32_t pruning_seed, uint64_t blockchain_height, const std::vector<crypto::hash> &block_hashes);
uint64_t get_next_needed_height(uint64_t blockchain_height) const;
std::pair<uint64_t, uint64_t> get_next_span_if_scheduled(std::vector<crypto::hash> &hashes, boost::uuids::uuid &connection_id, boost::posix_time::ptime &time) const;
void reset_next_span_time(boost::posix_time::ptime t = boost::posix_time::microsec_clock::universal_time());
std::pair<uint64_t, uint64_t> get_next_span_if_scheduled(std::vector<crypto::hash> &hashes, boost::uuids::uuid &connection_id) const;
void reset_next_span_time();
void set_span_hashes(uint64_t start_height, const boost::uuids::uuid &connection_id, std::vector<crypto::hash> hashes);
bool get_next_span(uint64_t &height, std::vector<cryptonote::block_complete_entry> &bcel, boost::uuids::uuid &connection_id, bool filled = true) const;
bool has_next_span(const boost::uuids::uuid &connection_id, bool &filled, boost::posix_time::ptime &time) const;
bool has_next_span(uint64_t height, bool &filled, boost::posix_time::ptime &time, boost::uuids::uuid &connection_id) const;
bool has_next_span(uint64_t height, bool &filled, std::chrono::steady_clock::time_point& time, boost::uuids::uuid &connection_id) const;
size_t get_data_size() const;
size_t get_num_filled_spans_prefix() const;
size_t get_num_filled_spans() const;
crypto::hash get_last_known_hash(const boost::uuids::uuid &connection_id) const;
bool has_spans(const boost::uuids::uuid &connection_id) const;

View File

@ -13,11 +13,22 @@ KV_SERIALIZE_MAP_CODE_BEGIN(connection_info)
KV_SERIALIZE(rpc_port)
KV_SERIALIZE(peer_id)
KV_SERIALIZE(recv_count)
KV_SERIALIZE(recv_idle_time)
uint64_t recv_idle_time, send_idle_time, live_time;
if (is_store) {
recv_idle_time = std::chrono::duration_cast<std::chrono::seconds>(this_ref.recv_idle_time).count();
send_idle_time = std::chrono::duration_cast<std::chrono::seconds>(this_ref.send_idle_time).count();
live_time = std::chrono::duration_cast<std::chrono::seconds>(this_ref.live_time).count();
}
KV_SERIALIZE_VALUE(recv_idle_time)
KV_SERIALIZE(send_count)
KV_SERIALIZE(send_idle_time)
KV_SERIALIZE_VALUE(send_idle_time)
KV_SERIALIZE(state)
KV_SERIALIZE(live_time)
KV_SERIALIZE_VALUE(live_time)
if constexpr (!is_store) {
this_ref.recv_idle_time = std::chrono::seconds{recv_idle_time};
this_ref.send_idle_time = std::chrono::seconds{send_idle_time};
this_ref.live_time = std::chrono::seconds{live_time};
}
KV_SERIALIZE(avg_download)
KV_SERIALIZE(current_download)
KV_SERIALIZE(avg_upload)

View File

@ -68,14 +68,14 @@ namespace cryptonote
std::string peer_id;
uint64_t recv_count;
uint64_t recv_idle_time;
std::chrono::milliseconds recv_idle_time;
uint64_t send_count;
uint64_t send_idle_time;
std::chrono::milliseconds send_idle_time;
std::string state;
uint64_t live_time;
std::chrono::milliseconds live_time;
uint64_t avg_download;
uint64_t current_download;

View File

@ -2,8 +2,8 @@
/// @author rfree (current maintainer/user in monero.cc project - most of code is from CryptoNote)
/// @brief This is the original cryptonote protocol network-events handler, modified by us
// Copyright (c) 2018-2020, The Loki Project
// Copyright (c) 2014-2019, The Monero Project
// Copyright (c) 2018, The Loki Project
//
// All rights reserved.
//
@ -40,6 +40,7 @@
#include <boost/uuid/nil_generator.hpp>
#include <list>
#include <ctime>
#include <chrono>
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_basic/verification_context.h"
@ -70,20 +71,24 @@
#define MLOG_PEER_STATE(x) \
MCINFO(LOKI_DEFAULT_LOG_CATEGORY, context << "[" << epee::string_tools::to_string_hex(context.m_pruning_seed) << "] state: " << x << " in state " << cryptonote::get_protocol_state_string(context.m_state))
#define BLOCK_QUEUE_NSPANS_THRESHOLD 10 // chunks of N blocks
#define BLOCK_QUEUE_SIZE_THRESHOLD (100*1024*1024) // MB
#define BLOCK_QUEUE_FORCE_DOWNLOAD_NEAR_BLOCKS 1000
#define REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY (5 * 1000000) // microseconds
#define REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD (30 * 1000000) // microseconds
#define IDLE_PEER_KICK_TIME (600 * 1000000) // microseconds
#define PASSIVE_PEER_KICK_TIME (60 * 1000000) // microseconds
#define DROP_ON_SYNC_WEDGE_THRESHOLD (30 * 1000000000ull) // nanoseconds
#define LAST_ACTIVITY_STALL_THRESHOLD (2.0f) // seconds
namespace cryptonote
{
constexpr size_t BLOCK_QUEUE_NSPANS_THRESHOLD = 10; // chunks of N blocks
constexpr size_t BLOCK_QUEUE_SIZE_THRESHOLD = 100*1024*1024; // bytes, i.e. 100 MB
constexpr uint64_t BLOCK_QUEUE_FORCE_DOWNLOAD_NEAR_BLOCKS = 1000;
constexpr auto REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY = 5s;
constexpr auto REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD = 30s;
constexpr auto IDLE_PEER_KICK_TIME = 10min;
constexpr auto PASSIVE_PEER_KICK_TIME = 1min;
constexpr auto DROP_ON_SYNC_WEDGE_THRESHOLD = 30s;
constexpr auto LAST_ACTIVITY_STALL_THRESHOLD = 2s;
using seconds_f = std::chrono::duration<double>;
// Converts a duration to integer seconds, truncating sub-second amounts.
template <typename Duration>
auto count_seconds(const Duration &d) { return std::chrono::duration_cast<std::chrono::seconds>(d).count(); }
//-----------------------------------------------------------------------------------------------------------------------
template<class t_core>
@ -222,26 +227,28 @@ namespace cryptonote
m_p2p->for_each_connection([&](const connection_context& cntxt, nodetool::peerid_type peer_id, uint32_t support_flags)
{
bool local_ip = cntxt.m_remote_address.is_local();
auto connection_time = time(NULL) - cntxt.m_started;
const auto now = std::chrono::steady_clock::now();
seconds_f connection_time{now - cntxt.m_started};
ss << std::setw(30) << std::left << std::string(cntxt.m_is_income ? " [INC]":"[OUT]") +
cntxt.m_remote_address.str()
<< std::setw(20) << nodetool::peerid_to_string(peer_id)
<< std::setw(20) << std::hex << support_flags
<< std::setw(30) << std::to_string(cntxt.m_recv_cnt)+ "(" + std::to_string(time(NULL) - cntxt.m_last_recv) + ")" + "/" + std::to_string(cntxt.m_send_cnt) + "(" + std::to_string(time(NULL) - cntxt.m_last_send) + ")"
<< std::setw(30) << std::to_string(cntxt.m_recv_cnt) + "(" + std::to_string(count_seconds(now - cntxt.m_last_recv)) + ")" +
"/" + std::to_string(cntxt.m_send_cnt) + "(" + std::to_string(count_seconds(now - cntxt.m_last_send)) + ")"
<< std::setw(25) << get_protocol_state_string(cntxt.m_state)
<< std::setw(20) << std::to_string(time(NULL) - cntxt.m_started)
<< std::setw(12) << std::fixed << (connection_time == 0 ? 0.0 : cntxt.m_recv_cnt / connection_time / 1024)
<< std::setw(20) << std::to_string(count_seconds(connection_time))
<< std::setw(12) << std::fixed << (connection_time < 1s ? 0.0 : cntxt.m_recv_cnt / connection_time.count() / 1024)
<< std::setw(14) << std::fixed << cntxt.m_current_speed_down / 1024
<< std::setw(10) << std::fixed << (connection_time == 0 ? 0.0 : cntxt.m_send_cnt / connection_time / 1024)
<< std::setw(10) << std::fixed << (connection_time < 1s ? 0.0 : cntxt.m_send_cnt / connection_time.count() / 1024)
<< std::setw(13) << std::fixed << cntxt.m_current_speed_up / 1024
<< (local_ip ? "[LAN]" : "")
<< std::left << (cntxt.m_remote_address.is_loopback() ? "[LOCALHOST]" : "") // 127.0.0.1
<< "\n";
if (connection_time > 1)
if (connection_time >= 1s)
{
down_sum += (cntxt.m_recv_cnt / connection_time / 1024);
up_sum += (cntxt.m_send_cnt / connection_time / 1024);
down_sum += (cntxt.m_recv_cnt / connection_time.count() / 1024);
up_sum += (cntxt.m_send_cnt / connection_time.count() / 1024);
}
down_curr_sum += (cntxt.m_current_speed_down / 1024);
@ -269,7 +276,7 @@ namespace cryptonote
m_p2p->for_each_connection([&](const connection_context& cntxt, nodetool::peerid_type peer_id, uint32_t support_flags)
{
connection_info cnx;
auto timestamp = time(NULL);
auto now = std::chrono::steady_clock::now();
cnx.incoming = cntxt.m_is_income ? true : false;
@ -288,21 +295,20 @@ namespace cryptonote
cnx.support_flags = support_flags;
cnx.recv_count = cntxt.m_recv_cnt;
cnx.recv_idle_time = timestamp - std::max(cntxt.m_started, cntxt.m_last_recv);
cnx.live_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - cntxt.m_started);
cnx.recv_idle_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - std::max(cntxt.m_started, cntxt.m_last_recv));
cnx.send_idle_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - std::max(cntxt.m_started, cntxt.m_last_send));
cnx.recv_count = cntxt.m_recv_cnt;
cnx.send_count = cntxt.m_send_cnt;
cnx.send_idle_time = timestamp - std::max(cntxt.m_started, cntxt.m_last_send);
cnx.state = get_protocol_state_string(cntxt.m_state);
cnx.live_time = timestamp - cntxt.m_started;
cnx.localhost = cntxt.m_remote_address.is_loopback();
cnx.local_ip = cntxt.m_remote_address.is_local();
auto connection_time = time(NULL) - cntxt.m_started;
if (connection_time == 0)
seconds_f connection_time{std::chrono::steady_clock::now() - cntxt.m_started};
if (connection_time < 1s)
{
cnx.avg_download = 0;
cnx.avg_upload = 0;
@ -310,8 +316,8 @@ namespace cryptonote
else
{
cnx.avg_download = cntxt.m_recv_cnt / connection_time / 1024;
cnx.avg_upload = cntxt.m_send_cnt / connection_time / 1024;
cnx.avg_download = cntxt.m_recv_cnt / connection_time.count() / 1024;
cnx.avg_upload = cntxt.m_send_cnt / connection_time.count() / 1024;
}
cnx.current_download = cntxt.m_current_speed_down / 1024;
@ -1158,8 +1164,8 @@ namespace cryptonote
MLOG_P2P_MESSAGE("Received NOTIFY_RESPONSE_GET_BLOCKS (" << arg.blocks.size() << " blocks)");
MLOG_PEER_STATE("received blocks");
boost::posix_time::ptime request_time = context.m_last_request_time;
context.m_last_request_time = boost::date_time::not_a_date_time;
auto request_time = *context.m_last_request_time;
context.m_last_request_time.reset();
// calculate size of request
size_t blocks_size = 0, others_size = 0;
@ -1201,7 +1207,7 @@ namespace cryptonote
std::vector<crypto::hash> block_hashes;
block_hashes.reserve(arg.blocks.size());
const boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
const auto now = std::chrono::steady_clock::now();
uint64_t start_height = std::numeric_limits<uint64_t>::max();
cryptonote::block b;
for(const block_complete_entry& block_entry: arg.blocks)
@ -1268,9 +1274,9 @@ namespace cryptonote
" (pruning seed " << epee::string_tools::to_string_hex(context.m_pruning_seed) << ")");
// add that new span to the block queue
const boost::posix_time::time_duration dt = now - request_time;
const float rate = size * 1e6 / (dt.total_microseconds() + 1);
MDEBUG(context << " adding span: " << arg.blocks.size() << " at height " << start_height << ", " << dt.total_microseconds()/1e6 << " seconds, " << (rate/1024) << " kB/s, size now " << (m_block_queue.get_data_size() + blocks_size) / 1048576.f << " MB");
seconds_f dt = now - request_time;
const double rate = size / dt.count();
MDEBUG(context << " adding span: " << arg.blocks.size() << " at height " << start_height << ", " << dt.count() << " seconds, " << (rate/1024) << " kB/s, size now " << (m_block_queue.get_data_size() + blocks_size) / 1048576.f << " MB");
m_block_queue.add_blocks(start_height, arg.blocks, context.m_connection_id, rate, blocks_size);
const crypto::hash last_block_hash = cryptonote::get_block_hash(b);
@ -1455,7 +1461,7 @@ namespace cryptonote
break;
}
const boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time();
const auto start = std::chrono::steady_clock::now();
if (starting)
{
@ -1584,7 +1590,7 @@ namespace cryptonote
if (current_blockchain_height > previous_height)
{
const uint64_t target_blockchain_height = m_core.get_target_blockchain_height();
const boost::posix_time::time_duration dt = boost::posix_time::microsec_clock::universal_time() - start;
seconds_f dt = std::chrono::steady_clock::now() - start;
std::string progress_message = "";
if (current_blockchain_height < target_blockchain_height)
{
@ -1607,8 +1613,8 @@ namespace cryptonote
const uint32_t current_stripe = tools::get_pruning_stripe(current_blockchain_height, target_blockchain_height, CRYPTONOTE_PRUNING_LOG_STRIPES);
std::string timing_message = "";
if (ELPP->vRegistry()->allowed(el::Level::Info, "sync-info"))
timing_message = std::string(" (") + std::to_string(dt.total_microseconds()/1e6) + " sec, "
+ std::to_string((current_blockchain_height - previous_height) * 1e6 / dt.total_microseconds())
timing_message = std::string(" (") + std::to_string(dt.count()) + " sec, "
+ std::to_string((current_blockchain_height - previous_height) / dt.count())
+ " blocks/sec), " + std::to_string(m_block_queue.get_data_size() / 1048576.f) + " MB queued in "
+ std::to_string(m_block_queue.get_num_filled_spans()) + " spans, stripe "
+ std::to_string(previous_stripe) + " -> " + std::to_string(current_stripe);
@ -1714,15 +1720,14 @@ skip:
MTRACE("Checking for idle peers...");
m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)->bool
{
if (context.m_state == cryptonote_connection_context::state_synchronizing && context.m_last_request_time != boost::date_time::not_a_date_time)
if (context.m_state == cryptonote_connection_context::state_synchronizing && context.m_last_request_time)
{
const boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
const boost::posix_time::time_duration dt = now - context.m_last_request_time;
if (dt.total_microseconds() > IDLE_PEER_KICK_TIME)
const auto dt = std::chrono::steady_clock::now() - *context.m_last_request_time;
if (dt > IDLE_PEER_KICK_TIME)
{
MINFO(context << " kicking idle peer, last update " << (dt.total_microseconds() / 1.e6) << " seconds ago");
MINFO(context << " kicking idle peer, last update " << seconds_f{dt}.count() << " seconds ago");
LOG_PRINT_CCONTEXT_L2("requesting callback");
context.m_last_request_time = boost::date_time::not_a_date_time;
context.m_last_request_time.reset();
context.m_state = cryptonote_connection_context::state_standby; // we'll go back to adding, then (if we can't), download
++context.m_callback_request_count;
m_p2p->request_callback(context);
@ -1809,9 +1814,7 @@ skip:
template<class t_core>
bool t_cryptonote_protocol_handler<t_core>::should_download_next_span(cryptonote_connection_context& context, bool standby)
{
std::vector<crypto::hash> hashes;
boost::uuids::uuid span_connection_id;
boost::posix_time::ptime request_time;
std::chrono::steady_clock::time_point request_time;
boost::uuids::uuid connection_id;
std::pair<uint64_t, uint64_t> span;
bool filled;
@ -1819,7 +1822,7 @@ skip:
const uint64_t blockchain_height = m_core.get_current_blockchain_height();
if (context.m_remote_blockchain_height <= blockchain_height)
return false;
const boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
const auto now = std::chrono::steady_clock::now();
const bool has_next_block = tools::has_unpruned_block(blockchain_height, context.m_remote_blockchain_height, context.m_pruning_seed);
if (has_next_block)
{
@ -1830,10 +1833,10 @@ skip:
}
if (!filled)
{
const long dt = (now - request_time).total_microseconds();
const auto dt = now - request_time;
if (dt >= REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD)
{
MDEBUG(context << " we should download it as it's not been received yet after " << dt/1e6);
MDEBUG(context << " we should download it as it's not been received yet after " << seconds_f{dt}.count());
return true;
}
@ -1845,13 +1848,11 @@ skip:
{
bool download = false;
if (m_p2p->for_connection(connection_id, [&](cryptonote_connection_context& ctx, nodetool::peerid_type peer_id, uint32_t f)->bool{
const time_t nowt = time(NULL);
const time_t time_since_last_recv = nowt - ctx.m_last_recv;
const float last_activity = std::min((float)time_since_last_recv, dt/1e6f);
const auto last_activity = std::min(now - ctx.m_last_recv, dt);
const bool stalled = last_activity > LAST_ACTIVITY_STALL_THRESHOLD;
if (stalled)
{
MDEBUG(context << " we should download it as the downloading peer is stalling for " << nowt - ctx.m_last_recv << " seconds");
MDEBUG(context << " we should download it as the downloading peer is stalling for " << seconds_f{last_activity}.count() << " seconds");
download = true;
return true;
}
@ -1866,13 +1867,21 @@ skip:
float multiplier = max_multiplier;
if (dt >= REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY)
{
multiplier = max_multiplier - (dt-REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY) * (max_multiplier - min_multiplier) / (REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD - REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY);
multiplier = max_multiplier - (
(max_multiplier - min_multiplier)
*
(
seconds_f{ dt - REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY}
/
seconds_f{REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD - REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY}
)
);
multiplier = std::min(max_multiplier, std::max(min_multiplier, multiplier));
}
if (dl_speed * .8f > ctx.m_current_speed_down * multiplier)
{
MDEBUG(context << " we should download it as we are substantially faster (" << dl_speed << " vs "
<< ctx.m_current_speed_down << ", multiplier " << multiplier << " after " << dt/1e6 << " seconds)");
<< ctx.m_current_speed_down << ", multiplier " << multiplier << " after " << seconds_f{dt}.count() << " seconds)");
download = true;
return true;
}
@ -2044,7 +2053,7 @@ skip:
if (sync)
{
bool filled = false;
boost::posix_time::ptime time;
std::chrono::steady_clock::time_point time;
boost::uuids::uuid connection_id;
if (m_block_queue.has_next_span(m_core.get_current_blockchain_height(), filled, time, connection_id) && filled)
{
@ -2062,7 +2071,7 @@ skip:
// if this has gone on for too long, drop incoming connection to guard against some wedge state
if (!context.m_is_income)
{
const uint64_t ns = epee::misc_utils::get_ns_count() - m_last_add_end_time;
std::chrono::nanoseconds ns{epee::misc_utils::get_ns_count() - m_last_add_end_time};
if (ns >= DROP_ON_SYNC_WEDGE_THRESHOLD)
{
MDEBUG(context << "Block addition seems to have wedged, dropping connection");
@ -2104,8 +2113,7 @@ skip:
{
std::vector<crypto::hash> hashes;
boost::uuids::uuid span_connection_id;
boost::posix_time::ptime time;
span = m_block_queue.get_next_span_if_scheduled(hashes, span_connection_id, time);
span = m_block_queue.get_next_span_if_scheduled(hashes, span_connection_id);
if (span.second > 0)
{
is_next = true;
@ -2148,8 +2156,7 @@ skip:
MDEBUG(context << " still no span reserved, we may be in the corner case of next span scheduled and everything else scheduled/filled");
std::vector<crypto::hash> hashes;
boost::uuids::uuid span_connection_id;
boost::posix_time::ptime time;
span = m_block_queue.get_next_span_if_scheduled(hashes, span_connection_id, time);
span = m_block_queue.get_next_span_if_scheduled(hashes, span_connection_id);
if (span.second > 0 && !tools::has_unpruned_block(span.first, context.m_remote_blockchain_height, context.m_pruning_seed))
span = std::make_pair(0, 0);
if (span.second > 0)
@ -2196,7 +2203,7 @@ skip:
context.m_needed_objects = std::vector<crypto::hash>(context.m_needed_objects.begin() + span.second, context.m_needed_objects.end());
}
context.m_last_request_time = boost::posix_time::microsec_clock::universal_time();
context.m_last_request_time = std::chrono::steady_clock::now();
MLOG_P2P_MESSAGE("-->>NOTIFY_REQUEST_GET_OBJECTS: blocks.size()=" << req.blocks.size()
<< "requested blocks count=" << count << " / " << count_limit << " from " << span.first << ", first hash " << req.blocks.front());
@ -2271,7 +2278,7 @@ skip:
r.block_ids.push_front(context.m_last_known_hash);
}
context.m_last_request_time = boost::posix_time::microsec_clock::universal_time();
context.m_last_request_time = std::chrono::steady_clock::now();
MLOG_P2P_MESSAGE("-->>NOTIFY_REQUEST_CHAIN: m_block_ids.size()=" << r.block_ids.size() << ", start_from_current_chain " << start_from_current_chain);
post_notify<NOTIFY_REQUEST_CHAIN>(r, context);
MLOG_PEER_STATE("requesting chain");
@ -2373,7 +2380,7 @@ skip:
<< ", m_start_height=" << arg.start_height << ", m_total_height=" << arg.total_height);
MLOG_PEER_STATE("received chain");
context.m_last_request_time = boost::date_time::not_a_date_time;
context.m_last_request_time.reset();
m_sync_download_chain_size += arg.m_block_ids.size() * sizeof(crypto::hash);
@ -2579,15 +2586,15 @@ skip:
template<class t_core>
std::string t_cryptonote_protocol_handler<t_core>::get_peers_overview() const
{
std::stringstream ss;
const boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
std::ostringstream ss;
const auto now = std::chrono::steady_clock::now();
m_p2p->for_each_connection([&](const connection_context &ctx, nodetool::peerid_type peer_id, uint32_t support_flags) {
const uint32_t stripe = tools::get_pruning_stripe(ctx.m_pruning_seed);
char state_char = cryptonote::get_protocol_state_char(ctx.m_state);
ss << stripe + state_char;
if (ctx.m_last_request_time != boost::date_time::not_a_date_time)
ss << (((now - ctx.m_last_request_time).total_microseconds() > IDLE_PEER_KICK_TIME) ? "!" : "?");
ss << + " ";
if (ctx.m_last_request_time)
ss << ((now - *ctx.m_last_request_time > IDLE_PEER_KICK_TIME) ? "!" : "?");
ss << " ";
return true;
});
return ss.str();

View File

@ -45,7 +45,6 @@ target_link_libraries(daemon
serialization
daemon_rpc_server
version
Boost::chrono
Boost::filesystem
Boost::program_options
Boost::system

View File

@ -614,6 +614,10 @@ bool rpc_command_executor::mining_status() {
return true;
}
// Converts a duration to integer seconds, truncating sub-second amounts.
template <typename Duration>
static auto count_seconds(const Duration &d) { return std::chrono::duration_cast<std::chrono::seconds>(d).count(); }
bool rpc_command_executor::print_connections() {
GET_CONNECTIONS::response res{};
@ -646,9 +650,9 @@ bool rpc_command_executor::print_connections() {
<< std::setw(6) << (info.ssl ? "yes" : "no")
<< std::setw(20) << info.peer_id
<< std::setw(20) << info.support_flags
<< std::setw(30) << std::to_string(info.recv_count) + "(" + std::to_string(info.recv_idle_time) + ")/" + std::to_string(info.send_count) + "(" + std::to_string(info.send_idle_time) + ")"
<< std::setw(30) << std::to_string(info.recv_count) + "(" + std::to_string(count_seconds(info.recv_idle_time)) + ")/" + std::to_string(info.send_count) + "(" + std::to_string(count_seconds(info.send_idle_time)) + ")"
<< std::setw(25) << info.state
<< std::setw(20) << info.live_time
<< std::setw(20) << std::to_string(count_seconds(info.live_time))
<< std::setw(12) << info.avg_download
<< std::setw(14) << info.current_download
<< std::setw(10) << info.avg_upload

View File

@ -35,7 +35,6 @@ if(MSVC OR MINGW)
target_link_libraries(daemonizer
PUBLIC
common
Boost::chrono
Boost::filesystem
Boost::program_options
PRIVATE

View File

@ -73,7 +73,7 @@ int main(int argc, char* argv[])
SL(boost::thread);
SL(boost::asio::io_service);
SL(boost::asio::io_service::work);
SL(boost::asio::deadline_timer);
SL(boost::asio::steady_timer);
SL(cryptonote::DB_ERROR);
SL(cryptonote::mdb_txn_safe);

View File

@ -56,7 +56,6 @@ if(DEVICE_TREZOR_READY)
cryptonote_core
common
sodium
Boost::chrono
libusb
protobuf
extra)

View File

@ -32,10 +32,10 @@
#endif
#include <algorithm>
#include <chrono>
#include <boost/endian/conversion.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/udp.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/format.hpp>
#include <boost/bind/bind.hpp>
#include "common/apply_permutation.h"
@ -567,7 +567,7 @@ namespace trezor{
return ping_int();
}
bool UdpTransport::ping_int(boost::posix_time::time_duration timeout){
bool UdpTransport::ping_int(std::chrono::milliseconds timeout){
require_socket();
try {
std::string req = "PINGPING";
@ -611,7 +611,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_at(std::chrono::steady_clock::time_point::max());
check_deadline();
m_proto->session_begin(*this);
@ -693,14 +693,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, std::chrono::milliseconds 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
@ -710,10 +710,9 @@ namespace trezor{
ec = boost::asio::error::would_block;
std::size_t length = 0;
// Start the asynchronous operation itself. The handle_receive function
// used as a callback will update the ec and length variables.
// Start the asynchronous operation itself.
m_socket->async_receive_from(boost::asio::buffer(buffer), m_endpoint,
boost::bind(&UdpTransport::handle_receive, _1, _2, &ec, &length));
[&ec, &length] (const boost::system::error_code &ec_, std::size_t length_) { ec = ec_; length = length_; });
// Block until the asynchronous operation has completed.
do {
@ -758,7 +757,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() <= std::chrono::steady_clock::now())
{
// The deadline has passed. The outstanding asynchronous operation needs
// to be cancelled so that the blocked receive() function will return.
@ -770,17 +769,11 @@ 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_at(std::chrono::steady_clock::time_point::max());
}
// Put the actor back to sleep.
m_deadline.async_wait(boost::bind(&UdpTransport::check_deadline, this));
}
void UdpTransport::handle_receive(const boost::system::error_code &ec, std::size_t length,
boost::system::error_code *out_ec, std::size_t *out_length) {
*out_ec = ec;
*out_length = length;
m_deadline.async_wait([this] (const boost::system::error_code&) { check_deadline(); });
}
std::ostream& UdpTransport::dump(std::ostream& o) const {

View File

@ -32,12 +32,11 @@
#include <boost/asio.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/array.hpp>
#include <boost/asio/steady_timer.hpp>
#include <string_view>
#include <typeinfo>
#include <type_traits>
#include <chrono>
#include "net/http_client.h"
#include "rapidjson/document.h"
@ -234,11 +233,9 @@ 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, std::chrono::milliseconds timeout = 10s);
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(std::chrono::milliseconds timeout = 1500ms);
std::shared_ptr<Protocol> m_proto;
std::string m_device_host;
@ -246,7 +243,7 @@ namespace trezor {
std::unique_ptr<udp::socket> m_socket;
boost::asio::io_service m_io_service;
boost::asio::deadline_timer m_deadline;
boost::asio::steady_timer m_deadline;
udp::endpoint m_endpoint;
};

View File

@ -37,7 +37,6 @@ target_link_libraries(gen_multisig
rpc_commands
cryptonote_core
epee
Boost::chrono
Boost::program_options
Boost::filesystem
version

View File

@ -40,7 +40,6 @@ target_link_libraries(p2p
version
net
miniupnpc
Boost::chrono
Boost::program_options
Boost::filesystem
Boost::serialization

View File

@ -28,9 +28,6 @@
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include <boost/algorithm/string/find_iterator.hpp>
#include <boost/algorithm/string/finder.hpp>
#include <boost/chrono/duration.hpp>
#include <boost/endian/conversion.hpp>
#include <future>
#include <optional>
@ -50,9 +47,11 @@
#include "p2p/p2p_protocol_defs.h"
#include "string_tools.h"
using namespace std::literals;
namespace
{
constexpr const boost::chrono::milliseconds future_poll_interval{500};
constexpr const std::chrono::milliseconds future_poll_interval = 500ms;
constexpr const std::chrono::seconds socks_connect_timeout{P2P_DEFAULT_SOCKS_CONNECT_TIMEOUT};
std::int64_t get_max_connections(const boost::iterator_range<std::string_view::const_iterator> value) noexcept

View File

@ -34,7 +34,6 @@
#include <algorithm>
#include <optional>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <atomic>
@ -906,7 +905,7 @@ namespace nodetool
{
// If this is a new (<10s) connection and we're still in before handshake mode then
// don't count it yet: it is probably a back ping connection that will be closed soon.
if (!(cntxt.m_state == p2p_connection_context::state_before_handshake && std::time(NULL) < cntxt.m_started + 10))
if (!(cntxt.m_state == p2p_connection_context::state_before_handshake && std::chrono::steady_clock::now() < cntxt.m_started + 10s))
++number_of_out_peers;
}
return true;

View File

@ -92,6 +92,5 @@ target_link_libraries(daemon_rpc_server
rpc
daemon_messages
serialization
Boost::chrono
Boost::thread
extra)

View File

@ -34,7 +34,6 @@ target_link_libraries(serialization
PRIVATE
cryptonote_core
cryptonote_protocol
Boost::chrono
Boost::thread
version
extra)

View File

@ -37,7 +37,6 @@ target_link_libraries(simplewallet
rpc_commands
cryptonote_core
mnemonics
Boost::chrono
Boost::program_options
Boost::filesystem
icu

View File

@ -46,7 +46,6 @@ target_link_libraries(wallet
device_trezor
net
lmdb
Boost::chrono
Boost::serialization
Boost::filesystem
Boost::thread

View File

@ -45,7 +45,6 @@ target_link_libraries(wallet_api
cryptonote_core
mnemonics
lmdb
Boost::chrono
Boost::serialization
Boost::filesystem
Boost::thread

View File

@ -2152,8 +2152,8 @@ void WalletImpl::refreshThreadFunc()
// if auto refresh enabled, we wait for the "m_refreshIntervalSeconds" interval.
// if not - we wait forever
if (m_refreshIntervalMillis > 0) {
boost::posix_time::milliseconds wait_for_ms(m_refreshIntervalMillis.load());
m_refreshCV.timed_wait(lock, wait_for_ms);
std::chrono::milliseconds wait_for_ms{m_refreshIntervalMillis.load()};
m_refreshCV.wait_for(lock, wait_for_ms);
} else {
m_refreshCV.wait(lock);
}

View File

@ -61,12 +61,13 @@
#undef LOKI_DEFAULT_LOG_CATEGORY
#define LOKI_DEFAULT_LOG_CATEGORY "wallet.rpc"
#define DEFAULT_AUTO_REFRESH_PERIOD 20 // seconds
namespace rpc = cryptonote::rpc;
namespace
{
using namespace std::literals;
constexpr auto DEFAULT_AUTO_REFRESH_PERIOD = 20s;
const command_line::arg_descriptor<std::string, true> arg_rpc_bind_port = {"rpc-bind-port", "Sets bind port for server"};
const command_line::arg_descriptor<bool> arg_disable_rpc_login = {"disable-rpc-login", "Disable HTTP authentication for RPC connections served by this process"};
const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", "Restricts to view-only commands", false};
@ -111,12 +112,13 @@ namespace tools
{
m_stop = false;
m_net_server.add_idle_handler([this](){
if (m_auto_refresh_period == 0) // disabled
if (m_auto_refresh_period == 0s) // disabled
return true;
const auto now = std::chrono::steady_clock::now();
if (!m_long_poll_new_changes)
{
if (boost::posix_time::microsec_clock::universal_time() < m_last_auto_refresh_time + boost::posix_time::seconds(m_auto_refresh_period))
if (now < m_last_auto_refresh_time + m_auto_refresh_period)
return true;
}
m_long_poll_new_changes = false; // Always consume the change, if we miss one due to thread race, not the end of the world.
@ -126,9 +128,9 @@ namespace tools
} catch (const std::exception& ex) {
LOG_ERROR("Exception at while refreshing, what=" << ex.what());
}
m_last_auto_refresh_time = boost::posix_time::microsec_clock::universal_time();
m_last_auto_refresh_time = now;
return true;
}, 1000);
}, 1s);
m_net_server.add_idle_handler([this](){
if (m_stop.load(std::memory_order_relaxed))
@ -137,13 +139,13 @@ namespace tools
return false;
}
return true;
}, 500);
}, 500ms);
m_long_poll_thread = std::thread([&] {
for (;;)
{
if (m_long_poll_disabled) return true;
if (m_auto_refresh_period == 0)
if (m_auto_refresh_period == 0s)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
continue;
@ -260,7 +262,7 @@ namespace tools
} // end auth enabled
m_auto_refresh_period = DEFAULT_AUTO_REFRESH_PERIOD;
m_last_auto_refresh_time = boost::posix_time::min_date_time;
m_last_auto_refresh_time = std::chrono::steady_clock::time_point::min();
m_net_server.set_threads_prefix("RPC");
auto rng = [](size_t len, uint8_t *ptr) { return crypto::rand(len, ptr); };
@ -2833,8 +2835,8 @@ namespace tools
}
try
{
m_auto_refresh_period = req.enable ? req.period ? req.period : DEFAULT_AUTO_REFRESH_PERIOD : 0;
MINFO("Auto refresh now " << (m_auto_refresh_period ? std::to_string(m_auto_refresh_period) + " seconds" : std::string("disabled")));
m_auto_refresh_period = req.enable ? req.period ? std::chrono::seconds{req.period} : DEFAULT_AUTO_REFRESH_PERIOD : 0s;
MINFO("Auto refresh now " << (m_auto_refresh_period != 0s ? std::to_string(std::chrono::duration<float>(m_auto_refresh_period).count()) + " seconds" : std::string("disabled")));
return true;
}
catch (const std::exception& e)

View File

@ -288,8 +288,8 @@ namespace tools
std::atomic<bool> m_stop;
bool m_restricted;
boost::program_options::variables_map m_vm;
uint32_t m_auto_refresh_period;
boost::posix_time::ptime m_last_auto_refresh_time;
std::chrono::milliseconds m_auto_refresh_period;
std::chrono::steady_clock::time_point m_last_auto_refresh_time;
std::thread m_long_poll_thread;
std::atomic<bool> m_long_poll_new_changes;
};

View File

@ -140,7 +140,6 @@ target_link_libraries(http-client_fuzz_tests
common
epee
Boost::thread
Boost::chrono
Boost::program_options
Boost::system
extra)
@ -154,7 +153,6 @@ target_link_libraries(levin_fuzz_tests
common
epee
Boost::thread
Boost::chrono
Boost::program_options
extra)
set_property(TARGET levin_fuzz_tests
@ -167,7 +165,6 @@ target_link_libraries(bulletproof_fuzz_tests
common
epee
Boost::thread
Boost::chrono
Boost::program_options
extra)
set_property(TARGET bulletproof_fuzz_tests

View File

@ -37,7 +37,6 @@ target_link_libraries(libwallet_api_tests
wallet
version
epee
Boost::chrono
Boost::serialization
Boost::filesystem
Boost::locale

View File

@ -34,7 +34,6 @@ target_link_libraries(net_load_tests_clt
cryptonote_core
epee
gtest
Boost::chrono
Boost::date_time
Boost::thread
extra)
@ -47,7 +46,6 @@ target_link_libraries(net_load_tests_srv
cryptonote_core
epee
gtest
Boost::chrono
Boost::date_time
extra)

View File

@ -190,10 +190,10 @@ namespace
if (0 < count)
{
// Perhaps not all connections were closed, try to close it after 7 seconds
std::shared_ptr<boost::asio::deadline_timer> sh_deadline(new boost::asio::deadline_timer(m_tcp_server.get_io_service(), boost::posix_time::seconds(7)));
auto sh_deadline = std::make_shared<boost::asio::steady_timer>(m_tcp_server.get_io_service(), 7s);
sh_deadline->async_wait([=](const boost::system::error_code& ec)
{
std::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);

View File

@ -34,7 +34,6 @@ target_link_libraries(performance_tests
cryptonote_core
common
epee
Boost::chrono
Boost::program_options
extra)
set_property(TARGET performance_tests

View File

@ -47,7 +47,6 @@ target_link_libraries(trezor_tests
rpc
cryptonote_protocol
daemon_rpc_server
Boost::chrono
Boost::filesystem
Boost::program_options
${ZMQ_LIB}

View File

@ -106,7 +106,6 @@ target_link_libraries(unit_tests
wallet
p2p
version
Boost::chrono
Boost::thread
miniupnpc
gtest

View File

@ -53,13 +53,13 @@ TEST(block_queue, empty)
TEST(block_queue, add_stepwise)
{
cryptonote::block_queue bq;
bq.add_blocks(0, 200, uuid1());
bq.add_blocks(0, 200, uuid1(), std::chrono::steady_clock::now());
ASSERT_EQ(bq.get_max_block_height(), 199);
bq.add_blocks(200, 200, uuid1());
bq.add_blocks(200, 200, uuid1(), std::chrono::steady_clock::now());
ASSERT_EQ(bq.get_max_block_height(), 399);
bq.add_blocks(401, 200, uuid1());
bq.add_blocks(401, 200, uuid1(), std::chrono::steady_clock::now());
ASSERT_EQ(bq.get_max_block_height(), 600);
bq.add_blocks(400, 10, uuid1());
bq.add_blocks(400, 10, uuid1(), std::chrono::steady_clock::now());
ASSERT_EQ(bq.get_max_block_height(), 600);
}
@ -67,21 +67,21 @@ TEST(block_queue, flush_uuid)
{
cryptonote::block_queue bq;
bq.add_blocks(0, 200, uuid1());
bq.add_blocks(0, 200, uuid1(), std::chrono::steady_clock::now());
ASSERT_EQ(bq.get_max_block_height(), 199);
bq.add_blocks(200, 200, uuid2());
bq.add_blocks(200, 200, uuid2(), std::chrono::steady_clock::now());
ASSERT_EQ(bq.get_max_block_height(), 399);
bq.flush_spans(uuid2());
ASSERT_EQ(bq.get_max_block_height(), 199);
bq.flush_spans(uuid1());
ASSERT_EQ(bq.get_max_block_height(), 0);
bq.add_blocks(0, 200, uuid1());
bq.add_blocks(0, 200, uuid1(), std::chrono::steady_clock::now());
ASSERT_EQ(bq.get_max_block_height(), 199);
bq.add_blocks(200, 200, uuid2());
bq.add_blocks(200, 200, uuid2(), std::chrono::steady_clock::now());
ASSERT_EQ(bq.get_max_block_height(), 399);
bq.flush_spans(uuid1());
ASSERT_EQ(bq.get_max_block_height(), 399);
bq.add_blocks(0, 200, uuid1());
bq.add_blocks(0, 200, uuid1(), std::chrono::steady_clock::now());
ASSERT_EQ(bq.get_max_block_height(), 399);
}