|
10 | 10 | #include <hash.h>
|
11 | 11 | #include <prevector.h>
|
12 | 12 | #include <tinyformat.h>
|
13 |
| -#include <util/asmap.h> |
14 | 13 | #include <util/strencodings.h>
|
15 | 14 | #include <util/string.h>
|
16 | 15 |
|
@@ -722,113 +721,6 @@ Network CNetAddr::GetNetClass() const
|
722 | 721 | return m_net;
|
723 | 722 | }
|
724 | 723 |
|
725 |
| -uint32_t CNetAddr::GetMappedAS(const std::vector<bool> &m_asmap) const { |
726 |
| - const CNetAddr& address = *this; |
727 |
| - uint32_t net_class = address.GetNetClass(); |
728 |
| - if (m_asmap.size() == 0 || (net_class != NET_IPV4 && net_class != NET_IPV6)) { |
729 |
| - return 0; // Indicates not found, safe because AS0 is reserved per RFC7607. |
730 |
| - } |
731 |
| - std::vector<bool> ip_bits(128); |
732 |
| - if (address.HasLinkedIPv4()) { |
733 |
| - // For lookup, treat as if it was just an IPv4 address (IPV4_IN_IPV6_PREFIX + IPv4 bits) |
734 |
| - for (int8_t byte_i = 0; byte_i < 12; ++byte_i) { |
735 |
| - for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) { |
736 |
| - ip_bits[byte_i * 8 + bit_i] = (IPV4_IN_IPV6_PREFIX[byte_i] >> (7 - bit_i)) & 1; |
737 |
| - } |
738 |
| - } |
739 |
| - uint32_t ipv4 = address.GetLinkedIPv4(); |
740 |
| - for (int i = 0; i < 32; ++i) { |
741 |
| - ip_bits[96 + i] = (ipv4 >> (31 - i)) & 1; |
742 |
| - } |
743 |
| - } else { |
744 |
| - // Use all 128 bits of the IPv6 address otherwise |
745 |
| - assert(address.IsIPv6()); |
746 |
| - auto addr_bytes = address.GetAddrBytes(); |
747 |
| - for (int8_t byte_i = 0; byte_i < 16; ++byte_i) { |
748 |
| - uint8_t cur_byte = addr_bytes[byte_i]; |
749 |
| - for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) { |
750 |
| - ip_bits[byte_i * 8 + bit_i] = (cur_byte >> (7 - bit_i)) & 1; |
751 |
| - } |
752 |
| - } |
753 |
| - } |
754 |
| - uint32_t mapped_as = Interpret(m_asmap, ip_bits); |
755 |
| - return mapped_as; |
756 |
| -} |
757 |
| - |
758 |
| -/** |
759 |
| - * Get the canonical identifier of our network group |
760 |
| - * |
761 |
| - * The groups are assigned in a way where it should be costly for an attacker to |
762 |
| - * obtain addresses with many different group identifiers, even if it is cheap |
763 |
| - * to obtain addresses with the same identifier. |
764 |
| - * |
765 |
| - * @note No two connections will be attempted to addresses with the same network |
766 |
| - * group. |
767 |
| - */ |
768 |
| -std::vector<unsigned char> CNetAddr::GetGroup(const std::vector<bool> &m_asmap) const |
769 |
| -{ |
770 |
| - const CNetAddr& address = *this; |
771 |
| - std::vector<unsigned char> vchRet; |
772 |
| - // If non-empty asmap is supplied and the address is IPv4/IPv6, |
773 |
| - // return ASN to be used for bucketing. |
774 |
| - uint32_t asn = GetMappedAS(m_asmap); |
775 |
| - if (asn != 0) { // Either asmap was empty, or address has non-asmappable net class (e.g. TOR). |
776 |
| - vchRet.push_back(NET_IPV6); // IPv4 and IPv6 with same ASN should be in the same bucket |
777 |
| - for (int i = 0; i < 4; i++) { |
778 |
| - vchRet.push_back((asn >> (8 * i)) & 0xFF); |
779 |
| - } |
780 |
| - return vchRet; |
781 |
| - } |
782 |
| - |
783 |
| - vchRet.push_back(address.GetNetClass()); |
784 |
| - int nStartByte{0}; |
785 |
| - int nBits{0}; |
786 |
| - |
787 |
| - if (address.IsLocal()) { |
788 |
| - // all local addresses belong to the same group |
789 |
| - } else if (address.IsInternal()) { |
790 |
| - // All internal-usage addresses get their own group. |
791 |
| - // Skip over the INTERNAL_IN_IPV6_PREFIX returned by CAddress::GetAddrBytes(). |
792 |
| - nStartByte = INTERNAL_IN_IPV6_PREFIX.size(); |
793 |
| - nBits = ADDR_INTERNAL_SIZE * 8; |
794 |
| - } else if (!address.IsRoutable()) { |
795 |
| - // all other unroutable addresses belong to the same group |
796 |
| - } else if (address.HasLinkedIPv4()) { |
797 |
| - // IPv4 addresses (and mapped IPv4 addresses) use /16 groups |
798 |
| - uint32_t ipv4 = address.GetLinkedIPv4(); |
799 |
| - vchRet.push_back((ipv4 >> 24) & 0xFF); |
800 |
| - vchRet.push_back((ipv4 >> 16) & 0xFF); |
801 |
| - return vchRet; |
802 |
| - } else if (address.IsTor() || address.IsI2P()) { |
803 |
| - nBits = 4; |
804 |
| - } else if (address.IsCJDNS()) { |
805 |
| - // Treat in the same way as Tor and I2P because the address in all of |
806 |
| - // them is "random" bytes (derived from a public key). However in CJDNS |
807 |
| - // the first byte is a constant 0xfc, so the random bytes come after it. |
808 |
| - // Thus skip the constant 8 bits at the start. |
809 |
| - nBits = 12; |
810 |
| - } else if (address.IsHeNet()) { |
811 |
| - // for he.net, use /36 groups |
812 |
| - nBits = 36; |
813 |
| - } else { |
814 |
| - // for the rest of the IPv6 network, use /32 groups |
815 |
| - nBits = 32; |
816 |
| - } |
817 |
| - |
818 |
| - // Push our address onto vchRet. |
819 |
| - auto addr_bytes = address.GetAddrBytes(); |
820 |
| - const size_t num_bytes = nBits / 8; |
821 |
| - vchRet.insert(vchRet.end(), addr_bytes.begin() + nStartByte, addr_bytes.begin() + nStartByte + num_bytes); |
822 |
| - nBits %= 8; |
823 |
| - // ...for the last byte, push nBits and for the rest of the byte push 1's |
824 |
| - if (nBits > 0) { |
825 |
| - assert(num_bytes < addr_bytes.size()); |
826 |
| - vchRet.push_back(addr_bytes[num_bytes] | ((1 << (8 - nBits)) - 1)); |
827 |
| - } |
828 |
| - |
829 |
| - return vchRet; |
830 |
| -} |
831 |
| - |
832 | 724 | std::vector<unsigned char> CNetAddr::GetAddrBytes() const
|
833 | 725 | {
|
834 | 726 | if (IsAddrV1Compatible()) {
|
|
0 commit comments