diff --git a/src/seeder/bitcoin.cpp b/src/seeder/bitcoin.cpp --- a/src/seeder/bitcoin.cpp +++ b/src/seeder/bitcoin.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -58,9 +59,9 @@ // nVersion); if (vAddr) { MessageWriter::WriteMessage(vSend, NetMsgType::GETADDR); - doneAfter = time(nullptr) + GetTimeout(); + doneAfter = GetTime() + GetTimeout(); } else { - doneAfter = time(nullptr) + 1; + doneAfter = GetTime() + 1; } return PeerMessagingState::AwaitingMessages; } @@ -71,7 +72,7 @@ // tfm::format(std::cout, "%s: got %i addresses\n", // ToString(you), // (int)vAddrNew.size()); - int64_t now = time(nullptr); + int64_t now = GetTime(); std::vector::iterator it = vAddrNew.begin(); if (vAddrNew.size() > 1) { if (doneAfter == 0 || doneAfter > now + 1) { @@ -169,7 +170,7 @@ : sock(INVALID_SOCKET), vSend(SER_NETWORK, 0), vRecv(SER_NETWORK, 0), nHeaderStart(-1), nMessageStart(-1), nVersion(0), vAddr(vAddrIn), ban(0), doneAfter(0), you(ip, ServiceFlags(NODE_NETWORK)) { - if (time(nullptr) > 1329696000) { + if (GetTime() > 1329696000) { vSend.SetVersion(209); vRecv.SetVersion(209); } @@ -211,22 +212,21 @@ return false; } - // Push version; + // Write version message uint64_t nLocalServices = 0; uint64_t nLocalNonce = BITCOIN_SEED_NONCE; CService myService; CAddress me(myService, ServiceFlags(NODE_NETWORK)); std::string ver = "/bitcoin-cash-seeder:0.15/"; MessageWriter::WriteMessage(vSend, NetMsgType::VERSION, PROTOCOL_VERSION, - nLocalServices, time(nullptr), you, me, - nLocalNonce, ver, GetRequireHeight()); + nLocalServices, GetTime(), you, me, nLocalNonce, + ver, GetRequireHeight()); Send(); bool res = true; int64_t now; - while (now = time(nullptr), ban == 0 && - (doneAfter == 0 || doneAfter > now) && - sock != INVALID_SOCKET) { + while (now = GetTime(), ban == 0 && (doneAfter == 0 || doneAfter > now) && + sock != INVALID_SOCKET) { char pchBuf[0x10000]; fd_set fdsetRecv; fd_set fdsetError; diff --git a/src/seeder/db.h b/src/seeder/db.h --- a/src/seeder/db.h +++ b/src/seeder/db.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -323,7 +324,7 @@ stats.nGood = goodId.size(); stats.nNew = unkId.size(); if (ourId.size() > 0) { - stats.nAge = time(nullptr) - idToInfo.at(ourId.at(0)).ourLastTry; + stats.nAge = GetTime() - idToInfo.at(ourId.at(0)).ourLastTry; } else { stats.nAge = 0; } diff --git a/src/seeder/db.cpp b/src/seeder/db.cpp --- a/src/seeder/db.cpp +++ b/src/seeder/db.cpp @@ -4,10 +4,12 @@ #include +#include + #include void SeederAddrInfo::Update(bool good) { - int64_t now = time(nullptr); + int64_t now = GetTime(); if (ourLastTry == 0) { ourLastTry = now - MIN_RETRY; } @@ -40,7 +42,7 @@ } bool CAddrDb::Get_(CServiceResult &ip, int &wait) { - int64_t now = time(nullptr); + int64_t now = GetTime(); size_t tot = unkId.size() + ourId.size(); if (tot == 0) { wait = 5; @@ -57,7 +59,7 @@ unkId.erase(it); } else { ret = ourId.front(); - if (time(nullptr) - idToInfo[ret].ourLastTry < MIN_RETRY) { + if (GetTime() - idToInfo[ret].ourLastTry < MIN_RETRY) { return false; } ourId.pop_front(); @@ -114,7 +116,7 @@ unkId.erase(id); SeederAddrInfo &info = idToInfo[id]; info.Update(false); - uint32_t now = time(nullptr); + uint32_t now = GetTime(); int ter = info.GetBanTime(); if (ter) { // tfm::format(std::cout, "%s: terrible\n", ToString(addr)); diff --git a/src/seeder/dns.cpp b/src/seeder/dns.cpp --- a/src/seeder/dns.cpp +++ b/src/seeder/dns.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -480,7 +481,7 @@ newpos = outpos; write_record_soa(&newpos, outend, "", offset, CLASS_IN, opt->nsttl, - opt->ns, opt->mbox, time(NULL), 604800, 86400, + opt->ns, opt->mbox, GetTime(), 604800, 86400, 2592000, 604800); if (max_auth_size < newpos - outpos) { max_auth_size = newpos - outpos; @@ -509,7 +510,7 @@ int ret2 = write_record_soa(&outpos, outend - max_auth_size, "", offset, CLASS_IN, opt->nsttl, opt->ns, opt->mbox, - time(NULL), 604800, 86400, 2592000, 604800); + GetTime(), 604800, 86400, 2592000, 604800); // tfm::format(std::cout, "wrote SOA record: %i\n", ret2); if (!ret2) { outbuf[7]++; @@ -562,7 +563,7 @@ // resolver should try next. int ret2 = write_record_soa( &outpos, outend, "", offset, CLASS_IN, opt->nsttl, opt->ns, - opt->mbox, time(NULL), 604800, 86400, 2592000, 604800); + opt->mbox, GetTime(), 604800, 86400, 2592000, 604800); // tfm::format(std::cout, "wrote SOA record: %i\n", ret2); if (!ret2) { outbuf[9]++; diff --git a/src/seeder/main.cpp b/src/seeder/main.cpp --- a/src/seeder/main.cpp +++ b/src/seeder/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -173,7 +174,7 @@ std::vector ips; int wait = 5; db.GetMany(ips, 16, wait); - int64_t now = time(nullptr); + int64_t now = GetTime(); if (ips.empty()) { wait *= 1000; wait += rand() % (500 * *nThreads); @@ -241,7 +242,7 @@ nets[NET_IPV4] = true; nets[NET_IPV6] = true; } - time_t now = time(nullptr); + int64_t now = GetTime(); FlagSpecificData &thisflag = perflag[requestedFlags]; thisflag.cacheHits++; if (force || @@ -413,9 +414,8 @@ stat[4] += rep.uptime[4]; } fsbridge::ofstream ff{"dnsstats.log", std::ios_base::app}; - tfm::format(ff, "%llu %g %g %g %g %g\n", - (unsigned long long)(time(nullptr)), stat[0], stat[1], - stat[2], stat[3], stat[4]); + tfm::format(ff, "%llu %g %g %g %g %g\n", GetTime(), stat[0], + stat[1], stat[2], stat[3], stat[4]); } } while (1); return nullptr; diff --git a/src/seeder/test/message_writer_tests.cpp b/src/seeder/test/message_writer_tests.cpp --- a/src/seeder/test/message_writer_tests.cpp +++ b/src/seeder/test/message_writer_tests.cpp @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(simple_header_and_payload_message_writer_test) { SelectParams(CBaseChainParams::MAIN); - uint64_t now = time(nullptr); + int64_t now = GetTime(); uint64_t nonce = 0; uint64_t serviceFlags = uint64_t(ServiceFlags(NODE_NETWORK)); CService service; diff --git a/src/seeder/test/p2p_messaging_tests.cpp b/src/seeder/test/p2p_messaging_tests.cpp --- a/src/seeder/test/p2p_messaging_tests.cpp +++ b/src/seeder/test/p2p_messaging_tests.cpp @@ -75,9 +75,8 @@ CService serviceFrom; CAddress addrFrom(serviceFrom, ServiceFlags(NODE_NETWORK)); - CDataStream versionMessage = - CreateVersionMessage(time(nullptr), vAddr[0], addrFrom, - GetRequireHeight(), INIT_PROTO_VERSION); + CDataStream versionMessage = CreateVersionMessage( + GetTime(), vAddr[0], addrFrom, GetRequireHeight(), INIT_PROTO_VERSION); // Verify the version is set as the initial value BOOST_CHECK_EQUAL(testNode->CSeederNode::GetClientVersion(),