version.version -> version.protoVersion
This commit is contained in:
parent
fe63ccf227
commit
96d63f0613
|
@ -83,10 +83,10 @@ var randomNonce = bmcrypto.randomBytes(8);
|
||||||
var version = exports.version = {
|
var version = exports.version = {
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} DecodeResult
|
* @typedef {Object} DecodeResult
|
||||||
* @property {number} version - Identifies protocol version being used
|
* @property {number} protoVersion - Identifies protocol version being
|
||||||
* by the node. Should equal 3. Nodes should disconnect if the remote
|
* used by the node. Should equal 3. Nodes should disconnect if the
|
||||||
* node's version is lower but continue with the connection if it is
|
* remote node's version is lower but continue with the connection if
|
||||||
* higher.
|
* it is higher.
|
||||||
* @property {Object} services -
|
* @property {Object} services -
|
||||||
* [Service]{@link module:bitmessage/structs.ServicesBitfield}
|
* [Service]{@link module:bitmessage/structs.ServicesBitfield}
|
||||||
* features to be enabled for this connection
|
* features to be enabled for this connection
|
||||||
|
@ -138,7 +138,7 @@ var version = exports.version = {
|
||||||
var decodedUa = UserAgent.decode(buf.slice(80));
|
var decodedUa = UserAgent.decode(buf.slice(80));
|
||||||
var decodedStreams = structs.var_int_list.decode(decodedUa.rest);
|
var decodedStreams = structs.var_int_list.decode(decodedUa.rest);
|
||||||
return {
|
return {
|
||||||
version: protoVersion,
|
protoVersion: protoVersion,
|
||||||
services: services,
|
services: services,
|
||||||
time: time,
|
time: time,
|
||||||
remoteHost: addrRecv.host,
|
remoteHost: addrRecv.host,
|
||||||
|
|
|
@ -125,11 +125,7 @@ TcpTransport.prototype._setupClient = function(client, incoming) {
|
||||||
}
|
}
|
||||||
cache = decoded.rest;
|
cache = decoded.rest;
|
||||||
if (decoded.message) {
|
if (decoded.message) {
|
||||||
self.emit(
|
self.emit("message", decoded.message.command, decoded.message.payload);
|
||||||
"message",
|
|
||||||
decoded.message.command,
|
|
||||||
decoded.message.payload,
|
|
||||||
decoded.message);
|
|
||||||
} else if (decoded.error) {
|
} else if (decoded.error) {
|
||||||
// TODO(Kagami): Wrap it in custom error class?
|
// TODO(Kagami): Wrap it in custom error class?
|
||||||
// TODO(Kagami): Send `error` message and ban node for some time
|
// TODO(Kagami): Send `error` message and ban node for some time
|
||||||
|
|
|
@ -117,7 +117,7 @@ WsTransport.prototype._setupClient = function(client, incoming) {
|
||||||
"Message decoding error: " + err.message
|
"Message decoding error: " + err.message
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
self.emit("message", decoded.command, decoded.payload, decoded);
|
self.emit("message", decoded.command, decoded.payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
// High-level message processing.
|
// High-level message processing.
|
||||||
|
|
|
@ -64,7 +64,7 @@ if (!process.browser) {
|
||||||
|
|
||||||
it("should automatically establish connection", function(done) {
|
it("should automatically establish connection", function(done) {
|
||||||
tcp.once("established", function(version) {
|
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.services.get(ServicesBitfield.NODE_NETWORK)).to.be.true;
|
||||||
expect(version.remoteHost).to.equal("127.0.0.1");
|
expect(version.remoteHost).to.equal("127.0.0.1");
|
||||||
expect(version.port).to.equal(22333);
|
expect(version.port).to.equal(22333);
|
||||||
|
@ -127,6 +127,7 @@ describe("WebSocket transport", function() {
|
||||||
|
|
||||||
it("should automatically establish connection", function(done) {
|
it("should automatically establish connection", function(done) {
|
||||||
ws.once("established", function(version) {
|
ws.once("established", function(version) {
|
||||||
|
expect(version.protoVersion).to.equal(3);
|
||||||
expect(version.services.get(ServicesBitfield.NODE_GATEWAY)).to.be.true;
|
expect(version.services.get(ServicesBitfield.NODE_GATEWAY)).to.be.true;
|
||||||
expect(version.remoteHost).to.equal("127.0.0.1");
|
expect(version.remoteHost).to.equal("127.0.0.1");
|
||||||
expect(version.port).to.equal(22334);
|
expect(version.port).to.equal(22334);
|
||||||
|
|
|
@ -37,7 +37,6 @@ module.exports = function() {
|
||||||
|
|
||||||
process.on("exit", cleanup());
|
process.on("exit", cleanup());
|
||||||
process.on("SIGINT", cleanup(true));
|
process.on("SIGINT", cleanup(true));
|
||||||
process.on("uncaughtException", cleanup(true));
|
|
||||||
|
|
||||||
var tcpNode = spawn("tcp-node.js");
|
var tcpNode = spawn("tcp-node.js");
|
||||||
var wsNode = spawn("ws-node.js");
|
var wsNode = spawn("ws-node.js");
|
||||||
|
|
|
@ -496,7 +496,7 @@ describe("Message types", function() {
|
||||||
});
|
});
|
||||||
expect(message.decode(encoded).command).to.equal("version");
|
expect(message.decode(encoded).command).to.equal("version");
|
||||||
var res = version.decode(encoded);
|
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.services.get(ServicesBitfield.NODE_NETWORK)).to.be.true;
|
||||||
expect(res.time).to.be.instanceof(Date);
|
expect(res.time).to.be.instanceof(Date);
|
||||||
expect(res.remoteHost).to.equal("1.2.3.4");
|
expect(res.remoteHost).to.equal("1.2.3.4");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user