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

View File

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

View File

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

View File

@ -36,8 +36,8 @@ var unmap = BaseTransport._unmap;
* @param {(Array|string|Buffer)} opts.userAgent -
* [User agent]{@link module:bitmessage/user-agent} of this node
* (user agent of bitmessage library by default)
* @param {number[]} opts.streamNumbers - Streams accepted by this node
* ([1] by default)
* @param {number[]} opts.streams - Streams accepted by this node ([1]
* by default)
* @param {number} opts.port - Incoming port of this node, makes sence
* only on Node platform (18444 by default)
* @constructor
@ -51,7 +51,7 @@ function WsTransport(opts) {
ServicesBitfield.NODE_MOBILE,
ServicesBitfield.NODE_GATEWAY,
]);
this.streamNumbers = this.streamNumbers || [1];
this.streams = this.streams || [1];
this.port = this.port || 18444;
}
@ -61,7 +61,7 @@ WsTransport.prototype._sendVersion = function() {
return this.send(messages.version.encode({
services: this.services,
userAgent: this.userAgent,
streamNumbers: this.streamNumbers,
streams: this.streams,
port: this.port,
remoteHost: this._client._socket.remoteAddress,
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.port).to.equal(22333);
expect(version.userAgent).to.be.a("string");
expect(version.streamNumbers).to.deep.equal([1]);
expect(version.streams).to.deep.equal([1]);
done();
});
});
@ -131,7 +131,7 @@ describe("WebSocket transport", function() {
expect(version.remoteHost).to.equal("127.0.0.1");
expect(version.port).to.equal(22334);
expect(version.userAgent).to.be.a("string");
expect(version.streamNumbers).to.deep.equal([1]);
expect(version.streams).to.deep.equal([1]);
done();
});
});

View File

@ -504,7 +504,7 @@ describe("Message types", function() {
expect(res.port).to.equal(8444);
expect(bufferEqual(res.nonce, nonce)).to.be.true;
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);
});