Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/db.cpp
Show All 15 Lines | void CAddrInfo::Update(bool good) { | ||||
stat2H.Update(good, age, 3600 * 2); | stat2H.Update(good, age, 3600 * 2); | ||||
stat8H.Update(good, age, 3600 * 8); | stat8H.Update(good, age, 3600 * 8); | ||||
stat1D.Update(good, age, 3600 * 24); | stat1D.Update(good, age, 3600 * 24); | ||||
stat1W.Update(good, age, 3600 * 24 * 7); | stat1W.Update(good, age, 3600 * 24 * 7); | ||||
stat1M.Update(good, age, 3600 * 24 * 30); | stat1M.Update(good, age, 3600 * 24 * 30); | ||||
int64_t ign = GetIgnoreTime(); | int64_t ign = GetIgnoreTime(); | ||||
if (ign && (ignoreTill == 0 || ignoreTill < ign + now)) | if (ign && (ignoreTill == 0 || ignoreTill < ign + now)) | ||||
ignoreTill = ign + now; | ignoreTill = ign + now; | ||||
// printf("%s: got %s result: success=%i/%i; 2H:%.2f%%-%.2f%%(%.2f) | // fprintf(stdout, "%s: got %s result: success=%i/%i; | ||||
// 8H:%.2f%%-%.2f%%(%.2f) 1D:%.2f%%-%.2f%%(%.2f) 1W:%.2f%%-%.2f%%(%.2f) | // 2H:%.2f%%-%.2f%%(%.2f) 8H:%.2f%%-%.2f%%(%.2f) 1D:%.2f%%-%.2f%%(%.2f) | ||||
// \n", ToString(ip).c_str(), good ? "good" : "bad", success, total, | // 1W:%.2f%%-%.2f%%(%.2f) \n", ToString(ip).c_str(), good ? "good" : "bad", | ||||
// 100.0 * stat2H.reliability, 100.0 * (stat2H.reliability + 1.0 - | // success, total, 100.0 * stat2H.reliability, 100.0 * (stat2H.reliability | ||||
// stat2H.weight), stat2H.count, | // + 1.0 - stat2H.weight), stat2H.count, 100.0 * stat8H.reliability, 100.0 | ||||
// 100.0 * stat8H.reliability, 100.0 * (stat8H.reliability + 1.0 - | // * (stat8H.reliability + 1.0 - stat8H.weight), stat8H.count, 100.0 * | ||||
// stat8H.weight), stat8H.count, | // stat1D.reliability, 100.0 * (stat1D.reliability + 1.0 - stat1D.weight), | ||||
// 100.0 * stat1D.reliability, 100.0 * (stat1D.reliability + 1.0 - | // stat1D.count, 100.0 * stat1W.reliability, 100.0 * (stat1W.reliability | ||||
// stat1D.weight), stat1D.count, | // + 1.0 - stat1W.weight), stat1W.count); | ||||
// 100.0 * stat1W.reliability, 100.0 * (stat1W.reliability + 1.0 - | |||||
// stat1W.weight), stat1W.count); | |||||
} | } | ||||
bool CAddrDb::Get_(CServiceResult &ip, int &wait) { | bool CAddrDb::Get_(CServiceResult &ip, int &wait) { | ||||
int64_t now = time(nullptr); | int64_t now = time(nullptr); | ||||
size_t tot = unkId.size() + ourId.size(); | size_t tot = unkId.size() + ourId.size(); | ||||
if (tot == 0) { | if (tot == 0) { | ||||
wait = 5; | wait = 5; | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, | ||||
banned.erase(addr); | banned.erase(addr); | ||||
CAddrInfo &info = idToInfo[id]; | CAddrInfo &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.IsGood() && goodId.count(id) == 0) { | if (info.IsGood() && goodId.count(id) == 0) { | ||||
goodId.insert(id); | goodId.insert(id); | ||||
// printf("%s: good; %i good nodes now\n", ToString(addr).c_str(), | // fprintf(stdout, "%s: good; %i good nodes now\n", | ||||
// (int)goodId.size()); | // ToString(addr).c_str(), (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) return; | if (id == -1) return; | ||||
unkId.erase(id); | unkId.erase(id); | ||||
CAddrInfo &info = idToInfo[id]; | CAddrInfo &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) { | ||||
// printf("%s: terrible\n", ToString(addr).c_str()); | // fprintf(stdout, "%s: terrible\n", ToString(addr).c_str()); | ||||
if (ban < ter) ban = ter; | if (ban < ter) ban = ter; | ||||
} | } | ||||
if (ban > 0) { | if (ban > 0) { | ||||
// printf("%s: ban for %i seconds\n", ToString(addr).c_str(), ban); | // fprintf(stdout, "%s: ban for %i seconds\n", | ||||
// ToString(addr).c_str(), ban); | |||||
banned[info.ip] = ban + now; | banned[info.ip] = ban + now; | ||||
ipToId.erase(info.ip); | ipToId.erase(info.ip); | ||||
goodId.erase(id); | goodId.erase(id); | ||||
idToInfo.erase(id); | idToInfo.erase(id); | ||||
} else { | } else { | ||||
if (/*!info.IsGood() && */ goodId.count(id) == 1) { | if (/*!info.IsGood() && */ goodId.count(id) == 1) { | ||||
goodId.erase(id); | goodId.erase(id); | ||||
// printf("%s: not good; %i good nodes left\n", | // fprintf(stdout, "%s: not good; %i good nodes left\n", | ||||
// ToString(addr).c_str(), (int)goodId.size()); | // ToString(addr).c_str(), (int)goodId.size()); | ||||
} | } | ||||
ourId.push_back(id); | ourId.push_back(id); | ||||
} | } | ||||
nDirty++; | nDirty++; | ||||
} | } | ||||
void CAddrDb::Skipped_(const CService &addr) { | void CAddrDb::Skipped_(const CService &addr) { | ||||
int id = Lookup_(addr); | int id = Lookup_(addr); | ||||
if (id == -1) return; | if (id == -1) return; | ||||
unkId.erase(id); | unkId.erase(id); | ||||
ourId.push_back(id); | ourId.push_back(id); | ||||
// printf("%s: skipped\n", ToString(addr).c_str()); | // fprintf(stdout, "%s: skipped\n", ToString(addr).c_str()); | ||||
nDirty++; | nDirty++; | ||||
} | } | ||||
void CAddrDb::Add_(const CAddress &addr, bool force) { | void CAddrDb::Add_(const CAddress &addr, bool force) { | ||||
if (!force && !addr.IsRoutable()) { | if (!force && !addr.IsRoutable()) { | ||||
return; | return; | ||||
} | } | ||||
CService ipp(addr); | CService ipp(addr); | ||||
if (banned.count(ipp)) { | 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]]; | CAddrInfo &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; | ||||
// printf("%s: updated\n", ToString(addr).c_str()); | // fprintf(stdout, "%s: updated\n", ToString(addr).c_str()); | ||||
} | } | ||||
if (force) { | if (force) { | ||||
ai.ignoreTill = 0; | ai.ignoreTill = 0; | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
CAddrInfo ai; | CAddrInfo 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; | ||||
ipToId[ipp] = id; | ipToId[ipp] = id; | ||||
// printf("%s: added\n", ToString(ipp).c_str(), ipToId[ipp]); | // fprintf(stdout, "%s: added\n", ToString(ipp).c_str(), ipToId[ipp]); | ||||
unkId.insert(id); | unkId.insert(id); | ||||
nDirty++; | nDirty++; | ||||
} | } | ||||
void CAddrDb::GetIPs_(std::set<CNetAddr> &ips, uint64_t requestedFlags, | void CAddrDb::GetIPs_(std::set<CNetAddr> &ips, uint64_t requestedFlags, | ||||
uint32_t max, const bool *nets) { | uint32_t max, const bool *nets) { | ||||
if (goodId.size() == 0) { | if (goodId.size() == 0) { | ||||
int id = -1; | int id = -1; | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |