net_node: allow bans for custom amounts of time

m_blocked_ips now stores the unblocking time, rather than the
blocking time.
Also change > to >=, since banning for 0 seconds should not ban
This commit is contained in:
moneromooo-monero 2015-11-25 22:04:27 +00:00
parent 4061a32082
commit 7bc4dce6ed
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
2 changed files with 4 additions and 4 deletions

View file

@ -171,7 +171,7 @@ namespace nodetool
virtual bool drop_connection(const epee::net_utils::connection_context_base& context);
virtual void request_callback(const epee::net_utils::connection_context_base& context);
virtual void for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type)> f);
virtual bool block_ip(uint32_t adress);
virtual bool block_ip(uint32_t adress, uint32_t seconds = P2P_IP_BLOCKTIME);
virtual bool add_ip_fail(uint32_t address);
//----------------- i_connection_filter --------------------------------------------------------
virtual bool is_remote_ip_allowed(uint32_t adress);

View file

@ -169,7 +169,7 @@ namespace nodetool
auto it = m_blocked_ips.find(addr);
if(it == m_blocked_ips.end())
return true;
if(time(nullptr) - it->second > P2P_IP_BLOCKTIME )
if(time(nullptr) >= it->second)
{
m_blocked_ips.erase(it);
LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << "is unblocked.", LOG_LEVEL_0);
@ -186,10 +186,10 @@ namespace nodetool
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::block_ip(uint32_t addr)
bool node_server<t_payload_net_handler>::block_ip(uint32_t addr, uint32_t seconds)
{
CRITICAL_REGION_LOCAL(m_blocked_ips_lock);
m_blocked_ips[addr] = time(nullptr);
m_blocked_ips[addr] = time(nullptr) + seconds;
LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " blocked.", LOG_LEVEL_0);
return true;
}