Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/db.h
Show All 16 Lines | |||||
#define MIN_RETRY 1000 | #define MIN_RETRY 1000 | ||||
#define REQUIRE_VERSION 70001 | #define REQUIRE_VERSION 70001 | ||||
static inline int GetRequireHeight(const bool testnet = fTestNet) { | static inline int GetRequireHeight(const bool testnet = fTestNet) { | ||||
return testnet ? 500000 : 350000; | return testnet ? 500000 : 350000; | ||||
} | } | ||||
static inline std::string ToString(const CService &ip) { | static inline std::string ToString(const CSeederService &ip) { | ||||
std::string str = ip.ToString(); | std::string str = ip.ToString(); | ||||
while (str.size() < 22) { | while (str.size() < 22) { | ||||
str += ' '; | str += ' '; | ||||
} | } | ||||
return str; | return str; | ||||
} | } | ||||
class CAddrStat { | class CAddrStat { | ||||
Show All 21 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(reliability); | READWRITE(reliability); | ||||
} | } | ||||
friend class CAddrInfo; | friend class CAddrInfo; | ||||
}; | }; | ||||
class CAddrReport { | class CAddrReport { | ||||
public: | public: | ||||
CService ip; | CSeederService ip; | ||||
int clientVersion; | int clientVersion; | ||||
int blocks; | int blocks; | ||||
double uptime[5]; | double uptime[5]; | ||||
std::string clientSubVersion; | std::string clientSubVersion; | ||||
int64_t lastSuccess; | int64_t lastSuccess; | ||||
bool fGood; | bool fGood; | ||||
uint64_t services; | uint64_t services; | ||||
}; | }; | ||||
class CAddrInfo { | class CAddrInfo { | ||||
private: | private: | ||||
CService ip; | CSeederService ip; | ||||
uint64_t services; | uint64_t services; | ||||
int64_t lastTry; | int64_t lastTry; | ||||
int64_t ourLastTry; | int64_t ourLastTry; | ||||
int64_t ourLastSuccess; | int64_t ourLastSuccess; | ||||
int64_t ignoreTill; | int64_t ignoreTill; | ||||
CAddrStat stat2H; | CAddrStat stat2H; | ||||
CAddrStat stat8H; | CAddrStat stat8H; | ||||
CAddrStat stat1D; | CAddrStat stat1D; | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | public: | ||||
int nBanned; | int nBanned; | ||||
int nAvail; | int nAvail; | ||||
int nTracked; | int nTracked; | ||||
int nNew; | int nNew; | ||||
int nGood; | int nGood; | ||||
int nAge; | int nAge; | ||||
}; | }; | ||||
struct CServiceResult { | struct CSeederServiceResult { | ||||
CService service; | CSeederService service; | ||||
bool fGood; | bool fGood; | ||||
int nBanTime; | int nBanTime; | ||||
int nHeight; | int nHeight; | ||||
int nClientV; | int nClientV; | ||||
std::string strClientV; | std::string strClientV; | ||||
int64_t ourLastSuccess; | int64_t ourLastSuccess; | ||||
}; | }; | ||||
Show All 9 Lines | |||||
class CAddrDb { | class CAddrDb { | ||||
private: | private: | ||||
mutable CCriticalSection cs; | mutable CCriticalSection cs; | ||||
// number of address id's | // number of address id's | ||||
int nId; | int nId; | ||||
// map address id to address info (b,c,d,e) | // map address id to address info (b,c,d,e) | ||||
std::map<int, CAddrInfo> idToInfo; | std::map<int, CAddrInfo> idToInfo; | ||||
// map ip to id (b,c,d,e) | // map ip to id (b,c,d,e) | ||||
std::map<CService, int> ipToId; | std::map<CSeederService, int> ipToId; | ||||
// sequence of tried nodes, in order we have tried connecting to them (c,d) | // sequence of tried nodes, in order we have tried connecting to them (c,d) | ||||
std::deque<int> ourId; | std::deque<int> ourId; | ||||
// set of nodes not yet tried (b) | // set of nodes not yet tried (b) | ||||
std::set<int> unkId; | std::set<int> unkId; | ||||
// set of good nodes (d, good e) | // set of good nodes (d, good e) | ||||
std::set<int> goodId; | std::set<int> goodId; | ||||
int nDirty; | int nDirty; | ||||
protected: | protected: | ||||
// internal routines that assume proper locks are acquired | // internal routines that assume proper locks are acquired | ||||
// add an address | // add an address | ||||
void Add_(const CAddress &addr, bool force); | void Add_(const CAddress &addr, bool force); | ||||
// get an IP to test (must call Good_, Bad_, or Skipped_ on result | // get an IP to test (must call Good_, Bad_, or Skipped_ on result | ||||
// afterwards) | // afterwards) | ||||
bool Get_(CServiceResult &ip, int &wait); | bool Get_(CSeederServiceResult &ip, int &wait); | ||||
bool GetMany_(std::vector<CServiceResult> &ips, int max, int &wait); | bool GetMany_(std::vector<CSeederServiceResult> &ips, int max, int &wait); | ||||
// mark an IP as good (must have been returned by Get_) | // mark an IP as good (must have been returned by Get_) | ||||
void Good_(const CService &ip, int clientV, std::string clientSV, | void Good_(const CSeederService &ip, int clientV, std::string clientSV, | ||||
int blocks); | int blocks); | ||||
// mark an IP as bad (and optionally ban it) (must have been returned by | // mark an IP as bad (and optionally ban it) (must have been returned by | ||||
// Get_) | // Get_) | ||||
void Bad_(const CService &ip, int ban); | void Bad_(const CSeederService &ip, int ban); | ||||
// mark an IP as skipped (must have been returned by Get_) | // mark an IP as skipped (must have been returned by Get_) | ||||
void Skipped_(const CService &ip); | void Skipped_(const CSeederService &ip); | ||||
// look up id of an IP | // look up id of an IP | ||||
int Lookup_(const CService &ip); | int Lookup_(const CSeederService &ip); | ||||
// get a random set of IPs (shared lock only) | // get a random set of IPs (shared lock only) | ||||
void GetIPs_(std::set<CNetAddr> &ips, uint64_t requestedFlags, uint32_t max, | void GetIPs_(std::set<CNetAddr> &ips, uint64_t requestedFlags, uint32_t max, | ||||
const bool *nets); | const bool *nets); | ||||
public: | public: | ||||
// nodes that are banned, with their unban time (a) | // nodes that are banned, with their unban time (a) | ||||
std::map<CService, int64_t> banned; | std::map<CSeederService, int64_t> banned; | ||||
void GetStats(CAddrDbStats &stats) { | void GetStats(CAddrDbStats &stats) { | ||||
LOCK(cs); | LOCK(cs); | ||||
stats.nBanned = banned.size(); | stats.nBanned = banned.size(); | ||||
stats.nAvail = idToInfo.size(); | stats.nAvail = idToInfo.size(); | ||||
stats.nTracked = ourId.size(); | stats.nTracked = ourId.size(); | ||||
stats.nGood = goodId.size(); | stats.nGood = goodId.size(); | ||||
stats.nNew = unkId.size(); | stats.nNew = unkId.size(); | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | public: | ||||
void Add(const std::vector<CAddress> &vAddr, bool fForce = false) { | void Add(const std::vector<CAddress> &vAddr, bool fForce = false) { | ||||
LOCK(cs); | LOCK(cs); | ||||
for (size_t i = 0; i < vAddr.size(); i++) { | for (size_t i = 0; i < vAddr.size(); i++) { | ||||
Add_(vAddr[i], fForce); | Add_(vAddr[i], fForce); | ||||
} | } | ||||
} | } | ||||
void Good(const CService &addr, int clientVersion, | void Good(const CSeederService &addr, int clientVersion, | ||||
std::string clientSubVersion, int blocks) { | std::string clientSubVersion, int blocks) { | ||||
LOCK(cs); | LOCK(cs); | ||||
Good_(addr, clientVersion, clientSubVersion, blocks); | Good_(addr, clientVersion, clientSubVersion, blocks); | ||||
} | } | ||||
void Skipped(const CService &addr) { | void Skipped(const CSeederService &addr) { | ||||
LOCK(cs); | LOCK(cs); | ||||
Skipped_(addr); | Skipped_(addr); | ||||
} | } | ||||
void Bad(const CService &addr, int ban = 0) { | void Bad(const CSeederService &addr, int ban = 0) { | ||||
LOCK(cs); | LOCK(cs); | ||||
Bad_(addr, ban); | Bad_(addr, ban); | ||||
} | } | ||||
bool Get(CServiceResult &ip, int &wait) { | bool Get(CSeederServiceResult &ip, int &wait) { | ||||
LOCK(cs); | LOCK(cs); | ||||
return Get_(ip, wait); | return Get_(ip, wait); | ||||
} | } | ||||
void GetMany(std::vector<CServiceResult> &ips, int max, int &wait) { | void GetMany(std::vector<CSeederServiceResult> &ips, int max, int &wait) { | ||||
LOCK(cs); | LOCK(cs); | ||||
while (max > 0) { | while (max > 0) { | ||||
CServiceResult ip = {}; | CSeederServiceResult ip = {}; | ||||
if (!Get_(ip, wait)) { | if (!Get_(ip, wait)) { | ||||
return; | return; | ||||
} | } | ||||
ips.push_back(ip); | ips.push_back(ip); | ||||
max--; | max--; | ||||
} | } | ||||
} | } | ||||
void ResultMany(const std::vector<CServiceResult> &ips) { | void ResultMany(const std::vector<CSeederServiceResult> &ips) { | ||||
LOCK(cs); | LOCK(cs); | ||||
for (size_t i = 0; i < ips.size(); i++) { | for (size_t i = 0; i < ips.size(); i++) { | ||||
if (ips[i].fGood) { | if (ips[i].fGood) { | ||||
Good_(ips[i].service, ips[i].nClientV, ips[i].strClientV, | Good_(ips[i].service, ips[i].nClientV, ips[i].strClientV, | ||||
ips[i].nHeight); | ips[i].nHeight); | ||||
} else { | } else { | ||||
Bad_(ips[i].service, ips[i].nBanTime); | Bad_(ips[i].service, ips[i].nBanTime); | ||||
} | } | ||||
Show All 11 Lines |