mirror of
https://github.com/wownero/wownero.git
synced 2026-10-28 11:58:34 +01:00
Transition asio::deadline_timer to asio::steady_timer
This commit is contained in:
@@ -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);
|
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);
|
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>
|
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
|
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):
|
idle_callback_conext_base(boost::asio::io_context& io_serice):
|
||||||
m_timer(io_serice)
|
m_timer(io_serice)
|
||||||
{}
|
{}
|
||||||
boost::asio::deadline_timer m_timer;
|
boost::asio::steady_timer m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class t_handler>
|
template <class t_handler>
|
||||||
struct idle_callback_conext: public idle_callback_conext_base
|
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),
|
idle_callback_conext_base(io_serice),
|
||||||
m_handler(h)
|
m_handler(h),
|
||||||
{this->m_period = period;}
|
m_period(period)
|
||||||
|
{}
|
||||||
|
|
||||||
t_handler m_handler;
|
t_handler m_handler;
|
||||||
virtual bool call_handler()
|
virtual bool call_handler()
|
||||||
{
|
{
|
||||||
return m_handler();
|
return m_handler();
|
||||||
}
|
}
|
||||||
uint64_t m_period;
|
const std::chrono::milliseconds m_period;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class t_handler>
|
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 ?...
|
//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));
|
ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler<t_handler>, this, ptr));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class t_handler>
|
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 handler return false - he don't want to be called anymore
|
||||||
if(!ptr->call_handler())
|
if(!ptr->call_handler())
|
||||||
return true;
|
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));
|
ptr->m_timer.async_wait(boost::bind(&boosted_tcp_server<t_protocol_handler>::global_timer_handler<t_handler>, this, ptr));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
#include <boost/chrono.hpp>
|
#include <boost/chrono.hpp>
|
||||||
#include <boost/utility/value_init.hpp>
|
#include <boost/utility/value_init.hpp>
|
||||||
#include <boost/asio/bind_executor.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/date_time/posix_time/posix_time.hpp> // TODO
|
||||||
#include <boost/thread/condition_variable.hpp> // TODO
|
#include <boost/thread/condition_variable.hpp> // TODO
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
@@ -1894,7 +1894,7 @@ namespace net_utils
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
template<class t_protocol_handler> template<class t_callback>
|
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();
|
TRY_ENTRY();
|
||||||
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_context_, m_state, m_connection_type, ssl_support, std::move(initial)) );
|
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
|
//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)
|
sh_deadline->async_wait([=](const boost::system::error_code& error)
|
||||||
{
|
{
|
||||||
if(error != boost::asio::error::operation_aborted)
|
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();
|
new_connection_l->socket().close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#ifndef _LEVIN_BASE_H_
|
#ifndef _LEVIN_BASE_H_
|
||||||
#define _LEVIN_BASE_H_
|
#define _LEVIN_BASE_H_
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include "byte_stream.h"
|
#include "byte_stream.h"
|
||||||
@@ -72,7 +73,7 @@ namespace levin
|
|||||||
#pragma pack(pop)
|
#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_INITIAL_MAX_PACKET_SIZE 256*1024 // 256 KiB before handshake
|
||||||
#define LEVIN_DEFAULT_MAX_PACKET_SIZE 100000000 //100MB by default after handshake
|
#define LEVIN_DEFAULT_MAX_PACKET_SIZE 100000000 //100MB by default after handshake
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
#include <boost/asio/steady_timer.hpp>
|
||||||
#include <boost/uuid/uuid_generators.hpp>
|
#include <boost/uuid/uuid_generators.hpp>
|
||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
#include <boost/smart_ptr/make_shared.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
@@ -100,10 +100,10 @@ public:
|
|||||||
typedef t_connection_context connection_context;
|
typedef t_connection_context connection_context;
|
||||||
uint64_t m_initial_max_packet_size;
|
uint64_t m_initial_max_packet_size;
|
||||||
uint64_t m_max_packet_size;
|
uint64_t m_max_packet_size;
|
||||||
uint64_t m_invoke_timeout;
|
std::chrono::milliseconds m_invoke_timeout;
|
||||||
|
|
||||||
template<class callback_t>
|
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);
|
int send(epee::byte_slice message, const boost::uuids::uuid& connection_id);
|
||||||
bool close(boost::uuids::uuid connection_id);
|
bool close(boost::uuids::uuid connection_id);
|
||||||
@@ -190,19 +190,19 @@ public:
|
|||||||
template <class callback_t>
|
template <class callback_t>
|
||||||
struct anvoke_handler: invoke_response_handler_base
|
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_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)
|
m_cancel_timer_called(false), m_timer_cancelled(false), m_command(command)
|
||||||
{
|
{
|
||||||
if(m_con.start_outer_call())
|
if(m_con.start_outer_call())
|
||||||
{
|
{
|
||||||
MDEBUG(con.get_context_ref() << "anvoke_handler, timeout: " << timeout);
|
MDEBUG(con.get_context_ref() << "anvoke_handler, timeout: " << timeout.count());
|
||||||
m_timer.expires_from_now(boost::posix_time::milliseconds(timeout));
|
m_timer.expires_after(timeout);
|
||||||
m_timer.async_wait([&con, command, cb, timeout](const boost::system::error_code& ec)
|
m_timer.async_wait([&con, command, cb, timeout](const boost::system::error_code& ec)
|
||||||
{
|
{
|
||||||
if(ec == boost::asio::error::operation_aborted)
|
if(ec == boost::asio::error::operation_aborted)
|
||||||
return;
|
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;
|
epee::span<const uint8_t> fake;
|
||||||
cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref());
|
cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref());
|
||||||
con.close();
|
con.close();
|
||||||
@@ -215,11 +215,11 @@ public:
|
|||||||
{}
|
{}
|
||||||
callback_t m_cb;
|
callback_t m_cb;
|
||||||
async_protocol_handler& m_con;
|
async_protocol_handler& m_con;
|
||||||
boost::asio::deadline_timer m_timer;
|
boost::asio::steady_timer m_timer;
|
||||||
bool m_timer_started;
|
bool m_timer_started;
|
||||||
bool m_cancel_timer_called;
|
bool m_cancel_timer_called;
|
||||||
bool m_timer_cancelled;
|
bool m_timer_cancelled;
|
||||||
uint64_t m_timeout;
|
const std::chrono::milliseconds m_timeout;
|
||||||
int m_command;
|
int m_command;
|
||||||
virtual bool handle(int res, const epee::span<const uint8_t> buff, typename async_protocol_handler::connection_context& context)
|
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)
|
if(!m_cancel_timer_called)
|
||||||
{
|
{
|
||||||
m_cancel_timer_called = true;
|
m_cancel_timer_called = true;
|
||||||
boost::system::error_code ignored_ec;
|
m_timer_cancelled = 1 == m_timer.cancel();
|
||||||
m_timer_cancelled = 1 == m_timer.cancel(ignored_ec);
|
|
||||||
}
|
}
|
||||||
return m_timer_cancelled;
|
return m_timer_cancelled;
|
||||||
}
|
}
|
||||||
virtual void reset_timer()
|
virtual void reset_timer()
|
||||||
{
|
{
|
||||||
boost::system::error_code ignored_ec;
|
if (!m_cancel_timer_called && m_timer.cancel() > 0)
|
||||||
if (!m_cancel_timer_called && m_timer.cancel(ignored_ec) > 0)
|
|
||||||
{
|
{
|
||||||
callback_t& cb = m_cb;
|
callback_t& cb = m_cb;
|
||||||
uint64_t timeout = m_timeout;
|
const auto timeout = m_timeout;
|
||||||
async_protocol_handler& con = m_con;
|
async_protocol_handler& con = m_con;
|
||||||
int command = m_command;
|
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)
|
m_timer.async_wait([&con, cb, command, timeout](const boost::system::error_code& ec)
|
||||||
{
|
{
|
||||||
if(ec == boost::asio::error::operation_aborted)
|
if(ec == boost::asio::error::operation_aborted)
|
||||||
return;
|
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;
|
epee::span<const uint8_t> fake;
|
||||||
cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref());
|
cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref());
|
||||||
con.close();
|
con.close();
|
||||||
@@ -279,7 +277,7 @@ public:
|
|||||||
std::list<boost::shared_ptr<invoke_response_handler_base> > m_invoke_response_handlers;
|
std::list<boost::shared_ptr<invoke_response_handler_base> > m_invoke_response_handlers;
|
||||||
|
|
||||||
template<class callback_t>
|
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);
|
CRITICAL_REGION_LOCAL(m_invoke_response_handlers_lock);
|
||||||
if (m_protocol_released)
|
if (m_protocol_released)
|
||||||
@@ -604,7 +602,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class callback_t>
|
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(
|
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler(
|
||||||
boost::bind(&async_protocol_handler::finish_outer_call, this));
|
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>
|
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;
|
async_protocol_handler<t_connection_context>* aph;
|
||||||
int r = find_and_lock_connection(connection_id, aph);
|
int r = find_and_lock_connection(connection_id, aph);
|
||||||
|
|||||||
@@ -56,7 +56,6 @@
|
|||||||
#include <boost/uuid/random_generator.hpp>
|
#include <boost/uuid/random_generator.hpp>
|
||||||
#include <boost/chrono.hpp>
|
#include <boost/chrono.hpp>
|
||||||
#include <boost/utility/value_init.hpp>
|
#include <boost/utility/value_init.hpp>
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
#include "misc_language.h"
|
#include "misc_language.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace epee
|
|||||||
namespace net_utils
|
namespace net_utils
|
||||||
{
|
{
|
||||||
template<class t_result, class t_arg, class callback_t, class t_transport>
|
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;
|
const boost::uuids::uuid &conn_id = context.m_connection_id;
|
||||||
typename serialization::portable_storage stg;
|
typename serialization::portable_storage stg;
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ int main(int argc, char* argv[])
|
|||||||
SL(boost::thread);
|
SL(boost::thread);
|
||||||
SL(boost::asio::io_context);
|
SL(boost::asio::io_context);
|
||||||
SL(boost::asio::executor_work_guard<boost::asio::io_context::executor_type>);
|
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::DB_ERROR);
|
||||||
SL(cryptonote::mdb_txn_safe);
|
SL(cryptonote::mdb_txn_safe);
|
||||||
|
|||||||
@@ -571,7 +571,7 @@ namespace trezor{
|
|||||||
return ping_int();
|
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();
|
require_socket();
|
||||||
try {
|
try {
|
||||||
std::string req = "PINGPING";
|
std::string req = "PINGPING";
|
||||||
@@ -619,7 +619,7 @@ namespace trezor{
|
|||||||
m_socket.reset(new udp::socket(m_io_service));
|
m_socket.reset(new udp::socket(m_io_service));
|
||||||
m_socket->open(udp::v4());
|
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();
|
check_deadline();
|
||||||
|
|
||||||
m_proto->session_begin(*this);
|
m_proto->session_begin(*this);
|
||||||
@@ -701,14 +701,14 @@ namespace trezor{
|
|||||||
return static_cast<size_t>(len);
|
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::system::error_code ec;
|
||||||
boost::asio::mutable_buffer buffer = boost::asio::buffer(buff, size);
|
boost::asio::mutable_buffer buffer = boost::asio::buffer(buff, size);
|
||||||
|
|
||||||
require_socket();
|
require_socket();
|
||||||
|
|
||||||
// Set a deadline for the asynchronous operation.
|
// 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
|
// Set up the variables that receive the result of the asynchronous
|
||||||
// operation. The error code is set to would_block to signal that the
|
// 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
|
// Check whether the deadline has passed. We compare the deadline against
|
||||||
// the current time since a new asynchronous operation may have moved the
|
// the current time since a new asynchronous operation may have moved the
|
||||||
// deadline before this actor had a chance to run.
|
// 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
|
// The deadline has passed. The outstanding asynchronous operation needs
|
||||||
// to be cancelled so that the blocked receive() function will return.
|
// 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
|
// 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.
|
// 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.
|
// Put the actor back to sleep.
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/asio/deadline_timer.hpp>
|
#include <boost/asio/steady_timer.hpp>
|
||||||
#include <boost/array.hpp>
|
#include <boost/array.hpp>
|
||||||
#include <boost/utility/string_ref.hpp>
|
#include <boost/utility/string_ref.hpp>
|
||||||
|
|
||||||
@@ -233,11 +233,11 @@ namespace trezor {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void require_socket();
|
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();
|
void check_deadline();
|
||||||
static void handle_receive(const boost::system::error_code& ec, std::size_t length,
|
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);
|
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::shared_ptr<Protocol> m_proto;
|
||||||
std::string m_device_host;
|
std::string m_device_host;
|
||||||
@@ -245,7 +245,7 @@ namespace trezor {
|
|||||||
|
|
||||||
std::unique_ptr<udp::socket> m_socket;
|
std::unique_ptr<udp::socket> m_socket;
|
||||||
boost::asio::io_context m_io_service;
|
boost::asio::io_context m_io_service;
|
||||||
boost::asio::deadline_timer m_deadline;
|
boost::asio::steady_timer m_deadline;
|
||||||
udp::endpoint m_endpoint;
|
udp::endpoint m_endpoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -230,7 +230,7 @@ namespace nodetool
|
|||||||
m_config.m_net_config.packet_max_size = P2P_DEFAULT_PACKET_MAX_SIZE;
|
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.config_id = 0;
|
||||||
m_config.m_net_config.connection_timeout = P2P_DEFAULT_CONNECTION_TIMEOUT;
|
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_net_config.send_peerlist_sz = P2P_DEFAULT_PEERS_IN_HANDSHAKE;
|
||||||
m_config.m_support_flags = 0; // only set in public zone
|
m_config.m_support_flags = 0; // only set in public zone
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -988,7 +988,7 @@ namespace nodetool
|
|||||||
for (auto& zone : m_network_zones)
|
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().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())
|
if (!zone.second.m_bind_ip.empty())
|
||||||
{
|
{
|
||||||
@@ -1073,8 +1073,8 @@ namespace nodetool
|
|||||||
})); // lambda
|
})); // lambda
|
||||||
|
|
||||||
network_zone& public_zone = m_network_zones.at(epee::net_utils::zone::public_);
|
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(&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), 1000);
|
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
|
//here you can set worker threads count
|
||||||
int thrds_count = 10;
|
int thrds_count = 10;
|
||||||
@@ -1234,7 +1234,7 @@ namespace nodetool
|
|||||||
LOG_DEBUG_CC(context, " COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK");
|
LOG_DEBUG_CC(context, " COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK");
|
||||||
}
|
}
|
||||||
context_ = context;
|
context_ = context;
|
||||||
}, P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT);
|
}, std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT});
|
||||||
|
|
||||||
if(r)
|
if(r)
|
||||||
{
|
{
|
||||||
@@ -2564,7 +2564,7 @@ namespace nodetool
|
|||||||
|
|
||||||
f(context_, rsp.support_flags);
|
f(context_, rsp.support_flags);
|
||||||
},
|
},
|
||||||
P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT
|
std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT}
|
||||||
);
|
);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
@@ -136,10 +136,10 @@ namespace nodetool
|
|||||||
KV_SERIALIZE(config_id)
|
KV_SERIALIZE(config_id)
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
|
|
||||||
|
std::chrono::milliseconds ping_connection_timeout;
|
||||||
uint32_t max_out_connection_count;
|
uint32_t max_out_connection_count;
|
||||||
uint32_t max_in_connection_count;
|
uint32_t max_in_connection_count;
|
||||||
uint32_t connection_timeout;
|
uint32_t connection_timeout;
|
||||||
uint32_t ping_connection_timeout;
|
|
||||||
uint32_t handshake_interval;
|
uint32_t handshake_interval;
|
||||||
uint32_t packet_max_size;
|
uint32_t packet_max_size;
|
||||||
uint32_t config_id;
|
uint32_t config_id;
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ namespace cryptonote
|
|||||||
http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password());
|
http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password());
|
||||||
|
|
||||||
if (m_rpc_payment)
|
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();
|
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();
|
const auto ssl_base_path = (boost::filesystem::path{data_dir} / "rpc_ssl").string();
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ namespace tools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, auto_refresh_evaluation_ms.count());
|
}, auto_refresh_evaluation_ms);
|
||||||
m_net_server.add_idle_handler([this](){
|
m_net_server.add_idle_handler([this](){
|
||||||
if (m_stop.load(std::memory_order_relaxed))
|
if (m_stop.load(std::memory_order_relaxed))
|
||||||
{
|
{
|
||||||
@@ -275,7 +275,7 @@ namespace tools
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, 500);
|
}, std::chrono::milliseconds{500});
|
||||||
|
|
||||||
//DO NOT START THIS SERVER IN MORE THEN 1 THREADS WITHOUT REFACTORING
|
//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);
|
return epee::http_server_impl_base<wallet_rpc_server, connection_context>::run(1, true);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ using namespace net_load_tests;
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const size_t CONNECTION_COUNT = 100000;
|
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 DEFAULT_OPERATION_TIMEOUT = 30000;
|
||||||
const size_t RESERVED_CONN_CNT = 1;
|
const size_t RESERVED_CONN_CNT = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
//
|
//
|
||||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
// 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/mutex.hpp>
|
||||||
#include <boost/thread/thread.hpp>
|
#include <boost/thread/thread.hpp>
|
||||||
|
|
||||||
@@ -189,10 +190,10 @@ namespace
|
|||||||
if (0 < count)
|
if (0 < count)
|
||||||
{
|
{
|
||||||
// Perhaps not all connections were closed, try to close it after 7 seconds
|
// 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)
|
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)
|
if (!ec)
|
||||||
{
|
{
|
||||||
close_connections(cmd_conn_id);
|
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);
|
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().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;
|
//tcp_server.get_config_object().m_max_packet_size = max_packet_size;
|
||||||
|
|
||||||
if (!tcp_server.run_server(thread_count, true))
|
if (!tcp_server.run_server(thread_count, true))
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ TEST(test_epee_connection, test_lifetime)
|
|||||||
while (shared_state->sock_count);
|
while (shared_state->sock_count);
|
||||||
ASSERT_TRUE(shared_state->get_connections_count() == 0);
|
ASSERT_TRUE(shared_state->get_connections_count() == 0);
|
||||||
constexpr auto DELAY = 30;
|
constexpr auto DELAY = 30;
|
||||||
constexpr auto TIMEOUT = 1;
|
constexpr std::chrono::milliseconds TIMEOUT{1};
|
||||||
while (server.get_connections_count()) {
|
while (server.get_connections_count()) {
|
||||||
server.get_config_shared()->del_in_connections(
|
server.get_config_shared()->del_in_connections(
|
||||||
server.get_config_shared()->get_in_connections_count()
|
server.get_config_shared()->get_in_connections_count()
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ namespace
|
|||||||
class async_protocol_handler_test : public ::testing::Test
|
class async_protocol_handler_test : public ::testing::Test
|
||||||
{
|
{
|
||||||
public:
|
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;
|
const static size_t max_packet_size = 10 * 1024 * 1024;
|
||||||
|
|
||||||
typedef std::unique_ptr<test_connection> test_connection_ptr;
|
typedef std::unique_ptr<test_connection> test_connection_ptr;
|
||||||
|
|||||||
@@ -690,7 +690,7 @@ TEST(cryptonote_protocol_handler, race_condition)
|
|||||||
net_node.core_protocol->process_payload_sync_data(msg.payload_data, context, true);
|
net_node.core_protocol->process_payload_sync_data(msg.payload_data, context, true);
|
||||||
handshaked.raise();
|
handshaked.raise();
|
||||||
},
|
},
|
||||||
P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT
|
std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT}
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1202,7 +1202,7 @@ TEST(node_server, race_condition)
|
|||||||
EXPECT_TRUE(code >= 0);
|
EXPECT_TRUE(code >= 0);
|
||||||
handshaked.raise();
|
handshaked.raise();
|
||||||
},
|
},
|
||||||
P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT
|
std::chrono::milliseconds{P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT}
|
||||||
);
|
);
|
||||||
handshaked.wait();
|
handshaked.wait();
|
||||||
boost::asio::post(conn->strand_, [conn]{
|
boost::asio::post(conn->strand_, [conn]{
|
||||||
|
|||||||
Reference in New Issue
Block a user