Don't issue a new timedsync while one is already in progress

A timedsync is issued every minute on a connection, but the input
tineout is 2 minutes. This means a new sync request could be issued
while a slow sync request was already in progress. The additional
request will further clog the network on a slow connection, and
cause a premature timeout.
This commit is contained in:
Howard Chu 2017-06-04 22:37:53 +01:00
parent cf3a376cb5
commit 07c4276cbe
No known key found for this signature in database
GPG Key ID: FD2A70B44AB11BA7
2 changed files with 9 additions and 2 deletions

View File

@ -56,6 +56,7 @@ namespace net_utils
const uint32_t m_remote_port; const uint32_t m_remote_port;
const bool m_is_income; const bool m_is_income;
const time_t m_started; const time_t m_started;
bool m_in_timedsync;
time_t m_last_recv; time_t m_last_recv;
time_t m_last_send; time_t m_last_send;
uint64_t m_recv_cnt; uint64_t m_recv_cnt;
@ -72,6 +73,7 @@ namespace net_utils
m_remote_port(remote_port), m_remote_port(remote_port),
m_is_income(is_income), m_is_income(is_income),
m_started(time(NULL)), m_started(time(NULL)),
m_in_timedsync(false),
m_last_recv(last_recv), m_last_recv(last_recv),
m_last_send(last_send), m_last_send(last_send),
m_recv_cnt(recv_cnt), m_recv_cnt(recv_cnt),
@ -85,6 +87,7 @@ namespace net_utils
m_remote_port(0), m_remote_port(0),
m_is_income(false), m_is_income(false),
m_started(time(NULL)), m_started(time(NULL)),
m_in_timedsync(false),
m_last_recv(0), m_last_recv(0),
m_last_send(0), m_last_send(0),
m_recv_cnt(0), m_recv_cnt(0),

View File

@ -814,6 +814,7 @@ namespace nodetool
bool r = epee::net_utils::async_invoke_remote_command2<typename COMMAND_TIMED_SYNC::response>(context_.m_connection_id, COMMAND_TIMED_SYNC::ID, arg, m_net_server.get_config_object(), bool r = epee::net_utils::async_invoke_remote_command2<typename COMMAND_TIMED_SYNC::response>(context_.m_connection_id, COMMAND_TIMED_SYNC::ID, arg, m_net_server.get_config_object(),
[this](int code, const typename COMMAND_TIMED_SYNC::response& rsp, p2p_connection_context& context) [this](int code, const typename COMMAND_TIMED_SYNC::response& rsp, p2p_connection_context& context)
{ {
context.m_in_timedsync = false;
if(code < 0) if(code < 0)
{ {
LOG_ERROR_CC(context, "COMMAND_TIMED_SYNC invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")"); LOG_ERROR_CC(context, "COMMAND_TIMED_SYNC invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")");
@ -1300,10 +1301,13 @@ namespace nodetool
MDEBUG("STARTED PEERLIST IDLE HANDSHAKE"); MDEBUG("STARTED PEERLIST IDLE HANDSHAKE");
typedef std::list<std::pair<epee::net_utils::connection_context_base, peerid_type> > local_connects_type; typedef std::list<std::pair<epee::net_utils::connection_context_base, peerid_type> > local_connects_type;
local_connects_type cncts; local_connects_type cncts;
m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) m_net_server.get_config_object().foreach_connection([&](p2p_connection_context& cntxt)
{ {
if(cntxt.peer_id) if(cntxt.peer_id && !cntxt.m_in_timedsync)
{
cntxt.m_in_timedsync = true;
cncts.push_back(local_connects_type::value_type(cntxt, cntxt.peer_id));//do idle sync only with handshaked connections cncts.push_back(local_connects_type::value_type(cntxt, cntxt.peer_id));//do idle sync only with handshaked connections
}
return true; return true;
}); });