peer: lock fixes. dos fixes.

This commit is contained in:
Christopher Jeffrey 2016-12-18 22:14:50 -08:00
parent 3732260350
commit 1df11caf71
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -995,18 +995,13 @@ Peer.prototype.sendRaw = function sendRaw(cmd, body, checksum) {
*/
Peer.prototype.error = function error(err) {
var i, args, msg;
var i, msg;
if (this.destroyed)
return;
if (typeof err === 'string') {
args = new Array(arguments.length);
for (i = 0; i < args.length; i++)
args[i] = arguments[i];
msg = util.fmt.apply(util, args);
msg = util.fmt.apply(util, arguments);
err = new Error(msg);
}
@ -1029,7 +1024,7 @@ Peer.prototype.request = function request(cmd) {
var entry;
if (self.destroyed)
return reject(new Error('Destroyed'));
return reject(new Error('Request destroyed.'));
entry = new RequestEntry(self, cmd, resolve, reject);
@ -1134,10 +1129,8 @@ Peer.prototype.handlePacket = co(function* handlePacket(packet) {
case packetTypes.GETUTXOS:
case packetTypes.GETBLOCKTXN:
unlock = yield this.locker.lock();
this.socket.pause();
try {
this.socket.pause();
return yield this.onPacket(packet);
} finally {
this.socket.resume();
@ -1342,6 +1335,15 @@ Peer.prototype.handleFilterClear = co(function* handleFilterClear(packet) {
Peer.prototype.handleMerkleBlock = co(function* handleMerkleBlock(packet) {
var block = packet.block;
// Potential DoS.
if (!this.options.spv) {
this.logger.warning(
'Peer sent unsolicited merkleblock (%s).',
this.hostname);
this.increaseBan(100);
return;
}
block.verifyPartial();
this.lastMerkle = block;
@ -2153,6 +2155,13 @@ Peer.prototype.handleSendHeaders = co(function* handleSendHeaders(packet) {
*/
Peer.prototype.handleBlock = co(function* handleBlock(packet) {
if (this.options.spv) {
this.logger.warning(
'Peer sent unsolicited block (%s).',
this.hostname);
return;
}
this.fire('block', packet.block);
});