Imply NODE_NETWORK in net_addr.encode by default

This commit is contained in:
Kagami Hiiragi 2015-01-06 02:34:15 +03:00
parent 0a6aa667db
commit 3187e9d766
2 changed files with 3 additions and 2 deletions

View File

@ -397,7 +397,8 @@ exports.net_addr = {
buf.writeUInt32BE(opts.stream, 8);
shift = 12;
}
serviceFeatures.encode(opts.services).copy(buf, shift);
var services = opts.services || [serviceFeatures.NODE_NETWORK];
serviceFeatures.encode(services).copy(buf, shift);
inet_pton(opts.host).copy(buf, shift + 8);
buf.writeUInt16BE(opts.port, shift + 24);
return buf;

View File

@ -201,7 +201,7 @@ describe("Common structures", function() {
var time = new Date(1420490432000);
expect(net_addr.encode({time: time, stream: 1, services: [serviceFeatures.NODE_NETWORK], host: "127.0.0.1", port: 8444}).toString("hex")).to.equal("0000000054aaf6c000000001000000000000000100000000000000000000ffff7f00000120fc");
expect(net_addr.encode({short: true, services: [serviceFeatures.NODE_NETWORK], host: "127.0.0.1", port: 8444}).toString("hex")).to.equal("000000000000000100000000000000000000ffff7f00000120fc");
expect(net_addr.encode({short: true, services: [serviceFeatures.NODE_NETWORK], host: "::1", port: 65000}).toString("hex")).to.equal("000000000000000100000000000000000000000000000001fde8");
expect(net_addr.encode({short: true, host: "::1", port: 65000}).toString("hex")).to.equal("000000000000000100000000000000000000000000000001fde8");
});
});