Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/db.cpp
Show All 24 Lines | void CAddrInfo::Update(bool good) { | ||||
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; | ||||
} | } | ||||
// tfm::format(std::cout, "%s: got %s result: success=%i/%i; | // tfm::format(std::cout, "%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), 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 | ||||
// + 1.0 - stat1W.weight), stat1W.count); | // + 1.0 - stat1W.weight), stat1W.count); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, | ||||
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.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).c_str(), (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]; | 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) { | ||||
// tfm::format(std::cout, "%s: terrible\n", ToString(addr).c_str()); | // tfm::format(std::cout, "%s: terrible\n", ToString(addr)); | ||||
if (ban < ter) { | if (ban < ter) { | ||||
ban = ter; | ban = ter; | ||||
} | } | ||||
} | } | ||||
if (ban > 0) { | if (ban > 0) { | ||||
// tfm::format(std::cout, "%s: ban for %i seconds\n", | // tfm::format(std::cout, "%s: ban for %i seconds\n", | ||||
// ToString(addr).c_str(), ban); | // ToString(addr), 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.IsReliable() && */ goodId.count(id) == 1) { | if (/*!info.IsReliable() && */ goodId.count(id) == 1) { | ||||
goodId.erase(id); | goodId.erase(id); | ||||
// tfm::format(std::cout, "%s: not good; %i good nodes left\n", | // tfm::format(std::cout, "%s: not good; %i good nodes left\n", | ||||
// ToString(addr).c_str(), (int)goodId.size()); | // ToString(addr), (int)goodId.size()); | ||||
} | } | ||||
ourId.push_back(id); | ourId.push_back(id); | ||||
} | } | ||||
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 All 9 Lines | if (banned.count(ipp)) { | ||||
} | } | ||||
} | } | ||||
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; | ||||
// tfm::format(std::cout, "%s: updated\n", | // tfm::format(std::cout, "%s: updated\n", | ||||
// ToString(addr).c_str()); | // ToString(addr)); | ||||
} | } | ||||
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; | ||||
// tfm::format(std::cout, "%s: added\n", ToString(ipp).c_str(), | // tfm::format(std::cout, "%s: added\n", ToString(ipp), | ||||
// ipToId[ipp]); | // 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) { | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |