21 std::vector<unsigned char> vchRet;
27 for (
int i = 0; i < 4; i++) {
28 vchRet.push_back((asn >> (8 * i)) & 0xFF);
49 vchRet.push_back((ipv4 >> 24) & 0xFF);
50 vchRet.push_back((ipv4 >> 16) & 0xFF);
52 }
else if (address.
IsTor() || address.
IsI2P()) {
70 const size_t num_bytes = nBits / 8;
71 vchRet.insert(vchRet.end(), addr_bytes.begin() + nStartByte, addr_bytes.begin() + nStartByte + num_bytes);
75 assert(num_bytes < addr_bytes.size());
76 vchRet.push_back(addr_bytes[num_bytes + nStartByte] | ((1 << (8 - nBits)) - 1));
88 std::vector<std::byte> ip_bytes(16);
94 for (
int i = 0; i < 4; ++i) {
95 ip_bytes[12 + i] = std::byte((ipv4 >> (24 - i * 8)) & 0xFF);
101 assert(addr_bytes.size() == ip_bytes.size());
102 std::copy_n(std::as_bytes(std::span{addr_bytes}).begin(),
103 addr_bytes.size(), ip_bytes.begin());
110 std::set<uint32_t> clearnet_asns{};
111 int unmapped_count{0};
113 for (
const auto& addr : clearnet_addrs) {
119 clearnet_asns.insert(asn);
122 LogInfo(
"ASMap Health Check: %i clearnet peers are mapped to %i ASNs with %i peers being unmapped\n", clearnet_addrs.size(), clearnet_asns.size(), unmapped_count);
Network GetNetClass() const
std::vector< unsigned char > GetAddrBytes() const
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
uint256 GetAsmapVersion() const
Get the asmap version, a checksum identifying the asmap being used.
bool UsingASMap() const
Indicates whether ASMap is being used for clearnet bucketing.
void ASMapHealthCheck(const std::vector< CNetAddr > &clearnet_addrs) const
Analyze and log current health of ASMap based buckets.
const std::span< const std::byte > m_asmap
Compressed IP->ASN mapping.
std::vector< unsigned char > GetGroup(const CNetAddr &address) const
Get the canonical identifier of the network group for address.
uint32_t GetMappedAS(const CNetAddr &address) const
Get the autonomous system on the BGP path to address.
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
static const std::array< uint8_t, 6 > INTERNAL_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded "internal" address.
static const std::array< uint8_t, 12 > IPV4_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded IPv4 address.
uint32_t Interpret(const std::span< const std::byte > asmap, const std::span< const std::byte > ip)
Execute the ASMap bytecode to find the ASN for an IP.
uint256 AsmapVersion(const std::span< const std::byte > data)
Computes SHA256 hash of ASMap data for versioning and consistency checks.