5 #ifndef BITCOIN_SEEDER_DB_H 6 #define BITCOIN_SEEDER_DB_H 24 #define MIN_RETRY 1000 26 #define REQUIRE_VERSION 70001 34 while (str.size() < 22) {
47 CAddrStat() : weight(0), count(0), reliability(0) {}
50 double f = exp(-age / tau);
51 reliability = reliability * f + (good ? (1.0 - f) : 0);
52 count = count * f + 1;
53 weight = weight * f + (1.0 - f);
58 template <
typename Stream,
typename Operation>
101 : services(0), lastTry(0), ourLastTry(0), ourLastSuccess(0),
102 ignoreTill(0), clientVersion(0), blocks(0), total(0), success(0) {}
116 ret.
fGood = IsReliable();
138 if (total <= 3 && success * 2 >= total) {
165 if (clientVersion && clientVersion < 31900) {
212 template <
typename Stream,
typename Operation>
219 uint8_t tried = ourLastTry != 0;
233 }
else if (!ser_action.ForRead()) {
300 void Add_(
const CAddress &addr,
bool force);
304 void Good_(
const CService &ip,
int clientV, std::string clientSV,
308 void Bad_(
const CService &ip,
int ban);
312 void GetIPs_(std::set<CNetAddr> &ips, uint64_t requestedFlags, uint32_t max,
322 stats.
nAvail = idToInfo.size();
324 stats.
nGood = goodId.size();
325 stats.
nNew = unkId.size();
326 if (ourId.size() > 0) {
327 stats.
nAge =
GetTime() - idToInfo.at(ourId.at(0)).ourLastTry;
334 for (std::map<int, SeederAddrInfo>::iterator it = idToInfo.begin();
335 it != idToInfo.end(); it++) {
336 (*it).second.ignoreTill = 0;
341 std::vector<CAddrReport> ret;
343 for (std::deque<int>::const_iterator it = ourId.begin();
344 it != ourId.end(); it++) {
362 template <
typename Stream>
void Serialize(Stream &s)
const {
369 int n = ourId.size() + unkId.size();
371 for (std::deque<int>::const_iterator it = ourId.begin();
372 it != ourId.end(); it++) {
373 std::map<int, SeederAddrInfo>::iterator ci = db->
idToInfo.find(*it);
376 for (std::set<int>::const_iterator it = unkId.begin();
377 it != unkId.end(); it++) {
378 std::map<int, SeederAddrInfo>::iterator ci = db->
idToInfo.find(*it);
394 for (
int i = 0; i < n; i++) {
397 if (!info.GetBanTime()) {
401 if (info.ourLastTry) {
402 db->
ourId.push_back(
id);
403 if (info.IsReliable()) {
407 db->
unkId.insert(
id);
421 void Add(
const std::vector<CAddress> &vAddr,
bool fForce =
false) {
423 for (
size_t i = 0; i < vAddr.size(); i++) {
424 Add_(vAddr[i], fForce);
428 void GetMany(std::vector<CServiceResult> &ips,
int max,
int &wait) {
432 if (!Get_(ip, wait)) {
442 for (
size_t i = 0; i < ips.size(); i++) {
444 Good_(ips[i].service, ips[i].nClientV, ips[i].strClientV,
447 Bad_(ips[i].service, ips[i].nBanTime);
452 void GetIPs(std::set<CNetAddr> &ips, uint64_t requestedFlags, uint32_t max,
455 GetIPs_(ips, requestedFlags, max, nets);
459 #endif // BITCOIN_SEEDER_DB_H
unsigned short GetPort() const
static unsigned short GetDefaultPort()
void SerializationOp(Stream &s, Operation ser_action)
std::map< CService, int64_t > banned
void Unserialize(Stream &s)
static std::string ToString(const CService &ip)
int64_t GetIgnoreTime() const
void SerializationOp(Stream &s, Operation ser_action)
const CCheckpointData & Checkpoints() const
void Serialize(Stream &s) const
void ResultMany(const std::vector< CServiceResult > &ips)
void GetIPs(std::set< CNetAddr > &ips, uint64_t requestedFlags, uint32_t max, const bool *nets)
void Update(bool good, int64_t age, double tau)
void Add(const std::vector< CAddress > &vAddr, bool fForce=false)
A combination of a network address (CNetAddr) and a (TCP) port.
CAddrReport GetReport() const
A CService with information about it as peer.
std::string clientSubVersion
std::map< int, SeederAddrInfo > idToInfo
static int GetRequireHeight()
static UniValue uptime(const Config &config, const JSONRPCRequest &request)
std::string clientSubVersion
static const uint8_t tau[]
seen nodes / \ (a) banned nodes available nodes-----------— / | \ tracked n...
MapCheckpoints mapCheckpoints
std::vector< CAddrReport > GetAll()
const CChainParams & Params()
Return the currently selected parameters.
void Add(const CAddress &addr, bool fForce=false)
int64_t GetBanTime() const
std::map< CService, int > ipToId
std::string ToString() const
int64_t GetTime()
Return system time (or mocked time, if set)
void GetMany(std::vector< CServiceResult > &ips, int max, int &wait)
void GetStats(CAddrDbStats &stats) const