|
|
@ -6,9 +6,22 @@ const WriteQueue = require("./write-queue");
|
|
|
|
const BatchRead = require("./batch-read");
|
|
|
|
const BatchRead = require("./batch-read");
|
|
|
|
const RPC = require("./rpc");
|
|
|
|
const RPC = require("./rpc");
|
|
|
|
const HK = require("./hk-util.js");
|
|
|
|
const HK = require("./hk-util.js");
|
|
|
|
|
|
|
|
const Core = require("./commands/core");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Store = require("./storage/file");
|
|
|
|
|
|
|
|
const BlobStore = require("./storage/blob");
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.create = function (config, cb) {
|
|
|
|
module.exports.create = function (config, cb) {
|
|
|
|
const Log = config.log;
|
|
|
|
const Log = config.log;
|
|
|
|
|
|
|
|
var WARN = function (e, output) {
|
|
|
|
|
|
|
|
if (e && output) {
|
|
|
|
|
|
|
|
Log.warn(e, {
|
|
|
|
|
|
|
|
output: output,
|
|
|
|
|
|
|
|
message: String(e),
|
|
|
|
|
|
|
|
stack: new Error(e).stack,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Log.silly('HK_LOADING', 'LOADING HISTORY_KEEPER MODULE');
|
|
|
|
Log.silly('HK_LOADING', 'LOADING HISTORY_KEEPER MODULE');
|
|
|
|
|
|
|
|
|
|
|
@ -25,9 +38,62 @@ module.exports.create = function (config, cb) {
|
|
|
|
channel_cache: {},
|
|
|
|
channel_cache: {},
|
|
|
|
queueStorage: WriteQueue(),
|
|
|
|
queueStorage: WriteQueue(),
|
|
|
|
batchIndexReads: BatchRead("HK_GET_INDEX"),
|
|
|
|
batchIndexReads: BatchRead("HK_GET_INDEX"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//historyKeeper: config.historyKeeper,
|
|
|
|
|
|
|
|
intervals: config.intervals || {},
|
|
|
|
|
|
|
|
maxUploadSize: config.maxUploadSize || (20 * 1024 * 1024),
|
|
|
|
|
|
|
|
Sessions: {},
|
|
|
|
|
|
|
|
paths: {},
|
|
|
|
|
|
|
|
//msgStore: config.store,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pinStore: undefined,
|
|
|
|
|
|
|
|
pinnedPads: {},
|
|
|
|
|
|
|
|
pinsLoaded: false,
|
|
|
|
|
|
|
|
pendingPinInquiries: {},
|
|
|
|
|
|
|
|
pendingUnpins: {},
|
|
|
|
|
|
|
|
pinWorkers: 5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
limits: {},
|
|
|
|
|
|
|
|
admins: [],
|
|
|
|
|
|
|
|
WARN: WARN,
|
|
|
|
|
|
|
|
flushCache: config.flushCache,
|
|
|
|
|
|
|
|
adminEmail: config.adminEmail,
|
|
|
|
|
|
|
|
allowSubscriptions: config.allowSubscriptions,
|
|
|
|
|
|
|
|
myDomain: config.myDomain,
|
|
|
|
|
|
|
|
mySubdomain: config.mySubdomain,
|
|
|
|
|
|
|
|
customLimits: config.customLimits,
|
|
|
|
|
|
|
|
// FIXME this attribute isn't in the default conf
|
|
|
|
|
|
|
|
// but it is referenced in Quota
|
|
|
|
|
|
|
|
domain: config.domain
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var paths = Env.paths;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var keyOrDefaultString = function (key, def) {
|
|
|
|
|
|
|
|
return typeof(config[key]) === 'string'? config[key]: def;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config.historyKeeper = {
|
|
|
|
var pinPath = paths.pin = keyOrDefaultString('pinPath', './pins');
|
|
|
|
|
|
|
|
paths.block = keyOrDefaultString('blockPath', './block');
|
|
|
|
|
|
|
|
paths.data = keyOrDefaultString('filePath', './datastore');
|
|
|
|
|
|
|
|
paths.staging = keyOrDefaultString('blobStagingPath', './blobstage');
|
|
|
|
|
|
|
|
paths.blob = keyOrDefaultString('blobPath', './blob');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Env.defaultStorageLimit = typeof(config.defaultStorageLimit) === 'number' && config.defaultStorageLimit > 0?
|
|
|
|
|
|
|
|
config.defaultStorageLimit:
|
|
|
|
|
|
|
|
Core.DEFAULT_LIMIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Env.admins = (config.adminKeys || []).map(function (k) {
|
|
|
|
|
|
|
|
k = k.replace(/\/+$/, '');
|
|
|
|
|
|
|
|
var s = k.split('/');
|
|
|
|
|
|
|
|
return s[s.length-1];
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
console.error("Can't parse admin keys. Please update or fix your config.js file!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.historyKeeper = Env.historyKeeper = {
|
|
|
|
metadata_cache: Env.metadata_cache,
|
|
|
|
metadata_cache: Env.metadata_cache,
|
|
|
|
channel_cache: Env.channel_cache,
|
|
|
|
channel_cache: Env.channel_cache,
|
|
|
|
|
|
|
|
|
|
|
@ -45,7 +111,7 @@ module.exports.create = function (config, cb) {
|
|
|
|
HK.dropChannel(Env, channelName);
|
|
|
|
HK.dropChannel(Env, channelName);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
channelOpen: function (Server, channelName, userId) {
|
|
|
|
channelOpen: function (Server, channelName, userId) {
|
|
|
|
Env.channel_cache[channelName] = {};
|
|
|
|
Env.channel_cache[channelName] = Env.channel_cache[channelName] || {};
|
|
|
|
Server.send(userId, [
|
|
|
|
Server.send(userId, [
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
Env.id,
|
|
|
|
Env.id,
|
|
|
@ -63,11 +129,34 @@ module.exports.create = function (config, cb) {
|
|
|
|
Log.verbose('HK_ID', 'History keeper ID: ' + Env.id);
|
|
|
|
Log.verbose('HK_ID', 'History keeper ID: ' + Env.id);
|
|
|
|
|
|
|
|
|
|
|
|
nThen(function (w) {
|
|
|
|
nThen(function (w) {
|
|
|
|
require('./storage/file').create(config, w(function (_store) {
|
|
|
|
// create a pin store
|
|
|
|
|
|
|
|
Store.create({
|
|
|
|
|
|
|
|
filePath: pinPath,
|
|
|
|
|
|
|
|
}, w(function (s) {
|
|
|
|
|
|
|
|
Env.pinStore = s;
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create a channel store
|
|
|
|
|
|
|
|
Store.create(config, w(function (_store) {
|
|
|
|
config.store = _store;
|
|
|
|
config.store = _store;
|
|
|
|
Env.store = _store;
|
|
|
|
Env.msgStore = _store; // API used by rpc
|
|
|
|
|
|
|
|
Env.store = _store; // API used by historyKeeper
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create a blob store
|
|
|
|
|
|
|
|
BlobStore.create({
|
|
|
|
|
|
|
|
blobPath: config.blobPath,
|
|
|
|
|
|
|
|
blobStagingPath: config.blobStagingPath,
|
|
|
|
|
|
|
|
archivePath: config.archivePath,
|
|
|
|
|
|
|
|
getSession: function (safeKey) {
|
|
|
|
|
|
|
|
return Core.getSession(Env.Sessions, safeKey);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}, w(function (err, blob) {
|
|
|
|
|
|
|
|
if (err) { throw new Error(err); }
|
|
|
|
|
|
|
|
Env.blobStore = blob;
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}).nThen(function (w) {
|
|
|
|
}).nThen(function (w) {
|
|
|
|
|
|
|
|
// create a task store
|
|
|
|
require("./storage/tasks").create(config, w(function (e, tasks) {
|
|
|
|
require("./storage/tasks").create(config, w(function (e, tasks) {
|
|
|
|
if (e) {
|
|
|
|
if (e) {
|
|
|
|
throw e;
|
|
|
|
throw e;
|
|
|
@ -87,7 +176,7 @@ module.exports.create = function (config, cb) {
|
|
|
|
}, 1000 * 60 * 5); // run every five minutes
|
|
|
|
}, 1000 * 60 * 5); // run every five minutes
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function () {
|
|
|
|
RPC.create(config, function (err, _rpc) {
|
|
|
|
RPC.create(Env, function (err, _rpc) {
|
|
|
|
if (err) { throw err; }
|
|
|
|
if (err) { throw err; }
|
|
|
|
|
|
|
|
|
|
|
|
Env.rpc = _rpc;
|
|
|
|
Env.rpc = _rpc;
|
|
|
|