From 851b69f2fa445279f6dc1cbe08d1653427607a77 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Sat, 1 Aug 2015 16:42:29 -0300 Subject: [PATCH] hack to support bootstraping with non standard ports using dns seeder --- src/net.cpp | 23 +++++++++++++++++++++++ src/netbase.cpp | 15 +++++++++++++++ src/netbase.h | 1 + 3 files changed, 39 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index cc701f83..7d21646a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1219,6 +1219,29 @@ void _ThreadDNSAddressSeed(const char *strDNS) vAdd.push_back(addr); found++; } + + // non std ports hack: see twister-seeder + string nonStdHost = "nonstd." + seed.host; + if (LookupHost(nonStdHost.c_str(), vIPs)) + { + BOOST_FOREACH(CNetAddr& ip, vIPs) + { + unsigned short crcAddr = ip.crc16(); + + BOOST_FOREACH(CNetAddr& ipPort, vIPs) + { + if( ipPort.GetByte(3) == (crcAddr >> 8) && + ipPort.GetByte(2) == (crcAddr & 0xff) ) { + int port = (ipPort.GetByte(1) << 8) + ipPort.GetByte(0); + int nOneDay = 24*3600; + CAddress addr = CAddress(CService(ip, port)); + addr.nTime = GetTime() - 3*nOneDay - GetRand(4*nOneDay); // use a random age between 3 and 7 days old + vAdd.push_back(addr); + found++; + } + } + } + } } addrman.Add(vAdd, CNetAddr(seed.name, true)); } diff --git a/src/netbase.cpp b/src/netbase.cpp index 8b82a40d..bd90a58e 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -894,6 +894,21 @@ uint64 CNetAddr::GetHash() const return nRet; } +unsigned short CNetAddr::crc16() const +{ + unsigned char x; + unsigned short crc = 0xFFFF; + const unsigned char* data_p = IsIPv4() ? &ip[12] : &ip[0]; + unsigned char length = IsIPv4() ? 4 : 16; + + while (length--){ + x = crc >> 8 ^ *data_p++; + x ^= x>>4; + crc = (crc << 8) ^ ((unsigned short)(x << 12)) ^ ((unsigned short)(x <<5)) ^ ((unsigned short)x); + } + return crc; +} + void CNetAddr::print() const { printf("CNetAddr(%s)\n", ToString().c_str()); diff --git a/src/netbase.h b/src/netbase.h index e4ec4ef5..e7d412fd 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -66,6 +66,7 @@ class CNetAddr std::string ToStringIP() const; unsigned int GetByte(int n) const; uint64 GetHash() const; + unsigned short crc16() const; bool GetInAddr(struct in_addr* pipv4Addr) const; std::vector GetGroup() const; int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const;