20 std::vector<unsigned char> vchRet;
26 for (
int i = 0; i < 4; i++) {
27 vchRet.push_back((asn >> (8 * i)) & 0xFF);
48 vchRet.push_back((ipv4 >> 24) & 0xFF);
49 vchRet.push_back((ipv4 >> 16) & 0xFF);
51 }
else if (address.
IsTor() || address.
IsI2P()) {
69 const size_t num_bytes = nBits / 8;
70 vchRet.insert(vchRet.end(), addr_bytes.begin() + nStartByte, addr_bytes.begin() + nStartByte + num_bytes);
74 assert(num_bytes < addr_bytes.size());
75 vchRet.push_back(addr_bytes[num_bytes + nStartByte] | ((1 << (8 - nBits)) - 1));
87 std::vector<bool> ip_bits(128);
90 for (int8_t byte_i = 0; byte_i < 12; ++byte_i) {
91 for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) {
96 for (
int i = 0; i < 32; ++i) {
97 ip_bits[96 + i] = (ipv4 >> (31 - i)) & 1;
103 for (int8_t byte_i = 0; byte_i < 16; ++byte_i) {
104 uint8_t cur_byte = addr_bytes[byte_i];
105 for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) {
106 ip_bits[byte_i * 8 + bit_i] = (cur_byte >> (7 - bit_i)) & 1;
115 std::set<uint32_t> clearnet_asns{};
116 int unmapped_count{0};
118 for (
const auto& addr : clearnet_addrs) {
124 clearnet_asns.insert(asn);
127 LogPrintf(
"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...
A writer stream (for serialization) that computes a 256-bit hash.
uint256 GetAsmapChecksum() const
Get a checksum identifying the asmap being used.
bool UsingASMap() const
Indicates whether ASMap is being used for clearnet bucketing.
const std::vector< bool > m_asmap
Compressed IP->ASN mapping, loaded from a file when a node starts.
void ASMapHealthCheck(const std::vector< CNetAddr > &clearnet_addrs) const
Analyze and log current health of ASMap based buckets.
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::vector< bool > &asmap, const std::vector< bool > &ip)