Skip to content

Commit

Permalink
fix kicking of peers for no reason
Browse files Browse the repository at this point in the history
  • Loading branch information
who-biz committed Jan 10, 2020
1 parent 317dadd commit 8f53d3c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
5 changes: 1 addition & 4 deletions src/cryptonote_basic/connection_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ namespace cryptonote

struct cryptonote_connection_context: public epee::net_utils::connection_context_base
{
cryptonote_connection_context(): m_state(state_before_handshake), m_remote_blockchain_height(0), m_last_response_height(0),
cryptonote_connection_context(): m_state(state_normal), m_remote_blockchain_height(0), m_last_response_height(0),
m_last_request_time(boost::posix_time::microsec_clock::universal_time()), m_callback_request_count(0), m_last_known_hash(crypto::null_hash) {}

enum state
{
state_before_handshake = 0, //default state
state_synchronizing,
state_standby,
state_idle,
Expand All @@ -66,8 +65,6 @@ namespace cryptonote
{
switch (s)
{
case cryptonote_connection_context::state_before_handshake:
return "state_before_handshake";
case cryptonote_connection_context::state_synchronizing:
return "state_synchronizing";
case cryptonote_connection_context::state_standby:
Expand Down
22 changes: 0 additions & 22 deletions src/cryptonote_protocol/cryptonote_protocol_handler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,6 @@ namespace cryptonote
template<class t_core>
bool t_cryptonote_protocol_handler<t_core>::process_payload_sync_data(const CORE_SYNC_DATA& hshd, cryptonote_connection_context& context, bool is_inital)
{
if(context.m_state == cryptonote_connection_context::state_before_handshake && !is_inital)
return true;

if(context.m_state == cryptonote_connection_context::state_synchronizing)
return true;

// from v6, if the peer advertises a top block version, reject if it's not what it should be (will only work if no voting)
if (hshd.current_height > 0)
{
Expand Down Expand Up @@ -1345,22 +1339,6 @@ skip:
{
MTRACE("Checking for idle peers...");
std::vector<boost::uuids::uuid> kick_connections;
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_state == cryptonote_connection_context::state_before_handshake)
{
const bool passive = context.m_state == cryptonote_connection_context::state_before_handshake;
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;
const int64_t threshold = passive ? PASSIVE_PEER_KICK_TIME : IDLE_PEER_KICK_TIME;
if (dt.total_microseconds() > threshold)
{
MINFO(context << " kicking " << (passive ? "passive" : "idle") << " peer");
kick_connections.push_back(context.m_connection_id);
}
}
return true;
});
for (const boost::uuids::uuid &conn_id: kick_connections)
{
m_p2p->for_connection(conn_id, [this](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags) {
Expand Down

0 comments on commit 8f53d3c

Please sign in to comment.