Bitcoin Core  31.0.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 
18 public:
19  NetGroupManager(const NetGroupManager&) = delete;
20  NetGroupManager(NetGroupManager&&) = default;
21  NetGroupManager& operator=(const NetGroupManager&) = delete;
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 
37  uint256 GetAsmapVersion() const;
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 
68 private:
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
std::vector< unsigned char > GetGroup(const CNetAddr &address) const
Get the canonical identifier of the network group for address.
Definition: netgroup.cpp:19
NetGroupManager & operator=(const NetGroupManager &)=delete
assert(!tx.IsCoinBase())
void ASMapHealthCheck(const std::vector< CNetAddr > &clearnet_addrs) const
Analyze and log current health of ASMap based buckets.
Definition: netgroup.cpp:109
std::vector< std::byte > m_loaded_asmap
Definition: netgroup.h:94
uint256 GetAsmapVersion() const
Get the asmap version, a checksum identifying the asmap being used.
Definition: netgroup.cpp:14
Netgroup manager.
Definition: netgroup.h:17
bool UsingASMap() const
Indicates whether ASMap is being used for clearnet bucketing.
Definition: netgroup.cpp:125
static NetGroupManager NoAsmap()
Definition: netgroup.h:32
static NetGroupManager WithEmbeddedAsmap(std::span< const std::byte > asmap)
Definition: netgroup.h:24
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
const std::span< const std::byte > m_asmap
Compressed IP->ASN mapping.
Definition: netgroup.h:93
Network address.
Definition: netaddress.h:112
256-bit opaque blob.
Definition: uint256.h:195
NetGroupManager(const NetGroupManager &)=delete
NetGroupManager(std::span< const std::byte > embedded_asmap, std::vector< std::byte > &&loaded_asmap)
Definition: netgroup.h:96