mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-22 12:34:24 +00:00
hack to support bootstraping with non standard ports using dns seeder
This commit is contained in:
parent
dbf804aacf
commit
851b69f2fa
23
src/net.cpp
23
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));
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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<unsigned char> GetGroup() const;
|
||||
int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user