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