diff --git a/src/seeder/bitcoin.cpp b/src/seeder/bitcoin.cpp --- a/src/seeder/bitcoin.cpp +++ b/src/seeder/bitcoin.cpp @@ -42,7 +42,7 @@ nHeaderStart = vSend.size(); vSend << CMessageHeader(netMagic, pszCommand, 0); nMessageStart = vSend.size(); - // printf("%s: SEND %s\n", ToString(you).c_str(), pszCommand); + // fprintf(stdout, "%s: SEND %s\n", ToString(you).c_str(), pszCommand); } void AbortMessage() { @@ -107,7 +107,8 @@ } void GotVersion() { - // printf("\n%s: version %i\n", ToString(you).c_str(), nVersion); + // fprintf(stdout, "\n%s: version %i\n", ToString(you).c_str(), + // nVersion); if (vAddr) { BeginMessage("getaddr"); EndMessage(); @@ -118,7 +119,8 @@ } bool ProcessMessage(std::string strCommand, CDataStream &recv) { - // printf("%s: RECV %s\n", ToString(you).c_str(), strCommand.c_str()); + // fprintf(stdout, "%s: RECV %s\n", ToString(you).c_str(), + // strCommand.c_str()); if (strCommand == "version") { int64_t nTime; CAddress addrMe; @@ -153,7 +155,7 @@ if (strCommand == "addr" && vAddr) { std::vector vAddrNew; recv >> vAddrNew; - // printf("%s: got %i addresses\n", ToString(you).c_str(), + // fprintf(stdout, "%s: got %i addresses\n", ToString(you).c_str(), // (int)vAddrNew.size()); int64_t now = time(nullptr); std::vector::iterator it = vAddrNew.begin(); @@ -162,7 +164,8 @@ } while (it != vAddrNew.end()) { CAddress &addr = *it; - // printf("%s: got address %s\n", ToString(you).c_str(), + // fprintf(stdout, "%s: got address %s\n", + // ToString(you).c_str(), // addr.ToString().c_str(), (int)(vAddr->size())); it++; if (addr.nTime <= 100000000 || addr.nTime > now + 600) { @@ -171,7 +174,8 @@ if (addr.nTime > now - 604800) { vAddr->push_back(addr); } - // printf("%s: added address %s (#%i)\n", ToString(you).c_str(), + // fprintf(stdout, "%s: added address %s (#%i)\n", + // ToString(you).c_str(), // addr.ToString().c_str(), (int)(vAddr->size())); if (vAddr->size() > 1000) { doneAfter = 1; @@ -206,14 +210,15 @@ CMessageHeader hdr(netMagic); vRecv >> hdr; if (!hdr.IsValidWithoutConfig(netMagic)) { - // printf("%s: BAD (invalid header)\n", ToString(you).c_str()); + // fprintf(stdout, "%s: BAD (invalid header)\n", + // ToString(you).c_str()); ban = 100000; return true; } std::string strCommand = hdr.GetCommand(); unsigned int nMessageSize = hdr.nMessageSize; if (nMessageSize > MAX_SIZE) { - // printf("%s: BAD (message too large)\n", + // fprintf(stdout, "%s: BAD (message too large)\n", // ToString(you).c_str()); ban = 100000; return true; @@ -237,7 +242,8 @@ if (ProcessMessage(strCommand, vMsg)) { return true; } - // printf("%s: done processing %s\n", ToString(you).c_str(), + // fprintf(stdout, "%s: done processing %s\n", + // ToString(you).c_str(), // strCommand.c_str()); } while (1); return false; @@ -285,7 +291,7 @@ } if (!connected) { - // printf("Cannot connect to %s\n", ToString(you).c_str()); + // fprintf(stdout, "Cannot connect to %s\n", ToString(you).c_str()); CloseSocket(sock); return false; } @@ -321,12 +327,12 @@ vRecv.resize(nPos + nBytes); memcpy(&vRecv[nPos], pchBuf, nBytes); } else if (nBytes == 0) { - // printf("%s: BAD (connection closed prematurely)\n", + // fprintf(stdout, "%s: BAD (connection closed prematurely)\n", // ToString(you).c_str()); res = false; break; } else { - // printf("%s: BAD (connection error)\n", + // fprintf(stdout, "%s: BAD (connection error)\n", // ToString(you).c_str()); res = false; break; @@ -363,7 +369,8 @@ clientV = node.GetClientVersion(); clientSV = node.GetClientSubVersion(); blocks = node.GetStartingHeight(); - // printf("%s: %s!!!\n", cip.ToString().c_str(), ret ? "GOOD" : "BAD"); + // fprintf(stdout, "%s: %s!!!\n", cip.ToString().c_str(), ret ? "GOOD" : + // "BAD"); return ret; } catch (std::ios_base::failure &e) { ban = 0; diff --git a/src/seeder/db.cpp b/src/seeder/db.cpp --- a/src/seeder/db.cpp +++ b/src/seeder/db.cpp @@ -21,17 +21,15 @@ int64_t 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); + // fprintf(stdout, "%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_(CServiceResult &ip, int &wait) { @@ -90,8 +88,8 @@ 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()); + // fprintf(stdout, "%s: good; %i good nodes now\n", + // ToString(addr).c_str(), (int)goodId.size()); } nDirty++; ourId.push_back(id); @@ -106,11 +104,12 @@ uint32_t now = time(nullptr); int ter = info.GetBanTime(); if (ter) { - // printf("%s: terrible\n", ToString(addr).c_str()); + // fprintf(stdout, "%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); + // fprintf(stdout, "%s: ban for %i seconds\n", + // ToString(addr).c_str(), ban); banned[info.ip] = ban + now; ipToId.erase(info.ip); goodId.erase(id); @@ -118,7 +117,7 @@ } else { if (/*!info.IsGood() && */ goodId.count(id) == 1) { goodId.erase(id); - // printf("%s: not good; %i good nodes left\n", + // fprintf(stdout, "%s: not good; %i good nodes left\n", // ToString(addr).c_str(), (int)goodId.size()); } ourId.push_back(id); @@ -131,7 +130,7 @@ if (id == -1) return; unkId.erase(id); ourId.push_back(id); - // printf("%s: skipped\n", ToString(addr).c_str()); + // fprintf(stdout, "%s: skipped\n", ToString(addr).c_str()); nDirty++; } @@ -153,7 +152,7 @@ if (addr.nTime > ai.lastTry || ai.services != addr.nServices) { ai.lastTry = addr.nTime; ai.services |= addr.nServices; - // printf("%s: updated\n", ToString(addr).c_str()); + // fprintf(stdout, "%s: updated\n", ToString(addr).c_str()); } if (force) { ai.ignoreTill = 0; @@ -171,7 +170,7 @@ int id = nId++; idToInfo[id] = ai; ipToId[ipp] = id; - // printf("%s: added\n", ToString(ipp).c_str(), ipToId[ipp]); + // fprintf(stdout, "%s: added\n", ToString(ipp).c_str(), ipToId[ipp]); unkId.insert(id); nDirty++; } diff --git a/src/seeder/dns.cpp b/src/seeder/dns.cpp --- a/src/seeder/dns.cpp +++ b/src/seeder/dns.cpp @@ -327,14 +327,14 @@ outbuf[3] &= ~15; // check qr if (inbuf[2] & 128) { - /* printf("Got response?\n"); */ + /* fprintf(stdout, "Got response?\n"); */ error = 1; goto error; } // check opcode if (((inbuf[2] & 120) >> 3) != 0) { - /* printf("Opcode nonzero?\n"); */ + /* fprintf(stdout, "Opcode nonzero?\n"); */ error = 4; goto error; } @@ -346,13 +346,13 @@ // check questions nquestion = (inbuf[4] << 8) + inbuf[5]; if (nquestion == 0) { - /* printf("No questions?\n"); */ + /* fprintf(stdout, "No questions?\n"); */ error = 0; goto error; } if (nquestion > 1) { - /* printf("Multiple questions %i?\n", nquestion); */ + /* fprintf(stdout, "Multiple questions %i?\n", nquestion); */ error = 4; goto error; } @@ -407,8 +407,8 @@ uint8_t *outpos = outbuf + (inpos - inbuf); uint8_t *outend = outbuf + BUFLEN; - // printf("DNS: Request host='%s' type=%i class=%i\n", name, typ, - // cls); + // fprintf(stdout, "DNS: Request host='%s' type=%i class=%i\n", name, + // typ, cls); // calculate max size of authority section @@ -425,7 +425,7 @@ 2592000, 604800); if (max_auth_size < newpos - outpos) max_auth_size = newpos - outpos; - // printf("Authority section will claim %i bytes max\n", + // fprintf(stdout, "Authority section will claim %i bytes max\n", // max_auth_size); } @@ -436,7 +436,7 @@ (cls == CLASS_IN || cls == QCLASS_ANY)) { int ret2 = write_record_ns(&outpos, outend - max_auth_size, "", offset, CLASS_IN, opt->nsttl, opt->ns); - // printf("wrote NS record: %i\n", ret2); + // fprintf(stdout, "wrote NS record: %i\n", ret2); if (!ret2) { outbuf[7]++; have_ns++; @@ -450,7 +450,7 @@ write_record_soa(&outpos, outend - max_auth_size, "", offset, CLASS_IN, opt->nsttl, opt->ns, opt->mbox, time(NULL), 604800, 86400, 2592000, 604800); - // printf("wrote SOA record: %i\n", ret2); + // fprintf(stdout, "wrote SOA record: %i\n", ret2); if (!ret2) { outbuf[7]++; } @@ -476,7 +476,7 @@ opt->datattl, &addr[n]); } - // printf("wrote A record: %i\n", mustbreak); + // fprintf(stdout, "wrote A record: %i\n", mustbreak); if (mustbreak) { break; } @@ -490,7 +490,7 @@ if (!have_ns && outbuf[7]) { int ret2 = write_record_ns(&outpos, outend, "", offset, CLASS_IN, opt->nsttl, opt->ns); - // printf("wrote NS record: %i\n", ret2); + // fprintf(stdout, "wrote NS record: %i\n", ret2); if (!ret2) { outbuf[9]++; } @@ -502,7 +502,7 @@ int ret2 = write_record_soa( &outpos, outend, "", offset, CLASS_IN, opt->nsttl, opt->ns, opt->mbox, time(NULL), 604800, 86400, 2592000, 604800); - // printf("wrote SOA record: %i\n", ret2); + // fprintf(stdout, "wrote SOA record: %i\n", ret2); if (!ret2) { outbuf[9]++; } @@ -580,9 +580,9 @@ for (; 1; ++(opt->nRequests)) { ssize_t insize = recvmsg(listenSocket, &msg, 0); // uint8_t *addr = (uint8_t*)&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); + // fprintf(stdout, "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); if (insize <= 0) continue; ssize_t ret = dnshandle(opt, inbuf, insize, outbuf); diff --git a/src/seeder/main.cpp b/src/seeder/main.cpp --- a/src/seeder/main.cpp +++ b/src/seeder/main.cpp @@ -424,22 +424,23 @@ db.GetStats(stats); if (first) { first = false; - printf("\n\n\n\x1b[3A"); + fprintf(stdout, "\n\n\n\x1b[3A"); } else - printf("\x1b[2K\x1b[u"); - printf("\x1b[s"); + fprintf(stdout, "\x1b[2K\x1b[u"); + fprintf(stdout, "\x1b[s"); uint64_t requests = 0; uint64_t queries = 0; for (unsigned int i = 0; i < dnsThread.size(); i++) { requests += dnsThread[i]->dns_opt.nRequests; queries += dnsThread[i]->dbQueries; } - printf("%s %i/%i available (%i tried in %is, %i new, %i active), %i " - "banned; %llu DNS requests, %llu db queries\n", - c, stats.nGood, stats.nAvail, stats.nTracked, stats.nAge, - stats.nNew, stats.nAvail - stats.nTracked - stats.nNew, - stats.nBanned, (unsigned long long)requests, - (unsigned long long)queries); + fprintf(stdout, + "%s %i/%i available (%i tried in %is, %i new, %i active), %i " + "banned; %llu DNS requests, %llu db queries\n", + c, stats.nGood, stats.nAvail, stats.nTracked, stats.nAge, + stats.nNew, stats.nAvail - stats.nTracked - stats.nNew, + stats.nBanned, (unsigned long long)requests, + (unsigned long long)queries); Sleep(1000); } while (1); return nullptr; @@ -479,41 +480,42 @@ setbuf(stdout, nullptr); CDnsSeedOpts opts; opts.ParseCommandLine(argc, argv); - printf("Supporting whitelisted filters: "); + fprintf(stdout, "Supporting whitelisted filters: "); for (std::set::const_iterator it = opts.filter_whitelist.begin(); it != opts.filter_whitelist.end(); it++) { if (it != opts.filter_whitelist.begin()) { - printf(","); + fprintf(stdout, ","); } - printf("0x%lx", (unsigned long)*it); + fprintf(stdout, "0x%lx", (unsigned long)*it); } - printf("\n"); + fprintf(stdout, "\n"); if (opts.tor) { CService service(LookupNumeric(opts.tor, 9050)); if (service.IsValid()) { - printf("Using Tor proxy at %s\n", service.ToStringIPPort().c_str()); + fprintf(stdout, "Using Tor proxy at %s\n", + service.ToStringIPPort().c_str()); SetProxy(NET_ONION, proxyType(service)); } } if (opts.ipv4_proxy) { CService service(LookupNumeric(opts.ipv4_proxy, 9050)); if (service.IsValid()) { - printf("Using IPv4 proxy at %s\n", - service.ToStringIPPort().c_str()); + fprintf(stdout, "Using IPv4 proxy at %s\n", + service.ToStringIPPort().c_str()); SetProxy(NET_IPV4, proxyType(service)); } } if (opts.ipv6_proxy) { CService service(LookupNumeric(opts.ipv6_proxy, 9050)); if (service.IsValid()) { - printf("Using IPv6 proxy at %s\n", - service.ToStringIPPort().c_str()); + fprintf(stdout, "Using IPv6 proxy at %s\n", + service.ToStringIPPort().c_str()); SetProxy(NET_IPV6, proxyType(service)); } } bool fDNS = true; if (opts.fUseTestNet) { - printf("Using testnet.\n"); + fprintf(stdout, "Using testnet.\n"); netMagic[0] = 0xf4; netMagic[1] = 0xe5; netMagic[2] = 0xf3; @@ -522,7 +524,7 @@ fTestNet = true; } if (!opts.ns) { - printf("No nameserver set. Not starting DNS server.\n"); + fprintf(stdout, "No nameserver set. Not starting DNS server.\n"); fDNS = false; } if (fDNS && !opts.host) { @@ -535,30 +537,30 @@ } FILE *f = fsbridge::fopen("dnsseed.dat", "r"); if (f) { - printf("Loading dnsseed.dat..."); + fprintf(stdout, "Loading dnsseed.dat..."); CAutoFile cf(f, SER_DISK, CLIENT_VERSION); cf >> db; if (opts.fWipeBan) db.banned.clear(); if (opts.fWipeIgnore) db.ResetIgnores(); - printf("done\n"); + fprintf(stdout, "done\n"); } pthread_t threadDns, threadSeed, threadDump, threadStats; if (fDNS) { - printf("Starting %i DNS threads for %s on %s (port %i)...", - opts.nDnsThreads, opts.host, opts.ns, opts.nPort); + fprintf(stdout, "Starting %i DNS threads for %s on %s (port %i)...", + opts.nDnsThreads, opts.host, opts.ns, opts.nPort); dnsThread.clear(); for (int i = 0; i < opts.nDnsThreads; i++) { dnsThread.push_back(new CDnsThread(&opts, i)); pthread_create(&threadDns, nullptr, ThreadDNS, dnsThread[i]); - printf("."); + fprintf(stdout, "."); Sleep(20); } - printf("done\n"); + fprintf(stdout, "done\n"); } - printf("Starting seeder..."); + fprintf(stdout, "Starting seeder..."); pthread_create(&threadSeed, nullptr, ThreadSeeder, nullptr); - printf("done\n"); - printf("Starting %i crawler threads...", opts.nThreads); + fprintf(stdout, "done\n"); + fprintf(stdout, "Starting %i crawler threads...", opts.nThreads); pthread_attr_t attr_crawler; pthread_attr_init(&attr_crawler); pthread_attr_setstacksize(&attr_crawler, 0x20000); @@ -567,7 +569,7 @@ pthread_create(&thread, &attr_crawler, ThreadCrawler, &opts.nThreads); } pthread_attr_destroy(&attr_crawler); - printf("done\n"); + fprintf(stdout, "done\n"); pthread_create(&threadStats, nullptr, ThreadStats, nullptr); pthread_create(&threadDump, nullptr, ThreadDumper, nullptr); void *res;