mirror of
https://github.com/monero-project/monero.git
synced 2025-09-19 19:04:39 -04:00
Upgrades to epee::net_utils::network_address
- internal nullptr checks - prevent modifications to network_address (shallow copy issues) - automagically works with any type containing interface functions - removed fnv1a hashing - ipv4_network_address now flattened with no base class
This commit is contained in:
parent
a2041c9874
commit
8b00687735
11 changed files with 446 additions and 92 deletions
|
@ -390,7 +390,7 @@ namespace nodetool
|
|||
ip::tcp::endpoint endpoint = *i;
|
||||
if (endpoint.address().is_v4())
|
||||
{
|
||||
epee::net_utils::network_address na(new epee::net_utils::ipv4_network_address(boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong()), endpoint.port()));
|
||||
epee::net_utils::network_address na{epee::net_utils::ipv4_network_address{boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong()), endpoint.port()}};
|
||||
seed_nodes.push_back(na);
|
||||
MINFO("Added seed node: " << na.str());
|
||||
}
|
||||
|
@ -1521,7 +1521,7 @@ namespace nodetool
|
|||
return false;
|
||||
std::string ip = epee::string_tools::get_ip_string_from_int32(actual_ip);
|
||||
std::string port = epee::string_tools::num_to_string_fast(node_data.my_port);
|
||||
epee::net_utils::network_address address(new epee::net_utils::ipv4_network_address(actual_ip, node_data.my_port));
|
||||
epee::net_utils::network_address address{epee::net_utils::ipv4_network_address(actual_ip, node_data.my_port)};
|
||||
peerid_type pr = node_data.peer_id;
|
||||
bool r = m_net_server.connect_async(ip, port, m_config.m_net_config.ping_connection_timeout, [cb, /*context,*/ address, pr, this](
|
||||
const typename net_server::t_connection_context& ping_context,
|
||||
|
@ -1669,7 +1669,7 @@ namespace nodetool
|
|||
if(arg.node_data.peer_id != m_config.m_peer_id && arg.node_data.my_port)
|
||||
{
|
||||
peerid_type peer_id_l = arg.node_data.peer_id;
|
||||
uint32_t port_l = arg.node_data.my_port;
|
||||
uint32_t port_l = arg.node_data.my_port;
|
||||
//try ping to be sure that we can add this peer to peer_list
|
||||
try_ping(arg.node_data, context, [peer_id_l, port_l, context, this]()
|
||||
{
|
||||
|
@ -1678,7 +1678,7 @@ namespace nodetool
|
|||
//called only(!) if success pinged, update local peerlist
|
||||
peerlist_entry pe;
|
||||
const epee::net_utils::network_address na = context.m_remote_address;
|
||||
pe.adr.reset(new epee::net_utils::ipv4_network_address(na.as<epee::net_utils::ipv4_network_address>().ip(), port_l));
|
||||
pe.adr = epee::net_utils::ipv4_network_address(na.as<epee::net_utils::ipv4_network_address>().ip(), port_l);
|
||||
time_t last_seen;
|
||||
time(&last_seen);
|
||||
pe.last_seen = static_cast<int64_t>(last_seen);
|
||||
|
|
|
@ -31,11 +31,19 @@
|
|||
#pragma once
|
||||
|
||||
#include "net/net_utils_base.h"
|
||||
#include "p2p/p2p_protocol_defs.h"
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace serialization
|
||||
{
|
||||
template <class T, class Archive>
|
||||
inline void do_serialize(Archive &a, epee::net_utils::network_address& na, T local)
|
||||
{
|
||||
if (typename Archive::is_saving()) local = na.as<T>();
|
||||
a & local;
|
||||
if (!typename Archive::is_saving()) na = local;
|
||||
}
|
||||
template <class Archive, class ver_type>
|
||||
inline void serialize(Archive &a, epee::net_utils::network_address& na, const ver_type ver)
|
||||
{
|
||||
|
@ -46,10 +54,8 @@ namespace boost
|
|||
switch (type)
|
||||
{
|
||||
case epee::net_utils::ipv4_network_address::ID:
|
||||
if (!typename Archive::is_saving())
|
||||
na.reset(new epee::net_utils::ipv4_network_address(0, 0));
|
||||
a & na.as<epee::net_utils::ipv4_network_address>();
|
||||
break;
|
||||
do_serialize(a, na, epee::net_utils::ipv4_network_address{0, 0});
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported network address type");
|
||||
}
|
||||
|
@ -57,13 +63,14 @@ namespace boost
|
|||
template <class Archive, class ver_type>
|
||||
inline void serialize(Archive &a, epee::net_utils::ipv4_network_address& na, const ver_type ver)
|
||||
{
|
||||
a & na.m_ip;
|
||||
a & na.m_port;
|
||||
uint32_t ip{na.ip()};
|
||||
uint16_t port{na.port()};
|
||||
a & ip;
|
||||
a & port;
|
||||
if (!typename Archive::is_saving())
|
||||
na.init_ids();
|
||||
na = epee::net_utils::ipv4_network_address{ip, port};
|
||||
}
|
||||
|
||||
|
||||
template <class Archive, class ver_type>
|
||||
inline void serialize(Archive &a, nodetool::peerlist_entry& pl, const ver_type ver)
|
||||
{
|
||||
|
|
|
@ -120,7 +120,7 @@ namespace nodetool
|
|||
ss << std::setfill ('0') << std::setw (8) << std::hex << std::noshowbase;
|
||||
for(const peerlist_entry& pe: pl)
|
||||
{
|
||||
ss << pe.id << "\t" << pe.adr->str() << " \tlast_seen: " << epee::misc_utils::get_time_interval_string(now_time - pe.last_seen) << std::endl;
|
||||
ss << pe.id << "\t" << pe.adr.str() << " \tlast_seen: " << epee::misc_utils::get_time_interval_string(now_time - pe.last_seen) << std::endl;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ namespace nodetool
|
|||
std::list<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(local_peerlist, stg, hparent_section, "local_peerlist");
|
||||
for (const auto &p: local_peerlist)
|
||||
((response&)this_ref).local_peerlist_new.push_back(peerlist_entry({new epee::net_utils::ipv4_network_address(p.adr.ip, p.adr.port), p.id, p.last_seen}));
|
||||
((response&)this_ref).local_peerlist_new.push_back(peerlist_entry({epee::net_utils::ipv4_network_address(p.adr.ip, p.adr.port), p.id, p.last_seen}));
|
||||
}
|
||||
}
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
@ -275,7 +275,7 @@ namespace nodetool
|
|||
std::list<peerlist_entry_base<network_address_old>> local_peerlist;
|
||||
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(local_peerlist, stg, hparent_section, "local_peerlist");
|
||||
for (const auto &p: local_peerlist)
|
||||
((response&)this_ref).local_peerlist_new.push_back(peerlist_entry({new epee::net_utils::ipv4_network_address(p.adr.ip, p.adr.port), p.id, p.last_seen}));
|
||||
((response&)this_ref).local_peerlist_new.push_back(peerlist_entry({epee::net_utils::ipv4_network_address(p.adr.ip, p.adr.port), p.id, p.last_seen}));
|
||||
}
|
||||
}
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
|
|
@ -1395,7 +1395,7 @@ namespace cryptonote
|
|||
}
|
||||
else
|
||||
{
|
||||
na.reset(new epee::net_utils::ipv4_network_address(i->ip, 0));
|
||||
na = epee::net_utils::ipv4_network_address{i->ip, 0};
|
||||
}
|
||||
if (i->ban)
|
||||
m_p2p.block_host(na, i->seconds);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue