|
|
|
@ -171,17 +171,19 @@ const checkExpired = function (Env, Server, channel) {
|
|
|
|
|
error: 'EEXPIRED',
|
|
|
|
|
channel: channel
|
|
|
|
|
}, Env.id);
|
|
|
|
|
dropChannel(channel);
|
|
|
|
|
dropChannel(Env, channel);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// return true to indicate that it has expired
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getMetadata = HK.getMetadata = function (Env, channelName, cb) {
|
|
|
|
|
const getMetadata = HK.getMetadata = function (Env, channelName, _cb) {
|
|
|
|
|
var cb = Util.once(Util.mkAsync(_cb));
|
|
|
|
|
|
|
|
|
|
var metadata = Env.metadata_cache[channelName];
|
|
|
|
|
if (metadata && typeof(metadata) === 'object') {
|
|
|
|
|
return void Util.mkAsync(cb)(undefined, metadata);
|
|
|
|
|
return void cb(undefined, metadata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MetaRPC.getMetadata(Env, channelName, function (err, metadata) {
|
|
|
|
@ -189,6 +191,10 @@ const getMetadata = HK.getMetadata = function (Env, channelName, cb) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
return void cb(err);
|
|
|
|
|
}
|
|
|
|
|
if (!(metadata && typeof(metadata.channel) === 'string' && metadata.channel.length === STANDARD_CHANNEL_LENGTH)) {
|
|
|
|
|
return cb();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// cache it
|
|
|
|
|
Env.metadata_cache[channelName] = metadata;
|
|
|
|
|
cb(undefined, metadata);
|
|
|
|
@ -231,7 +237,8 @@ const computeIndex = function (Env, channelName, cb) {
|
|
|
|
|
nThen(function (w) {
|
|
|
|
|
getMetadata(Env, channelName, w(function (err, _metadata) {
|
|
|
|
|
if (err) {
|
|
|
|
|
throw new Error(err);
|
|
|
|
|
console.log(err);
|
|
|
|
|
throw new Error(err); // XXX
|
|
|
|
|
}
|
|
|
|
|
metadata = _metadata;
|
|
|
|
|
}));
|
|
|
|
@ -693,7 +700,7 @@ const handleGetHistory = function (Env, Server, seq, userId, parsed) {
|
|
|
|
|
}, (err) => {
|
|
|
|
|
if (err && err.code !== 'ENOENT') {
|
|
|
|
|
if (err.message !== 'EINVAL') { Log.error("HK_GET_HISTORY", err); }
|
|
|
|
|
const parsedMsg = {error:err.message, channel: channelName, txid: txid};
|
|
|
|
|
const parsedMsg = {error:err.message, channel: channelName, txid: txid}; // XXX history retrieval error format
|
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(parsedMsg)]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -876,6 +883,7 @@ HK.onDirectMessage = function (Env, Server, seq, userId, json) {
|
|
|
|
|
if (checkExpired(Env, Server, parsed[1])) {
|
|
|
|
|
// if the channel is expired just abort.
|
|
|
|
|
w.abort();
|
|
|
|
|
// XXX what do we tell the person who asked?
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -891,6 +899,9 @@ HK.onDirectMessage = function (Env, Server, seq, userId, json) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// XXX NOT ALLOWED
|
|
|
|
|
// respond to txid with error as in handleGetHistory
|
|
|
|
|
// send the allow list anyway, it might not get used currently
|
|
|
|
|
// but will in the future
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
// run the appropriate command from the map
|
|
|
|
|