Skip to content

Commit e791b27

Browse files
committed
[DHT] Fix Dynode put checks before saving hash table records fragments
1 parent b66f201 commit e791b27

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/dht/limits.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,35 @@ bool CheckSalt(const std::string& strSalt, const unsigned int nHeight, std::stri
4545
std::vector<std::string> vSplit;
4646
boost::split(vSplit, strSalt, boost::is_any_of(":"));
4747
if (vSplit.size() != 2) {
48-
strErrorMessage = strprintf("Invalid salt (%s). Could not find ':' delimiter", strSalt);
48+
strErrorMessage = strprintf("Invalid salt (%s). Could not find ':' delimiter\n", strSalt);
4949
return false;
5050
}
5151
uint32_t nSlots;
52-
if (ParseUInt32(vSplit[1], &nSlots)) {
53-
strErrorMessage = strprintf("Invalid salt (%s). Could not parse slot number after :", strSalt);
52+
if (!ParseUInt32(vSplit[1], &nSlots)) {
53+
strErrorMessage = strprintf("Invalid salt (%s). Could not parse slot number after : %s\n", strSalt, vSplit[1]);
5454
return false;
5555
}
5656
std::multimap<std::string, CAllowDataCode>::iterator iAllowed = mapAllowedData.find(vSplit[0]);
5757
while (iAllowed != mapAllowedData.end()) {
58-
if (nHeight > iAllowed->second.nStartHeight) {
59-
strErrorMessage = strprintf("%s, Allow data type found but height is greater than allowed data start height %d. ", strErrorMessage, iAllowed->second.nStartHeight);
58+
if (iAllowed->second.nStartHeight > nHeight) {
59+
strErrorMessage = strprintf("%sAllow data type found but height (%d) is greater than allowed data start height %d.\n", strErrorMessage, nHeight, iAllowed->second.nStartHeight);
6060
iAllowed++;
6161
continue;
6262
}
63-
if (iAllowed->second.nExpireTime >= nHeight && iAllowed->second.nExpireTime != 0) {
64-
strErrorMessage = strprintf("%s, Allow data type found but expired %d. ", strErrorMessage, iAllowed->second.nExpireTime);
63+
if (nHeight > iAllowed->second.nExpireTime && iAllowed->second.nExpireTime != 0) {
64+
strErrorMessage = strprintf("%sAllow data type found but expired %d.\n", strErrorMessage, iAllowed->second.nExpireTime);
6565
iAllowed++;
6666
continue;
6767
}
68-
if (nSlots <= iAllowed->second.nMaximumSlots) {
69-
strErrorMessage = strprintf("%s, Allow data type found but too many slots (%d) used. Max slots = %d", strErrorMessage, nSlots, iAllowed->second.nMaximumSlots);
68+
if (nSlots > iAllowed->second.nMaximumSlots) {
69+
strErrorMessage = strprintf("%sAllow data type found but too many slots (%d) used. Max slots = %d\n", strErrorMessage, nSlots, iAllowed->second.nMaximumSlots);
7070
iAllowed++;
7171
continue;
7272
}
73-
// Passes all checks so it is a valid data record salt.
73+
LogPrintf("%s -- Salt %s passed all checks. Valid data record salt\n", __func__, strSalt);
7474
return true;
7575
}
76-
strErrorMessage = strprintf("%s, Invalid salt. Allow data type salt not found in allowed data map.", strErrorMessage);
76+
strErrorMessage = strprintf("%sInvalid salt (%s). Allow data type salt not found in allowed data map.", strErrorMessage, vSplit[0]);
7777
return false;
7878
}
7979

src/dht/storage.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ void CDHTStorage::put_mutable_item(sha1_hash const& target
172172
CharString vchPublicKey = vchFromString(strPublicKey);
173173
if (!CheckPubKey(vchPublicKey)) {
174174
LogPrintf("%s -- Invalid pubkey used (%s). DHT put storage request failed.\n", __func__, strPublicKey);
175+
return;
175176
}
176177
std::unique_ptr<char[]> saltValue;
177178
ExtractValueFromSpan(saltValue, salt);
@@ -180,7 +181,8 @@ void CDHTStorage::put_mutable_item(sha1_hash const& target
180181
std::string strErrorMessage;
181182
unsigned int nHeight = (unsigned int)chainActive.Height();
182183
if (!CheckSalt(strSalt, nHeight, strErrorMessage)) {
183-
LogPrintf("%s -- Invalid salt used (%s) at height %d. DHT put storage request failed.\n", __func__, strSalt, nHeight);
184+
LogPrintf("%s -- Invalid salt used (%s) at height %d. DHT put storage request failed. %s\n", __func__, strSalt, nHeight, strErrorMessage);
185+
return;
184186
}
185187
CharString vchSalt = vchFromString(strSalt);
186188

0 commit comments

Comments
 (0)