add startingheight to output
This commit is contained in:
parent
d6dfa9a8ab
commit
2b29f0a760
5 changed files with 25 additions and 13 deletions
|
@ -258,9 +258,13 @@ public:
|
|||
std::string GetClientSubVersion() {
|
||||
return strSubVer;
|
||||
}
|
||||
|
||||
int GetStartingHeight() {
|
||||
return nStartingHeight;
|
||||
}
|
||||
};
|
||||
|
||||
bool TestNode(const CService &cip, int &ban, int &clientV, std::string &clientSV, vector<CAddress>& vAddr) {
|
||||
bool TestNode(const CService &cip, int &ban, int &clientV, std::string &clientSV, int &blocks, vector<CAddress>& vAddr) {
|
||||
try {
|
||||
CNode node(cip, vAddr);
|
||||
bool ret = node.Run();
|
||||
|
@ -271,6 +275,7 @@ bool TestNode(const CService &cip, int &ban, int &clientV, std::string &clientSV
|
|||
}
|
||||
clientV = node.GetClientVersion();
|
||||
clientSV = node.GetClientSubVersion();
|
||||
blocks = node.GetStartingHeight();
|
||||
// printf("%s: %s!!!\n", cip.ToString().c_str(), ret ? "GOOD" : "BAD");
|
||||
return ret;
|
||||
} catch(std::ios_base::failure& e) {
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
#include "protocol.h"
|
||||
|
||||
bool TestNode(const CService &cip, int &ban, int &client, std::string &clientSV, std::vector<CAddress>& vAddr);
|
||||
bool TestNode(const CService &cip, int &ban, int &client, std::string &clientSV, int &blocks, std::vector<CAddress>& vAddr);
|
||||
|
||||
#endif
|
||||
|
|
3
db.cpp
3
db.cpp
|
@ -84,7 +84,7 @@ int CAddrDb::Lookup_(const CService &ip) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV) {
|
||||
void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV, int blocks) {
|
||||
int id = Lookup_(addr);
|
||||
if (id == -1) return;
|
||||
unkId.erase(id);
|
||||
|
@ -92,6 +92,7 @@ void CAddrDb::Good_(const CService &addr, int clientV, std::string clientSV) {
|
|||
CAddrInfo &info = idToInfo[id];
|
||||
info.clientVersion = clientV;
|
||||
info.clientSubVersion = clientSV;
|
||||
info.blocks = blocks;
|
||||
info.Update(true);
|
||||
if (info.IsGood() && goodId.count(id)==0) {
|
||||
goodId.insert(id);
|
||||
|
|
17
db.h
17
db.h
|
@ -46,6 +46,7 @@ class CAddrReport {
|
|||
public:
|
||||
CService ip;
|
||||
int clientVersion;
|
||||
int blocks;
|
||||
double uptime[5];
|
||||
std::string clientSubVersion;
|
||||
};
|
||||
|
@ -64,17 +65,19 @@ private:
|
|||
CAddrStat stat1W;
|
||||
CAddrStat stat1M;
|
||||
int clientVersion;
|
||||
int blocks;
|
||||
int total;
|
||||
int success;
|
||||
std::string clientSubVersion;
|
||||
public:
|
||||
CAddrInfo() : services(0), lastTry(0), ourLastTry(0), ignoreTill(0), clientVersion(0), total(0), success(0) {}
|
||||
CAddrInfo() : services(0), lastTry(0), ourLastTry(0), ignoreTill(0), clientVersion(0), blocks(0), total(0), success(0) {}
|
||||
|
||||
CAddrReport GetReport() const {
|
||||
CAddrReport ret;
|
||||
ret.ip = ip;
|
||||
ret.clientVersion = clientVersion;
|
||||
ret.clientSubVersion = clientSubVersion;
|
||||
ret.blocks = blocks;
|
||||
ret.uptime[0] = stat2H.reliability;
|
||||
ret.uptime[1] = stat8H.reliability;
|
||||
ret.uptime[2] = stat1D.reliability;
|
||||
|
@ -118,7 +121,7 @@ public:
|
|||
friend class CAddrDb;
|
||||
|
||||
IMPLEMENT_SERIALIZE (
|
||||
unsigned char version = 2;
|
||||
unsigned char version = 3;
|
||||
READWRITE(version);
|
||||
READWRITE(ip);
|
||||
READWRITE(services);
|
||||
|
@ -142,6 +145,8 @@ public:
|
|||
READWRITE(clientVersion);
|
||||
if (version >= 2)
|
||||
READWRITE(clientSubVersion);
|
||||
if (version >= 3)
|
||||
READWRITE(blocks);
|
||||
}
|
||||
)
|
||||
};
|
||||
|
@ -179,11 +184,11 @@ protected:
|
|||
// internal routines that assume proper locks are acquired
|
||||
void Add_(const CAddress &addr, bool force); // add an address
|
||||
bool Get_(CService &ip, int& wait); // get an IP to test (must call Good_, Bad_, or Skipped_ on result afterwards)
|
||||
void Good_(const CService &ip, int clientV, std::string clientSV); // mark an IP as good (must have been returned by Get_)
|
||||
void Good_(const CService &ip, int clientV, std::string clientSV, int blocks); // 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
|
||||
void GetIPs_(std::set<CNetAddr>& ips, int max, const bool* nets); // get a random set of IPs (shared lock only)
|
||||
void GetIPs_(std::set<CNetAddr>& ips, int max, const bool *nets); // get a random set of IPs (shared lock only)
|
||||
|
||||
public:
|
||||
std::map<CService, time_t> banned; // nodes that are banned, with their unban time (a)
|
||||
|
@ -271,9 +276,9 @@ public:
|
|||
for (int i=0; i<vAddr.size(); i++)
|
||||
Add_(vAddr[i], fForce);
|
||||
}
|
||||
void Good(const CService &addr, int clientVersion, std::string clientSubVersion) {
|
||||
void Good(const CService &addr, int clientVersion, std::string clientSubVersion, int blocks) {
|
||||
CRITICAL_BLOCK(cs)
|
||||
Good_(addr, clientVersion, clientSubVersion);
|
||||
Good_(addr, clientVersion, clientSubVersion, blocks);
|
||||
}
|
||||
void Skipped(const CService &addr) {
|
||||
CRITICAL_BLOCK(cs)
|
||||
|
|
9
main.cpp
9
main.cpp
|
@ -116,11 +116,12 @@ extern "C" void* ThreadCrawler(void* data) {
|
|||
int ban = 0;
|
||||
vector<CAddress> addr;
|
||||
int clientV = 0;
|
||||
int blocks = 0;
|
||||
std::string clientSV;
|
||||
bool ret = TestNode(ip,ban,clientV,clientSV,addr);
|
||||
bool ret = TestNode(ip,ban,clientV,clientSV,blocks,addr);
|
||||
db.Add(addr);
|
||||
if (ret) {
|
||||
db.Good(ip, clientV, clientSV);
|
||||
db.Good(ip, clientV, clientSV, blocks);
|
||||
} else {
|
||||
db.Bad(ip, ban);
|
||||
}
|
||||
|
@ -256,11 +257,11 @@ extern "C" void* ThreadDumper(void*) {
|
|||
FILE *d = fopen("dnsseed.dump", "w");
|
||||
vector<CAddrReport> v = db.GetAll();
|
||||
sort(v.begin(), v.end(), StatCompare);
|
||||
fprintf(d, "# address \t%%(2h)\t%%(8h)\t%%(1d)\t%%(7d)\t%%(30d)\tversion\n");
|
||||
fprintf(d, "# address \t%%(2h)\t%%(8h)\t%%(1d)\t%%(7d)\t%%(30d)\tblocks\tversion\n");
|
||||
double stat[5]={0,0,0,0,0};
|
||||
for (vector<CAddrReport>::const_iterator it = v.begin(); it < v.end(); it++) {
|
||||
CAddrReport rep = *it;
|
||||
fprintf(d, "%s\t%.2f%%\t%.2f%%\t%.2f%%\t%.2f%%\t%.2f%%\t%i \"%s\"\n", rep.ip.ToString().c_str(), 100.0*rep.uptime[0], 100.0*rep.uptime[1], 100.0*rep.uptime[2], 100.0*rep.uptime[3], 100.0*rep.uptime[4], rep.clientVersion, rep.clientSubVersion.c_str());
|
||||
fprintf(d, "%s\t%.2f%%\t%.2f%%\t%.2f%%\t%.2f%%\t%.2f%%\t%i\t%i \"%s\"\n", rep.ip.ToString().c_str(), 100.0*rep.uptime[0], 100.0*rep.uptime[1], 100.0*rep.uptime[2], 100.0*rep.uptime[3], 100.0*rep.uptime[4], rep.blocks, rep.clientVersion, rep.clientSubVersion.c_str());
|
||||
stat[0] += rep.uptime[0];
|
||||
stat[1] += rep.uptime[1];
|
||||
stat[2] += rep.uptime[2];
|
||||
|
|
Loading…
Reference in a new issue