diff options
author | luigi1111 <luigi1111w@gmail.com> | 2020-12-07 10:23:24 -0600 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2020-12-07 10:23:24 -0600 |
commit | fb73f2b2be3ec9802d9e1df7380eb92b472c5925 (patch) | |
tree | 1ec4647efd33403de4970439b92ac11f1391bb05 /src/p2p | |
parent | Merge pull request #7055 (diff) | |
parent | p2p: fix race condition accessing a deleted context (diff) | |
download | monero-fb73f2b2be3ec9802d9e1df7380eb92b472c5925.tar.xz |
Merge pull request #7070
281b42a p2p: fix race condition accessing a deleted context (moneromooo-monero)
Diffstat (limited to 'src/p2p')
-rw-r--r-- | src/p2p/net_node.h | 2 | ||||
-rw-r--r-- | src/p2p/net_node.inl | 16 | ||||
-rw-r--r-- | src/p2p/net_node_common.h | 4 |
3 files changed, 12 insertions, 10 deletions
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index b16f587c9..f13b36a82 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -287,7 +287,7 @@ namespace nodetool uint32_t get_max_out_public_peers() const; void change_max_in_public_peers(size_t count); uint32_t get_max_in_public_peers() const; - virtual bool block_host(const epee::net_utils::network_address &adress, time_t seconds = P2P_IP_BLOCKTIME); + virtual bool block_host(epee::net_utils::network_address address, time_t seconds = P2P_IP_BLOCKTIME); virtual bool unblock_host(const epee::net_utils::network_address &address); virtual bool block_subnet(const epee::net_utils::ipv4_network_subnet &subnet, time_t seconds = P2P_IP_BLOCKTIME); virtual bool unblock_subnet(const epee::net_utils::ipv4_network_subnet &subnet); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 93202f93f..cec037916 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -226,7 +226,7 @@ namespace nodetool } //----------------------------------------------------------------------------------- template<class t_payload_net_handler> - bool node_server<t_payload_net_handler>::block_host(const epee::net_utils::network_address &addr, time_t seconds) + bool node_server<t_payload_net_handler>::block_host(epee::net_utils::network_address addr, time_t seconds) { if(!addr.is_blockable()) return false; @@ -239,7 +239,8 @@ namespace nodetool limit = std::numeric_limits<time_t>::max(); else limit = now + seconds; - m_blocked_hosts[addr.host_str()] = limit; + const std::string host_str = addr.host_str(); + m_blocked_hosts[host_str] = limit; // drop any connection to that address. This should only have to look into // the zone related to the connection, but really make sure everything is @@ -255,17 +256,18 @@ namespace nodetool } return true; }); - for (const auto &c: conns) - zone.second.m_net_server.get_config_object().close(c); - - conns.clear(); peerlist_entry pe{}; pe.adr = addr; zone.second.m_peerlist.remove_from_peer_white(pe); + + for (const auto &c: conns) + zone.second.m_net_server.get_config_object().close(c); + + conns.clear(); } - MCLOG_CYAN(el::Level::Info, "global", "Host " << addr.host_str() << " blocked."); + MCLOG_CYAN(el::Level::Info, "global", "Host " << host_str << " blocked."); return true; } //----------------------------------------------------------------------------------- diff --git a/src/p2p/net_node_common.h b/src/p2p/net_node_common.h index 2ace5987f..f1490a0db 100644 --- a/src/p2p/net_node_common.h +++ b/src/p2p/net_node_common.h @@ -58,7 +58,7 @@ namespace nodetool virtual uint64_t get_public_connections_count()=0; virtual void for_each_connection(std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0; virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(t_connection_context&, peerid_type, uint32_t)> f)=0; - virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds = 0)=0; + virtual bool block_host(epee::net_utils::network_address address, time_t seconds = 0)=0; virtual bool unblock_host(const epee::net_utils::network_address &address)=0; virtual std::map<std::string, time_t> get_blocked_hosts()=0; virtual std::map<epee::net_utils::ipv4_network_subnet, time_t> get_blocked_subnets()=0; @@ -108,7 +108,7 @@ namespace nodetool { return false; } - virtual bool block_host(const epee::net_utils::network_address &address, time_t seconds) + virtual bool block_host(epee::net_utils::network_address address, time_t seconds) { return true; } |