diff options
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/util.cpp b/src/util.cpp index 71994587cf..539e759ddd 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -73,7 +73,6 @@ using namespace std; map<string, string> mapArgs; map<string, vector<string> > mapMultiArgs; bool fDebug = false; -bool fDebugNet = false; bool fPrintToConsole = false; bool fPrintToDebugger = false; bool fDaemon = false; @@ -81,7 +80,6 @@ bool fServer = false; string strMiscWarning; bool fNoListen = false; bool fLogTimestamps = false; -CMedianFilter<int64> vTimeOffsets(200,0); volatile bool fReopenDebugLog = false; // Init OpenSSL library multithreading support @@ -226,10 +224,20 @@ int LogPrint(const char* category, const char* pszFormat, ...) { if (category != NULL) { - if (!fDebug) return 0; - const vector<string>& categories = mapMultiArgs["-debug"]; - if (find(categories.begin(), categories.end(), string(category)) == categories.end()) + if (!fDebug) return 0; + + const vector<string>& categories = mapMultiArgs["-debug"]; + bool allCategories = count(categories.begin(), categories.end(), string("")); + + // Only look for categories, if not -debug/-debug=1 was passed, + // as that implies every category should be logged. + if (!allCategories) + { + // Category was not found (not supplied via -debug=<category>) + if (find(categories.begin(), categories.end(), string(category)) == categories.end()) + return 0; + } } int ret = 0; // Returns total number of characters written @@ -452,7 +460,7 @@ bool ParseMoney(const char* pszIn, int64& nRet) } -static const signed char phexdigit[256] = +const signed char p_util_hexdigit[256] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, @@ -472,9 +480,9 @@ static const signed char phexdigit[256] = bool IsHex(const string& str) { - BOOST_FOREACH(unsigned char c, str) + BOOST_FOREACH(char c, str) { - if (phexdigit[c] < 0) + if (HexDigit(c) < 0) return false; } return (str.size() > 0) && (str.size()%2 == 0); @@ -488,11 +496,11 @@ vector<unsigned char> ParseHex(const char* psz) { while (isspace(*psz)) psz++; - signed char c = phexdigit[(unsigned char)*psz++]; + signed char c = HexDigit(*psz++); if (c == (signed char)-1) break; unsigned char n = (c << 4); - c = phexdigit[(unsigned char)*psz++]; + c = HexDigit(*psz++); if (c == (signed char)-1) break; n |= c; @@ -1296,10 +1304,12 @@ void SetMockTime(int64 nMockTimeIn) nMockTime = nMockTimeIn; } +static CCriticalSection cs_nTimeOffset; static int64 nTimeOffset = 0; int64 GetTimeOffset() { + LOCK(cs_nTimeOffset); return nTimeOffset; } @@ -1312,12 +1322,14 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) { int64 nOffsetSample = nTime - GetTime(); + LOCK(cs_nTimeOffset); // Ignore duplicates static set<CNetAddr> setKnown; if (!setKnown.insert(ip).second) return; // Add data + static CMedianFilter<int64> vTimeOffsets(200,0); vTimeOffsets.input(nOffsetSample); LogPrintf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) |