Rename option inventory -> vectors
This commit is contained in:
parent
542d31d387
commit
956d58ce2f
|
@ -366,8 +366,8 @@ var addr = exports.addr = {
|
||||||
var inv = exports.inv = {
|
var inv = exports.inv = {
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} DecodeResult
|
* @typedef {Object} DecodeResult
|
||||||
* @property {Buffer[]} inventory - List of
|
* @property {Buffer[]} vectors - List of [inventory vectors]{@link
|
||||||
* [inventory vectors]{@link module:bitmessage/structs.inv_vect}
|
* module:bitmessage/structs.inv_vect}
|
||||||
* @property {number} length - Real data length
|
* @property {number} length - Real data length
|
||||||
* @memberof module:bitmessage/messages.inv
|
* @memberof module:bitmessage/messages.inv
|
||||||
*/
|
*/
|
||||||
|
@ -391,16 +391,16 @@ var inv = exports.inv = {
|
||||||
decodePayload: function(buf) {
|
decodePayload: function(buf) {
|
||||||
var decoded = structs.var_int.decode(buf);
|
var decoded = structs.var_int.decode(buf);
|
||||||
var listLength = decoded.value;
|
var listLength = decoded.value;
|
||||||
assert(listLength <= 50000, "Too many inventory entires");
|
assert(listLength <= 50000, "Too many vectors");
|
||||||
var length = decoded.length + listLength * 32;
|
var length = decoded.length + listLength * 32;
|
||||||
assert(buf.length >= length, "Buffer is too small");
|
assert(buf.length >= length, "Buffer is too small");
|
||||||
var rest = decoded.rest;
|
var rest = decoded.rest;
|
||||||
var inventory = new Array(listLength);
|
var vectors = new Array(listLength);
|
||||||
for (var i = 0; i < listLength; i++) {
|
for (var i = 0; i < listLength; i++) {
|
||||||
inventory[i] = rest.slice(i*32, (i+1)*32);
|
vectors[i] = rest.slice(i*32, (i+1)*32);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
inventory: inventory,
|
vectors: vectors,
|
||||||
// Real data length.
|
// Real data length.
|
||||||
length: length,
|
length: length,
|
||||||
};
|
};
|
||||||
|
@ -408,12 +408,12 @@ var inv = exports.inv = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode `inv` message.
|
* Encode `inv` message.
|
||||||
* @param {Buffer[]} inventory -
|
* @param {Buffer[]} vectors - [Inventory vector]{@link
|
||||||
* [Inventory vector]{@link module:bitmessage/structs.inv_vect} list
|
* module:bitmessage/structs.inv_vect} list
|
||||||
* @return {Buffer} Encoded message.
|
* @return {Buffer} Encoded message.
|
||||||
*/
|
*/
|
||||||
encode: function(inventory) {
|
encode: function(vectors) {
|
||||||
var payload = inv.encodePayload(inventory);
|
var payload = inv.encodePayload(vectors);
|
||||||
return message.encode("inv", payload);
|
return message.encode("inv", payload);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -421,10 +421,10 @@ var inv = exports.inv = {
|
||||||
* Encode `inv` message payload.
|
* Encode `inv` message payload.
|
||||||
* The same as [encode]{@link module:bitmessage/messages.inv.encode}.
|
* The same as [encode]{@link module:bitmessage/messages.inv.encode}.
|
||||||
*/
|
*/
|
||||||
encodePayload: function(inventory) {
|
encodePayload: function(vectors) {
|
||||||
assert(inventory.length <= 50000, "Too many inventory entires");
|
assert(vectors.length <= 50000, "Too many vectors");
|
||||||
// TODO(Kagami): Validate vectors length.
|
// TODO(Kagami): Validate vectors length.
|
||||||
var bufs = [structs.var_int.encode(inventory.length)].concat(inventory);
|
var bufs = [structs.var_int.encode(vectors.length)].concat(vectors);
|
||||||
return Buffer.concat(bufs);
|
return Buffer.concat(bufs);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -439,8 +439,8 @@ var inv = exports.inv = {
|
||||||
exports.getdata = objectAssign({}, inv, {
|
exports.getdata = objectAssign({}, inv, {
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} DecodeResult
|
* @typedef {Object} DecodeResult
|
||||||
* @property {Buffer[]} inventory - List of
|
* @property {Buffer[]} vectors - List of [inventory vectors]{@link
|
||||||
* [inventory vectors]{@link module:bitmessage/structs.inv_vect}
|
* module:bitmessage/structs.inv_vect}
|
||||||
* @property {number} length - Real data length
|
* @property {number} length - Real data length
|
||||||
* @memberof module:bitmessage/messages.getdata
|
* @memberof module:bitmessage/messages.getdata
|
||||||
*/
|
*/
|
||||||
|
@ -467,13 +467,13 @@ exports.getdata = objectAssign({}, inv, {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode `getdata` message.
|
* Encode `getdata` message.
|
||||||
* @param {Buffer[]} inventory -
|
* @param {Buffer[]} vectors - [Inventory vector]{@link
|
||||||
* [Inventory vector]{@link module:bitmessage/structs.inv_vect} list
|
* module:bitmessage/structs.inv_vect} list
|
||||||
* @return {Buffer} Encoded message.
|
* @return {Buffer} Encoded message.
|
||||||
* @memberof module:bitmessage/messages.getdata
|
* @memberof module:bitmessage/messages.getdata
|
||||||
*/
|
*/
|
||||||
encode: function(inventory) {
|
encode: function(vectors) {
|
||||||
var payload = inv.encodePayload(inventory);
|
var payload = inv.encodePayload(vectors);
|
||||||
return message.encode("getdata", payload);
|
return message.encode("getdata", payload);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -530,9 +530,8 @@ var error = exports.error = {
|
||||||
* @property {number} type - Type of the error
|
* @property {number} type - Type of the error
|
||||||
* @property {number} banTime - The other node informs that it will
|
* @property {number} banTime - The other node informs that it will
|
||||||
* not accept further connections for this number of seconds
|
* not accept further connections for this number of seconds
|
||||||
* @property {?Buffer} vector -
|
* @property {?Buffer} vector - [Inventory vector]{@link
|
||||||
* [Inventory vector]{@link module:bitmessage/structs.inv_vect}
|
* module:bitmessage/structs.inv_vect} related to the error
|
||||||
* related to the error
|
|
||||||
* @property {string} errorText - A human-readable error description
|
* @property {string} errorText - A human-readable error description
|
||||||
* @property {number} length - Real data length
|
* @property {number} length - Real data length
|
||||||
* @memberof module:bitmessage/messages.error
|
* @memberof module:bitmessage/messages.error
|
||||||
|
@ -598,9 +597,9 @@ var error = exports.error = {
|
||||||
* @param {number=} opts.banTime - Inform the other node, that you
|
* @param {number=} opts.banTime - Inform the other node, that you
|
||||||
* will not accept further connections for this number of seconds (0
|
* will not accept further connections for this number of seconds (0
|
||||||
* by default)
|
* by default)
|
||||||
* @param {Buffer=} opts.vector - A 32-byte
|
* @param {Buffer=} opts.vector - A 32-byte [inventory vector]{@link
|
||||||
* [inventory vector]{@link module:bitmessage/structs.inv_vect}
|
* module:bitmessage/structs.inv_vect} related to the error (empty by
|
||||||
* related to the error (empty by default)
|
* default)
|
||||||
* @param {string} opts.errorText - A human-readable error description
|
* @param {string} opts.errorText - A human-readable error description
|
||||||
* @return {Buffer} Encoded message.
|
* @return {Buffer} Encoded message.
|
||||||
*/
|
*/
|
||||||
|
|
20
test.js
20
test.js
|
@ -599,13 +599,13 @@ describe("Message types", function() {
|
||||||
it("should encode and decode", function() {
|
it("should encode and decode", function() {
|
||||||
var vect1 = inv_vect.encode(Buffer("test"));
|
var vect1 = inv_vect.encode(Buffer("test"));
|
||||||
var vect2 = inv_vect.encode(Buffer("test2"));
|
var vect2 = inv_vect.encode(Buffer("test2"));
|
||||||
var inventory = [vect1, vect2];
|
var vectors = [vect1, vect2];
|
||||||
var encoded = inv.encode(inventory);
|
var encoded = inv.encode(vectors);
|
||||||
expect(message.decode(encoded).command).to.equal("inv");
|
expect(message.decode(encoded).command).to.equal("inv");
|
||||||
var res = inv.decode(encoded);
|
var res = inv.decode(encoded);
|
||||||
expect(res.inventory.length).to.equal(2);
|
expect(res.vectors.length).to.equal(2);
|
||||||
expect(bufferEqual(res.inventory[0], vect1)).to.be.true;
|
expect(bufferEqual(res.vectors[0], vect1)).to.be.true;
|
||||||
expect(bufferEqual(res.inventory[1], vect2)).to.be.true;
|
expect(bufferEqual(res.vectors[1], vect2)).to.be.true;
|
||||||
expect(res.length).to.equal(65);
|
expect(res.length).to.equal(65);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -619,13 +619,13 @@ describe("Message types", function() {
|
||||||
it("should encode and decode", function() {
|
it("should encode and decode", function() {
|
||||||
var vect1 = inv_vect.encode(Buffer("test"));
|
var vect1 = inv_vect.encode(Buffer("test"));
|
||||||
var vect2 = inv_vect.encode(Buffer("test2"));
|
var vect2 = inv_vect.encode(Buffer("test2"));
|
||||||
var inventory = [vect1, vect2];
|
var vectors = [vect1, vect2];
|
||||||
var encoded = getdata.encode(inventory);
|
var encoded = getdata.encode(vectors);
|
||||||
expect(message.decode(encoded).command).to.equal("getdata");
|
expect(message.decode(encoded).command).to.equal("getdata");
|
||||||
var res = getdata.decode(encoded);
|
var res = getdata.decode(encoded);
|
||||||
expect(res.inventory.length).to.equal(2);
|
expect(res.vectors.length).to.equal(2);
|
||||||
expect(bufferEqual(res.inventory[0], vect1)).to.be.true;
|
expect(bufferEqual(res.vectors[0], vect1)).to.be.true;
|
||||||
expect(bufferEqual(res.inventory[1], vect2)).to.be.true;
|
expect(bufferEqual(res.vectors[1], vect2)).to.be.true;
|
||||||
expect(res.length).to.equal(65);
|
expect(res.length).to.equal(65);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user