mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-13 11:35:20 +01:00
c9d548c91f
net: remove CService::ToStringPort() (Vasil Dimov)fd4f0f41e9
gui: simplify OptionsDialog::updateDefaultProxyNets() (Vasil Dimov)96c791dd20
net: remove CService::ToString() use ToStringAddrPort() instead (Vasil Dimov)944a9de08a
net: remove CNetAddr::ToString() and use ToStringAddr() instead (Vasil Dimov)043b9de59a
scripted-diff: rename ToStringIP[Port]() to ToStringAddr[Port]() (Vasil Dimov) Pull request description: Before this PR we had the somewhat confusing combination of methods: `CNetAddr::ToStringIP()` `CNetAddr::ToString()` (duplicate of the above) `CService::ToStringIPPort()` `CService::ToString()` (duplicate of the above, overrides a non-virtual method from `CNetAddr`) `CService::ToStringPort()` Avoid [overriding non-virtual methods](https://github.com/bitcoin/bitcoin/pull/25349/#issuecomment-1185226396). "IP" stands for "Internet Protocol" and while sometimes "IP addresses" are called just "IPs", it is incorrect to call Tor or I2P addresses "IPs". Thus use "Addr" instead of "IP". Change the above to: `CNetAddr::ToStringAddr()` `CService::ToStringAddrPort()` The changes touch a lot of files, but are mostly mechanical. ACKs for top commit: sipa: utACKc9d548c91f
achow101: ACKc9d548c91f
jonatack: re-ACKc9d548c91f
only change since my previous reviews is rebase, but as a sanity check rebased to current master and at each commit quickly re-reviewed and re-verified clean build and green unit tests LarryRuane: ACKc9d548c91f
Tree-SHA512: 633fb044bdecf9f551b5e3314c385bf10e2b78e8027dc51ec324b66b018da35e5b01f3fbe6295bbc455ea1bcd1a3629de1918d28de510693afaf6a52693f2157
100 lines
3.7 KiB
C++
100 lines
3.7 KiB
C++
// Copyright (c) 2020-2022 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <netaddress.h>
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <test/fuzz/util/net.h>
|
|
|
|
#include <cassert>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
FUZZ_TARGET(netaddress)
|
|
{
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
|
|
|
const CNetAddr net_addr = ConsumeNetAddr(fuzzed_data_provider);
|
|
(void)net_addr.GetNetClass();
|
|
if (net_addr.GetNetwork() == Network::NET_IPV4) {
|
|
assert(net_addr.IsIPv4());
|
|
}
|
|
if (net_addr.GetNetwork() == Network::NET_IPV6) {
|
|
assert(net_addr.IsIPv6());
|
|
}
|
|
if (net_addr.GetNetwork() == Network::NET_ONION) {
|
|
assert(net_addr.IsTor());
|
|
}
|
|
if (net_addr.GetNetwork() == Network::NET_INTERNAL) {
|
|
assert(net_addr.IsInternal());
|
|
}
|
|
if (net_addr.GetNetwork() == Network::NET_UNROUTABLE) {
|
|
assert(!net_addr.IsRoutable());
|
|
}
|
|
(void)net_addr.IsBindAny();
|
|
if (net_addr.IsInternal()) {
|
|
assert(net_addr.GetNetwork() == Network::NET_INTERNAL);
|
|
}
|
|
if (net_addr.IsIPv4()) {
|
|
assert(net_addr.GetNetwork() == Network::NET_IPV4 || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
|
|
}
|
|
if (net_addr.IsIPv6()) {
|
|
assert(net_addr.GetNetwork() == Network::NET_IPV6 || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
|
|
}
|
|
(void)net_addr.IsLocal();
|
|
if (net_addr.IsRFC1918() || net_addr.IsRFC2544() || net_addr.IsRFC6598() || net_addr.IsRFC5737() || net_addr.IsRFC3927()) {
|
|
assert(net_addr.IsIPv4());
|
|
}
|
|
(void)net_addr.IsRFC2544();
|
|
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()) {
|
|
assert(net_addr.IsIPv6());
|
|
}
|
|
(void)net_addr.IsRFC3927();
|
|
(void)net_addr.IsRFC3964();
|
|
if (net_addr.IsRFC4193()) {
|
|
assert(net_addr.GetNetwork() == Network::NET_INTERNAL || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
|
|
}
|
|
(void)net_addr.IsRFC4380();
|
|
(void)net_addr.IsRFC4843();
|
|
(void)net_addr.IsRFC4862();
|
|
(void)net_addr.IsRFC5737();
|
|
(void)net_addr.IsRFC6052();
|
|
(void)net_addr.IsRFC6145();
|
|
(void)net_addr.IsRFC6598();
|
|
(void)net_addr.IsRFC7343();
|
|
if (!net_addr.IsRoutable()) {
|
|
assert(net_addr.GetNetwork() == Network::NET_UNROUTABLE || net_addr.GetNetwork() == Network::NET_INTERNAL);
|
|
}
|
|
if (net_addr.IsTor()) {
|
|
assert(net_addr.GetNetwork() == Network::NET_ONION);
|
|
}
|
|
(void)net_addr.IsValid();
|
|
(void)net_addr.ToStringAddr();
|
|
|
|
const CSubNet sub_net{net_addr, fuzzed_data_provider.ConsumeIntegral<uint8_t>()};
|
|
(void)sub_net.IsValid();
|
|
(void)sub_net.ToString();
|
|
|
|
const CService service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
|
|
(void)service.GetKey();
|
|
(void)service.GetPort();
|
|
(void)service.ToStringAddrPort();
|
|
(void)CServiceHash()(service);
|
|
(void)CServiceHash(0, 0)(service);
|
|
|
|
const CNetAddr other_net_addr = ConsumeNetAddr(fuzzed_data_provider);
|
|
(void)net_addr.GetReachabilityFrom(&other_net_addr);
|
|
(void)sub_net.Match(other_net_addr);
|
|
|
|
const CService other_service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
|
|
assert((service == other_service) != (service != other_service));
|
|
(void)(service < other_service);
|
|
|
|
const CSubNet sub_net_copy_1{net_addr, other_net_addr};
|
|
const CSubNet sub_net_copy_2{net_addr};
|
|
|
|
CNetAddr mutable_net_addr;
|
|
mutable_net_addr.SetIP(net_addr);
|
|
assert(net_addr == mutable_net_addr);
|
|
}
|