bip151: minor.
This commit is contained in:
parent
d6576c51f1
commit
58a5372b09
@ -31,7 +31,7 @@ var HKDF_SALT = new Buffer('bitcoinecdh', 'ascii');
|
|||||||
var INFO_KEY1 = new Buffer('BitcoinK1', 'ascii');
|
var INFO_KEY1 = new Buffer('BitcoinK1', 'ascii');
|
||||||
var INFO_KEY2 = new Buffer('BitcoinK2', 'ascii');
|
var INFO_KEY2 = new Buffer('BitcoinK2', 'ascii');
|
||||||
var INFO_SID = new Buffer('BitcoinSessionID', '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.
|
* Represents a BIP151 input or output stream.
|
||||||
@ -122,7 +122,7 @@ BIP151Stream.prototype.shouldRekey = function shouldRekey(data) {
|
|||||||
this.processed += data.length;
|
this.processed += data.length;
|
||||||
|
|
||||||
if (now >= this.lastRekey + 10
|
if (now >= this.lastRekey + 10
|
||||||
|| this.processed >= HIGH_WATER_MARK) {
|
|| this.processed >= HIGH_WATERMARK) {
|
||||||
this.lastRekey = now;
|
this.lastRekey = now;
|
||||||
this.processed = 0;
|
this.processed = 0;
|
||||||
return true;
|
return true;
|
||||||
@ -408,11 +408,14 @@ BIP151.prototype.encack = function encack(publicKey) {
|
|||||||
|
|
||||||
if (utils.equal(publicKey, constants.ZERO_KEY)) {
|
if (utils.equal(publicKey, constants.ZERO_KEY)) {
|
||||||
assert(this.handshake, 'No initialization before rekey.');
|
assert(this.handshake, 'No initialization before rekey.');
|
||||||
|
|
||||||
if (this.bip150 && this.bip150.auth) {
|
if (this.bip150 && this.bip150.auth) {
|
||||||
this.bip150.rekeyInput();
|
this.bip150.rekeyInput();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.input.rekey();
|
this.input.rekey();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,10 +618,10 @@ BIP151.prototype.parse = function parse(data) {
|
|||||||
// from buffering tons of data due to either an
|
// from buffering tons of data due to either an
|
||||||
// potential dos'er or a cipher state mismatch.
|
// potential dos'er or a cipher state mismatch.
|
||||||
// Note that 6 is the minimum size:
|
// 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) {
|
if (size < 6 || size > constants.MAX_MESSAGE * 3) {
|
||||||
this.waiting = 4;
|
this.waiting = 4;
|
||||||
this.error('Bad packet size.');
|
this.error('Bad packet size: %d.', utils.mb(size));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,7 +645,7 @@ BIP151.prototype.parse = function parse(data) {
|
|||||||
|
|
||||||
if (!this.input.verify(tag)) {
|
if (!this.input.verify(tag)) {
|
||||||
this.input.sequence();
|
this.input.sequence();
|
||||||
this.error('Bad tag.');
|
this.error('Bad tag: %s.', tag.toString('hex'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user