Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/db.cpp
// Copyright (c) 2017-2019 The Bitcoin developers | // Copyright (c) 2017-2019 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 CAddrInfo::Update(bool good) { | ||||
int64_t now = time(nullptr); | int64_t now = time(nullptr); | ||||
if (ourLastTry == 0) ourLastTry = now - MIN_RETRY; | if (ourLastTry == 0) { | ||||
ourLastTry = now - MIN_RETRY; | |||||
} | |||||
int age = now - ourLastTry; | int age = now - ourLastTry; | ||||
lastTry = now; | lastTry = now; | ||||
ourLastTry = now; | ourLastTry = now; | ||||
total++; | total++; | ||||
if (good) { | if (good) { | ||||
success++; | success++; | ||||
ourLastSuccess = now; | ourLastSuccess = now; | ||||
} | } | ||||
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; | ||||
} | |||||
// fprintf(stdout, "%s: got %s result: success=%i/%i; | // fprintf(stdout, "%s: got %s result: success=%i/%i; | ||||
// 2H:%.2f%%-%.2f%%(%.2f) 8H:%.2f%%-%.2f%%(%.2f) 1D:%.2f%%-%.2f%%(%.2f) | // 2H:%.2f%%-%.2f%%(%.2f) 8H:%.2f%%-%.2f%%(%.2f) 1D:%.2f%%-%.2f%%(%.2f) | ||||
// 1W:%.2f%%-%.2f%%(%.2f) \n", ToString(ip).c_str(), good ? "good" : "bad", | // 1W:%.2f%%-%.2f%%(%.2f) \n", ToString(ip).c_str(), good ? "good" : "bad", | ||||
// success, total, 100.0 * stat2H.reliability, 100.0 * (stat2H.reliability | // success, total, 100.0 * stat2H.reliability, 100.0 * (stat2H.reliability | ||||
// + 1.0 - stat2H.weight), stat2H.count, 100.0 * stat8H.reliability, 100.0 | // + 1.0 - stat2H.weight), stat2H.count, 100.0 * stat8H.reliability, 100.0 | ||||
// * (stat8H.reliability + 1.0 - stat8H.weight), stat8H.count, 100.0 * | // * (stat8H.reliability + 1.0 - stat8H.weight), stat8H.count, 100.0 * | ||||
// stat1D.reliability, 100.0 * (stat1D.reliability + 1.0 - stat1D.weight), | // stat1D.reliability, 100.0 * (stat1D.reliability + 1.0 - stat1D.weight), | ||||
// stat1D.count, 100.0 * stat1W.reliability, 100.0 * (stat1W.reliability | // stat1D.count, 100.0 * stat1W.reliability, 100.0 * (stat1W.reliability | ||||
Show All 34 Lines | do { | ||||
} | } | ||||
} while (1); | } while (1); | ||||
nDirty++; | nDirty++; | ||||
return true; | return true; | ||||
} | } | ||||
int CAddrDb::Lookup_(const CService &ip) { | int CAddrDb::Lookup_(const CService &ip) { | ||||
if (ipToId.count(ip)) return ipToId[ip]; | if (ipToId.count(ip)) { | ||||
return ipToId[ip]; | |||||
} | |||||
return -1; | return -1; | ||||
} | } | ||||
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) return; | if (id == -1) { | ||||
return; | |||||
} | |||||
unkId.erase(id); | unkId.erase(id); | ||||
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); | ||||
// fprintf(stdout, "%s: good; %i good nodes now\n", | // fprintf(stdout, "%s: good; %i good nodes now\n", | ||||
// ToString(addr).c_str(), (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) { | ||||
// fprintf(stdout, "%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; | ||||
Show All 13 Lines | if (ban > 0) { | ||||
} | } | ||||
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); | ||||
// fprintf(stdout, "%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()) { | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |