calculate pin list checksums in a worker
This commit is contained in:
parent
51e6fe1cce
commit
14feef1757
@ -142,23 +142,9 @@ var getFreeSpace = Pinning.getFreeSpace = function (Env, safeKey, cb) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var hashChannelList = function (A) {
|
|
||||||
var uniques = [];
|
|
||||||
|
|
||||||
A.forEach(function (a) {
|
|
||||||
if (uniques.indexOf(a) === -1) { uniques.push(a); }
|
|
||||||
});
|
|
||||||
uniques.sort();
|
|
||||||
|
|
||||||
var hash = Nacl.util.encodeBase64(Nacl.hash(Nacl
|
|
||||||
.util.decodeUTF8(JSON.stringify(uniques))));
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
};
|
|
||||||
|
|
||||||
var getHash = Pinning.getHash = function (Env, safeKey, cb) {
|
var getHash = Pinning.getHash = function (Env, safeKey, cb) {
|
||||||
getChannelList(Env, safeKey, function (channels) {
|
getChannelList(Env, safeKey, function (channels) {
|
||||||
cb(void 0, hashChannelList(channels));
|
Env.hashChannelList(channels, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -951,7 +951,7 @@ HK.initializeValidationWorkers = function (Env) {
|
|||||||
worker.on('message', function (res) {
|
worker.on('message', function (res) {
|
||||||
if (!res || !res.txid) { return; }
|
if (!res || !res.txid) { return; }
|
||||||
//console.log(+new Date(), "Received verification response");
|
//console.log(+new Date(), "Received verification response");
|
||||||
response.handle(res.txid, [res.error]);
|
response.handle(res.txid, [res.error, res.value]);
|
||||||
});
|
});
|
||||||
// Spawn a new process in one ends
|
// Spawn a new process in one ends
|
||||||
worker.on('exit', function () {
|
worker.on('exit', function () {
|
||||||
@ -1001,6 +1001,13 @@ HK.initializeValidationWorkers = function (Env) {
|
|||||||
key: publicKey,
|
key: publicKey,
|
||||||
}, cb);
|
}, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Env.hashChannelList = function (channels, cb) {
|
||||||
|
send({
|
||||||
|
command: 'HASH_CHANNEL_LIST',
|
||||||
|
channels: channels,
|
||||||
|
}, cb);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* onChannelMessage
|
/* onChannelMessage
|
||||||
|
|||||||
@ -73,17 +73,34 @@ COMMANDS.DETACHED = function (data, cb) {
|
|||||||
cb();
|
cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
COMMANDS.HASH_CHANNEL_LIST = function (data, cb) {
|
||||||
|
var channels = data.channels;
|
||||||
|
if (!Array.isArray(channels)) { return void cb('INVALID_CHANNEL_LIST'); }
|
||||||
|
var uniques = [];
|
||||||
|
|
||||||
|
channels.forEach(function (a) {
|
||||||
|
if (uniques.indexOf(a) === -1) { uniques.push(a); }
|
||||||
|
});
|
||||||
|
uniques.sort();
|
||||||
|
|
||||||
|
var hash = Nacl.util.encodeBase64(Nacl.hash(Nacl
|
||||||
|
.util.decodeUTF8(JSON.stringify(uniques))));
|
||||||
|
|
||||||
|
cb(void 0, hash);
|
||||||
|
};
|
||||||
|
|
||||||
process.on('message', function (data) {
|
process.on('message', function (data) {
|
||||||
if (!data || !data.key || !data.msg || !data.txid) {
|
if (!data || !data.txid) {
|
||||||
return void process.send({
|
return void process.send({
|
||||||
error:'E_INVAL'
|
error:'E_INVAL'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const cb = function (err) {
|
const cb = function (err, value) {
|
||||||
process.send({
|
process.send({
|
||||||
txid: data.txid,
|
txid: data.txid,
|
||||||
error: err,
|
error: err,
|
||||||
|
value: value,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user