dump db to text file

This commit is contained in:
Pieter Wuille 2011-12-31 00:39:53 +01:00
parent 54efe5f9d0
commit f8a529c744
2 changed files with 37 additions and 3 deletions

33
db.h
View file

@ -42,6 +42,13 @@ public:
friend class CAddrInfo; friend class CAddrInfo;
}; };
class CAddrReport {
public:
CIPPort ip;
int clientVersion;
};
class CAddrInfo { class CAddrInfo {
private: private:
CIPPort ip; CIPPort ip;
@ -59,7 +66,14 @@ private:
public: 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), total(0), success(0) {}
bool IsGood() { CAddrReport GetReport() const {
CAddrReport ret;
ret.ip = ip;
ret.clientVersion = clientVersion;
return ret;
}
bool IsGood() const {
if (ip.GetPort() != 8333) return false; if (ip.GetPort() != 8333) return false;
if (!(services & NODE_NETWORK)) return false; if (!(services & NODE_NETWORK)) return false;
if (!ip.IsRoutable()) return false; if (!ip.IsRoutable()) return false;
@ -75,14 +89,14 @@ public:
return false; return false;
} }
int GetBanTime() { int GetBanTime() const {
if (IsGood()) return 0; if (IsGood()) return 0;
if (clientVersion && clientVersion < 31900) { return 1000000; } if (clientVersion && clientVersion < 31900) { return 1000000; }
if (stat1D.reliability < 0.01 && stat1D.count > 5) { return 500000; } if (stat1D.reliability < 0.01 && stat1D.count > 5) { return 500000; }
if (stat1W.reliability - stat1W.weight + 1.0 < 0.10 && stat1W.count > 4) { return 240*3600; } if (stat1W.reliability - stat1W.weight + 1.0 < 0.10 && stat1W.count > 4) { return 240*3600; }
return 0; return 0;
} }
int GetIgnoreTime() { int GetIgnoreTime() const {
if (IsGood()) return 0; if (IsGood()) return 0;
if (stat2H.reliability - stat2H.weight + 1.0 < 0.2 && stat2H.count > 3) { return 3*3600; } if (stat2H.reliability - stat2H.weight + 1.0 < 0.2 && stat2H.count > 3) { return 3*3600; }
if (stat8H.reliability - stat8H.weight + 1.0 < 0.2 && stat8H.count > 6) { return 12*3600; } if (stat8H.reliability - stat8H.weight + 1.0 < 0.2 && stat8H.count > 6) { return 12*3600; }
@ -169,6 +183,19 @@ public:
} }
} }
std::vector<CAddrReport> GetAll() {
std::vector<CAddrReport> ret;
SHARED_CRITICAL_BLOCK(cs) {
for (std::deque<int>::const_iterator it = ourId.begin(); it != ourId.end(); it++) {
const CAddrInfo &info = idToInfo[*it];
if (info.success > 0) {
ret.push_back(info.GetReport());
}
}
}
return ret;
}
// serialization code // serialization code
// format: // format:
// nVersion (0 for now) // nVersion (0 for now)

View file

@ -114,6 +114,13 @@ int main(void) {
if (f) { if (f) {
CAutoFile cf(f); CAutoFile cf(f);
cf >> db; cf >> db;
FILE *d = fopen("dnsseed.dump", "w");
vector<CAddrReport> v = db.GetAll();
for (vector<CAddrReport>::const_iterator it = v.begin(); it < v.end(); it++) {
CAddrReport rep = *it;
fprintf(d, "%s %i\n", rep.ip.ToString().c_str(), rep.clientVersion);
}
fclose(d);
} }
pthread_t thread[NTHREADS+4]; pthread_t thread[NTHREADS+4];
for (int i=0; i<NTHREADS; i++) { for (int i=0; i<NTHREADS; i++) {