diff options
author | Matt Corallo <git@bluematt.me> | 2017-02-06 12:08:31 -0500 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2017-02-10 11:32:41 -0500 |
commit | 22b4966a29501c4f3f2e970ac5008fbd91e665a9 (patch) | |
tree | 2beb02b98598c74d44f4471bf157405804b7c321 | |
parent | 0f3187261519c7568ef4211ce12b9740a3c1200f (diff) |
Move [clean|str]SubVer writes/copyStats into a lock
-rw-r--r-- | src/net.cpp | 5 | ||||
-rw-r--r-- | src/net.h | 1 | ||||
-rw-r--r-- | src/net_processing.cpp | 11 |
3 files changed, 13 insertions, 4 deletions
diff --git a/src/net.cpp b/src/net.cpp index ea8a2a0a4a..e7521f86d1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -610,7 +610,10 @@ void CNode::copyStats(CNodeStats &stats) X(nTimeOffset); X(addrName); X(nVersion); - X(cleanSubVer); + { + LOCK(cs_SubVer); + X(cleanSubVer); + } X(fInbound); X(fAddnode); X(nStartingHeight); @@ -598,6 +598,7 @@ public: // store the sanitized version in cleanSubVer. The original should be used when dealing with // the network or wire types and the cleaned string used when displayed or logged. std::string strSubVer, cleanSubVer; + CCriticalSection cs_SubVer; // used for both cleanSubVer and strSubVer bool fWhitelisted; // This peer can bypass DoS banning. bool fFeeler; // If true this node is being used as a short lived feeler. bool fOneShot; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index e89a897bd5..b5feac2d59 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1211,6 +1211,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr int nVersion; int nSendVersion; std::string strSubVer; + std::string cleanSubVer; int nStartingHeight = -1; bool fRelay = true; @@ -1246,6 +1247,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr vRecv >> addrFrom >> nNonce; if (!vRecv.empty()) { vRecv >> LIMITED_STRING(strSubVer, MAX_SUBVERSION_LENGTH); + cleanSubVer = SanitizeString(strSubVer); } if (!vRecv.empty()) { vRecv >> nStartingHeight; @@ -1273,8 +1275,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr pfrom->nServices = nServices; pfrom->addrLocal = addrMe; - pfrom->strSubVer = strSubVer; - pfrom->cleanSubVer = SanitizeString(strSubVer); + { + LOCK(pfrom->cs_SubVer); + pfrom->strSubVer = strSubVer; + pfrom->cleanSubVer = cleanSubVer; + } pfrom->nStartingHeight = nStartingHeight; pfrom->fClient = !(nServices & NODE_NETWORK); { @@ -1330,7 +1335,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr remoteAddr = ", peeraddr=" + pfrom->addr.ToString(); LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, peer=%d%s\n", - pfrom->cleanSubVer, pfrom->nVersion, + cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), pfrom->id, remoteAddr); |