net: remove noDiscovery. exempt bip150 packets from lock.
This commit is contained in:
parent
33fbdff127
commit
25899827fd
@ -56,7 +56,6 @@ selfish: false
|
||||
headers: true
|
||||
compact: true
|
||||
bip151: true
|
||||
no-discovery: false
|
||||
listen: true
|
||||
max-outbound: 8
|
||||
max-inbound: 30
|
||||
|
||||
@ -1482,15 +1482,32 @@ Peer.prototype.getTX = function getTX(hashes) {
|
||||
Peer.prototype.readPacket = co(function* readPacket(packet) {
|
||||
var unlock;
|
||||
|
||||
if (this.destroyed)
|
||||
return;
|
||||
|
||||
// The "pre-handshake" packets get
|
||||
// to bypass the lock, since they
|
||||
// are meant to change the way input
|
||||
// is handled at a low level. They
|
||||
// must be handled immediately.
|
||||
switch (packet.type) {
|
||||
case packetTypes.ENCINIT:
|
||||
case packetTypes.ENCACK:
|
||||
return yield this.handlePacket(packet);
|
||||
case packetTypes.AUTHCHALLENGE:
|
||||
case packetTypes.AUTHREPLY:
|
||||
case packetTypes.AUTHPROPOSE:
|
||||
try {
|
||||
this.socket.pause();
|
||||
yield this.handlePacket(packet);
|
||||
} finally {
|
||||
this.socket.resume();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
unlock = yield this.locker.lock();
|
||||
try {
|
||||
this.socket.pause();
|
||||
return yield this.handlePacket(packet);
|
||||
yield this.handlePacket(packet);
|
||||
} finally {
|
||||
this.socket.resume();
|
||||
unlock();
|
||||
@ -1516,7 +1533,7 @@ Peer.prototype.handlePacket = co(function* handlePacket(packet) {
|
||||
&& !this.bip151.completed
|
||||
&& packet.type !== packetTypes.ENCINIT
|
||||
&& packet.type !== packetTypes.ENCACK) {
|
||||
this.bip151.reject(new Error('Message before handshake.'));
|
||||
this.bip151.reject(new Error('Message before BIP151 handshake.'));
|
||||
}
|
||||
|
||||
if (this.bip150
|
||||
@ -1525,7 +1542,7 @@ Peer.prototype.handlePacket = co(function* handlePacket(packet) {
|
||||
&& packet.type !== packetTypes.AUTHCHALLENGE
|
||||
&& packet.type !== packetTypes.AUTHREPLY
|
||||
&& packet.type !== packetTypes.AUTHPROPOSE) {
|
||||
this.bip150.reject(new Error('Message before auth.'));
|
||||
this.bip150.reject(new Error('Message before BIP150 auth.'));
|
||||
}
|
||||
|
||||
entry = this.fulfill(packet);
|
||||
@ -1715,6 +1732,13 @@ Peer.prototype.handlePong = co(function* handlePong(packet) {
|
||||
*/
|
||||
|
||||
Peer.prototype.handleSendHeaders = co(function* handleSendHeaders(packet) {
|
||||
if (this.preferHeaders) {
|
||||
this.logger.debug(
|
||||
'Peer sent a duplicate sendheaders (%s).',
|
||||
this.hostname());
|
||||
return;
|
||||
}
|
||||
|
||||
this.preferHeaders = true;
|
||||
});
|
||||
|
||||
@ -1793,27 +1817,35 @@ Peer.prototype.handleFeeFilter = co(function* handleFeeFilter(packet) {
|
||||
Peer.prototype.handleSendCmpct = co(function* handleSendCmpct(packet) {
|
||||
var max = this.options.witness ? 2 : 1;
|
||||
|
||||
// Core witness nodes send this twice
|
||||
// with both version 1 and 2 (why
|
||||
// would you even _want_ non-witness
|
||||
// blocks if you use segwit??).
|
||||
if (this.compactMode !== -1) {
|
||||
this.logger.info(
|
||||
'Peer sent a duplicate sendcmpct (%s).',
|
||||
this.hostname());
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.version > max) {
|
||||
// Ignore
|
||||
this.logger.info('Peer request compact blocks version %d (%s).',
|
||||
this.logger.info(
|
||||
'Peer request compact blocks version %d (%s).',
|
||||
packet.version, this.hostname());
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.mode > 1) {
|
||||
this.logger.info('Peer request compact blocks mode %d (%s).',
|
||||
this.logger.info(
|
||||
'Peer request compact blocks mode %d (%s).',
|
||||
packet.mode, this.hostname());
|
||||
return;
|
||||
}
|
||||
|
||||
// Core witness nodes send this twice
|
||||
// with both version 1 and 2 (why
|
||||
// would you even _want_ non-witness
|
||||
// blocks if you use segwit??).
|
||||
if (this.compactMode !== -1)
|
||||
return;
|
||||
|
||||
this.logger.info('Peer initialized compact blocks (%s).', this.hostname());
|
||||
this.logger.info(
|
||||
'Peer initialized compact blocks (%s).',
|
||||
this.hostname());
|
||||
|
||||
this.compactMode = packet.mode;
|
||||
this.compactWitness = packet.version === 2;
|
||||
|
||||
@ -58,8 +58,6 @@ var packetTypes = packets.types;
|
||||
* headers, hashes, utxos, or transactions to peers.
|
||||
* @param {Boolean?} options.broadcast - Whether to automatically broadcast
|
||||
* transactions accepted to our mempool.
|
||||
* @param {Boolean} options.noDiscovery - Automatically discover new
|
||||
* peers.
|
||||
* @param {String[]} options.seeds
|
||||
* @param {Function?} options.createSocket - Custom function to create a socket.
|
||||
* Must accept (port, host) and return a node-like socket.
|
||||
@ -1292,9 +1290,6 @@ Pool.prototype.handleAddr = co(function* handleAddr(peer, packet) {
|
||||
|
||||
peer.addrFilter.add(addr.hostname, 'ascii');
|
||||
|
||||
if (this.options.noDiscovery)
|
||||
continue;
|
||||
|
||||
if (!addr.isRoutable())
|
||||
continue;
|
||||
|
||||
@ -2014,7 +2009,7 @@ Pool.prototype.resolveChain = co(function* resolveChain(peer, hash) {
|
||||
*/
|
||||
|
||||
Pool.prototype.logStatus = function logStatus(block) {
|
||||
if (this.logger.level >= 4 && this.chain.total % 20 === 0) {
|
||||
if (this.chain.total % 20 === 0) {
|
||||
this.logger.debug('Status:'
|
||||
+ ' ts=%s height=%d progress=%s'
|
||||
+ ' blocks=%d orphans=%d active=%d'
|
||||
@ -3194,7 +3189,6 @@ function PoolOptions(options) {
|
||||
this.banScore = common.BAN_SCORE;
|
||||
this.banTime = common.BAN_TIME;
|
||||
this.feeRate = -1;
|
||||
this.noDiscovery = false;
|
||||
this.seeds = this.network.seeds;
|
||||
this.nodes = [];
|
||||
this.invTimeout = 60000;
|
||||
@ -3394,11 +3388,6 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) {
|
||||
this.feeRate = this.options.feeRate;
|
||||
}
|
||||
|
||||
if (options.noDiscovery != null) {
|
||||
assert(typeof options.noDiscovery === 'boolean');
|
||||
this.noDiscovery = options.noDiscovery;
|
||||
}
|
||||
|
||||
if (options.seeds) {
|
||||
assert(Array.isArray(options.seeds));
|
||||
this.seeds = options.seeds;
|
||||
|
||||
@ -198,7 +198,6 @@ config.parseData = function parseData(data, prefix, dirname) {
|
||||
options.nodes = list(data.nodes);
|
||||
options.maxOutbound = num(data.maxoutbound);
|
||||
options.maxInbound = num(data.maxinbound);
|
||||
options.noDiscovery = bool(data.nodiscovery);
|
||||
options.publicHost = str(data.publichost);
|
||||
options.publicPort = num(data.publicport);
|
||||
options.host = str(data.host);
|
||||
|
||||
@ -114,7 +114,6 @@ function FullNode(options) {
|
||||
proxyServer: this.options.proxyServer,
|
||||
seeds: this.options.seeds,
|
||||
nodes: this.options.nodes,
|
||||
noDiscovery: this.options.noDiscovery,
|
||||
publicHost: this.options.publicHost,
|
||||
publicPort: this.options.publicPort,
|
||||
host: this.options.host,
|
||||
|
||||
@ -71,7 +71,6 @@ function SPVNode(options) {
|
||||
knownPeers: this.options.knownPeers,
|
||||
identityKey: this.options.identityKey,
|
||||
maxOutbound: this.options.maxOutbound,
|
||||
noDiscovery: this.options.noDiscovery,
|
||||
headers: this.options.headers,
|
||||
selfish: true,
|
||||
listen: false
|
||||
|
||||
Loading…
Reference in New Issue
Block a user