diff --git a/lib/historyKeeper.js b/lib/historyKeeper.js index b8ac2ca58..e0a9fea2c 100644 --- a/lib/historyKeeper.js +++ b/lib/historyKeeper.js @@ -67,10 +67,7 @@ module.exports.create = function (Env, cb) { } if (metadata && metadata.selfdestruct && metadata.selfdestruct !== Env.id) { - if (Env.store) { - Env.store.archiveChannel(channelName, false, - () => {}); - } + HK.removeChannel(Env, channelName); return void cb('ESELFDESTRUCT'); } diff --git a/lib/hk-util.js b/lib/hk-util.js index 069be04a3..2ba656376 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -134,6 +134,13 @@ const expireChannel = HK.expireChannel = function (Env, channel) { }); }; +const removeChannel = HK.removeChannel = function (Env, channel) { + if (!Env.store) { return; } + Env.store.archiveChannel(channel, void 0, () => {}); + delete Env.metadata_cache[channel]; + delete Env.channel_cache[channel]; +}; + /* dropChannel * cleans up memory structures which are managed entirely by the historyKeeper */ @@ -143,8 +150,7 @@ const dropChannel = HK.dropChannel = function (Env, chanName) { delete Env.channel_cache[chanName]; if (meta && meta.selfdestruct && Env.selfDestructTo) { Env.selfDestructTo[chanName] = setTimeout(function () { - if (!Env.store) { return; } - Env.store.archiveChannel(chanName, false, () => {}); + removeChannel(Env, chanName); }, TEMPORARY_CHANNEL_LIFETIME); } if (Env.store) { Env.store.closeChannel(chanName, function () {}); } @@ -693,6 +699,7 @@ const handleGetHistory = function (Env, Server, seq, userId, parsed) { }, (err, reason) => { // Any error but ENOENT: abort // ENOENT is allowed in case we want to create a new pad + if (err && err.error) { err = err.error; } if (err && err.code !== 'ENOENT') { if (err.message === "EUNKNOWN") { Log.error("HK_GET_HISTORY", { @@ -708,7 +715,7 @@ const handleGetHistory = function (Env, Server, seq, userId, parsed) { stack: err && err.stack, }); } // FIXME err.message isn't useful for users - const parsedMsg = {error:err.message, channel: channelName, txid: txid}; + const parsedMsg = {error:err.message || 'ERROR', channel: channelName, txid: txid}; Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(parsedMsg)]); return; } diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 704038b2c..f4568dbc9 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1843,7 +1843,7 @@ define([ Store.leavePad(null, data, function () {}); }; var conf = { - Cache: Cache, // ICE pad cache + Cache: store.neverCache ? undefined : Cache, // ICE pad cache onCacheStart: function () { postMessage(clientId, "PAD_CACHE"); }, @@ -3271,6 +3271,7 @@ define([ // ==> don't create a drive // Or "neverDrive" (integration into another platform?) // ==> don't create a drive BUT create temp RPC (we may need to upload) + if (data.neverDrive) { store.neverCache = true; } if (data.neverDrive || (data.noDrive && !data.userHash && !data.anonHash)) { return void onNoDrive(clientId, function (obj) { if (obj && obj.error) {