Bitcoin Core 30.99.0
P2P Digital Currency
netgroup.h
Go to the documentation of this file.
1// Copyright (c) 2021-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_NETGROUP_H
6#define BITCOIN_NETGROUP_H
7
8#include <netaddress.h>
9#include <uint256.h>
10
11#include <cstddef>
12#include <vector>
13
18public:
23
24 static NetGroupManager WithEmbeddedAsmap(std::span<const std::byte> asmap) {
25 return NetGroupManager(asmap, {});
26 }
27
28 static NetGroupManager WithLoadedAsmap(std::vector<std::byte>&& asmap) {
29 return NetGroupManager(std::span{asmap}, std::move(asmap));
30 }
31
33 return NetGroupManager({}, {});
34 }
35
38
49 std::vector<unsigned char> GetGroup(const CNetAddr& address) const;
50
56 uint32_t GetMappedAS(const CNetAddr& address) const;
57
61 void ASMapHealthCheck(const std::vector<CNetAddr>& clearnet_addrs) const;
62
66 bool UsingASMap() const;
67
68private:
93 const std::span<const std::byte> m_asmap;
94 std::vector<std::byte> m_loaded_asmap;
95
96 explicit NetGroupManager(std::span<const std::byte> embedded_asmap, std::vector<std::byte>&& loaded_asmap)
97 : m_asmap{embedded_asmap},
98 m_loaded_asmap{std::move(loaded_asmap)}
99 {
100 assert(m_loaded_asmap.empty() || m_asmap.data() == m_loaded_asmap.data());
101 }
102};
103
104#endif // BITCOIN_NETGROUP_H
Network address.
Definition: netaddress.h:113
Netgroup manager.
Definition: netgroup.h:17
NetGroupManager(NetGroupManager &&)=default
NetGroupManager(const NetGroupManager &)=delete
static NetGroupManager NoAsmap()
Definition: netgroup.h:32
uint256 GetAsmapVersion() const
Get the asmap version, a checksum identifying the asmap being used.
Definition: netgroup.cpp:14
NetGroupManager & operator=(NetGroupManager &&)=delete
static NetGroupManager WithEmbeddedAsmap(std::span< const std::byte > asmap)
Definition: netgroup.h:24
NetGroupManager & operator=(const NetGroupManager &)=delete
NetGroupManager(std::span< const std::byte > embedded_asmap, std::vector< std::byte > &&loaded_asmap)
Definition: netgroup.h:96
bool UsingASMap() const
Indicates whether ASMap is being used for clearnet bucketing.
Definition: netgroup.cpp:125
std::vector< std::byte > m_loaded_asmap
Definition: netgroup.h:94
void ASMapHealthCheck(const std::vector< CNetAddr > &clearnet_addrs) const
Analyze and log current health of ASMap based buckets.
Definition: netgroup.cpp:109
const std::span< const std::byte > m_asmap
Compressed IP->ASN mapping.
Definition: netgroup.h:93
std::vector< unsigned char > GetGroup(const CNetAddr &address) const
Get the canonical identifier of the network group for address.
Definition: netgroup.cpp:19
static NetGroupManager WithLoadedAsmap(std::vector< std::byte > &&asmap)
Definition: netgroup.h:28
uint32_t GetMappedAS(const CNetAddr &address) const
Get the autonomous system on the BGP path to address.
Definition: netgroup.cpp:82
256-bit opaque blob.
Definition: uint256.h:195
assert(!tx.IsCoinBase())