peer: add lastSend and lastRecv.
This commit is contained in:
parent
74ec03607b
commit
d053a25f53
@ -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);
|
||||
|
||||
@ -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();
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user