Use MSB 0 for pubkey behavior bitfield

This commit is contained in:
Kagami Hiiragi 2015-01-19 00:50:57 +03:00
parent 0cd386d65c
commit 5d812eba47
2 changed files with 9 additions and 6 deletions

View File

@ -496,7 +496,7 @@ exports.encrypted = {
}, },
}; };
// Creates bitfield class of the specified size. // Creates bitfield (LSB 0) class of the specified size.
var bitfield = function(size) { var bitfield = function(size) {
var bytesize = size / 8; var bytesize = size / 8;
return { return {
@ -550,16 +550,19 @@ var serviceFeatures = exports.serviceFeatures = objectAssign(bitfield(64), {
* @namespace * @namespace
*/ */
// TODO(Kagami): Document methods. // TODO(Kagami): Document methods.
// XXX(Kagami): PyBitmessage uses MSB 0 scheme for this bitfield so we
// invert the numberes. See
// <https://github.com/Bitmessage/PyBitmessage/issues/769> for details.
exports.pubkeyFeatures = objectAssign(bitfield(32), { exports.pubkeyFeatures = objectAssign(bitfield(32), {
/** /**
* Receiving node expects that the RIPE hash encoded in their address * Receiving node expects that the RIPE hash encoded in their address
* preceedes the encrypted message data of msg messages bound for * preceedes the encrypted message data of msg messages bound for
* them. * them.
*/ */
INCLUDE_DESTINATION: 30, INCLUDE_DESTINATION: 1,
/** /**
* If true, the receiving node does send acknowledgements (rather than * If true, the receiving node does send acknowledgements (rather than
* dropping them). * dropping them).
*/ */
DOES_ACK: 31, DOES_ACK: 0,
}); });

View File

@ -277,12 +277,12 @@ describe("Common structures", function() {
describe("pubkey features", function() { describe("pubkey features", function() {
it("should decode", function() { it("should decode", function() {
expect(pubkeyFeatures.decode(Buffer("c0000000", "hex"))).to.have.members([pubkeyFeatures.DOES_ACK, pubkeyFeatures.INCLUDE_DESTINATION]); expect(pubkeyFeatures.decode(Buffer("00000003", "hex"))).to.have.members([pubkeyFeatures.DOES_ACK, pubkeyFeatures.INCLUDE_DESTINATION]);
}); });
it("should encode", function() { it("should encode", function() {
expect(pubkeyFeatures.encode([pubkeyFeatures.INCLUDE_DESTINATION, pubkeyFeatures.DOES_ACK]).toString("hex")).to.equal("c0000000"); expect(pubkeyFeatures.encode([pubkeyFeatures.INCLUDE_DESTINATION, pubkeyFeatures.DOES_ACK]).toString("hex")).to.equal("00000003");
expect(pubkeyFeatures.encode(pubkeyFeatures.INCLUDE_DESTINATION).toString("hex")).to.equal("40000000"); expect(pubkeyFeatures.encode(pubkeyFeatures.DOES_ACK).toString("hex")).to.equal("00000001");
}); });
}); });
}); });