diff options
author | luigi1111 <luigi1111w@gmail.com> | 2020-12-07 10:07:33 -0600 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2020-12-07 10:07:33 -0600 |
commit | 3d2a50a5c035d59c804740229bb0829ad04845ee (patch) | |
tree | cee83a87f7e754c0369e032104945f2a04d7b9b0 /contrib | |
parent | Merge pull request #7068 (diff) | |
parent | protocol: drop peers that don't reply to queries (diff) | |
download | monero-3d2a50a5c035d59c804740229bb0829ad04845ee.tar.xz |
Merge pull request #7055
ff7fdf6 protocol: drop peers that don't reply to queries (moneromooo-monero)
89e984d keep only the last seen node on a given host in the white list (moneromooo-monero)
c74d8ff protocol: drop peers that decrease claimed height (moneromooo-monero)
61f5001 protocol: add scoring system to drop peers that don't behave (moneromooo-monero)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/epee/src/net_utils_base.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/contrib/epee/src/net_utils_base.cpp b/contrib/epee/src/net_utils_base.cpp index 5cc49cc71..a2ca3d3d6 100644 --- a/contrib/epee/src/net_utils_base.cpp +++ b/contrib/epee/src/net_utils_base.cpp @@ -6,6 +6,17 @@ #include "string_tools.h" #include "net/local_ip.h" +static inline uint32_t 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 htonl(v4); +} + namespace epee { namespace net_utils { bool ipv4_network_address::equal(const ipv4_network_address& other) const noexcept @@ -83,8 +94,28 @@ namespace epee { namespace net_utils network_address::interface const* const other_self = other.self.get(); if (self_ == other_self) return true; if (!self_ || !other_self) return false; - if (typeid(*self_) != typeid(*other_self)) return false; - return self_->is_same_host(*other_self); + if (typeid(*self_) == typeid(*other_self)) + return self_->is_same_host(*other_self); + const auto this_id = get_type_id(); + if (this_id == ipv4_network_address::get_type_id() && other.get_type_id() == ipv6_network_address::get_type_id()) + { + const boost::asio::ip::address_v6 &actual_ip = other.as<const epee::net_utils::ipv6_network_address>().ip(); + if (actual_ip.is_v4_mapped()) + { + const uint32_t v4ip = make_address_v4_from_v6(actual_ip); + return is_same_host(ipv4_network_address(v4ip, 0)); + } + } + else if (this_id == ipv6_network_address::get_type_id() && other.get_type_id() == ipv4_network_address::get_type_id()) + { + const boost::asio::ip::address_v6 &actual_ip = this->as<const epee::net_utils::ipv6_network_address>().ip(); + if (actual_ip.is_v4_mapped()) + { + const uint32_t v4ip = make_address_v4_from_v6(actual_ip); + return other.is_same_host(ipv4_network_address(v4ip, 0)); + } + } + return false; } std::string print_connection_context(const connection_context_base& ctx) |