version.version -> version.protoVersion

This commit is contained in:
Kagami Hiiragi 2015-02-24 19:09:01 +03:00
parent fe63ccf227
commit 96d63f0613
6 changed files with 10 additions and 14 deletions

View File

@ -83,10 +83,10 @@ var randomNonce = bmcrypto.randomBytes(8);
var version = exports.version = {
/**
* @typedef {Object} DecodeResult
* @property {number} version - Identifies protocol version being used
* by the node. Should equal 3. Nodes should disconnect if the remote
* node's version is lower but continue with the connection if it is
* higher.
* @property {number} protoVersion - Identifies protocol version being
* used by the node. Should equal 3. Nodes should disconnect if the
* remote node's version is lower but continue with the connection if
* it is higher.
* @property {Object} services -
* [Service]{@link module:bitmessage/structs.ServicesBitfield}
* features to be enabled for this connection
@ -138,7 +138,7 @@ var version = exports.version = {
var decodedUa = UserAgent.decode(buf.slice(80));
var decodedStreams = structs.var_int_list.decode(decodedUa.rest);
return {
version: protoVersion,
protoVersion: protoVersion,
services: services,
time: time,
remoteHost: addrRecv.host,

View File

@ -125,11 +125,7 @@ TcpTransport.prototype._setupClient = function(client, incoming) {
}
cache = decoded.rest;
if (decoded.message) {
self.emit(
"message",
decoded.message.command,
decoded.message.payload,
decoded.message);
self.emit("message", decoded.message.command, decoded.message.payload);
} else if (decoded.error) {
// TODO(Kagami): Wrap it in custom error class?
// TODO(Kagami): Send `error` message and ban node for some time

View File

@ -117,7 +117,7 @@ WsTransport.prototype._setupClient = function(client, incoming) {
"Message decoding error: " + err.message
));
}
self.emit("message", decoded.command, decoded.payload, decoded);
self.emit("message", decoded.command, decoded.payload);
});
// High-level message processing.

View File

@ -64,7 +64,7 @@ if (!process.browser) {
it("should automatically establish connection", function(done) {
tcp.once("established", function(version) {
expect(version.version).to.equal(3);
expect(version.protoVersion).to.equal(3);
expect(version.services.get(ServicesBitfield.NODE_NETWORK)).to.be.true;
expect(version.remoteHost).to.equal("127.0.0.1");
expect(version.port).to.equal(22333);
@ -127,6 +127,7 @@ describe("WebSocket transport", function() {
it("should automatically establish connection", function(done) {
ws.once("established", function(version) {
expect(version.protoVersion).to.equal(3);
expect(version.services.get(ServicesBitfield.NODE_GATEWAY)).to.be.true;
expect(version.remoteHost).to.equal("127.0.0.1");
expect(version.port).to.equal(22334);

View File

@ -37,7 +37,6 @@ module.exports = function() {
process.on("exit", cleanup());
process.on("SIGINT", cleanup(true));
process.on("uncaughtException", cleanup(true));
var tcpNode = spawn("tcp-node.js");
var wsNode = spawn("ws-node.js");

View File

@ -496,7 +496,7 @@ describe("Message types", function() {
});
expect(message.decode(encoded).command).to.equal("version");
var res = version.decode(encoded);
expect(res.version).to.equal(3);
expect(res.protoVersion).to.equal(3);
expect(res.services.get(ServicesBitfield.NODE_NETWORK)).to.be.true;
expect(res.time).to.be.instanceof(Date);
expect(res.remoteHost).to.equal("1.2.3.4");