diff options
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 54 |
1 files changed, 19 insertions, 35 deletions
diff --git a/src/net.cpp b/src/net.cpp index 9193e873e7..d510709082 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -47,7 +47,8 @@ struct LocalServiceInfo { // Global state variables // bool fClient = false; -static bool fUseUPnP = false; +bool fDiscover = true; +bool fUseUPnP = false; uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK); static CCriticalSection cs_mapLocalHost; static map<CNetAddr, LocalServiceInfo> mapLocalHost; @@ -99,7 +100,7 @@ void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd) // find 'best' local address for a particular peer bool GetLocal(CService& addr, const CNetAddr *paddrPeer) { - if (fUseProxy || mapArgs.count("-connect") || fNoListen) + if (fNoListen) return false; int nBestScore = -1; @@ -211,7 +212,7 @@ bool AddLocal(const CService& addr, int nScore) if (!addr.IsRoutable()) return false; - if (!GetBoolArg("-discover", true) && nScore < LOCAL_MANUAL) + if (!fDiscover && nScore < LOCAL_MANUAL) return false; if (IsLimited(addr)) @@ -345,9 +346,6 @@ bool GetMyExternalIP(CNetAddr& ipRet) const char* pszGet; const char* pszKeyword; - if (fNoListen||fUseProxy) - return false; - for (int nLookup = 0; nLookup <= 1; nLookup++) for (int nHost = 1; nHost <= 2; nHost++) { @@ -542,7 +540,7 @@ void CNode::PushVersion() { /// when NTP implemented, change to just nTime = GetAdjustedTime() int64 nTime = (fInbound ? GetAdjustedTime() : GetTime()); - CAddress addrYou = (fUseProxy ? CAddress(CService("0.0.0.0",0)) : addr); + CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0",0))); CAddress addrMe = GetLocalAddress(&addr); RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, @@ -1016,7 +1014,7 @@ void ThreadMapPort2(void* parg) r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)); if (r == 1) { - if (GetBoolArg("-discover", true)) { + if (fDiscover) { char externalIPAddress[40]; r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress); if(r != UPNPCOMMAND_SUCCESS) @@ -1093,12 +1091,8 @@ void ThreadMapPort2(void* parg) } } -void MapPort(bool fMapPort) +void MapPort() { - if (fUseUPnP != fMapPort) - { - fUseUPnP = fMapPort; - } if (fUseUPnP && vnThreadsRunning[THREAD_UPNP] < 1) { if (!CreateThread(ThreadMapPort, NULL)) @@ -1106,7 +1100,7 @@ void MapPort(bool fMapPort) } } #else -void MapPort(bool /* unused fMapPort */) +void MapPort() { // Intentionally left blank. } @@ -1160,7 +1154,7 @@ void ThreadDNSAddressSeed2(void* parg) printf("Loading addresses from DNS seeds (could take a while)\n"); for (unsigned int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) { - if (fProxyNameLookup) { + if (GetNameProxy()) { AddOneShot(strDNSSeed[seed_idx][1]); } else { vector<CNetAddr> vaddr; @@ -1394,8 +1388,7 @@ void ThreadOpenConnections2(void* parg) return; // Add seed nodes if IRC isn't working - bool fTOR = (fUseProxy && addrProxy.GetPort() == 9050); - if (addrman.size()==0 && (GetTime() - nStart > 60 || fTOR) && !fTestNet) + if (addrman.size()==0 && (GetTime() - nStart > 60) && !fTestNet) { std::vector<CAddress> vAdd; for (unsigned int i = 0; i < ARRAYLEN(pnSeed); i++) @@ -1492,7 +1485,7 @@ void ThreadOpenAddedConnections2(void* parg) if (mapArgs.count("-addnode") == 0) return; - if (fProxyNameLookup) { + if (GetNameProxy()) { while(!fShutdown) { BOOST_FOREACH(string& strAddNode, mapMultiArgs["-addnode"]) { CAddress addr; @@ -1778,7 +1771,7 @@ bool BindListenPort(const CService &addrBind, string& strError) vhListenSocket.push_back(hListenSocket); - if (addrBind.IsRoutable() && GetBoolArg("-discover", true)) + if (addrBind.IsRoutable() && fDiscover) AddLocal(addrBind, LOCAL_BIND); return true; @@ -1786,7 +1779,7 @@ bool BindListenPort(const CService &addrBind, string& strError) void static Discover() { - if (!GetBoolArg("-discover", true)) + if (!fDiscover) return; #ifdef WIN32 @@ -1835,22 +1828,11 @@ void static Discover() } #endif - if (!fUseProxy && !mapArgs.count("-connect") && !fNoListen) - { - CreateThread(ThreadGetMyExternalIP, NULL); - } + CreateThread(ThreadGetMyExternalIP, NULL); } void StartNode(void* parg) { -#ifdef USE_UPNP -#if USE_UPNP - fUseUPnP = GetBoolArg("-upnp", true); -#else - fUseUPnP = GetBoolArg("-upnp", false); -#endif -#endif - if (semOutbound == NULL) { // initialize semaphore int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, (int)GetArg("-maxconnections", 125)); @@ -1873,8 +1855,8 @@ void StartNode(void* parg) printf("Error: CreateThread(ThreadDNSAddressSeed) failed\n"); // Map ports with UPnP - if (fHaveUPnP) - MapPort(fUseUPnP); + if (fUseUPnP) + MapPort(); // Get addresses from IRC and advertise ours if (!CreateThread(ThreadIRCSeed, NULL)) @@ -1930,7 +1912,9 @@ bool StopNode() if (vnThreadsRunning[THREAD_MINER] > 0) printf("ThreadBitcoinMiner still running\n"); if (vnThreadsRunning[THREAD_RPCLISTENER] > 0) printf("ThreadRPCListener still running\n"); if (vnThreadsRunning[THREAD_RPCHANDLER] > 0) printf("ThreadsRPCServer still running\n"); - if (fHaveUPnP && vnThreadsRunning[THREAD_UPNP] > 0) printf("ThreadMapPort still running\n"); +#ifdef USE_UPNP + if (vnThreadsRunning[THREAD_UPNP] > 0) printf("ThreadMapPort still running\n"); +#endif if (vnThreadsRunning[THREAD_DNSSEED] > 0) printf("ThreadDNSAddressSeed still running\n"); if (vnThreadsRunning[THREAD_ADDEDCONNECTIONS] > 0) printf("ThreadOpenAddedConnections still running\n"); if (vnThreadsRunning[THREAD_DUMPADDRESS] > 0) printf("ThreadDumpAddresses still running\n"); |