diff --git a/src/httpserver.cpp b/src/httpserver.cpp index febfee5f5..3eb5b1042 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -38,9 +38,6 @@ /** Maximum size of http request (request line + headers) */ static const size_t MAX_HEADERS_SIZE = 8192; -/** Maximum size of http request (request line + headers) */ -static const size_t MAX_HEADERS_SIZE = 8192; - /** HTTP request work item */ class HTTPWorkItem : public HTTPClosure { diff --git a/src/init.cpp b/src/init.cpp index cf5ee4f40..88e6c1abb 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -759,11 +759,6 @@ static std::string ResolveErrMsg(const char * const optname, const std::string& return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind); } -static std::string AmountErrMsg(const char * const optname, const std::string& strValue) -{ - return strprintf(_("Invalid amount for -%s=: '%s'"), optname, strValue); -} - void InitLogging() { fPrintToConsole = GetBoolArg("-printtoconsole", false); diff --git a/src/net.cpp b/src/net.cpp index 86e6e72f2..b1ece59cd 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -636,6 +636,7 @@ void CNode::SweepBanned() banmap_t::iterator it = setBanned.begin(); while(it != setBanned.end()) { + CSubNet subNet = (*it).first; CBanEntry banEntry = (*it).second; if(now > banEntry.nBanUntil) { diff --git a/src/netbase.cpp b/src/netbase.cpp index 5b8a2ee6d..4f243ec6f 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -658,51 +658,32 @@ bool LookupSubNet(const char* pszName, CSubNet& ret) std::string strAddress = strSubnet.substr(0, slash); if (LookupHost(strAddress.c_str(), vIP, 1, false)) { - network = vIP[0]; + CNetAddr network = vIP[0]; if (slash != strSubnet.npos) { std::string strNetmask = strSubnet.substr(slash + 1); int32_t n; // IPv4 addresses start at offset 12, and first 12 bytes must match, so just offset n - const int astartofs = network.IsIPv4() ? 12 : 0; - if (ParseInt32(strNetmask, &n)) // If valid number, assume /24 symtex - { - if(n >= 0 && n <= (128 - astartofs*8)) // Only valid if in range of bits of address - { - n += astartofs*8; - // Clear bits [n..127] - for (; n < 128; ++n) - netmask[n>>3] &= ~(1<<(7-(n&7))); - } - else - { - valid = false; - } + if (ParseInt32(strNetmask, &n)) { // If valid number, assume /24 syntax + ret = CSubNet(network, n); + return ret.IsValid(); } else // If not a valid number, try full netmask syntax { - if (LookupHost(strNetmask.c_str(), vIP, 1, false)) // Never allow lookup for netmask - { - // Copy only the *last* four bytes in case of IPv4, the rest of the mask should stay 1's as - // we don't want pchIPv4 to be part of the mask. - for(int x=astartofs; x<16; ++x) - netmask[x] = vIP[0].ip[x]; - } - else - { - valid = false; + // Never allow lookup for netmask + if (LookupHost(strNetmask.c_str(), vIP, 1, false)) { + ret = CSubNet(network, vIP[0]); + return ret.IsValid(); } } } + else + { + ret = CSubNet(network); + return ret.IsValid(); + } } - else - { - valid = false; - } - - // Normalize network according to netmask - for(int x=0; x<16; ++x) - network.ip[x] &= netmask[x]; + return false; } #ifdef WIN32 diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index 3884bf3fe..a5417a28d 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -5,6 +5,7 @@ #include "blockencodings.h" #include "consensus/merkle.h" #include "chainparams.h" +#include "pow.h" #include "random.h" #include "test/test_bitcoin.h" diff --git a/src/util.h b/src/util.h index 477dcf46f..04de93846 100644 --- a/src/util.h +++ b/src/util.h @@ -28,6 +28,12 @@ #include #include +#ifndef WIN32 +#include +#include +#include +#endif + // Application startup time (used for uptime calculation) int64_t GetStartupTime(); @@ -219,6 +225,30 @@ std::string HelpMessageOpt(const std::string& option, const std::string& message */ int GetNumCores(); +#ifdef WIN32 +inline void SetThreadPriority(int nPriority) +{ + SetThreadPriority(GetCurrentThread(), nPriority); +} +#else + +#define THREAD_PRIORITY_LOWEST PRIO_MAX +#define THREAD_PRIORITY_BELOW_NORMAL 2 +#define THREAD_PRIORITY_NORMAL 0 +#define THREAD_PRIORITY_ABOVE_NORMAL 0 + +inline void SetThreadPriority(int nPriority) +{ + // It's unclear if it's even possible to change thread priorities on Linux, + // but we really and truly need it for the generation threads. +#ifdef PRIO_THREAD + setpriority(PRIO_THREAD, 0, nPriority); +#else + setpriority(PRIO_PROCESS, 0, nPriority); +#endif +} +#endif + void RenameThread(const char* name); /**