version.streamNumbers -> version.streams

This commit is contained in:
Kagami Hiiragi 2015-02-24 18:42:57 +03:00
parent 9d535bb25d
commit fe63ccf227
7 changed files with 23 additions and 23 deletions

View File

@ -101,7 +101,7 @@ var version = exports.version = {
* to self * to self
* @property {string} userAgent - [User agent]{@link * @property {string} userAgent - [User agent]{@link
* module:bitmessage/user-agent} of the node * module:bitmessage/user-agent} of the node
* @property {number[]} streamNumbers - Streams accepted by the node * @property {number[]} streams - Streams accepted by the node
* @property {number} length - Real data length * @property {number} length - Real data length
* @memberof module:bitmessage/messages.version * @memberof module:bitmessage/messages.version
*/ */
@ -136,7 +136,7 @@ var version = exports.version = {
buf.copy(nonce, 0, 72, 80); buf.copy(nonce, 0, 72, 80);
assert(!bufferEqual(nonce, randomNonce), "Connection to self"); assert(!bufferEqual(nonce, randomNonce), "Connection to self");
var decodedUa = UserAgent.decode(buf.slice(80)); var decodedUa = UserAgent.decode(buf.slice(80));
var decodedStreamNumbers = structs.var_int_list.decode(decodedUa.rest); var decodedStreams = structs.var_int_list.decode(decodedUa.rest);
return { return {
version: protoVersion, version: protoVersion,
services: services, services: services,
@ -146,12 +146,12 @@ var version = exports.version = {
port: addrFrom.port, port: addrFrom.port,
nonce: nonce, nonce: nonce,
userAgent: decodedUa.str, userAgent: decodedUa.str,
streamNumbers: decodedStreamNumbers.list, streams: decodedStreams.list,
// NOTE(Kagami): Real data length. It may be some gap between end // NOTE(Kagami): Real data length. It may be some gap between end
// of stream numbers list and end of payload: // of stream numbers list and end of payload:
// [payload..............[stream numbers]xxxx] // [payload..............[stream numbers]xxxx]
// We are currently ignoring that. // We are currently ignoring that.
length: 80 + decodedUa.length + decodedStreamNumbers.length, length: 80 + decodedUa.length + decodedStreams.length,
}; };
}, },
@ -174,8 +174,8 @@ var version = exports.version = {
* @param {(Array|string|Buffer)=} opts.userAgent - * @param {(Array|string|Buffer)=} opts.userAgent -
* [User agent]{@link module:bitmessage/user-agent} of the node * [User agent]{@link module:bitmessage/user-agent} of the node
* (user agent of bitmessage library by default) * (user agent of bitmessage library by default)
* @param {Array<number>=} opts.streamNumbers - Streams accepted by the * @param {Array<number>=} opts.streams - Streams accepted by the node
* node ([1] by default) * ([1] by default)
* @return {Buffer} Encoded message. * @return {Buffer} Encoded message.
*/ */
encode: function(opts) { encode: function(opts) {
@ -196,7 +196,7 @@ var version = exports.version = {
assert(nonce.length === 8, "Bad nonce"); assert(nonce.length === 8, "Bad nonce");
var port = opts.port || 8444; var port = opts.port || 8444;
var userAgent = opts.userAgent || UserAgent.SELF; var userAgent = opts.userAgent || UserAgent.SELF;
var streamNumbers = opts.streamNumbers || [1]; var streams = opts.streams || [1];
// Start encoding. // Start encoding.
var protoVersion = new Buffer(4); var protoVersion = new Buffer(4);
protoVersion.writeUInt32BE(util.PROTOCOL_VERSION, 0); protoVersion.writeUInt32BE(util.PROTOCOL_VERSION, 0);
@ -220,7 +220,7 @@ var version = exports.version = {
addrFrom, addrFrom,
nonce, nonce,
UserAgent.encode(userAgent), UserAgent.encode(userAgent),
structs.var_int_list.encode(streamNumbers), structs.var_int_list.encode(streams),
]); ]);
}, },
}; };

View File

