merge server components from staging
This commit is contained in:
17
lib/rpc.js
17
lib/rpc.js
@@ -9,6 +9,7 @@ const Block = require("./commands/block");
|
||||
const Metadata = require("./commands/metadata");
|
||||
const Channel = require("./commands/channel");
|
||||
const Upload = require("./commands/upload");
|
||||
const HK = require("./hk-util");
|
||||
|
||||
var RPC = module.exports;
|
||||
|
||||
@@ -26,7 +27,7 @@ var isUnauthenticateMessage = function (msg) {
|
||||
return msg && msg.length === 2 && typeof(UNAUTHENTICATED_CALLS[msg[0]]) === 'function';
|
||||
};
|
||||
|
||||
var handleUnauthenticatedMessage = function (Env, msg, respond, Server) {
|
||||
var handleUnauthenticatedMessage = function (Env, msg, respond, Server, netfluxId) {
|
||||
Env.Log.silly('LOG_RPC', msg[0]);
|
||||
|
||||
var method = UNAUTHENTICATED_CALLS[msg[0]];
|
||||
@@ -36,7 +37,7 @@ var handleUnauthenticatedMessage = function (Env, msg, respond, Server) {
|
||||
return void respond(err);
|
||||
}
|
||||
respond(err, [null, value, null]);
|
||||
}, Server);
|
||||
}, Server, netfluxId);
|
||||
};
|
||||
|
||||
const AUTHENTICATED_USER_TARGETED = {
|
||||
@@ -117,7 +118,7 @@ var handleAuthenticatedMessage = function (Env, unsafeKey, msg, respond, Server)
|
||||
return void Respond('UNSUPPORTED_RPC_CALL', msg);
|
||||
};
|
||||
|
||||
var rpc = function (Env, Server, data, respond) {
|
||||
var rpc = function (Env, Server, userId, data, respond) {
|
||||
if (!Array.isArray(data)) {
|
||||
Env.Log.debug('INVALID_ARG_FORMET', data);
|
||||
return void respond('INVALID_ARG_FORMAT');
|
||||
@@ -136,15 +137,16 @@ var rpc = function (Env, Server, data, respond) {
|
||||
}
|
||||
|
||||
if (isUnauthenticateMessage(msg)) {
|
||||
return handleUnauthenticatedMessage(Env, msg, respond, Server);
|
||||
return handleUnauthenticatedMessage(Env, msg, respond, Server, userId);
|
||||
}
|
||||
|
||||
var signature = msg.shift();
|
||||
var publicKey = msg.shift();
|
||||
|
||||
// make sure a user object is initialized in the cookie jar
|
||||
var session;
|
||||
if (publicKey) {
|
||||
Core.getSession(Env.Sessions, publicKey);
|
||||
session = Core.getSession(Env.Sessions, publicKey);
|
||||
} else {
|
||||
Env.Log.debug("NO_PUBLIC_KEY_PROVIDED", publicKey);
|
||||
}
|
||||
@@ -174,6 +176,7 @@ var rpc = function (Env, Server, data, respond) {
|
||||
// check the signature on the message
|
||||
// refuse the command if it doesn't validate
|
||||
if (Core.checkSignature(Env, serialized, signature, publicKey) === true) {
|
||||
HK.authenticateNetfluxSession(Env, userId, publicKey);
|
||||
return void handleAuthenticatedMessage(Env, publicKey, msg, respond, Server);
|
||||
}
|
||||
return void respond("INVALID_SIGNATURE_OR_PUBLIC_KEY");
|
||||
@@ -202,9 +205,9 @@ RPC.create = function (Env, cb) {
|
||||
Core.expireSessions(Sessions);
|
||||
}, Core.SESSION_EXPIRATION_TIME);
|
||||
|
||||
cb(void 0, function (Server, data, respond) {
|
||||
cb(void 0, function (Server, userId, data, respond) {
|
||||
try {
|
||||
return rpc(Env, Server, data, respond);
|
||||
return rpc(Env, Server, userId, data, respond);
|
||||
} catch (e) {
|
||||
console.log("Error from RPC with data " + JSON.stringify(data));
|
||||
console.log(e.stack);
|
||||
|
||||
Reference in New Issue
Block a user