Add txid in GET_HISTORY
This commit is contained in:
parent
c58a50081b
commit
d736f783e7
@ -739,6 +739,7 @@ module.exports.create = function (cfg) {
|
|||||||
var config = parsed[2];
|
var config = parsed[2];
|
||||||
var metadata = {};
|
var metadata = {};
|
||||||
var lastKnownHash;
|
var lastKnownHash;
|
||||||
|
var txid;
|
||||||
|
|
||||||
// clients can optionally pass a map of attributes
|
// clients can optionally pass a map of attributes
|
||||||
// if the channel already exists this map will be ignored
|
// if the channel already exists this map will be ignored
|
||||||
@ -746,6 +747,7 @@ module.exports.create = function (cfg) {
|
|||||||
if (config && typeof config === "object" && !Array.isArray(parsed[2])) {
|
if (config && typeof config === "object" && !Array.isArray(parsed[2])) {
|
||||||
lastKnownHash = config.lastKnownHash;
|
lastKnownHash = config.lastKnownHash;
|
||||||
metadata = config.metadata || {};
|
metadata = config.metadata || {};
|
||||||
|
txid = config.txid;
|
||||||
if (metadata.expire) {
|
if (metadata.expire) {
|
||||||
metadata.expire = +metadata.expire * 1000 + (+new Date());
|
metadata.expire = +metadata.expire * 1000 + (+new Date());
|
||||||
}
|
}
|
||||||
@ -796,11 +798,12 @@ module.exports.create = function (cfg) {
|
|||||||
msgCount++;
|
msgCount++;
|
||||||
// avoid sending the metadata message a second time
|
// avoid sending the metadata message a second time
|
||||||
if (isMetadataMessage(msg) && metadata_cache[channelName]) { return readMore(); }
|
if (isMetadataMessage(msg) && metadata_cache[channelName]) { return readMore(); }
|
||||||
|
if (txid) { msg[0] = txid; }
|
||||||
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(msg)], readMore);
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(msg)], readMore);
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
if (err && err.code !== 'ENOENT') {
|
if (err && err.code !== 'ENOENT') {
|
||||||
if (err.message !== 'EINVAL') { Log.error("HK_GET_HISTORY", err); }
|
if (err.message !== 'EINVAL') { Log.error("HK_GET_HISTORY", err); }
|
||||||
const parsedMsg = {error:err.message, channel: channelName};
|
const parsedMsg = {error:err.message, channel: channelName, txid: txid};
|
||||||
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(parsedMsg)]);
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(parsedMsg)]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -848,7 +851,7 @@ module.exports.create = function (cfg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End of history message:
|
// End of history message:
|
||||||
let parsedMsg = {state: 1, channel: channelName};
|
let parsedMsg = {state: 1, channel: channelName, txid: txid};
|
||||||
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(parsedMsg)]);
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(parsedMsg)]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1855,6 +1855,8 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var txid = Math.floor(Math.random() * 1000000);
|
||||||
|
|
||||||
var msgs = [];
|
var msgs = [];
|
||||||
var completed = false;
|
var completed = false;
|
||||||
var onMsg = function (msg, sender) {
|
var onMsg = function (msg, sender) {
|
||||||
@ -1863,6 +1865,8 @@ define([
|
|||||||
var parsed = parse(msg);
|
var parsed = parse(msg);
|
||||||
if (!parsed) { return; }
|
if (!parsed) { return; }
|
||||||
|
|
||||||
|
if (parsed.txid && parsed.txid !== txid) { return; }
|
||||||
|
|
||||||
// Ignore the metadata message
|
// Ignore the metadata message
|
||||||
if (parsed.validateKey && parsed.channel) { return; }
|
if (parsed.validateKey && parsed.channel) { return; }
|
||||||
if (parsed.error && parsed.channel) {
|
if (parsed.error && parsed.channel) {
|
||||||
@ -1883,9 +1887,20 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = parsed[4];
|
if (Array.isArray(parsed) && parsed[0] && parsed[0] !== txid) { return; }
|
||||||
|
|
||||||
// Keep only the history for our channel
|
// Keep only the history for our channel
|
||||||
if (parsed[3] !== data.channel) { return; }
|
if (parsed[3] !== data.channel) { return; }
|
||||||
|
// If we want the full messages, push the parsed data
|
||||||
|
if (parsed[4] && full) {
|
||||||
|
msgs.push({
|
||||||
|
msg: msg,
|
||||||
|
hash: parsed[4].slice(0,64)
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Otherwise, push the messages
|
||||||
|
msg = parsed[4];
|
||||||
if (msg) {
|
if (msg) {
|
||||||
msg = msg.replace(/cp\|(([A-Za-z0-9+\/=]+)\|)?/, '');
|
msg = msg.replace(/cp\|(([A-Za-z0-9+\/=]+)\|)?/, '');
|
||||||
msgs.push(msg);
|
msgs.push(msg);
|
||||||
@ -1894,6 +1909,7 @@ define([
|
|||||||
network.on('message', onMsg);
|
network.on('message', onMsg);
|
||||||
|
|
||||||
var cfg = {
|
var cfg = {
|
||||||
|
txid: txid,
|
||||||
lastKnownHash: data.lastKnownHash
|
lastKnownHash: data.lastKnownHash
|
||||||
};
|
};
|
||||||
var msg = ['GET_HISTORY', data.channel, cfg];
|
var msg = ['GET_HISTORY', data.channel, cfg];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user