peer: add lastSend and lastRecv.

This commit is contained in:
Christopher Jeffrey 2016-08-17 03:20:34 -07:00
parent 74ec03607b
commit d053a25f53
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 9 additions and 1 deletions

View File

@ -108,6 +108,8 @@ function Peer(pool, options) {
this.compactBlocks = {};
this.sentAddr = false;
this.bip151 = null;
this.lastSend = 0;
this.lastRecv = 0;
if (this.pool.options.bip151)
this.bip151 = new bcoin.bip151();
@ -673,6 +675,8 @@ Peer.prototype.write = function write(chunk) {
if (this.destroyed)
return false;
this.lastSend = utils.ms();
return this.socket.write(chunk);
};
@ -824,6 +828,8 @@ Peer.prototype._onPacket = function onPacket(packet) {
if (this.lastBlock && cmd !== 'tx')
this._flushMerkle();
this.lastRecv = utils.ms();
switch (cmd) {
case 'version':
return this._handleVersion(payload);

View File

@ -1007,7 +1007,7 @@ utils.testTarget = function testTarget(hash, target) {
*/
utils.now = function now() {
return Math.floor(+new Date() / 1000);
return Math.floor(utils.ms() / 1000);
};
/**
@ -1016,6 +1016,8 @@ utils.now = function now() {
*/
utils.ms = function ms() {
if (Date.now)
return Date.now();
return +new Date();
};