peer: lock fixes. dos fixes.
This commit is contained in:
parent
3732260350
commit
1df11caf71
@ -995,18 +995,13 @@ Peer.prototype.sendRaw = function sendRaw(cmd, body, checksum) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Peer.prototype.error = function error(err) {
|
Peer.prototype.error = function error(err) {
|
||||||
var i, args, msg;
|
var i, msg;
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (typeof err === 'string') {
|
if (typeof err === 'string') {
|
||||||
args = new Array(arguments.length);
|
msg = util.fmt.apply(util, arguments);
|
||||||
|
|
||||||
for (i = 0; i < args.length; i++)
|
|
||||||
args[i] = arguments[i];
|
|
||||||
|
|
||||||
msg = util.fmt.apply(util, args);
|
|
||||||
err = new Error(msg);
|
err = new Error(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1029,7 +1024,7 @@ Peer.prototype.request = function request(cmd) {
|
|||||||
var entry;
|
var entry;
|
||||||
|
|
||||||
if (self.destroyed)
|
if (self.destroyed)
|
||||||
return reject(new Error('Destroyed'));
|
return reject(new Error('Request destroyed.'));
|
||||||
|
|
||||||
entry = new RequestEntry(self, cmd, resolve, reject);
|
entry = new RequestEntry(self, cmd, resolve, reject);
|
||||||
|
|
||||||
@ -1134,10 +1129,8 @@ Peer.prototype.handlePacket = co(function* handlePacket(packet) {
|
|||||||
case packetTypes.GETUTXOS:
|
case packetTypes.GETUTXOS:
|
||||||
case packetTypes.GETBLOCKTXN:
|
case packetTypes.GETBLOCKTXN:
|
||||||
unlock = yield this.locker.lock();
|
unlock = yield this.locker.lock();
|
||||||
|
|
||||||
this.socket.pause();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.socket.pause();
|
||||||
return yield this.onPacket(packet);
|
return yield this.onPacket(packet);
|
||||||
} finally {
|
} finally {
|
||||||
this.socket.resume();
|
this.socket.resume();
|
||||||
@ -1342,6 +1335,15 @@ Peer.prototype.handleFilterClear = co(function* handleFilterClear(packet) {
|
|||||||
Peer.prototype.handleMerkleBlock = co(function* handleMerkleBlock(packet) {
|
Peer.prototype.handleMerkleBlock = co(function* handleMerkleBlock(packet) {
|
||||||
var block = packet.block;
|
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();
|
block.verifyPartial();
|
||||||
|
|
||||||
this.lastMerkle = block;
|
this.lastMerkle = block;
|
||||||
@ -2153,6 +2155,13 @@ Peer.prototype.handleSendHeaders = co(function* handleSendHeaders(packet) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Peer.prototype.handleBlock = co(function* handleBlock(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);
|
this.fire('block', packet.block);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user