cache the metadata to save a few lookups
This commit is contained in:
parent
c5de4164bc
commit
c17938a8e3
@ -334,13 +334,14 @@ module.exports.create = function (cfg) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (metadata_cache[channel.id] && metadata_cache[channel.id].validateKey) {
|
var metadata = metadata_cache[channel.id];
|
||||||
|
if (metadata && metadata.validateKey) {
|
||||||
/*::if (typeof(msgStruct[4]) !== 'string') { throw new Error(); }*/
|
/*::if (typeof(msgStruct[4]) !== 'string') { throw new Error(); }*/
|
||||||
let signedMsg = (isCp) ? msgStruct[4].replace(CHECKPOINT_PATTERN, '') : msgStruct[4];
|
let signedMsg = (isCp) ? msgStruct[4].replace(CHECKPOINT_PATTERN, '') : msgStruct[4];
|
||||||
signedMsg = Nacl.util.decodeBase64(signedMsg);
|
signedMsg = Nacl.util.decodeBase64(signedMsg);
|
||||||
// FIXME PERFORMANCE: cache the decoded key instead of decoding it every time
|
// FIXME PERFORMANCE: cache the decoded key instead of decoding it every time
|
||||||
// CPU/Memory tradeoff
|
// CPU/Memory tradeoff
|
||||||
const validateKey = Nacl.util.decodeBase64(metadata_cache[channel.id].validateKey);
|
const validateKey = Nacl.util.decodeBase64(metadata.validateKey);
|
||||||
const validated = Nacl.sign.open(signedMsg, validateKey);
|
const validated = Nacl.sign.open(signedMsg, validateKey);
|
||||||
if (!validated) {
|
if (!validated) {
|
||||||
Log.info("HK_SIGNED_MESSAGE_REJECTED", 'Channel '+channel.id);
|
Log.info("HK_SIGNED_MESSAGE_REJECTED", 'Channel '+channel.id);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user