Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/db.cpp
// Copyright (c) 2017-2020 The Bitcoin developers | // Copyright (c) 2017-2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <seeder/db.h> | #include <seeder/db.h> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
void CAddrInfo::Update(bool good) { | void SeederAddrInfo::Update(bool good) { | ||||
int64_t now = time(nullptr); | int64_t now = time(nullptr); | ||||
if (ourLastTry == 0) { | if (ourLastTry == 0) { | ||||
ourLastTry = now - MIN_RETRY; | ourLastTry = now - MIN_RETRY; | ||||
} | } | ||||
int age = now - ourLastTry; | int age = now - ourLastTry; | ||||
lastTry = now; | lastTry = now; | ||||
ourLastTry = now; | ourLastTry = now; | ||||
total++; | total++; | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, | void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, | ||||
int blocks) { | int blocks) { | ||||
int id = Lookup_(addr); | int id = Lookup_(addr); | ||||
if (id == -1) { | if (id == -1) { | ||||
return; | return; | ||||
} | } | ||||
unkId.erase(id); | unkId.erase(id); | ||||
banned.erase(addr); | banned.erase(addr); | ||||
CAddrInfo &info = idToInfo[id]; | SeederAddrInfo &info = idToInfo[id]; | ||||
info.clientVersion = clientV; | info.clientVersion = clientV; | ||||
info.clientSubVersion = clientSV; | info.clientSubVersion = clientSV; | ||||
info.blocks = blocks; | info.blocks = blocks; | ||||
info.Update(true); | info.Update(true); | ||||
if (info.IsReliable() && goodId.count(id) == 0) { | if (info.IsReliable() && goodId.count(id) == 0) { | ||||
goodId.insert(id); | goodId.insert(id); | ||||
// tfm::format(std::cout, "%s: good; %i good nodes now\n", | // tfm::format(std::cout, "%s: good; %i good nodes now\n", | ||||
// ToString(addr), (int)goodId.size()); | // ToString(addr), (int)goodId.size()); | ||||
} | } | ||||
nDirty++; | nDirty++; | ||||
ourId.push_back(id); | ourId.push_back(id); | ||||
} | } | ||||
void CAddrDb::Bad_(const CService &addr, int ban) { | void CAddrDb::Bad_(const CService &addr, int ban) { | ||||
int id = Lookup_(addr); | int id = Lookup_(addr); | ||||
if (id == -1) { | if (id == -1) { | ||||
return; | return; | ||||
} | } | ||||
unkId.erase(id); | unkId.erase(id); | ||||
CAddrInfo &info = idToInfo[id]; | SeederAddrInfo &info = idToInfo[id]; | ||||
info.Update(false); | info.Update(false); | ||||
uint32_t now = time(nullptr); | uint32_t now = time(nullptr); | ||||
int ter = info.GetBanTime(); | int ter = info.GetBanTime(); | ||||
if (ter) { | if (ter) { | ||||
// tfm::format(std::cout, "%s: terrible\n", ToString(addr)); | // tfm::format(std::cout, "%s: terrible\n", ToString(addr)); | ||||
if (ban < ter) { | if (ban < ter) { | ||||
ban = ter; | ban = ter; | ||||
} | } | ||||
Show All 25 Lines | if (banned.count(ipp)) { | ||||
time_t bantime = banned[ipp]; | time_t bantime = banned[ipp]; | ||||
if (force || (bantime < time(nullptr) && addr.nTime > bantime)) { | if (force || (bantime < time(nullptr) && addr.nTime > bantime)) { | ||||
banned.erase(ipp); | banned.erase(ipp); | ||||
} else { | } else { | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
if (ipToId.count(ipp)) { | if (ipToId.count(ipp)) { | ||||
CAddrInfo &ai = idToInfo[ipToId[ipp]]; | SeederAddrInfo &ai = idToInfo[ipToId[ipp]]; | ||||
if (addr.nTime > ai.lastTry || ai.services != addr.nServices) { | if (addr.nTime > ai.lastTry || ai.services != addr.nServices) { | ||||
ai.lastTry = addr.nTime; | ai.lastTry = addr.nTime; | ||||
ai.services |= addr.nServices; | ai.services |= addr.nServices; | ||||
// tfm::format(std::cout, "%s: updated\n", | // tfm::format(std::cout, "%s: updated\n", | ||||
// ToString(addr)); | // ToString(addr)); | ||||
} | } | ||||
if (force) { | if (force) { | ||||
ai.ignoreTill = 0; | ai.ignoreTill = 0; | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
CAddrInfo ai; | SeederAddrInfo ai; | ||||
ai.ip = ipp; | ai.ip = ipp; | ||||
ai.services = addr.nServices; | ai.services = addr.nServices; | ||||
ai.lastTry = addr.nTime; | ai.lastTry = addr.nTime; | ||||
ai.ourLastTry = 0; | ai.ourLastTry = 0; | ||||
ai.total = 0; | ai.total = 0; | ||||
ai.success = 0; | ai.success = 0; | ||||
int id = nId++; | int id = nId++; | ||||
idToInfo[id] = ai; | idToInfo[id] = ai; | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |