bip151: max message size.

This commit is contained in:
Christopher Jeffrey 2016-07-25 21:44:34 -07:00
parent 94af094322
commit 73deb5430e
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -79,7 +79,6 @@ BIP151Stream.prototype.init = function init(publicKey) {
};
BIP151Stream.prototype.maybeRekey = function maybeRekey(data) {
var self = this;
this.processed += data.length;
if (this.processed >= this.highWaterMark) {
this.processed -= this.highWaterMark;
@ -171,7 +170,11 @@ BIP151Stream.prototype.feed = function feed(data) {
this.waiting = this.decryptSize(chunk) + 16;
if (this.waiting - 32 > constants.MAX_MESSAGE) {
// Allow 3 batched packets of max message size.
// Not technically standard, but this protects us
// from buffering tons of data due to either an
// potential dos'er or a cipher state mismatch.
if (this.waiting - 32 > constants.MAX_MESSAGE * 3) {
this.waiting = 0;
this.emit('error', new Error('Packet too large.'));
continue;