nicer output

This commit is contained in:
Pieter Wuille 2011-12-26 15:53:22 +01:00
parent 3cb418361b
commit f7ce03cf70
6 changed files with 36 additions and 31 deletions

View file

@ -81,7 +81,7 @@ class CNode {
}
void GotVersion() {
printf("%s: version %i\n", ToString(you).c_str(), nVersion);
// printf("%s: version %i\n", ToString(you).c_str(), nVersion);
BeginMessage("getaddr");
EndMessage();
doneAfter = time(NULL) + 10;
@ -124,7 +124,7 @@ class CNode {
if (strCommand == "addr") {
vector<CAddress> vAddrNew;
vRecv >> vAddrNew;
printf("%s: got %i addresses\n", ToString(you).c_str(), (int)vAddrNew.size());
// printf("%s: got %i addresses\n", ToString(you).c_str(), (int)vAddrNew.size());
int64 now = time(NULL);
vector<CAddress>::iterator it = vAddrNew.begin();
if (doneAfter == 0 || doneAfter > now + 1) doneAfter = now + 1;
@ -162,13 +162,13 @@ class CNode {
CMessageHeader hdr;
vRecv >> hdr;
if (!hdr.IsValid()) {
printf("%s: BAD (invalid header)\n", ToString(you).c_str());
// printf("%s: BAD (invalid header)\n", ToString(you).c_str());
ban = 100000; return true;
}
string strCommand = hdr.GetCommand();
unsigned int nMessageSize = hdr.nMessageSize;
if (nMessageSize > MAX_SIZE) {
printf("%s: BAD (message too large)\n", ToString(you).c_str());
// printf("%s: BAD (message too large)\n", ToString(you).c_str());
ban = 100000;
return true;
}
@ -232,11 +232,11 @@ public:
vRecv.resize(nPos + nBytes);
memcpy(&vRecv[nPos], pchBuf, nBytes);
} else if (nBytes == 0) {
printf("%s: BAD (connection closed prematurely)\n", ToString(you).c_str());
// printf("%s: BAD (connection closed prematurely)\n", ToString(you).c_str());
res = false;
break;
} else {
printf("%s: BAD (connection error)\n", ToString(you).c_str());
// printf("%s: BAD (connection error)\n", ToString(you).c_str());
res = false;
break;
}

20
db.cpp
View file

@ -18,11 +18,11 @@ void CAddrInfo::Update(bool good) {
stat1W.Update(good, age, 3600*24*7);
int ign = GetIgnoreTime();
if (ign && (ignoreTill==0 || ignoreTill < ign+now)) ignoreTill = ign+now;
printf("%s: got %s result: success=%i/%i; 2H:%.2f%%-%.2f%%(%.2f) 8H:%.2f%%-%.2f%%(%.2f) 1D:%.2f%%-%.2f%%(%.2f) 1W:%.2f%%-%.2f%%(%.2f) \n", ToString(ip).c_str(), good ? "good" : "bad", success, total,
100.0 * stat2H.reliability, 100.0 * (stat2H.reliability + 1.0 - stat2H.weight), stat2H.count,
100.0 * stat8H.reliability, 100.0 * (stat8H.reliability + 1.0 - stat8H.weight), stat8H.count,
100.0 * stat1D.reliability, 100.0 * (stat1D.reliability + 1.0 - stat1D.weight), stat1D.count,
100.0 * stat1W.reliability, 100.0 * (stat1W.reliability + 1.0 - stat1W.weight), stat1W.count);
// printf("%s: got %s result: success=%i/%i; 2H:%.2f%%-%.2f%%(%.2f) 8H:%.2f%%-%.2f%%(%.2f) 1D:%.2f%%-%.2f%%(%.2f) 1W:%.2f%%-%.2f%%(%.2f) \n", ToString(ip).c_str(), good ? "good" : "bad", success, total,
// 100.0 * stat2H.reliability, 100.0 * (stat2H.reliability + 1.0 - stat2H.weight), stat2H.count,
// 100.0 * stat8H.reliability, 100.0 * (stat8H.reliability + 1.0 - stat8H.weight), stat8H.count,
// 100.0 * stat1D.reliability, 100.0 * (stat1D.reliability + 1.0 - stat1D.weight), stat1D.count,
// 100.0 * stat1W.reliability, 100.0 * (stat1W.reliability + 1.0 - stat1W.weight), stat1W.count);
}
bool CAddrDb::Get_(CIPPort &ip, int &wait) {
@ -92,7 +92,7 @@ void CAddrDb::Good_(const CIPPort &addr, int clientV) {
info.Update(true);
if (info.IsGood() && goodId.count(id)==0) {
goodId.insert(id);
printf("%s: good; %i good nodes now\n", ToString(addr).c_str(), (int)goodId.size());
// printf("%s: good; %i good nodes now\n", ToString(addr).c_str(), (int)goodId.size());
}
nDirty++;
ourId.push_back(id);
@ -108,11 +108,11 @@ void CAddrDb::Bad_(const CIPPort &addr, int ban)
uint32_t now = time(NULL);
int ter = info.GetBanTime();
if (ter) {
printf("%s: terrible\n", ToString(addr).c_str());
// printf("%s: terrible\n", ToString(addr).c_str());
if (ban < ter) ban = ter;
}
if (ban > 0) {
printf("%s: ban for %i seconds\n", ToString(addr).c_str(), ban);
// printf("%s: ban for %i seconds\n", ToString(addr).c_str(), ban);
banned[info.ip] = ban + now;
ipToId.erase(info.ip);
goodId.erase(id);
@ -120,7 +120,7 @@ void CAddrDb::Bad_(const CIPPort &addr, int ban)
} else {
if (!info.IsGood() && goodId.count(id)==1) {
goodId.erase(id);
printf("%s: not good; %i good nodes left\n", ToString(addr).c_str(), (int)goodId.size());
// printf("%s: not good; %i good nodes left\n", ToString(addr).c_str(), (int)goodId.size());
}
ourId.push_back(id);
}
@ -133,7 +133,7 @@ void CAddrDb::Skipped_(const CIPPort &addr)
if (id == -1) return;
unkId.erase(id);
ourId.push_back(id);
printf("%s: skipped\n", ToString(addr).c_str());
// printf("%s: skipped\n", ToString(addr).c_str());
nDirty++;
}

2
db.h
View file

@ -123,6 +123,7 @@ public:
int nTracked;
int nNew;
int nGood;
int nAge;
};
// seen nodes
@ -164,6 +165,7 @@ public:
stats.nTracked = ourId.size();
stats.nGood = goodId.size();
stats.nNew = unkId.size();
stats.nAge = time(NULL) - idToInfo[ourId[0]].ourLastTry;
}
}

5
dns.c
View file

@ -261,7 +261,7 @@ ssize_t static dnshandle(dns_opt_t *opt, const unsigned char *inbuf, size_t insi
unsigned char *outpos = outbuf+(inpos-inbuf);
unsigned char *outend = outbuf + BUFLEN;
printf("DNS: Request host='%s' type=%i class=%i\n", name, typ, cls);
// printf("DNS: Request host='%s' type=%i class=%i\n", name, typ, cls);
// calculate size of authority section
@ -348,7 +348,8 @@ int dnsserver(dns_opt_t *opt) {
do {
ssize_t insize = recvfrom(s, inbuf, BUFLEN, 0, (struct sockaddr*)&si_other, &slen);
unsigned char *addr = (unsigned char*)&si_other.sin_addr.s_addr;
printf("DNS: Request %llu from %i.%i.%i.%i:%i of %i bytes\n", (unsigned long long)(++opt->nRequests), addr[0], addr[1], addr[2], addr[3], ntohs(si_other.sin_port), (int)insize);
// printf("DNS: Request %llu from %i.%i.%i.%i:%i of %i bytes\n", (unsigned long long)(opt->nRequests), addr[0], addr[1], addr[2], addr[3], ntohs(si_other.sin_port), (int)insize);
opt->nRequests++;
if (insize > 0) {
ssize_t ret = dnshandle(opt, inbuf, insize, outbuf);
if (ret > 0)

View file

@ -65,7 +65,7 @@ extern "C" void* ThreadDNS(void*) {
dns_opt.datattl = 60;
dns_opt.nsttl = 40000;
dns_opt.cb = GetIPList;
dns_opt.port = 53;
dns_opt.port = 5353;
dns_opt.nRequests = 0;
dnsserver(&dns_opt);
}
@ -87,8 +87,9 @@ extern "C" void* ThreadStats(void*) {
do {
CAddrDbStats stats;
db.GetStats(stats);
printf("*** %i available (%i tracked, %i new, %i active), %i banned; %i good; %llu DNS requests\n", stats.nAvail, stats.nTracked, stats.nNew, stats.nAvail - stats.nTracked - stats.nNew, stats.nBanned, stats.nGood, (unsigned long long)dns_opt.nRequests);
Sleep(10000);
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
printf("*** %i available (%i tracked (%is old), %i new, %i active), %i banned; %i good; %llu DNS requests", stats.nAvail, stats.nTracked, stats.nAge, stats.nNew, stats.nAvail - stats.nTracked - stats.nNew, stats.nBanned, stats.nGood, (unsigned long long)dns_opt.nRequests);
Sleep(1000);
} while(1);
}
@ -108,6 +109,7 @@ extern "C" void* ThreadSeeder(void*) {
}
int main(void) {
setbuf(stdout, NULL);
FILE *f = fopen("dnsseed.dat","r");
if (f) {
CAutoFile cf(f);

View file

@ -178,7 +178,7 @@ bool CIPPort::ConnectSocket(SOCKET& hSocketRet, int nTimeout) const
SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (hSocket == INVALID_SOCKET)
{
printf("Failed to create socket: %s\n", strerror(errno));
// printf("Failed to create socket: %s\n", strerror(errno));
return false;
}
@ -198,7 +198,7 @@ bool CIPPort::ConnectSocket(SOCKET& hSocketRet, int nTimeout) const
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == -1)
#endif
{
printf("Failed to set socket NONBLOCK\n");
// printf("Failed to set socket NONBLOCK\n");
closesocket(hSocket);
}
@ -218,13 +218,13 @@ bool CIPPort::ConnectSocket(SOCKET& hSocketRet, int nTimeout) const
int nRet = select(hSocket + 1, NULL, &fdset, NULL, &timeout);
if (nRet == 0)
{
printf("connection timeout\n");
// printf("connection timeout\n");
closesocket(hSocket);
return false;
}
if (nRet == SOCKET_ERROR)
{
printf("select() for connection failed: %s\n",strerror(WSAGetLastError()));
// printf("select() for connection failed: %s\n",strerror(WSAGetLastError()));
closesocket(hSocket);
return false;
}
@ -235,13 +235,13 @@ bool CIPPort::ConnectSocket(SOCKET& hSocketRet, int nTimeout) const
if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR)
#endif
{
printf("getsockopt() for connection failed: %s\n",strerror(WSAGetLastError()));
// printf("getsockopt() for connection failed: %s\n",strerror(WSAGetLastError()));
closesocket(hSocket);
return false;
}
if (nRet != 0)
{
printf("connect() failed after select(): %s\n",strerror(nRet));
// printf("connect() failed after select(): %s\n",strerror(nRet));
closesocket(hSocket);
return false;
}
@ -252,7 +252,7 @@ bool CIPPort::ConnectSocket(SOCKET& hSocketRet, int nTimeout) const
else
#endif
{
printf("connect() failed: %i\n",WSAGetLastError());
// printf("connect() failed: %i\n",WSAGetLastError());
closesocket(hSocket);
return false;
}
@ -269,7 +269,7 @@ bool CIPPort::ConnectSocket(SOCKET& hSocketRet, int nTimeout) const
if (fcntl(hSocket, F_SETFL, fFlags & !O_NONBLOCK) == SOCKET_ERROR)
#endif
{
printf("Failed to set socket blocking\n");
// printf("Failed to set socket blocking\n");
closesocket(hSocket);
return false;
}
@ -571,7 +571,7 @@ int64 CIP::GetHash() const
void CIP::print() const
{
printf("CIP(%s)\n", ToString().c_str());
// printf("CIP(%s)\n", ToString().c_str());
}
void CIPPort::Init()
@ -699,7 +699,7 @@ std::string CIPPort::ToString() const
void CIPPort::print() const
{
printf("CIPPort(%s)\n", ToString().c_str());
// printf("CIPPort(%s)\n", ToString().c_str());
}
void CIPPort::SetPort(unsigned short portIn)