Expose "expires" field for objects
This commit is contained in:
parent
f29f32b3aa
commit
da0eb28eb6
|
@ -94,6 +94,7 @@ var getpubkey = exports.getpubkey = {
|
|||
* @typedef {Object} DecodeResult
|
||||
* @property {Buffer} nonce - A 8-byte object nonce
|
||||
* @property {number} ttl - Time to live in seconds
|
||||
* @property {Date} expires - Object expiration date
|
||||
* @property {number} type - Object type
|
||||
* @property {number} version - Object version
|
||||
* @property {number} stream - Object stream
|
||||
|
@ -254,6 +255,7 @@ var pubkey = exports.pubkey = {
|
|||
* @typedef {Object} DecodeResult
|
||||
* @property {Buffer} nonce - A 8-byte object nonce
|
||||
* @property {number} ttl - Time to live in seconds
|
||||
* @property {Date} expires - Object expiration date
|
||||
* @property {number} type - Object type
|
||||
* @property {number} version - Object version
|
||||
* @property {number} stream - Object stream
|
||||
|
@ -587,6 +589,7 @@ var msg = exports.msg = {
|
|||
* @typedef {Object} DecodeResult
|
||||
* @property {Buffer} nonce - A 8-byte object nonce
|
||||
* @property {number} ttl - Time to live in seconds
|
||||
* @property {Date} expires - Object expiration date
|
||||
* @property {number} type - Object type
|
||||
* @property {number} version - Object version
|
||||
* @property {number} stream - Object stream
|
||||
|
@ -877,6 +880,7 @@ var broadcast = exports.broadcast = {
|
|||
* @typedef {Object} DecodeResult
|
||||
* @property {Buffer} nonce - A 8-byte object nonce
|
||||
* @property {number} ttl - Time to live in seconds
|
||||
* @property {Date} expires - Object expiration date
|
||||
* @property {number} type - Object type
|
||||
* @property {number} version - Object version
|
||||
* @property {number} stream - Object stream
|
||||
|
|
|
@ -304,6 +304,7 @@ var object = exports.object = {
|
|||
* @typedef {Object} DecodeResult
|
||||
* @property {Buffer} nonce - A 8-byte object nonce
|
||||
* @property {number} ttl - Time to live in seconds
|
||||
* @property {Date} expires - Object expiration date
|
||||
* @property {number} type - Object type
|
||||
* @property {number} version - Object version
|
||||
* @property {number} stream - Object stream
|
||||
|
@ -347,6 +348,7 @@ var object = exports.object = {
|
|||
|
||||
// TTL.
|
||||
var expiresTime = util.readTimestamp64BE(buf.slice(8, 16));
|
||||
var expires = new Date(expiresTime * 1000);
|
||||
var ttl = expiresTime - util.tnow();
|
||||
assert(ttl <= 2430000, "expiresTime is too far in the future");
|
||||
if (!opts.allowExpired) {
|
||||
|
@ -375,6 +377,7 @@ var object = exports.object = {
|
|||
return {
|
||||
nonce: nonce,
|
||||
ttl: ttl,
|
||||
expires: expires,
|
||||
type: type,
|
||||
version: decodedVersion.value,
|
||||
stream: decodedStream.value,
|
||||
|
|
6
test.js
6
test.js
|
@ -187,6 +187,7 @@ describe("Common structures", function() {
|
|||
describe("object", function() {
|
||||
it("should encode and decode", function() {
|
||||
var nonce = Buffer(8);
|
||||
var now = new Date().getTime();
|
||||
var res = object.decode(object.encode({
|
||||
nonce: nonce,
|
||||
ttl: 100,
|
||||
|
@ -197,6 +198,8 @@ describe("Common structures", function() {
|
|||
|
||||
expect(bufferEqual(nonce, res.nonce)).to.be.true;
|
||||
expect(res.ttl).to.be.at.most(100);
|
||||
expect(res.expires.getTime()).to.be.at.least(now);
|
||||
expect(res.expires.getTime()).to.be.at.most(now + 100*1000);
|
||||
expect(res.type).to.equal(2);
|
||||
expect(res.version).to.equal(1);
|
||||
expect(res.stream).to.equal(1);
|
||||
|
@ -789,6 +792,7 @@ describe("Object types", function() {
|
|||
|
||||
describe("pubkey", function() {
|
||||
it("should encode and decode pubkey v2", function() {
|
||||
var now = new Date().getTime();
|
||||
return pubkey.encodeAsync({
|
||||
ttl: 123,
|
||||
from: from,
|
||||
|
@ -799,6 +803,8 @@ describe("Object types", function() {
|
|||
return pubkey.decodeAsync(buf, skipPow);
|
||||
}).then(function(res) {
|
||||
expect(res.ttl).to.be.at.most(123);
|
||||
expect(res.expires.getTime()).to.be.at.least(now);
|
||||
expect(res.expires.getTime()).to.be.at.most(now + 123*1000);
|
||||
expect(res.type).to.equal(object.PUBKEY);
|
||||
expect(res.version).to.equal(2);
|
||||
expect(res.stream).to.equal(1);
|
||||
|
|
Loading…
Reference in New Issue
Block a user