continue refactoring rpc
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
const BatchRead = require("../batch-read");
|
||||
const nThen = require("nthen");
|
||||
const getFolderSize = require("get-folder-size");
|
||||
const Util = require("../common-util");
|
||||
|
||||
var Fs = require("fs");
|
||||
|
||||
var Admin = module.exports;
|
||||
@@ -90,9 +92,10 @@ var getDiskUsage = function (Env, cb) {
|
||||
});
|
||||
};
|
||||
|
||||
Admin.command = function (Env, Server, publicKey, data, cb) {
|
||||
Admin.command = function (Env, safeKey, data, cb, Server) {
|
||||
var admins = Env.admins;
|
||||
if (admins.indexOf(publicKey) === -1) {
|
||||
var unsafeKey = Util.unescapeKeyCharacters(safeKey);
|
||||
if (admins.indexOf(unsafeKey) === -1) {
|
||||
return void cb("FORBIDDEN");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ const Util = require("../common-util");
|
||||
author of the block, since we assume that the block will have been
|
||||
encrypted with xsalsa20-poly1305 which is authenticated.
|
||||
*/
|
||||
Block.validateLoginBlock = function (Env, publicKey, signature, block, cb) { // FIXME BLOCKS
|
||||
var validateLoginBlock = function (Env, publicKey, signature, block, cb) { // FIXME BLOCKS
|
||||
// convert the public key to a Uint8Array and validate it
|
||||
if (typeof(publicKey) !== 'string') { return void cb('E_INVALID_KEY'); }
|
||||
|
||||
@@ -86,13 +86,13 @@ var createLoginBlockPath = function (Env, publicKey) { // FIXME BLOCKS
|
||||
return Path.join(Env.paths.block, safeKey.slice(0, 2), safeKey);
|
||||
};
|
||||
|
||||
Block.writeLoginBlock = function (Env, msg, cb) { // FIXME BLOCKS
|
||||
Block.writeLoginBlock = function (Env, safeKey, msg, cb) { // FIXME BLOCKS
|
||||
//console.log(msg);
|
||||
var publicKey = msg[0];
|
||||
var signature = msg[1];
|
||||
var block = msg[2];
|
||||
|
||||
Block.validateLoginBlock(Env, publicKey, signature, block, function (e, validatedBlock) {
|
||||
validateLoginBlock(Env, publicKey, signature, block, function (e, validatedBlock) {
|
||||
if (e) { return void cb(e); }
|
||||
if (!(validatedBlock instanceof Uint8Array)) { return void cb('E_INVALID_BLOCK'); }
|
||||
|
||||
@@ -141,12 +141,12 @@ Block.writeLoginBlock = function (Env, msg, cb) { // FIXME BLOCKS
|
||||
information, we can just sign some constant and use that as proof.
|
||||
|
||||
*/
|
||||
Block.removeLoginBlock = function (Env, msg, cb) { // FIXME BLOCKS
|
||||
Block.removeLoginBlock = function (Env, safeKey, msg, cb) { // FIXME BLOCKS
|
||||
var publicKey = msg[0];
|
||||
var signature = msg[1];
|
||||
var block = Nacl.util.decodeUTF8('DELETE_BLOCK'); // clients and the server will have to agree on this constant
|
||||
|
||||
Block.validateLoginBlock(Env, publicKey, signature, block, function (e /*::, validatedBlock */) {
|
||||
validateLoginBlock(Env, publicKey, signature, block, function (e /*::, validatedBlock */) {
|
||||
if (e) { return void cb(e); }
|
||||
// derive the filepath
|
||||
var path = createLoginBlockPath(Env, publicKey);
|
||||
|
||||
@@ -160,7 +160,7 @@ Channel.isNewChannel = function (Env, channel, cb) {
|
||||
|
||||
Otherwise behaves the same as sending to a channel
|
||||
*/
|
||||
Channel.writePrivateMessage = function (Env, args, Server, cb) {
|
||||
Channel.writePrivateMessage = function (Env, args, cb, Server) { // XXX odd signature
|
||||
var channelId = args[0];
|
||||
var msg = args[1];
|
||||
|
||||
|
||||
@@ -184,5 +184,7 @@ Core.isPendingOwner = function (metadata, unsafeKey) {
|
||||
return metadata.pending_owners.indexOf(unsafeKey) !== -1;
|
||||
};
|
||||
|
||||
|
||||
Core.haveACookie = function (Env, safeKey, cb) {
|
||||
cb();
|
||||
};
|
||||
|
||||
|
||||
@@ -8,10 +8,12 @@ const Core = require("./core");
|
||||
const Util = require("../common-util");
|
||||
|
||||
const batchMetadata = BatchRead("GET_METADATA");
|
||||
Data.getMetadata = function (Env, channel, cb) {
|
||||
Data.getMetadata = function (Env, channel, cb/* , Server */) {
|
||||
if (!Core.isValidId(channel)) { return void cb('INVALID_CHAN'); }
|
||||
if (channel.length !== 32) { return cb("INVALID_CHAN_LENGTH"); }
|
||||
|
||||
// XXX get metadata from the server cache if it is available
|
||||
// Server isn't always passed, though...
|
||||
batchMetadata(channel, cb, function (done) {
|
||||
var ref = {};
|
||||
var lineHandler = Meta.createLineHandler(ref, Env.Log.error);
|
||||
|
||||
@@ -454,10 +454,10 @@ Pinning.loadChannelPins = function (Env) {
|
||||
Pinning.isChannelPinned = function (Env, channel, cb) {
|
||||
Env.evPinnedPadsReady.reg(() => {
|
||||
if (Env.pinnedPads[channel] && Object.keys(Env.pinnedPads[channel]).length) {
|
||||
cb(true);
|
||||
cb(void 0, true);
|
||||
} else {
|
||||
delete Env.pinnedPads[channel];
|
||||
cb(false);
|
||||
delete Env.pinnedPads[channel]; // XXX WAT
|
||||
cb(void 0, false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user