From 61fc4a3f8698f6320b07c98ba99243d015f85fe6 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 15 Mar 2017 15:55:25 +0100 Subject: [PATCH] respond to GET_FILE_SIZE rpc calls --- NetfluxWebsocketSrv.js | 2 +- rpc.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/NetfluxWebsocketSrv.js b/NetfluxWebsocketSrv.js index 0108659fb..2d894a5c0 100644 --- a/NetfluxWebsocketSrv.js +++ b/NetfluxWebsocketSrv.js @@ -214,7 +214,7 @@ const handleMessage = function (ctx, user, msg) { var rpc_call = parsed.slice(1); // slice off the sequence number and pass in the rest of the message - ctx.rpc(rpc_call, function (err, output) { + ctx.rpc(ctx, rpc_call, function (err, output) { if (err) { console.error('[' + err + ']', output); // TODO make this disableable sendMsg(ctx, user, [seq, 'ACK']); diff --git a/rpc.js b/rpc.js index 66973039b..053d8cf6e 100644 --- a/rpc.js +++ b/rpc.js @@ -11,11 +11,15 @@ var getHash = function (ctx, cb) { }; var getTotalSize = function (ctx, cb) { }; var getFileSize = function (ctx, cb) { }; +var isValidChannel = function (chan) { + return /^[a-fA-F0-9]/.test(chan); +}; + RPC.create = function (config, cb) { // load pin-store... console.log('loading rpc module...'); - rpc = function (msg, respond) { + rpc = function (ctx, msg, respond) { switch (msg[0]) { case 'ECHO': respond(void 0, msg); @@ -25,7 +29,14 @@ RPC.create = function (config, cb) { case 'GET_HASH': case 'GET_TOTAL_SIZE': case 'GET_FILE_SIZE': - + if (!isValidChannel(msg[1])) { + return void respond('INVALID_CHAN'); + } + + return void ctx.store.getChannelSize(msg[1], function (e, size) { + if (e) { return void respond(e.code); } + respond(void 0, size); + }); default: respond('UNSUPPORTED_RPC_CALL', msg); break;