22 #include <boost/test/unit_test.hpp>
52 unsigned char nVersion = 1;
54 s << ((
unsigned char)32);
63 Lookup(
"252.1.1.1", serv, 7777,
false);
77 std::string str = ssPeersIn.
str();
78 std::vector<unsigned char> vchData(str.begin(), str.end());
90 uint16_t altPort = 12345;
106 BOOST_CHECK(!
Lookup(std::string(
"250.7.3.3\0example.com", 21), addr3, 9999,
false));
117 bool exceptionThrown =
false;
122 unsigned char pchMsgTmp[4];
123 ssPeers1 >> pchMsgTmp;
124 ssPeers1 >> addrman1;
125 }
catch (
const std::exception& e) {
126 exceptionThrown =
true;
149 bool exceptionThrown =
false;
153 unsigned char pchMsgTmp[4];
154 ssPeers1 >> pchMsgTmp;
155 ssPeers1 >> addrman1;
156 }
catch (
const std::exception& e) {
157 exceptionThrown =
true;
179 ipv4Addr.s_addr = 0xa0b0c001;
182 std::string pszDest =
"";
183 bool fInboundIn =
false;
186 std::unique_ptr<CNode> pnode1(
new CNode(
id++,
NODE_NETWORK, height, hSocket, addr, 0, 0, pszDest, fInboundIn));
191 std::unique_ptr<CNode> pnode2(
new CNode(
id++,
NODE_NETWORK, height, hSocket, addr, 1, 1, pszDest, fInboundIn));
201 BOOST_REQUIRE(
LookupHost(
"0.0.0.0", addr,
false));
202 BOOST_REQUIRE(!addr.
IsValid());
203 BOOST_REQUIRE(addr.
IsIPv4());
210 BOOST_REQUIRE(
LookupHost(
"255.255.255.255", addr,
false));
211 BOOST_REQUIRE(!addr.
IsValid());
212 BOOST_REQUIRE(addr.
IsIPv4());
219 BOOST_REQUIRE(
LookupHost(
"12.34.56.78", addr,
false));
221 BOOST_REQUIRE(addr.
IsIPv4());
229 BOOST_REQUIRE(!addr.
IsValid());
230 BOOST_REQUIRE(addr.
IsIPv6());
237 BOOST_REQUIRE(
LookupHost(
"1122:3344:5566:7788:9900:aabb:ccdd:eeff", addr,
false));
239 BOOST_REQUIRE(addr.
IsIPv6());
246 BOOST_REQUIRE(addr.
SetSpecial(
"6hzph5hv6337r6p2.onion"));
248 BOOST_REQUIRE(addr.
IsTor());
255 const char* torv3_addr =
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion";
258 BOOST_REQUIRE(addr.
IsTor());
272 "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd\0wtf.onion", 66}));
282 BOOST_REQUIRE(!addr.
IsValid());
302 BOOST_REQUIRE(
LookupHost(
"1.2.3.4", addr,
false));
307 BOOST_REQUIRE(
LookupHost(
"1a1b:2a2b:3a3b:4a4b:5a5b:6a6b:7a7b:8a8b", addr,
false));
312 BOOST_REQUIRE(addr.
SetSpecial(
"6hzph5hv6337r6p2.onion"));
317 BOOST_REQUIRE(addr.
SetSpecial(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
340 BOOST_REQUIRE(
LookupHost(
"1.2.3.4", addr,
false));
345 BOOST_REQUIRE(
LookupHost(
"1a1b:2a2b:3a3b:4a4b:5a5b:6a6b:7a7b:8a8b", addr,
false));
350 BOOST_REQUIRE(addr.
SetSpecial(
"6hzph5hv6337r6p2.onion"));
355 BOOST_REQUIRE(addr.
SetSpecial(
"kpgvmscirrdqpekbqjsvw5teanhatztpp2gl6eee4zkowvwfxwenqaid.onion"));
383 BOOST_REQUIRE(s.
empty());
389 BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
HasReason(
"end of data"));
390 BOOST_REQUIRE(!s.
empty());
397 BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
398 HasReason(
"BIP155 IPv4 address with length 5 (should be 4)"));
399 BOOST_REQUIRE(!s.
empty());
406 BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
407 HasReason(
"Address too long: 513 > 512"));
408 BOOST_REQUIRE(!s.
empty());
414 "0102030405060708090a0b0c0d0e0f10"));
420 BOOST_REQUIRE(s.
empty());
426 "fd6b88c08724ca978112ca1bbdcafac2"));
432 BOOST_REQUIRE(s.
empty());
438 BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
439 HasReason(
"BIP155 IPv6 address with length 4 (should be 16)"));
440 BOOST_REQUIRE(!s.
empty());
446 "00000000000000000000ffff01020304"));
449 BOOST_REQUIRE(s.
empty());
454 "fd87d87eeb430102030405060708090a"));
457 BOOST_REQUIRE(s.
empty());
462 "f1f2f3f4f5f6f7f8f9fa"));
468 BOOST_REQUIRE(s.
empty());
474 BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
475 HasReason(
"BIP155 TORv2 address with length 7 (should be 10)"));
476 BOOST_REQUIRE(!s.
empty());
482 "79bcc625184b05194975c28b66b66b04"
483 "69f7f6556fb1ac3189a79b40dda32f1f"
490 "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion");
491 BOOST_REQUIRE(s.
empty());
498 BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
499 HasReason(
"BIP155 TORv3 address with length 0 (should be 32)"));
500 BOOST_REQUIRE(!s.
empty());
506 "a2894dabaec08c0051a481a6dac88b64"
507 "f98232ae42d4b6fd2fa81952dfe36a87"));
513 "ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p");
514 BOOST_REQUIRE(s.
empty());
521 BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
522 HasReason(
"BIP155 I2P address with length 3 (should be 32)"));
523 BOOST_REQUIRE(!s.
empty());
529 "fc000001000200030004000500060007"
536 BOOST_REQUIRE(s.
empty());
543 BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
544 HasReason(
"BIP155 CJDNS address with length 1 (should be 16)"));
545 BOOST_REQUIRE(!s.
empty());
553 BOOST_CHECK_EXCEPTION(s >> addr, std::ios_base::failure,
554 HasReason(
"Address too long: 33554432 > 512"));
555 BOOST_REQUIRE(!s.
empty());
565 BOOST_REQUIRE(s.
empty());
574 BOOST_REQUIRE(s.
empty());
585 in_addr ipv4AddrLocal;
586 ipv4AddrLocal.s_addr = 0x0100007f;
595 in_addr ipv4AddrPeer;
596 ipv4AddrPeer.s_addr = 0xa0b0c001;
599 pnode->fSuccessfullyConnected.store(
true);
602 in6_addr ipv6AddrLocal;
603 memset(ipv6AddrLocal.s6_addr, 0, 16);
604 ipv6AddrLocal.s6_addr[0] = 0xcc;
606 pnode->SetAddrLocal(addrLocal);
653 unsigned char ip[] = {p1, p2, p3, p4};
655 struct sockaddr_in sa;
656 memset(&sa, 0,
sizeof(sockaddr_in));
695 int average_interval_seconds = 600;
698 std::chrono::microseconds poisson_chrono =
::PoissonNextSend(std::chrono::microseconds{now}, std::chrono::seconds{average_interval_seconds});
#define ADDRMAN_NEW_BUCKET_COUNT
const CChainParams & Params()
Return the currently selected parameters.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
bool Read(CAddrMan &addr)
Extended statistics about a CAddress.
void Serialize(CDataStream::CBaseDataStream &s) const
Stochastical (IP) address manager.
bool Add(const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty=0)
Add a single address.
void Serialize(Stream &s_) const
Serialized format.
size_t size() const
Return the number of (unique) addresses in all tables.
uint256 nKey
secret key to randomize bucket select with
virtual void Serialize(CDataStream::CBaseDataStream &s) const =0
void MakeDeterministic()
Ensure that bucket placement is always the same for testing purposes.
void Serialize(CDataStream::CBaseDataStream &s) const
A CService with information about it as peer.
CBaseDataStream(int nTypeIn, int nVersionIn)
const CMessageHeader::MessageStartChars & MessageStart() const
std::string ToString() const
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
bool IsTor() const
Check whether this object represents a TOR address.
bool SetSpecial(const std::string &strName)
Parse a TOR address and set this object to it.
bool SetInternal(const std::string &name)
Transform an arbitrary string into a non-routable ipv6 address.
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
bool IsI2P() const
Check whether this object represents an I2P address.
Information about a peer.
A combination of a network address (CNetAddr) and a (TCP) port.
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
BOOST_AUTO_TEST_SUITE_END()
void * memcpy(void *a, const void *b, size_t c)
bool RemoveLocal(const CService &addr)
std::map< CNetAddr, LocalServiceInfo > mapLocalHost
void AdvertiseLocal(CNode *pnode)
bool IsLocal(const CService &addr)
check whether a given address is potentially local
RecursiveMutex cs_mapLocalHost
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds)
Return a timestamp in the future (in microseconds) for exponentially distributed events.
void SetReachable(enum Network net, bool reachable)
Mark a network as reachable or unreachable (no automatic connects to it)
bool AddLocal(const CService &addr, int nScore)
bool IsReachable(enum Network net)
BOOST_AUTO_TEST_CASE(cnode_listen_port)
CDataStream AddrmanToStream(CAddrManSerializationMock &addrman)
CNetAddr UtilBuildAddress(unsigned char p1, unsigned char p2, unsigned char p3, unsigned char p4)
@ 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.
bool Lookup(const std::string &name, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
bool LookupHost(const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool g_mock_deterministic_tests
Flag to make GetRand in random.h return the same number.
constexpr Span< A > MakeSpan(A(&a)[N])
MakeSpan for arrays:
@ ZEROS
Seed with a compile time constant of zeros.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::vector< unsigned char > ParseHex(const char *psz)