18#include <boost/test/unit_test.hpp>
20using namespace std::literals;
66 BOOST_CHECK(
ResolveIP(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion").IsTor());
77bool static TestSplitHost(
const std::string& test,
const std::string& host, uint16_t port,
bool validPort=
true)
82 return hostOut == host && portOut == port && validPortOut == validPort;
121bool static TestParse(std::string src, std::string canon)
229 ResolveIP(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion")};
236 !subnet.
Match(
ResolveIP(
"kpgvmscirrdqpekbqjsvw5teanhatztpp2gl6eee4zkowvwfxwenqaid.onion")));
309 subnet =
LookupSubNet(
"1:2:3:4:5:6:7:8/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
311 subnet =
LookupSubNet(
"1:2:3:4:5:6:7:8/ffff:0000:0000:0000:0000:0000:0000:0000");
313 subnet =
LookupSubNet(
"1:2:3:4:5:6:7:8/0000:0000:0000:0000:0000:0000:0000:0000");
320 subnet =
LookupSubNet(
"1:2:3:4:5:6:7:8/ffff:ffff:ffff:fffe:ffff:ffff:ffff:ff0f");
334 BOOST_CHECK(netgroupman.GetGroup(
ResolveIP(
"2002:102:304:9999:9999:9999:9999:9999")) == std::vector<unsigned char>({(
unsigned char)
NET_IPV4, 1, 2}));
335 BOOST_CHECK(netgroupman.GetGroup(
ResolveIP(
"2001:0:9999:9999:9999:9999:FEFD:FCFB")) == std::vector<unsigned char>({(
unsigned char)
NET_IPV4, 1, 2}));
336 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}));
337 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}));
340 std::vector<unsigned char> internal_group = {
NET_INTERNAL, 0x12, 0x92, 0x94, 0x00, 0xeb, 0x46, 0x07, 0xc4, 0xac, 0x07};
373 BOOST_CHECK(error.
original.find(
"Cannot resolve -whitebind address") != std::string::npos);
375 BOOST_CHECK(error.
original.find(
"Need to specify a port with -whitebind") != std::string::npos);
440 BOOST_CHECK(error.
original.find(
"whitebind may only be used for incoming connections (\"out\" was passed)") != std::string::npos);
448 BOOST_CHECK(error.
original.find(
"Invalid netmask specified in -whitelist") != std::string::npos);
469 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"bloomfilter") != strings.end());
470 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"forcerelay") != strings.end());
471 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"relay") != strings.end());
472 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"noban") != strings.end());
473 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"mempool") != strings.end());
474 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"download") != strings.end());
475 BOOST_CHECK(std::find(strings.begin(), strings.end(),
"addr") != strings.end());
491 BOOST_CHECK(!
LookupSubNet(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion\0example.com"s).IsValid());
492 BOOST_CHECK(!
LookupSubNet(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion\0example.com\0"s).IsValid());
523 "00000000000000000000000000000001"
528 "00000000000000000000000000000001"
533 "00000000000000000000000000000001"
545 "00000000000000000000000000000001"
552 "00000000000000000000000000000001"
559 "00000000000000000000000000000001"
573 std::vector<CAddress> addresses_unserialized;
590 std::vector<CAddress> addresses_unserialized;
607 size_t total_bad_ports{0};
608 for (uint16_t port = std::numeric_limits<uint16_t>::max(); port > 0; --port) {
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 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.
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
bool SplitHostPort(std::string_view in, uint16_t &portOut, std::string &hostOut)
Splits socket address string into host string and port value.