Fix warning reporting in net transports

This commit is contained in:
Kagami Hiiragi 2015-02-21 20:52:26 +03:00
parent 0642977538
commit 0f2a21c134
3 changed files with 6 additions and 14 deletions

View File

@ -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

View File

@ -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
));
}
}

View File

@ -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);