WIP allow list changes

This commit is contained in:
ansuz
2020-02-21 08:18:05 -05:00
parent 597f417ad6
commit 791aad53f2
3 changed files with 38 additions and 26 deletions

View File

@@ -38,6 +38,7 @@ module.exports.create = function (config, cb) {
channel_cache: {},
queueStorage: WriteQueue(),
batchIndexReads: BatchRead("HK_GET_INDEX"),
batchMetadata: BatchRead('GET_METADATA'),
//historyKeeper: config.historyKeeper,
intervals: config.intervals || {},
@@ -115,22 +116,23 @@ module.exports.create = function (config, cb) {
channelOpen: function (Server, channelName, userId, wait) {
Env.channel_cache[channelName] = Env.channel_cache[channelName] || {};
var proceed = function () {
Server.send(userId, [
0,
Env.id,
'JOIN',
channelName
]);
var next = wait();
var cb = function (err, info) {
next(err, info, function () {
Server.send(userId, [
0,
Env.id,
'JOIN',
channelName
]);
});
};
// only conventional channels can be restricted
if ((channelName || "").length !== 32) { // XXX use contants
return proceed();
if ((channelName || "").length !== HK.STANDARD_CHANNEL_LENGTH) {
return void cb();
}
var next = wait();
// gets and caches the metadata...
// XXX make sure it doesn't get stuck in cache...
HK.getMetadata(Env, channelName, function (err, metadata) {
@@ -142,8 +144,7 @@ module.exports.create = function (config, cb) {
if (!metadata || (metadata && !metadata.restricted)) {
// the channel doesn't have metadata, or it does and it's not restricted
// either way, let them join.
proceed();
return void next();
return void cb();
}
// this channel is restricted. verify that the user in question is in the allow list
@@ -154,15 +155,14 @@ module.exports.create = function (config, cb) {
var session = HK.getNetfluxSession(Env, userId);
if (HK.isUserSessionAllowed(allowed, session)) {
proceed();
return void next();
return void cb();
}
// otherwise they're not allowed.
// respond with a special error that includes the list of keys
// which would be allowed...
// XXX bonus points if you hash the keys to limit data exposure
next(["ERESTRICTED"].concat(allowed));
cb("ERESTRICTED", allowed);
});
},
sessionClose: function (userId, reason) {