From a7a96253d4644fbdfed9befad6de63afe76f656b Mon Sep 17 00:00:00 2001 From: olivierlemoine Date: Fri, 26 Apr 2019 16:57:22 +0200 Subject: [PATCH] Fix message type routing bug --- lib/knode.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/knode.js b/lib/knode.js index fa254fd..3cf4558 100644 --- a/lib/knode.js +++ b/lib/knode.js @@ -55,14 +55,31 @@ exports.KNode.prototype._onMessage = function(message) { if (!message.type || typeof message.type !== 'string') return; - var methodName = '_on' + _.str.titleize(_.str.camelize(message.type.toLowerCase())); - var action = this[methodName]; - if (action) { - this._updateContact(MC(message)); - _.bind(action, this)(message); + let action = null; + switch (message.type) { + case 'PING': + action = this._onPing(); + break; + + case 'FIND_NODE': + action = this._onFindNode(); + break; + + case 'FIND_VALUE': + action = this._onFindValue(); + break; + + case 'STORE': + action = this._onStore(); + break; + + default: + console.warn('Unknown message', message); + return; } - else - console.warn("Unknown message", message); + + this._updateContact(MC(message)); + _.bind(action, this)(message); } exports.KNode.prototype._onPing = function(message) {