Overwrite db services with version message results

This commit is contained in:
Pieter Wuille 2020-10-09 19:37:28 -07:00
parent 529a667f30
commit a1e9394284
5 changed files with 16 additions and 8 deletions

View file

@ -275,9 +275,13 @@ public:
int GetStartingHeight() {
return nStartingHeight;
}
uint64_t GetServices() {
return you.nServices;
}
};
bool TestNode(const CService &cip, int &ban, int &clientV, std::string &clientSV, int &blocks, vector<CAddress>* vAddr) {
bool TestNode(const CService &cip, int &ban, int &clientV, std::string &clientSV, int &blocks, vector<CAddress>* vAddr, uint64_t& services) {
try {
CNode node(cip, vAddr);
bool ret = node.Run();
@ -289,6 +293,7 @@ bool TestNode(const CService &cip, int &ban, int &clientV, std::string &clientSV
clientV = node.GetClientVersion();
clientSV = node.GetClientSubVersion();
blocks = node.GetStartingHeight();
services = node.GetServices();
// printf("%s: %s!!!\n", cip.ToString().c_str(), ret ? "GOOD" : "BAD");
return ret;
} catch(std::ios_base::failure& e) {

View file

@ -3,6 +3,6 @@
#include "protocol.h"
bool TestNode(const CService &cip, int &ban, int &client, std::string &clientSV, int &blocks, std::vector<CAddress>* vAddr);
bool TestNode(const CService &cip, int &ban, int &client, std::string &clientSV, int &blocks, std::vector<CAddress>* vAddr, uint64_t& services);
#endif

3
db.cpp
View file

@ -69,7 +69,7 @@ int CAddrDb::Lookup_(const CService &ip) {
return -1;
}
void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, int blocks) {
void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, int blocks, uint64_t services) {
int id = Lookup_(addr);
if (id == -1) return;
unkId.erase(id);
@ -78,6 +78,7 @@ void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, int
info.clientVersion = clientV;
info.clientSubVersion = clientSV;
info.blocks = blocks;
info.services = services;
info.Update(true);
if (info.IsGood() && goodId.count(id)==0) {
goodId.insert(id);

9
db.h
View file

@ -183,6 +183,7 @@ public:
struct CServiceResult {
CService service;
uint64_t services;
bool fGood;
int nBanTime;
int nHeight;
@ -215,7 +216,7 @@ protected:
void Add_(const CAddress &addr, bool force); // add an address
bool Get_(CServiceResult &ip, int& wait); // get an IP to test (must call Good_, Bad_, or Skipped_ on result afterwards)
bool GetMany_(std::vector<CServiceResult> &ips, int max, int& wait);
void Good_(const CService &ip, int clientV, std::string clientSV, int blocks); // mark an IP as good (must have been returned by Get_)
void Good_(const CService &ip, int clientV, std::string clientSV, int blocks, uint64_t services); // mark an IP as good (must have been returned by Get_)
void Bad_(const CService &ip, int ban); // mark an IP as bad (and optionally ban it) (must have been returned by Get_)
void Skipped_(const CService &ip); // mark an IP as skipped (must have been returned by Get_)
int Lookup_(const CService &ip); // look up id of an IP
@ -313,9 +314,9 @@ public:
for (int i=0; i<vAddr.size(); i++)
Add_(vAddr[i], fForce);
}
void Good(const CService &addr, int clientVersion, std::string clientSubVersion, int blocks) {
void Good(const CService &addr, int clientVersion, std::string clientSubVersion, int blocks, uint64_t services) {
CRITICAL_BLOCK(cs)
Good_(addr, clientVersion, clientSubVersion, blocks);
Good_(addr, clientVersion, clientSubVersion, blocks, services);
}
void Skipped(const CService &addr) {
CRITICAL_BLOCK(cs)
@ -344,7 +345,7 @@ public:
CRITICAL_BLOCK(cs) {
for (int i=0; i<ips.size(); i++) {
if (ips[i].fGood) {
Good_(ips[i].service, ips[i].nClientV, ips[i].strClientV, ips[i].nHeight);
Good_(ips[i].service, ips[i].nClientV, ips[i].strClientV, ips[i].nHeight, ips[i].services);
} else {
Bad_(ips[i].service, ips[i].nBanTime);
}

View file

@ -187,8 +187,9 @@ extern "C" void* ThreadCrawler(void* data) {
res.nClientV = 0;
res.nHeight = 0;
res.strClientV = "";
res.services = 0;
bool getaddr = res.ourLastSuccess + 86400 < now;
res.fGood = TestNode(res.service,res.nBanTime,res.nClientV,res.strClientV,res.nHeight,getaddr ? &addr : NULL);
res.fGood = TestNode(res.service,res.nBanTime,res.nClientV,res.strClientV,res.nHeight,getaddr ? &addr : NULL, res.services);
}
db.ResultMany(ips);
db.Add(addr);