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 <util/time.h> | |||||
#include <cstdlib> | #include <cstdlib> | ||||
void SeederAddrInfo::Update(bool good) { | void SeederAddrInfo::Update(bool good) { | ||||
int64_t now = time(nullptr); | int64_t now = GetTime(); | ||||
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++; | ||||
if (good) { | if (good) { | ||||
Show All 16 Lines | void SeederAddrInfo::Update(bool good) { | ||||
// + 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); | ||||
} | } | ||||
bool CAddrDb::Get_(CServiceResult &ip, int &wait) { | bool CAddrDb::Get_(CServiceResult &ip, int &wait) { | ||||
int64_t now = time(nullptr); | int64_t now = GetTime(); | ||||
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; | ||||
} | } | ||||
do { | do { | ||||
size_t rnd = rand() % tot; | size_t rnd = rand() % tot; | ||||
int ret; | int ret; | ||||
if (rnd < unkId.size()) { | if (rnd < unkId.size()) { | ||||
std::set<int>::iterator it = unkId.end(); | std::set<int>::iterator it = unkId.end(); | ||||
it--; | it--; | ||||
ret = *it; | ret = *it; | ||||
unkId.erase(it); | unkId.erase(it); | ||||
} else { | } else { | ||||
ret = ourId.front(); | ret = ourId.front(); | ||||
if (time(nullptr) - idToInfo[ret].ourLastTry < MIN_RETRY) { | if (GetTime() - idToInfo[ret].ourLastTry < MIN_RETRY) { | ||||
return false; | return false; | ||||
} | } | ||||
ourId.pop_front(); | ourId.pop_front(); | ||||
} | } | ||||
if (idToInfo[ret].ignoreTill && idToInfo[ret].ignoreTill < now) { | if (idToInfo[ret].ignoreTill && idToInfo[ret].ignoreTill < now) { | ||||
ourId.push_back(ret); | ourId.push_back(ret); | ||||
idToInfo[ret].ourLastTry = now; | idToInfo[ret].ourLastTry = now; | ||||
Show All 40 Lines | |||||
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); | ||||
SeederAddrInfo &info = idToInfo[id]; | SeederAddrInfo &info = idToInfo[id]; | ||||
info.Update(false); | info.Update(false); | ||||
uint32_t now = time(nullptr); | uint32_t now = GetTime(); | ||||
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; | ||||
} | } | ||||
} | } | ||||
if (ban > 0) { | if (ban > 0) { | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |