commit
4231eb217c
1 changed files with 34 additions and 27 deletions
31
src/net.cpp
31
src/net.cpp
|
@ -496,21 +496,25 @@ bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB)
|
|||
|
||||
void AddressCurrentlyConnected(const CAddress& addr)
|
||||
{
|
||||
CAddress *paddrFound = NULL;
|
||||
|
||||
CRITICAL_BLOCK(cs_mapAddresses)
|
||||
{
|
||||
// Only if it's been published already
|
||||
map<vector<unsigned char>, CAddress>::iterator it = mapAddresses.find(addr.GetKey());
|
||||
if (it != mapAddresses.end())
|
||||
paddrFound = &(*it).second;
|
||||
}
|
||||
|
||||
if (paddrFound)
|
||||
{
|
||||
CAddress& addrFound = (*it).second;
|
||||
int64 nUpdateInterval = 20 * 60;
|
||||
if (addrFound.nTime < GetAdjustedTime() - nUpdateInterval)
|
||||
if (paddrFound->nTime < GetAdjustedTime() - nUpdateInterval)
|
||||
{
|
||||
// Periodically update most recently seen time
|
||||
addrFound.nTime = GetAdjustedTime();
|
||||
paddrFound->nTime = GetAdjustedTime();
|
||||
CAddrDB addrdb;
|
||||
addrdb.WriteAddress(addrFound);
|
||||
}
|
||||
addrdb.WriteAddress(*paddrFound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1271,13 +1275,13 @@ void ThreadDNSAddressSeed2(void* parg)
|
|||
if (!fTestNet)
|
||||
{
|
||||
printf("Loading addresses from DNS seeds (could take a while)\n");
|
||||
CAddrDB addrDB;
|
||||
addrDB.TxnBegin();
|
||||
|
||||
for (int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) {
|
||||
vector<CAddress> vaddr;
|
||||
if (Lookup(strDNSSeed[seed_idx], vaddr, NODE_NETWORK, -1, true))
|
||||
{
|
||||
CAddrDB addrDB;
|
||||
addrDB.TxnBegin();
|
||||
BOOST_FOREACH (CAddress& addr, vaddr)
|
||||
{
|
||||
if (addr.GetByte(3) != 127)
|
||||
|
@ -1287,11 +1291,10 @@ void ThreadDNSAddressSeed2(void* parg)
|
|||
found++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addrDB.TxnCommit(); // Save addresses (it's ok if this fails)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d addresses found from DNS seeds\n", found);
|
||||
}
|
||||
|
@ -1462,11 +1465,17 @@ void ThreadOpenConnections2(void* parg)
|
|||
if (fShutdown)
|
||||
return;
|
||||
|
||||
bool fAddSeeds = false;
|
||||
|
||||
CRITICAL_BLOCK(cs_mapAddresses)
|
||||
{
|
||||
// Add seed nodes if IRC isn't working
|
||||
bool fTOR = (fUseProxy && addrProxy.port == htons(9050));
|
||||
if (mapAddresses.empty() && (GetTime() - nStart > 60 || fTOR) && !fTestNet)
|
||||
fAddSeeds = true;
|
||||
}
|
||||
|
||||
if (fAddSeeds)
|
||||
{
|
||||
for (int i = 0; i < ARRAYLEN(pnSeed); i++)
|
||||
{
|
||||
|
@ -1481,8 +1490,6 @@ void ThreadOpenConnections2(void* parg)
|
|||
AddAddress(addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Choose an address to connect to based on most recently seen
|
||||
|
|
Loading…
Reference in a new issue