From 58a5372b0969f4ee696d849bb147819e29bc6878 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 16 Sep 2016 19:26:24 -0700 Subject: [PATCH] bip151: minor. --- lib/net/bip151.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/net/bip151.js b/lib/net/bip151.js index cbb92436..00d39e87 100644 --- a/lib/net/bip151.js +++ b/lib/net/bip151.js @@ -31,7 +31,7 @@ var HKDF_SALT = new Buffer('bitcoinecdh', 'ascii'); var INFO_KEY1 = new Buffer('BitcoinK1', 'ascii'); var INFO_KEY2 = new Buffer('BitcoinK2', 'ascii'); var INFO_SID = new Buffer('BitcoinSessionID', 'ascii'); -var HIGH_WATER_MARK = 1024 * (1 << 20); +var HIGH_WATERMARK = 1024 * (1 << 20); /** * Represents a BIP151 input or output stream. @@ -122,7 +122,7 @@ BIP151Stream.prototype.shouldRekey = function shouldRekey(data) { this.processed += data.length; if (now >= this.lastRekey + 10 - || this.processed >= HIGH_WATER_MARK) { + || this.processed >= HIGH_WATERMARK) { this.lastRekey = now; this.processed = 0; return true; @@ -408,11 +408,14 @@ BIP151.prototype.encack = function encack(publicKey) { if (utils.equal(publicKey, constants.ZERO_KEY)) { assert(this.handshake, 'No initialization before rekey.'); + if (this.bip150 && this.bip150.auth) { this.bip150.rekeyInput(); return; } + this.input.rekey(); + return; } @@ -615,10 +618,10 @@ BIP151.prototype.parse = function parse(data) { // from buffering tons of data due to either an // potential dos'er or a cipher state mismatch. // Note that 6 is the minimum size: - // varinti-clen(1) string-cmd(1) uint32-size(4) data(0) + // varint-cmdlen(1) str-cmd(1) u32-size(4) payload(0) if (size < 6 || size > constants.MAX_MESSAGE * 3) { this.waiting = 4; - this.error('Bad packet size.'); + this.error('Bad packet size: %d.', utils.mb(size)); return; } @@ -642,7 +645,7 @@ BIP151.prototype.parse = function parse(data) { if (!this.input.verify(tag)) { this.input.sequence(); - this.error('Bad tag.'); + this.error('Bad tag: %s.', tag.toString('hex')); return; }