Skip to content
Snippets Groups Projects
Commit b3f96830 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud
Browse files

securedht: avoid to update cache if not necessary

parent 6d1819ac
No related branches found
No related tags found
No related merge requests found
......@@ -625,6 +625,12 @@ struct OPENDHT_PUBLIC Value
*/
unsigned priority {0};
inline bool isSignatureChecked() const {
return signatureChecked;
}
inline bool isDecrypted() const {
return decrypted;
}
bool checkSignature();
Sp<Value> decrypt(const crypto::PrivateKey& key);
......
......@@ -238,8 +238,10 @@ SecureDht::checkValue(const Sp<Value>& v)
return {};
}
try {
auto isDecrypted = v->isDecrypted();
if (auto decrypted_val = v->decrypt(*key_)) {
if (decrypted_val->owner)
auto cacheValue = not isDecrypted and decrypted_val->owner;
if (cacheValue)
nodesPubKeys_[decrypted_val->owner->getId()] = decrypted_val->owner;
return decrypted_val;
}
......@@ -250,8 +252,9 @@ SecureDht::checkValue(const Sp<Value>& v)
}
// Check signed values
else if (v->isSigned()) {
auto cacheValue = not v->isSignatureChecked() and enableCache_ and v->owner;
if (v->checkSignature()) {
if (enableCache_ and v->owner)
if (cacheValue)
nodesPubKeys_[v->owner->getId()] = v->owner;
return v;
} else if (logger_)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment