From f09ef072ac49743570be3d8d89d6ec5755650ae7 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 17 Feb 2021 12:56:51 +0100 Subject: [PATCH] Fix XXX --- lib/hk-util.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/hk-util.js b/lib/hk-util.js index d63ff1b75..031cdf259 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -334,7 +334,8 @@ const storeMessage = function (Env, channel, msg, isCp, optionalMessageHash, cb) if (err) { Log.warn("HK_STORE_MESSAGE_INDEX", err.stack); // non-critical, we'll be able to get the channel index later - // XXX cb with no error so that the message is broadcast + // cb with no error so that the message is broadcast + cb(); return void next(); } if (typeof (index.line) === "number") { index.line++; } @@ -873,7 +874,7 @@ HK.onChannelMessage = function (Env, Server, channel, msgStruct, cb) { // we should probably just change this to expect a channel id directly // don't store messages if the channel id indicates that it's an ephemeral message - if (!channel.id || channel.id.length === EPHEMERAL_CHANNEL_LENGTH) { return; } // XXX cb no error to broadcast + if (!channel.id || channel.id.length === EPHEMERAL_CHANNEL_LENGTH) { return void cb(); } const isCp = /^cp\|/.test(msgStruct[4]); let id; @@ -885,7 +886,7 @@ HK.onChannelMessage = function (Env, Server, channel, msgStruct, cb) { // more straightforward and reliable. if (Array.isArray(id) && id[2] && id[2] === channel.lastSavedCp) { // Reject duplicate checkpoints - return; // XXX cb with error? + return void cb('DUPLICATE'); } } @@ -898,7 +899,10 @@ HK.onChannelMessage = function (Env, Server, channel, msgStruct, cb) { metadata = _metadata; // don't write messages to expired channels - if (checkExpired(Env, Server, channel)) { return void w.abort(); } // XXX cb with error + if (checkExpired(Env, Server, channel)) { + cb('EEXPIRED'); + return void w.abort(); + } })); }).nThen(function (w) { // if there's no validateKey present skip to the next block @@ -927,7 +931,8 @@ HK.onChannelMessage = function (Env, Server, channel, msgStruct, cb) { Log.info("HK_SIGNED_MESSAGE_REJECTED", 'Channel '+channel.id); } // always abort if there was an error... - return void w.abort(); // XXX cb failed validation + cb('FAILED_VALIDATION); + return void w.abort(); }); }); }).nThen(function () {