Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/db.cpp
Show All 28 Lines | void CAddrInfo::Update(bool good) { | ||||
// 100.0 * stat8H.reliability, 100.0 * (stat8H.reliability + 1.0 - | // 100.0 * stat8H.reliability, 100.0 * (stat8H.reliability + 1.0 - | ||||
// stat8H.weight), stat8H.count, | // stat8H.weight), stat8H.count, | ||||
// 100.0 * stat1D.reliability, 100.0 * (stat1D.reliability + 1.0 - | // 100.0 * stat1D.reliability, 100.0 * (stat1D.reliability + 1.0 - | ||||
// stat1D.weight), stat1D.count, | // stat1D.weight), stat1D.count, | ||||
// 100.0 * stat1W.reliability, 100.0 * (stat1W.reliability + 1.0 - | // 100.0 * stat1W.reliability, 100.0 * (stat1W.reliability + 1.0 - | ||||
// stat1W.weight), stat1W.count); | // stat1W.weight), stat1W.count); | ||||
} | } | ||||
bool CAddrDb::Get_(CSeederServiceResult &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; | ||||
} | } | ||||
do { | do { | ||||
Show All 21 Lines | do { | ||||
break; | break; | ||||
} | } | ||||
} while (1); | } while (1); | ||||
nDirty++; | nDirty++; | ||||
return true; | return true; | ||||
} | } | ||||
int CAddrDb::Lookup_(const CSeederService &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 CSeederService &addr, int clientV, | void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, | ||||
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); | ||||
// printf("%s: good; %i good nodes now\n", ToString(addr).c_str(), | // printf("%s: good; %i good nodes now\n", ToString(addr).c_str(), | ||||
// (int)goodId.size()); | // (int)goodId.size()); | ||||
} | } | ||||
nDirty++; | nDirty++; | ||||
ourId.push_back(id); | ourId.push_back(id); | ||||
} | } | ||||
void CAddrDb::Bad_(const CSeederService &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) { | ||||
Show All 12 Lines | if (ban > 0) { | ||||
// printf("%s: not good; %i good nodes left\n", | // printf("%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 CSeederService &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()); | // printf("%s: skipped\n", ToString(addr).c_str()); | ||||
nDirty++; | nDirty++; | ||||
} | } | ||||
void CAddrDb::Add_(const CSeederAddress &addr, bool force) { | void CAddrDb::Add_(const CSeederAddress &addr, bool force) { | ||||
if (!force && !addr.IsRoutable()) { | if (!force && !addr.IsRoutable()) { | ||||
return; | return; | ||||
} | } | ||||
CSeederService 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; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | void CAddrDb::GetIPs_(std::set<CNetAddr> &ips, uint64_t requestedFlags, | ||||
} | } | ||||
std::set<int> ids; | std::set<int> ids; | ||||
while (ids.size() < max) { | while (ids.size() < max) { | ||||
ids.insert(goodIdFiltered[rand() % goodIdFiltered.size()]); | ids.insert(goodIdFiltered[rand() % goodIdFiltered.size()]); | ||||
} | } | ||||
for (auto &id : ids) { | for (auto &id : ids) { | ||||
CSeederService &ip = idToInfo[id].ip; | CService &ip = idToInfo[id].ip; | ||||
if (nets[ip.GetNetwork()]) { | if (nets[ip.GetNetwork()]) { | ||||
ips.insert(ip); | ips.insert(ip); | ||||
} | } | ||||
} | } | ||||
} | } |