aboutsummaryrefslogtreecommitdiff
path: root/src/p2p
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-11-30 00:16:32 +0200
committerRiccardo Spagni <ric@spagni.net>2015-11-30 00:16:34 +0200
commita2d1e5a82cdc67f3b84ef476a08fb0f4da047ab1 (patch)
treeed35b91ab9e9b6a90e612cfe1ad42d54ce1d5321 /src/p2p
parentMerge pull request #501 (diff)
parentadd RPC calls and commands to get/set bans (diff)
downloadmonero-a2d1e5a82cdc67f3b84ef476a08fb0f4da047ab1.tar.xz
Merge pull request #502
38ceb73 add RPC calls and commands to get/set bans (moneromooo-monero) 7bc4dce net_node: allow bans for custom amounts of time (moneromooo-monero)
Diffstat (limited to 'src/p2p')
-rw-r--r--src/p2p/net_node.h4
-rw-r--r--src/p2p/net_node.inl18
-rw-r--r--src/p2p/net_node_common.h14
3 files changed, 30 insertions, 6 deletions
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 4aaac813e..39cbe01fa 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -117,6 +117,9 @@ namespace nodetool
size_t get_outgoing_connections_count();
peerlist_manager& get_peerlist_manager(){return m_peerlist;}
void delete_connections(size_t count);
+ virtual bool block_ip(uint32_t adress, time_t seconds = P2P_IP_BLOCKTIME);
+ virtual bool unblock_ip(uint32_t address);
+ virtual std::map<uint32_t, time_t> get_blocked_ips() const { return m_blocked_ips; }
private:
const std::vector<std::string> m_seed_nodes_list =
{ "seeds.moneroseeds.se"
@@ -171,7 +174,6 @@ 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 add_ip_fail(uint32_t address);
//----------------- i_connection_filter --------------------------------------------------------
virtual bool is_remote_ip_allowed(uint32_t adress);
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);
diff --git a/src/p2p/net_node_common.h b/src/p2p/net_node_common.h
index 93b29deb2..2505006ad 100644
--- a/src/p2p/net_node_common.h
+++ b/src/p2p/net_node_common.h
@@ -50,7 +50,9 @@ namespace nodetool
virtual void request_callback(const epee::net_utils::connection_context_base& context)=0;
virtual uint64_t get_connections_count()=0;
virtual void for_each_connection(std::function<bool(t_connection_context&, peerid_type)> f)=0;
- virtual bool block_ip(uint32_t adress)=0;
+ virtual bool block_ip(uint32_t adress, time_t seconds = 0)=0;
+ virtual bool unblock_ip(uint32_t adress)=0;
+ virtual std::map<uint32_t, time_t> get_blocked_ips()const=0;
virtual bool add_ip_fail(uint32_t adress)=0;
};
@@ -86,10 +88,18 @@ namespace nodetool
{
return false;
}
- virtual bool block_ip(uint32_t adress)
+ virtual bool block_ip(uint32_t adress, time_t seconds)
{
return true;
}
+ virtual bool unblock_ip(uint32_t adress)
+ {
+ return true;
+ }
+ virtual std::map<uint32_t, time_t> get_blocked_ips() const
+ {
+ return std::map<uint32_t, time_t>();
+ }
virtual bool add_ip_fail(uint32_t adress)
{
return true;