From 0f2a21c1346a42fc4aa310e734e7e98f0cea4aae Mon Sep 17 00:00:00 2001 From: Kagami Hiiragi Date: Sat, 21 Feb 2015 20:52:26 +0300 Subject: [PATCH] Fix warning reporting in net transports --- lib/messages.js | 3 +++ lib/net/tcp.js | 7 +------ lib/net/ws.js | 10 ++-------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/messages.js b/lib/messages.js index ab3b86e..4cf1597 100644 --- a/lib/messages.js +++ b/lib/messages.js @@ -466,6 +466,9 @@ var error = exports.error = { } }, + // XXX(Kagami): Rename `fatal` field to `type`? `fatal` used in spec + // but it's rather unintuitive. + /** * @typedef {Object} DecodeResult * @property {number} fatal - Type of the error diff --git a/lib/net/tcp.js b/lib/net/tcp.js index eee1b84..4428301 100644 --- a/lib/net/tcp.js +++ b/lib/net/tcp.js @@ -76,10 +76,6 @@ function TcpTransport(opts) { inherits(TcpTransport, BaseTransport); -function getfrom(client) { - return unmap(client.remoteAddress) + ":" + client.remotePort; -} - TcpTransport.prototype._sendVersion = function() { return this.send(messages.version.encode({ services: this.services, @@ -137,8 +133,7 @@ TcpTransport.prototype._setupClient = function(client, incoming) { // TODO(Kagami): Send `error` message and ban node for some time // if there were too many errors? self.emit("warning", new Error( - "Message decoding error from " + getfrom(client) + ": " + - decoded.error + "Message decoding error: " + decoded.error.message )); } } diff --git a/lib/net/ws.js b/lib/net/ws.js index 49c5655..df5400d 100644 --- a/lib/net/ws.js +++ b/lib/net/ws.js @@ -50,10 +50,6 @@ function WsTransport(opts) { inherits(WsTransport, BaseTransport); -function getfrom(client) { - return unmap(client._socket.remoteAddress) + ":" + client._socket.remotePort; -} - WsTransport.prototype._sendVersion = function() { return this.send(messages.version.encode({ services: this.services, @@ -105,15 +101,13 @@ WsTransport.prototype._setupClient = function(client, incoming) { if (!flags.binary) { // TODO(Kagami): Send `error` message and ban node for some time // if there were too many errors? - return self.emit("warning", new Error( - "Peer " + getfrom(client) + " sent non-binary data" - )); + return self.emit("warning", new Error("Peer sent non-binary data")); } try { decoded = structs.message.decode(data); } catch (err) { return self.emit("warning", new Error( - "Message decoding error from " + getfrom(client) + ": " + err + "Message decoding error: " + err.message )); } self.emit("message", decoded.command, decoded.payload, decoded);