19#include <boost/test/unit_test.hpp>
21using namespace std::literals;
67 BOOST_CHECK(
ResolveIP(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion").IsTor());
78bool static TestSplitHost(
const std::string& test,
const std::string& host, uint16_t port,
bool validPort=
true)
83 return hostOut == host && portOut == port && validPortOut == validPort;
122bool static TestParse(std::string src, std::string canon)
230 ResolveIP(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion")};
237 !subnet.
Match(
ResolveIP(
"kpgvmscirrdqpekbqjsvw5teanhatztpp2gl6eee4zkowvwfxwenqaid.onion")));
310 subnet =
LookupSubNet(
"1:2:3:4:5:6:7:8/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
312 subnet =
LookupSubNet(
"1:2:3:4:5:6:7:8/ffff:0000:0000:0000:0000:0000:0000:0000");
314 subnet =
LookupSubNet(
"1:2:3:4:5:6:7:8/0000:0000:0000:0000:0000:0000:0000:0000");
321 subnet =
LookupSubNet(
"1:2:3:4:5:6:7:8/ffff:ffff:ffff:fffe:ffff:ffff:ffff:ff0f");
335 BOOST_CHECK(netgroupman.GetGroup(
ResolveIP(
"2002:102:304:9999:9999:9999:9999:9999")) == std::vector<unsigned char>({(
unsigned char)
NET_IPV4, 1, 2}));
336 BOOST_CHECK(netgroupman.GetGroup(
ResolveIP(
"2001:0:9999:9999:9999:9999:FEFD:FCFB")) == std::vector<unsigned char>({(
unsigned char)
NET_IPV4, 1, 2}));
337 BOOST_CHECK(netgroupman.GetGroup(
ResolveIP(
"2001:470:abcd:9999:9999:9999:9999:9999")) == std::vector<unsigned char>({(
unsigned char)
NET_IPV6, 32, 1, 4, 112, 175}));
338 BOOST_CHECK(netgroupman.GetGroup(
ResolveIP(
"2001:2001:9999:9999:9999:9999:9999:9999")) == std::vector<unsigned char>({(
unsigned char)
NET_IPV6, 32, 1, 32, 1}));
341 std::vector<unsigned char> internal_group = {
NET_INTERNAL, 0x12, 0x92, 0x94, 0x00, 0xeb, 0x46, 0x07, 0xc4, 0xac, 0x07};
374 BOOST_CHECK(error.
original.find(
"Cannot resolve -whitebind address") != std::string::npos);
376 BOOST_CHECK(error.
original.find(
"Need to specify a port with -whitebind") != std::string::npos);
441 BOOST_CHECK(error.
original.find(
"whitebind may only be used for incoming connections (\"out\" was passed)") != std::string::npos);
449 BOOST_CHECK(error.
original.find(
"Invalid netmask specified in -whitelist") != std::string::npos);
470 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"bloomfilter") != strings.end());
471 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"forcerelay") != strings.end());
472 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"relay") != strings.end());
473 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"noban") != strings.end());
474 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"mempool") != strings.end());
475 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"download") != strings.end());
476 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"addr") != strings.end());
492 BOOST_CHECK(!
LookupSubNet(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion\0example.com"s).IsValid());
493 BOOST_CHECK(!
LookupSubNet(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion\0example.com\0"s).IsValid());
524 "00000000000000000000000000000001"
529 "00000000000000000000000000000001"
534 "00000000000000000000000000000001"
546 "00000000000000000000000000000001"
553 "00000000000000000000000000000001"
560 "00000000000000000000000000000001"
574 std::vector<CAddress> addresses_unserialized;
591 std::vector<CAddress> addresses_unserialized;
608 std::list<int> ports(std::numeric_limits<uint16_t>::max());
609 std::iota(ports.begin(), ports.end(), 1);
A CService with information about it as peer.
static constexpr SerParams V1_NETWORK
static constexpr SerParams V2_NETWORK
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
A combination of a network address (CNetAddr) and a (TCP) port.
std::string ToStringAddrPort() const
std::string ToString() const
bool Match(const CNetAddr &addr) const
Double ended buffer combining vector and stream-like interfaces.
NetPermissionFlags m_flags
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
static void ClearFlag(NetPermissionFlags &flags, NetPermissionFlags f)
ClearFlag is only called with f == NetPermissionFlags::Implicit.
static std::vector< std::string > ToStrings(NetPermissionFlags flags)
static bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
static bool TryParse(const std::string &str, NetWhitebindPermissions &output, bilingual_str &error)
static bool TryParse(const std::string &str, NetWhitelistPermissions &output, ConnectionDirection &output_connection_direction, bilingual_str &error)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
static CService ip(uint32_t i)
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
static const std::string addr1
static const std::string addr2
std::string ToString(const T &t)
Locale-independent version of std::to_string.
bool IsLocal(const CService &addr)
check whether a given address is potentially local
@ NET_ONION
TOR (v2 or v3)
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
CSubNet LookupSubNet(const std::string &subnet_str)
Parse and resolve a specified subnet string into the appropriate internal representation.
std::vector< CNetAddr > LookupHost(const std::string &name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
Resolve a host string to its corresponding network addresses.
enum Network ParseNetwork(const std::string &net_in)
CService LookupNumeric(const std::string &name, uint16_t portDefault, DNSLookupFn dns_lookup_function)
Resolve a service string with a numeric IP to its first corresponding service.
bool IsBadPort(uint16_t port)
Determine if a port is "bad" from the perspective of attempting to connect to a node on that port.
static constexpr const char * stream_addrv1_hex
static constexpr const char * stream_addrv2_hex
static bool TestParse(std::string src, std::string canon)
static const std::vector< CAddress > fixture_addresses({ CAddress{ CService(CNetAddr(in6_addr(IN6ADDR_LOOPBACK_INIT)), 0), NODE_NONE, NodeSeconds{0x4966bc61s}, }, CAddress{ CService(CNetAddr(in6_addr(IN6ADDR_LOOPBACK_INIT)), 0x00f1), NODE_NETWORK, NodeSeconds{0x83766279s}, }, CAddress{ CService(CNetAddr(in6_addr(IN6ADDR_LOOPBACK_INIT)), 0xf1f2), static_cast< ServiceFlags >(NODE_WITNESS|NODE_COMPACT_FILTERS|NODE_NETWORK_LIMITED), NodeSeconds{0xffffffffs}, }, })
static bool TestSplitHost(const std::string &test, const std::string &host, uint16_t port, bool validPort=true)
BOOST_AUTO_TEST_CASE(netbase_networks)
static CNetAddr CreateInternal(const std::string &host)
static CNetAddr ResolveIP(const std::string &ip)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
ServiceFlags
nServices flags
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
bool SplitHostPort(std::string_view in, uint16_t &portOut, std::string &hostOut)
Splits socket address string into host string and port value.
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds