|
|
|
@ -1,6 +1,4 @@
|
|
|
|
|
/*jshint esversion: 6 */
|
|
|
|
|
const nThen = require("nthen");
|
|
|
|
|
|
|
|
|
|
const Util = require("./common-util");
|
|
|
|
|
|
|
|
|
|
const Core = require("./commands/core");
|
|
|
|
@ -14,9 +12,6 @@ const Upload = require("./commands/upload");
|
|
|
|
|
|
|
|
|
|
var RPC = module.exports;
|
|
|
|
|
|
|
|
|
|
const Store = require("./storage/file");
|
|
|
|
|
const BlobStore = require("./storage/blob");
|
|
|
|
|
|
|
|
|
|
const UNAUTHENTICATED_CALLS = {
|
|
|
|
|
GET_FILE_SIZE: Pinning.getFileSize,
|
|
|
|
|
GET_MULTIPLE_FILE_SIZE: Pinning.getMultipleFileSize,
|
|
|
|
@ -187,86 +182,12 @@ var rpc = function (Env, Server, data, respond) {
|
|
|
|
|
return void respond("INVALID_RPC_CALL");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RPC.create = function (config, cb) {
|
|
|
|
|
var Log = config.log;
|
|
|
|
|
|
|
|
|
|
// load pin-store...
|
|
|
|
|
Log.silly('LOADING RPC MODULE');
|
|
|
|
|
|
|
|
|
|
var keyOrDefaultString = function (key, def) {
|
|
|
|
|
return typeof(config[key]) === 'string'? config[key]: def;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var WARN = function (e, output) {
|
|
|
|
|
if (e && output) {
|
|
|
|
|
Log.warn(e, {
|
|
|
|
|
output: output,
|
|
|
|
|
message: String(e),
|
|
|
|
|
stack: new Error(e).stack,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (typeof(config.domain) !== 'undefined') {
|
|
|
|
|
throw new Error('fuck');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Env = {
|
|
|
|
|
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: [],
|
|
|
|
|
Log: Log,
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RPC.create = function (Env, cb) {
|
|
|
|
|
var Sessions = Env.Sessions;
|
|
|
|
|
var paths = Env.paths;
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
|
|
var updateLimitDaily = function () {
|
|
|
|
|
Quota.updateCachedLimits(Env, function (e) {
|
|
|
|
|
if (e) {
|
|
|
|
|
WARN('limitUpdate', e);
|
|
|
|
|
Env.WARN('limitUpdate', e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
@ -276,35 +197,17 @@ RPC.create = function (config, cb) {
|
|
|
|
|
|
|
|
|
|
Pinning.loadChannelPins(Env);
|
|
|
|
|
|
|
|
|
|
nThen(function (w) {
|
|
|
|
|
Store.create({
|
|
|
|
|
filePath: pinPath,
|
|
|
|
|
}, w(function (s) {
|
|
|
|
|
Env.pinStore = s;
|
|
|
|
|
}));
|
|
|
|
|
BlobStore.create({
|
|
|
|
|
blobPath: config.blobPath,
|
|
|
|
|
blobStagingPath: config.blobStagingPath,
|
|
|
|
|
archivePath: config.archivePath,
|
|
|
|
|
getSession: function (safeKey) {
|
|
|
|
|
return Core.getSession(Sessions, safeKey);
|
|
|
|
|
},
|
|
|
|
|
}, w(function (err, blob) {
|
|
|
|
|
if (err) { throw new Error(err); }
|
|
|
|
|
Env.blobStore = blob;
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
cb(void 0, function (Server, data, respond) {
|
|
|
|
|
try {
|
|
|
|
|
return rpc(Env, Server, data, respond);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("Error from RPC with data " + JSON.stringify(data));
|
|
|
|
|
console.log(e.stack);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// expire old sessions once per minute
|
|
|
|
|
Env.intervals.sessionExpirationInterval = setInterval(function () {
|
|
|
|
|
Core.expireSessions(Sessions);
|
|
|
|
|
}, Core.SESSION_EXPIRATION_TIME);
|
|
|
|
|
// expire old sessions once per minute
|
|
|
|
|
Env.intervals.sessionExpirationInterval = setInterval(function () {
|
|
|
|
|
Core.expireSessions(Sessions);
|
|
|
|
|
}, Core.SESSION_EXPIRATION_TIME);
|
|
|
|
|
|
|
|
|
|
cb(void 0, function (Server, data, respond) {
|
|
|
|
|
try {
|
|
|
|
|
return rpc(Env, Server, data, respond);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("Error from RPC with data " + JSON.stringify(data));
|
|
|
|
|
console.log(e.stack);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|