@ -157,10 +157,10 @@ BaseTransport.prototype._decodeVersion = function(payload, opts) {
if (delta < -3600) { if (delta < -3600) {
throw new Error("Peer's time is too far in the past: " + delta + "s"); throw new Error("Peer's time is too far in the past: " + delta + "s");
} }
if (!intersects(this.streamNumbers, version.streamNumbers)) { if (!intersects(this.streams, version.streams)) {
throw new Error( throw new Error(
"Peer isn't interested in our streams; " + "Peer isn't interested in our streams; " +
"first 10 peer's streams: " + version.streamNumbers.slice(0, 10) "first 10 peer's streams: " + version.streams.slice(0, 10)
); );
} }
if (opts.network && !version.services.get(ServicesBitfield.NODE_NETWORK)) { if (opts.network && !version.services.get(ServicesBitfield.NODE_NETWORK)) {

View File

@ -60,8 +60,8 @@ var unmap = BaseTransport._unmap;
* @param {(Array|string|Buffer)} opts.userAgent - * @param {(Array|string|Buffer)} opts.userAgent -
* [User agent]{@link module:bitmessage/user-agent} of this node * [User agent]{@link module:bitmessage/user-agent} of this node
* (user agent of bitmessage library by default) * (user agent of bitmessage library by default)
* @param {number[]} opts.streamNumbers - Streams accepted by this node * @param {number[]} opts.streams - Streams accepted by this node ([1]
* ([1] by default) * by default)
* @param {number} opts.port - Incoming port of this node (8444 by * @param {number} opts.port - Incoming port of this node (8444 by
* default) * default)
* @constructor * @constructor
@ -72,7 +72,7 @@ function TcpTransport(opts) {
objectAssign(this, opts); objectAssign(this, opts);
this.seeds = this.seeds || []; this.seeds = this.seeds || [];
this.dnsSeeds = this.dnsSeeds || []; this.dnsSeeds = this.dnsSeeds || [];
this.streamNumbers = this.streamNumbers || [1]; this.streams = this.streams || [1];
this._clients = {}; this._clients = {};
} }
@ -82,7 +82,7 @@ TcpTransport.prototype._sendVersion = function() {
return this.send(messages.version.encode({ return this.send(messages.version.encode({
services: this.services, services: this.services,
userAgent: this.userAgent, userAgent: this.userAgent,
streamNumbers: this.streamNumbers, streams: this.streams,
port: this.port, port: this.port,
remoteHost: this._client.remoteAddress, remoteHost: this._client.remoteAddress,
remotePort: this._client.remotePort, remotePort: this._client.remotePort,

View File

@ -22,7 +22,7 @@ function WsTransport(opts) {
this.services = this.services || ServicesBitfield().set([ this.services = this.services || ServicesBitfield().set([
ServicesBitfield.NODE_MOBILE, ServicesBitfield.NODE_MOBILE,
]); ]);
this.streamNumbers = this.streamNumbers || [1]; this.streams = this.streams || [1];
} }
inherits(WsTransport, BaseTransport); inherits(WsTransport, BaseTransport);
@ -47,7 +47,7 @@ WsTransport.prototype.connect = function(url, protocols) {
self.send(messages.version.encode({ self.send(messages.version.encode({
services: self.services, services: self.services,
userAgent: self.userAgent, userAgent: self.userAgent,
streamNumbers: self.streamNumbers, streams: self.streams,
// This parameters aren't used by the remote node so we fake them // This parameters aren't used by the remote node so we fake them
// (because we can't resolve domain name in a Browser). // (because we can't resolve domain name in a Browser).
remoteHost: "127.0.0.1", remoteHost: "127.0.0.1",

View File

@ -36,8 +36,8 @@ var unmap = BaseTransport._unmap;
* @param {(Array|string|Buffer)} opts.userAgent - * @param {(Array|string|Buffer)} opts.userAgent -
* [User agent]{@link module:bitmessage/user-agent} of this node * [User agent]{@link module:bitmessage/user-agent} of this node
* (user agent of bitmessage library by default) * (user agent of bitmessage library by default)
* @param {number[]} opts.streamNumbers - Streams accepted by this node * @param {number[]} opts.streams - Streams accepted by this node ([1]
* ([1] by default) * by default)
* @param {number} opts.port - Incoming port of this node, makes sence * @param {number} opts.port - Incoming port of this node, makes sence
* only on Node platform (18444 by default) * only on Node platform (18444 by default)
* @constructor * @constructor
@ -51,7 +51,7 @@ function WsTransport(opts) {
ServicesBitfield.NODE_MOBILE, ServicesBitfield.NODE_MOBILE,
ServicesBitfield.NODE_GATEWAY, ServicesBitfield.NODE_GATEWAY,
]); ]);
this.streamNumbers = this.streamNumbers || [1]; this.streams = this.streams || [1];
this.port = this.port || 18444; this.port = this.port || 18444;
} }
@ -61,7 +61,7 @@ WsTransport.prototype._sendVersion = function() {
return this.send(messages.version.encode({ return this.send(messages.version.encode({
services: this.services, services: this.services,
userAgent: this.userAgent, userAgent: this.userAgent,
streamNumbers: this.streamNumbers, streams: this.streams,
port: this.port, port: this.port,
remoteHost: this._client._socket.remoteAddress, remoteHost: this._client._socket.remoteAddress,
remotePort: this._client._socket.remotePort, remotePort: this._client._socket.remotePort,

View File

@ -69,7 +69,7 @@ if (!process.browser) {
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);
expect(version.userAgent).to.be.a("string"); expect(version.userAgent).to.be.a("string");
expect(version.streamNumbers).to.deep.equal([1]); expect(version.streams).to.deep.equal([1]);
done(); done();
}); });
}); });
@ -131,7 +131,7 @@ describe("WebSocket transport", function() {
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);
expect(version.userAgent).to.be.a("string"); expect(version.userAgent).to.be.a("string");
expect(version.streamNumbers).to.deep.equal([1]); expect(version.streams).to.deep.equal([1]);
done(); done();
}); });
}); });

View File

@ -504,7 +504,7 @@ describe("Message types", function() {
expect(res.port).to.equal(8444); expect(res.port).to.equal(8444);
expect(bufferEqual(res.nonce, nonce)).to.be.true; expect(bufferEqual(res.nonce, nonce)).to.be.true;
expect(UserAgent.parse(res.userAgent)).to.deep.equal(UserAgent.SELF); expect(UserAgent.parse(res.userAgent)).to.deep.equal(UserAgent.SELF);
expect(res.streamNumbers).to.deep.equal([1]); expect(res.streams).to.deep.equal([1]);
expect(res.length).to.equal(101); expect(res.length).to.equal(101);
}); });