Browse Source

hack to support bootstraping with non standard ports using dns seeder

miguelfreitas
Miguel Freitas 9 years ago
parent
commit
851b69f2fa
  1. 23
      src/net.cpp
  2. 15
      src/netbase.cpp
  3. 1
      src/netbase.h

23
src/net.cpp

@ -1219,6 +1219,29 @@ void _ThreadDNSAddressSeed(const char *strDNS)
vAdd.push_back(addr); vAdd.push_back(addr);
found++; 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)); addrman.Add(vAdd, CNetAddr(seed.name, true));
} }

15
src/netbase.cpp

@ -894,6 +894,21 @@ uint64 CNetAddr::GetHash() const
return nRet; 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 void CNetAddr::print() const
{ {
printf("CNetAddr(%s)\n", ToString().c_str()); printf("CNetAddr(%s)\n", ToString().c_str());

1
src/netbase.h

@ -66,6 +66,7 @@ class CNetAddr
std::string ToStringIP() const; std::string ToStringIP() const;
unsigned int GetByte(int n) const; unsigned int GetByte(int n) const;
uint64 GetHash() const; uint64 GetHash() const;
unsigned short crc16() const;
bool GetInAddr(struct in_addr* pipv4Addr) const; bool GetInAddr(struct in_addr* pipv4Addr) const;
std::vector<unsigned char> GetGroup() const; std::vector<unsigned char> GetGroup() const;
int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const; int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const;

Loading…
Cancel
Save