From 2bc6cecebba52e32db43a0b2d9b519ac4a48c479 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 21 Nov 2011 12:25:00 -0500 Subject: [PATCH] Move DNS Seed lookup to a new thread. --- src/init.cpp | 5 ----- src/net.cpp | 39 ++++++++++++++++++++++++++++++++++++++- src/net.h | 1 - 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index a6d0ab56e3e..ee31ff9485e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -476,11 +476,6 @@ bool AppInit2(int argc, char* argv[]) } } - if (GetBoolArg("-nodnsseed")) - printf("DNS seeding disabled\n"); - else - DNSAddressSeed(); - if (mapArgs.count("-paytxfee")) { if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee)) diff --git a/src/net.cpp b/src/net.cpp index 0c28eaa379a..199fb407f2e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -32,6 +32,7 @@ void ThreadOpenConnections2(void* parg); #ifdef USE_UPNP void ThreadMapPort2(void* parg); #endif +void ThreadDNSAddressSeed2(void* parg); bool OpenNetworkConnection(const CAddress& addrConnect); @@ -1213,8 +1214,28 @@ static const char *strDNSSeed[] = { "dnsseed.bluematt.me", }; -void DNSAddressSeed() +void ThreadDNSAddressSeed(void* parg) { + IMPLEMENT_RANDOMIZE_STACK(ThreadDNSAddressSeed(parg)); + try + { + vnThreadsRunning[6]++; + ThreadDNSAddressSeed2(parg); + vnThreadsRunning[6]--; + } + catch (std::exception& e) { + vnThreadsRunning[6]--; + PrintException(&e, "ThreadDNSAddressSeed()"); + } catch (...) { + vnThreadsRunning[6]--; + throw; // support pthread_cancel() + } + printf("ThreadDNSAddressSeed exiting\n"); +} + +void ThreadDNSAddressSeed2(void* parg) +{ + printf("ThreadDNSAddressSeed started\n"); int found = 0; if (!fTestNet) @@ -1247,6 +1268,15 @@ void DNSAddressSeed() + + + + + + + + + unsigned int pnSeed[] = { 0x6884ac63, 0x3ffecead, 0x2919b953, 0x0942fe50, 0x7a1d922e, 0xcdd6734a, 0x953a5bb6, 0x2c46922e, @@ -1757,6 +1787,12 @@ void StartNode(void* parg) // Start threads // + if (GetBoolArg("-nodnsseed")) + printf("DNS seeding disabled\n"); + else + if (!CreateThread(ThreadDNSAddressSeed, NULL)) + printf("Error: CreateThread(ThreadDNSAddressSeed) failed\n"); + // Map ports with UPnP if (fHaveUPnP) MapPort(fUseUPnP); @@ -1803,6 +1839,7 @@ bool StopNode() if (vnThreadsRunning[3] > 0) printf("ThreadBitcoinMiner still running\n"); if (vnThreadsRunning[4] > 0) printf("ThreadRPCServer still running\n"); if (fHaveUPnP && vnThreadsRunning[5] > 0) printf("ThreadMapPort still running\n"); + if (vnThreadsRunning[6] > 0) printf("ThreadDNSAddressSeed still running\n"); while (vnThreadsRunning[2] > 0 || vnThreadsRunning[4] > 0) Sleep(20); Sleep(50); diff --git a/src/net.h b/src/net.h index d8472689990..03da382df36 100644 --- a/src/net.h +++ b/src/net.h @@ -40,7 +40,6 @@ CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0); void AbandonRequests(void (*fn)(void*, CDataStream&), void* param1); bool AnySubscribed(unsigned int nChannel); void MapPort(bool fMapPort); -void DNSAddressSeed(); bool BindListenPort(std::string& strError=REF(std::string())); void StartNode(void* parg); bool StopNode();