p2p: rewrite boost's make_address_v4 to cater for < 1.66
This commit is contained in:
parent
38f0472a6e
commit
0f998b9b55
|
@ -71,6 +71,17 @@
|
||||||
|
|
||||||
#define MIN_WANTED_SEED_NODES 12
|
#define MIN_WANTED_SEED_NODES 12
|
||||||
|
|
||||||
|
static inline boost::asio::ip::address_v4 make_address_v4_from_v6(const boost::asio::ip::address_v6& a)
|
||||||
|
{
|
||||||
|
const auto &bytes = a.to_bytes();
|
||||||
|
uint32_t v4 = 0;
|
||||||
|
v4 = (v4 << 8) | bytes[12];
|
||||||
|
v4 = (v4 << 8) | bytes[13];
|
||||||
|
v4 = (v4 << 8) | bytes[14];
|
||||||
|
v4 = (v4 << 8) | bytes[15];
|
||||||
|
return boost::asio::ip::address_v4(v4);
|
||||||
|
}
|
||||||
|
|
||||||
namespace nodetool
|
namespace nodetool
|
||||||
{
|
{
|
||||||
template<class t_payload_net_handler>
|
template<class t_payload_net_handler>
|
||||||
|
@ -1463,36 +1474,32 @@ namespace nodetool
|
||||||
const uint32_t actual_ip = na.as<const epee::net_utils::ipv4_network_address>().ip();
|
const uint32_t actual_ip = na.as<const epee::net_utils::ipv4_network_address>().ip();
|
||||||
classB.insert(actual_ip & 0x0000ffff);
|
classB.insert(actual_ip & 0x0000ffff);
|
||||||
}
|
}
|
||||||
#if BOOST_VERSION > 106600
|
|
||||||
else if (cntxt.m_remote_address.get_type_id() == epee::net_utils::ipv6_network_address::get_type_id())
|
else if (cntxt.m_remote_address.get_type_id() == epee::net_utils::ipv6_network_address::get_type_id())
|
||||||
{
|
{
|
||||||
const epee::net_utils::network_address na = cntxt.m_remote_address;
|
const epee::net_utils::network_address na = cntxt.m_remote_address;
|
||||||
const boost::asio::ip::address_v6 &actual_ip = na.as<const epee::net_utils::ipv6_network_address>().ip();
|
const boost::asio::ip::address_v6 &actual_ip = na.as<const epee::net_utils::ipv6_network_address>().ip();
|
||||||
if (actual_ip.is_v4_mapped())
|
if (actual_ip.is_v4_mapped())
|
||||||
{
|
{
|
||||||
boost::asio::ip::address_v4 v4ip = make_address_v4(boost::asio::ip::v4_mapped, actual_ip);
|
boost::asio::ip::address_v4 v4ip = make_address_v4_from_v6(actual_ip);
|
||||||
uint32_t actual_ipv4;
|
uint32_t actual_ipv4;
|
||||||
memcpy(&actual_ipv4, v4ip.to_bytes().data(), sizeof(actual_ipv4));
|
memcpy(&actual_ipv4, v4ip.to_bytes().data(), sizeof(actual_ipv4));
|
||||||
classB.insert(actual_ipv4 & ntohl(0xffff0000));
|
classB.insert(actual_ipv4 & ntohl(0xffff0000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get_host_string = [](const epee::net_utils::network_address &address) {
|
auto get_host_string = [](const epee::net_utils::network_address &address) {
|
||||||
#if BOOST_VERSION > 106600
|
|
||||||
if (address.get_type_id() == epee::net_utils::ipv6_network_address::get_type_id())
|
if (address.get_type_id() == epee::net_utils::ipv6_network_address::get_type_id())
|
||||||
{
|
{
|
||||||
boost::asio::ip::address_v6 actual_ip = address.as<const epee::net_utils::ipv6_network_address>().ip();
|
boost::asio::ip::address_v6 actual_ip = address.as<const epee::net_utils::ipv6_network_address>().ip();
|
||||||
if (actual_ip.is_v4_mapped())
|
if (actual_ip.is_v4_mapped())
|
||||||
{
|
{
|
||||||
boost::asio::ip::address_v4 v4ip = make_address_v4(boost::asio::ip::v4_mapped, actual_ip);
|
boost::asio::ip::address_v4 v4ip = make_address_v4_from_v6(actual_ip);
|
||||||
return epee::net_utils::ipv4_network_address(v4ip.to_uint(), 0).host_str();
|
return epee::net_utils::ipv4_network_address(v4ip.to_uint(), 0).host_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return address.host_str();
|
return address.host_str();
|
||||||
};
|
};
|
||||||
std::unordered_set<std::string> hosts_added;
|
std::unordered_set<std::string> hosts_added;
|
||||||
|
@ -1512,20 +1519,18 @@ namespace nodetool
|
||||||
uint32_t actual_ip = na.as<const epee::net_utils::ipv4_network_address>().ip();
|
uint32_t actual_ip = na.as<const epee::net_utils::ipv4_network_address>().ip();
|
||||||
skip = classB.find(actual_ip & 0x0000ffff) != classB.end();
|
skip = classB.find(actual_ip & 0x0000ffff) != classB.end();
|
||||||
}
|
}
|
||||||
#if BOOST_VERSION > 106600
|
|
||||||
else if (skip_duplicate_class_B && pe.adr.get_type_id() == epee::net_utils::ipv6_network_address::get_type_id())
|
else if (skip_duplicate_class_B && pe.adr.get_type_id() == epee::net_utils::ipv6_network_address::get_type_id())
|
||||||
{
|
{
|
||||||
const epee::net_utils::network_address na = pe.adr;
|
const epee::net_utils::network_address na = pe.adr;
|
||||||
const boost::asio::ip::address_v6 &actual_ip = na.as<const epee::net_utils::ipv6_network_address>().ip();
|
const boost::asio::ip::address_v6 &actual_ip = na.as<const epee::net_utils::ipv6_network_address>().ip();
|
||||||
if (actual_ip.is_v4_mapped())
|
if (actual_ip.is_v4_mapped())
|
||||||
{
|
{
|
||||||
boost::asio::ip::address_v4 v4ip = make_address_v4(boost::asio::ip::v4_mapped, actual_ip);
|
boost::asio::ip::address_v4 v4ip = make_address_v4_from_v6(actual_ip);
|
||||||
uint32_t actual_ipv4;
|
uint32_t actual_ipv4;
|
||||||
memcpy(&actual_ipv4, v4ip.to_bytes().data(), sizeof(actual_ipv4));
|
memcpy(&actual_ipv4, v4ip.to_bytes().data(), sizeof(actual_ipv4));
|
||||||
skip = classB.find(actual_ipv4 & ntohl(0xffff0000)) != classB.end();
|
skip = classB.find(actual_ipv4 & ntohl(0xffff0000)) != classB.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// consider each host once, to avoid giving undue inflence to hosts running several nodes
|
// consider each host once, to avoid giving undue inflence to hosts running several nodes
|
||||||
if (!skip)
|
if (!skip)
|
||||||
|
|
Loading…
Reference in New Issue