|
|
|
@ -730,43 +730,12 @@ module.exports.create = function (cfg) {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* onDirectMessage
|
|
|
|
|
* exported for use by the netflux-server
|
|
|
|
|
* parses and handles all direct messages directed to the history keeper
|
|
|
|
|
* check if it's expired and execute all the associated side-effects
|
|
|
|
|
* routes queries to the appropriate handlers
|
|
|
|
|
* GET_HISTORY
|
|
|
|
|
* GET_HISTORY_RANGE
|
|
|
|
|
* GET_FULL_HISTORY
|
|
|
|
|
* RPC
|
|
|
|
|
* if the rpc has special hooks that the history keeper needs to be aware of...
|
|
|
|
|
* execute them here...
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
const onDirectMessage = function (ctx, seq, user, json) {
|
|
|
|
|
let parsed;
|
|
|
|
|
let channelName;
|
|
|
|
|
|
|
|
|
|
Log.silly('HK_MESSAGE', json);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
parsed = JSON.parse(json[2]);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
Log.error("HK_PARSE_CLIENT_MESSAGE", json);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the requested history is for an expired channel, abort
|
|
|
|
|
// Note the if we don't have the keys for that channel in metadata_cache, we'll
|
|
|
|
|
// have to abort later (once we know the expiration time)
|
|
|
|
|
if (checkExpired(ctx, parsed[1])) { return; }
|
|
|
|
|
|
|
|
|
|
if (parsed[0] === 'GET_HISTORY') {
|
|
|
|
|
const handleGetHistory = function (ctx, seq, user, parsed) {
|
|
|
|
|
// parsed[1] is the channel id
|
|
|
|
|
// parsed[2] is a validation key or an object containing metadata (optionnal)
|
|
|
|
|
// parsed[3] is the last known hash (optionnal)
|
|
|
|
|
sendMsg(ctx, user, [seq, 'ACK']);
|
|
|
|
|
channelName = parsed[1];
|
|
|
|
|
var channelName = parsed[1];
|
|
|
|
|
var config = parsed[2];
|
|
|
|
|
var metadata = {};
|
|
|
|
|
var lastKnownHash;
|
|
|
|
@ -883,8 +852,10 @@ module.exports.create = function (cfg) {
|
|
|
|
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(parsedMsg)]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else if (parsed[0] === 'GET_HISTORY_RANGE') {
|
|
|
|
|
channelName = parsed[1];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleGetHistoryRange = function (ctx, seq, user, parsed) {
|
|
|
|
|
var channelName = parsed[1];
|
|
|
|
|
var map = parsed[2];
|
|
|
|
|
if (!(map && typeof(map) === 'object')) {
|
|
|
|
|
return void sendMsg(ctx, user, [seq, 'ERROR', 'INVALID_ARGS', HISTORY_KEEPER_ID]);
|
|
|
|
@ -926,7 +897,9 @@ module.exports.create = function (cfg) {
|
|
|
|
|
JSON.stringify(['HISTORY_RANGE_END', txid, channelName])
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
} else if (parsed[0] === 'GET_FULL_HISTORY') {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleGetFullHistory = function (ctx, seq, user, parsed) {
|
|
|
|
|
// parsed[1] is the channel id
|
|
|
|
|
// parsed[2] is a validation key (optionnal)
|
|
|
|
|
// parsed[3] is the last known hash (optionnal)
|
|
|
|
@ -934,7 +907,7 @@ module.exports.create = function (cfg) {
|
|
|
|
|
|
|
|
|
|
// FIXME should we send metadata here too?
|
|
|
|
|
// none of the clientside code which uses this API needs metadata, but it won't hurt to send it (2019-08-22)
|
|
|
|
|
getHistoryAsync(ctx, parsed[1], -1, false, (msg, readMore) => {
|
|
|
|
|
return void getHistoryAsync(ctx, parsed[1], -1, false, (msg, readMore) => {
|
|
|
|
|
if (!msg) { return; }
|
|
|
|
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(['FULL_HISTORY', msg])], readMore);
|
|
|
|
|
}, (err) => {
|
|
|
|
@ -945,7 +918,11 @@ module.exports.create = function (cfg) {
|
|
|
|
|
}
|
|
|
|
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(parsedMsg)]);
|
|
|
|
|
});
|
|
|
|
|
} else if (rpc) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRPC = function (ctx, seq, user, parsed) {
|
|
|
|
|
if (typeof(rpc) !== 'function') { return; }
|
|
|
|
|
|
|
|
|
|
/* RPC Calls... */
|
|
|
|
|
var rpc_call = parsed.slice(1);
|
|
|
|
|
|
|
|
|
@ -995,7 +972,40 @@ module.exports.create = function (cfg) {
|
|
|
|
|
} catch (e) {
|
|
|
|
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify([parsed[0], 'ERROR', 'SERVER_ERROR'])]);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* onDirectMessage
|
|
|
|
|
* exported for use by the netflux-server
|
|
|
|
|
* parses and handles all direct messages directed to the history keeper
|
|
|
|
|
* check if it's expired and execute all the associated side-effects
|
|
|
|
|
* routes queries to the appropriate handlers
|
|
|
|
|
*/
|
|
|
|
|
const onDirectMessage = function (ctx, seq, user, json) {
|
|
|
|
|
Log.silly('HK_MESSAGE', json);
|
|
|
|
|
|
|
|
|
|
let parsed;
|
|
|
|
|
try {
|
|
|
|
|
parsed = JSON.parse(json[2]);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
Log.error("HK_PARSE_CLIENT_MESSAGE", json);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the requested history is for an expired channel, abort
|
|
|
|
|
// Note the if we don't have the keys for that channel in metadata_cache, we'll
|
|
|
|
|
// have to abort later (once we know the expiration time)
|
|
|
|
|
if (checkExpired(ctx, parsed[1])) { return; }
|
|
|
|
|
|
|
|
|
|
if (parsed[0] === 'GET_HISTORY') {
|
|
|
|
|
return void handleGetHistory(ctx, seq, user, parsed);
|
|
|
|
|
}
|
|
|
|
|
if (parsed[0] === 'GET_HISTORY_RANGE') {
|
|
|
|
|
return void handleGetHistoryRange(ctx, seq, user, parsed);
|
|
|
|
|
}
|
|
|
|
|
if (parsed[0] === 'GET_FULL_HISTORY') {
|
|
|
|
|
return void handleGetFullHistory(ctx, seq, user, parsed);
|
|
|
|
|
}
|
|
|
|
|
return void handleRPC(ctx, seq, user, parsed);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|