Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
netaddress.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-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#include <netaddress.h>
7#include <test/fuzz/fuzz.h>
9#include <test/util/random.h>
10
11#include <cassert>
12#include <cstdint>
13#include <vector>
14
16{
18 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
19
21 (void)net_addr.GetNetClass();
22 if (net_addr.GetNetwork() == Network::NET_IPV4) {
23 assert(net_addr.IsIPv4());
24 }
25 if (net_addr.GetNetwork() == Network::NET_IPV6) {
26 assert(net_addr.IsIPv6());
27 }
28 if (net_addr.GetNetwork() == Network::NET_ONION) {
29 assert(net_addr.IsTor());
30 }
31 if (net_addr.GetNetwork() == Network::NET_I2P) {
32 assert(net_addr.IsI2P());
33 }
34 if (net_addr.GetNetwork() == Network::NET_CJDNS) {
35 assert(net_addr.IsCJDNS());
36 }
37 if (net_addr.GetNetwork() == Network::NET_INTERNAL) {
38 assert(net_addr.IsInternal());
39 }
40 if (net_addr.GetNetwork() == Network::NET_UNROUTABLE) {
41 assert(!net_addr.IsRoutable());
42 }
43 (void)net_addr.IsBindAny();
44 if (net_addr.IsInternal()) {
45 assert(net_addr.GetNetwork() == Network::NET_INTERNAL);
46 }
47 if (net_addr.IsIPv4()) {
48 assert(net_addr.GetNetwork() == Network::NET_IPV4 || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
49 }
50 if (net_addr.IsIPv6()) {
51 assert(net_addr.GetNetwork() == Network::NET_IPV6 || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
52 }
53 (void)net_addr.IsLocal();
54 if (net_addr.IsRFC1918() || net_addr.IsRFC2544() || net_addr.IsRFC6598() || net_addr.IsRFC5737() || net_addr.IsRFC3927()) {
55 assert(net_addr.IsIPv4());
56 }
57 (void)net_addr.IsRFC2544();
58 if (net_addr.IsRFC3849() || net_addr.IsRFC3964() || net_addr.IsRFC4380() || net_addr.IsRFC4843() || net_addr.IsRFC7343() || net_addr.IsRFC4862() || net_addr.IsRFC6052() || net_addr.IsRFC6145()) {
59 assert(net_addr.IsIPv6());
60 }
61 (void)net_addr.IsRFC3927();
62 (void)net_addr.IsRFC3964();
63 if (net_addr.IsRFC4193()) {
64 assert(net_addr.GetNetwork() == Network::NET_INTERNAL || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
65 }
66 (void)net_addr.IsRFC4380();
67 (void)net_addr.IsRFC4843();
68 (void)net_addr.IsRFC4862();
69 (void)net_addr.IsRFC5737();
70 (void)net_addr.IsRFC6052();
71 (void)net_addr.IsRFC6145();
72 (void)net_addr.IsRFC6598();
73 (void)net_addr.IsRFC7343();
74 if (!net_addr.IsRoutable()) {
75 assert(net_addr.GetNetwork() == Network::NET_UNROUTABLE || net_addr.GetNetwork() == Network::NET_INTERNAL);
76 }
77 if (net_addr.IsTor()) {
78 assert(net_addr.GetNetwork() == Network::NET_ONION);
79 }
80 if (net_addr.IsI2P()) {
81 assert(net_addr.GetNetwork() == Network::NET_I2P);
82 }
83 if (net_addr.IsCJDNS()) {
84 assert(net_addr.GetNetwork() == Network::NET_CJDNS);
85 }
86 (void)net_addr.IsValid();
87 (void)net_addr.ToStringAddr();
88
90 (void)sub_net.IsValid();
91 (void)sub_net.ToString();
92
94 (void)service.GetKey();
95 (void)service.GetPort();
96 (void)service.ToStringAddrPort();
97 (void)CServiceHash()(service);
98 (void)CServiceHash(0, 0)(service);
99
101 (void)net_addr.GetReachabilityFrom(other_net_addr);
103
105 assert((service == other_service) != (service != other_service));
106 (void)(service < other_service);
107
108 if (service.ToStringAddrPort() == other_service.ToStringAddrPort()) {
109 assert(static_cast<CNetAddr>(service) == static_cast<CNetAddr>(other_service));
110 }
111
114
118}
Network address.
Definition netaddress.h:113
void SetIP(const CNetAddr &ip)
A combination of a network address (CNetAddr) and a (TCP) port.
Definition netaddress.h:530
#define FUZZ_TARGET(...)
Definition fuzz.h:35
@ NET_I2P
I2P.
Definition netaddress.h:47
@ NET_CJDNS
CJDNS.
Definition netaddress.h:50
@ NET_ONION
TOR (v2 or v3)
Definition netaddress.h:44
@ NET_IPV6
IPv6.
Definition netaddress.h:41
@ NET_IPV4
IPv4.
Definition netaddress.h:38
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition netaddress.h:35
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition netaddress.h:54
CNetAddr ConsumeNetAddr(FuzzedDataProvider &fuzzed_data_provider, FastRandomContext *rand) noexcept
Create a CNetAddr.
Definition net.cpp:29
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
Definition random.cpp:19
@ ZEROS
Seed with a compile time constant of zeros.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73
assert(!tx.IsCoinBase())
FuzzedDataProvider & fuzzed_data_provider
Definition fees.cpp:38