aboutsummaryrefslogtreecommitdiff
path: root/src/p2p/net_node.inl
diff options
context:
space:
mode:
Diffstat (limited to 'src/p2p/net_node.inl')
-rw-r--r--src/p2p/net_node.inl18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 11df7ee49..067f6378d 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -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,15 +186,27 @@ 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, time_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;
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
+ bool node_server<t_payload_net_handler>::unblock_ip(uint32_t addr)
+ {
+ CRITICAL_REGION_LOCAL(m_blocked_ips_lock);
+ auto i = m_blocked_ips.find(addr);
+ if (i == m_blocked_ips.end())
+ return false;
+ m_blocked_ips.erase(i);
+ LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked.", LOG_LEVEL_0);
+ return true;
+ }
+ //-----------------------------------------------------------------------------------
+ template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::add_ip_fail(uint32_t address)
{
CRITICAL_REGION_LOCAL(m_ip_fails_score_lock);