@dashevo/abci
Advanced tools
Comparing version 0.18.4 to 0.18.5
@@ -0,1 +1,10 @@ | ||
## [0.18.5](https://github.com/tendermint/js-abci/compare/v0.18.3...v0.18.5) (2021-02-16) | ||
### Features | ||
* better handle connection errors ([53cac14](https://github.com/tendermint/js-abci/commit/53cac14b7bed6dced9712e8fd62e98b3d3d58a4b)) | ||
## [0.18.4](https://github.com/tendermint/js-abci/compare/v0.18.3...v0.18.4) (2021-02-16) | ||
@@ -2,0 +11,0 @@ |
{ | ||
"name": "@dashevo/abci", | ||
"version": "0.18.4", | ||
"version": "0.18.5", | ||
"description": "Tenderdash ABCI server", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,41 +45,43 @@ 'use strict' | ||
try { | ||
this.maybeReadNextMessage() | ||
} catch (e) { | ||
e.recvBuf = this.recvBuf.toString('hex') | ||
this.error(e) | ||
} | ||
this.maybeReadNextMessage() | ||
} | ||
maybeReadNextMessage () { | ||
let length = varint.decode(this.recvBuf.slice(0, 8)) >> 1 | ||
let message | ||
let messageLength = varint.decode.bytes | ||
try { | ||
let length = varint.decode(this.recvBuf.slice(0, 8)) >> 1 | ||
if (length > MAX_MESSAGE_SIZE) { | ||
this.error(Error('message is longer than maximum size')) | ||
return | ||
} | ||
let messageLength = varint.decode.bytes | ||
if (messageLength + length > this.recvBuf.length) { | ||
// buffering message, don't read yet | ||
return | ||
} | ||
if (length > MAX_MESSAGE_SIZE) { | ||
this.error(Error('message is longer than maximum size')) | ||
return | ||
} | ||
let messageBytes = this.recvBuf.slice( | ||
messageLength, | ||
messageLength + length | ||
) | ||
if (messageLength + length > this.recvBuf.length) { | ||
// buffering message, don't read yet | ||
return | ||
} | ||
this.recvBuf.consume(messageLength + length) | ||
let messageBytes = this.recvBuf.slice( | ||
messageLength, | ||
messageLength + length | ||
) | ||
let message = Request.decode(messageBytes) | ||
this.recvBuf.consume(messageLength + length) | ||
this.waiting = true | ||
this.stream.pause() | ||
message = Request.decode(messageBytes) | ||
// log incoming messages, except for 'flush' | ||
if (!message.flush) { | ||
debug('<<', message) | ||
this.waiting = true | ||
this.stream.pause() | ||
// log incoming messages, except for 'flush' | ||
if (!message.flush) { | ||
debug('<<', message) | ||
} | ||
} catch (e) { | ||
e.recvBuf = this.recvBuf.toString('hex') | ||
this.error(e) | ||
} | ||
@@ -98,8 +100,4 @@ | ||
write (message) { | ||
this._write(message) | ||
.catch((err) => this.emit('error', err, true)) | ||
} | ||
Response.verify(message) | ||
async _write (message) { | ||
Response.verify(message) | ||
// log outgoing messages, except for 'flush' | ||
@@ -109,6 +107,13 @@ if (debug.enabled && !message.flush) { | ||
} | ||
let messageBytes = Response.encode(message).finish() | ||
let lengthBytes = varint.encode(messageBytes.length << 1) | ||
this.stream.write(Buffer.from(lengthBytes)) | ||
this.stream.write(messageBytes) | ||
try { | ||
this.stream.write(Buffer.from(lengthBytes)) | ||
this.stream.write(messageBytes) | ||
} catch (e) { | ||
this.error(e, true) | ||
} | ||
} | ||
@@ -115,0 +120,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1846455
33838