peer: better options handling and logs.
This commit is contained in:
parent
215a3ad6fc
commit
c18bb98b3c
@ -1561,22 +1561,24 @@ Peer.prototype._sendBlock = co(function* _sendBlock(item, witness) {
|
|||||||
|
|
||||||
// If we have the same serialization, we
|
// If we have the same serialization, we
|
||||||
// can write the raw binary to the socket.
|
// can write the raw binary to the socket.
|
||||||
if (witness === !!this.options.witness) {
|
if (witness === this.chain.db.options.witness) {
|
||||||
block = yield this.chain.db.getRawBlock(item.hash);
|
block = yield this.chain.db.getRawBlock(item.hash);
|
||||||
|
|
||||||
if (!block)
|
if (!block)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
yield this.sendRaw('block', block);
|
yield this.sendRaw('block', block);
|
||||||
} else {
|
|
||||||
block = yield this.chain.db.getBlock(item.hash);
|
|
||||||
|
|
||||||
if (!block)
|
return true;
|
||||||
return false;
|
|
||||||
|
|
||||||
yield this.send(new packets.BlockPacket(block, witness));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
block = yield this.chain.db.getBlock(item.hash);
|
||||||
|
|
||||||
|
if (!block)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
yield this.send(new packets.BlockPacket(block, witness));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1610,6 +1612,9 @@ Peer.prototype._sendCompactBlock = function _sendCompactBlock(block, witness) {
|
|||||||
|
|
||||||
Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
||||||
var notFound = [];
|
var notFound = [];
|
||||||
|
var txs = 0;
|
||||||
|
var blocks = 0;
|
||||||
|
var unknown = -1;
|
||||||
var items = packet.items;
|
var items = packet.items;
|
||||||
var i, j, item, tx, block, result;
|
var i, j, item, tx, block, result;
|
||||||
|
|
||||||
@ -1639,6 +1644,8 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
|||||||
|
|
||||||
yield this.send(new packets.TXPacket(tx, item.hasWitness()));
|
yield this.send(new packets.TXPacket(tx, item.hasWitness()));
|
||||||
|
|
||||||
|
txs++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1650,6 +1657,7 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
|||||||
notFound.push(item);
|
notFound.push(item);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
blocks++;
|
||||||
break;
|
break;
|
||||||
case constants.inv.FILTERED_BLOCK:
|
case constants.inv.FILTERED_BLOCK:
|
||||||
case constants.inv.WITNESS_FILTERED_BLOCK:
|
case constants.inv.WITNESS_FILTERED_BLOCK:
|
||||||
@ -1672,8 +1680,11 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
|||||||
for (j = 0; j < block.txs.length; j++) {
|
for (j = 0; j < block.txs.length; j++) {
|
||||||
tx = block.txs[j];
|
tx = block.txs[j];
|
||||||
yield this.send(new packets.TXPacket(tx, item.hasWitness()));
|
yield this.send(new packets.TXPacket(tx, item.hasWitness()));
|
||||||
|
txs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blocks++;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case constants.inv.CMPCT_BLOCK:
|
case constants.inv.CMPCT_BLOCK:
|
||||||
// Fallback to full block.
|
// Fallback to full block.
|
||||||
@ -1683,6 +1694,7 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
|||||||
notFound.push(item);
|
notFound.push(item);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
blocks++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1695,12 +1707,11 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
|||||||
|
|
||||||
yield this._sendCompactBlock(block, this.compactWitness);
|
yield this._sendCompactBlock(block, this.compactWitness);
|
||||||
|
|
||||||
|
blocks++;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.logger.warning(
|
unknown = item.type;
|
||||||
'Peer sent an unknown getdata type: %s (%s).',
|
|
||||||
item.type,
|
|
||||||
this.hostname);
|
|
||||||
notFound.push(item);
|
notFound.push(item);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1711,14 +1722,26 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.debug(
|
|
||||||
'Served %d items with getdata (notfound=%d) (%s).',
|
|
||||||
items.length - notFound.length,
|
|
||||||
notFound.length,
|
|
||||||
this.hostname);
|
|
||||||
|
|
||||||
if (notFound.length > 0)
|
if (notFound.length > 0)
|
||||||
yield this.send(new packets.NotFoundPacket(notFound));
|
yield this.send(new packets.NotFoundPacket(notFound));
|
||||||
|
|
||||||
|
if (txs > 0) {
|
||||||
|
this.logger.debug(
|
||||||
|
'Served %d txs with getdata (notfound=%d) (%s).',
|
||||||
|
txs, notFound.length, this.hostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blocks > 0) {
|
||||||
|
this.logger.debug(
|
||||||
|
'Served %d blocks with getdata (notfound=%d) (%s).',
|
||||||
|
blocks, notFound.length, this.hostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unknown !== -1) {
|
||||||
|
this.logger.warning(
|
||||||
|
'Peer sent an unknown getdata type: %s (%d).',
|
||||||
|
unknown, this.hostname);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2293,7 +2316,9 @@ Peer.prototype.sendGetHeaders = function sendGetHeaders(locator, stop) {
|
|||||||
if (stop)
|
if (stop)
|
||||||
stop = utils.revHex(stop);
|
stop = utils.revHex(stop);
|
||||||
|
|
||||||
this.logger.debug('Height: %d, Hash: %s, Stop: %s', height, hash, stop);
|
this.logger.debug(
|
||||||
|
'Height: %d, Hash: %s, Stop: %s',
|
||||||
|
height, hash, stop || null);
|
||||||
|
|
||||||
return this.send(packet);
|
return this.send(packet);
|
||||||
};
|
};
|
||||||
@ -2321,7 +2346,9 @@ Peer.prototype.sendGetBlocks = function getBlocks(locator, stop) {
|
|||||||
if (stop)
|
if (stop)
|
||||||
stop = utils.revHex(stop);
|
stop = utils.revHex(stop);
|
||||||
|
|
||||||
this.logger.debug('Height: %d, Hash: %s, Stop: %s', height, hash, stop);
|
this.logger.debug(
|
||||||
|
'Height: %d, Hash: %s, Stop: %s',
|
||||||
|
height, hash, stop || null);
|
||||||
|
|
||||||
return this.send(packet);
|
return this.send(packet);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user