services.

This commit is contained in:
Christopher Jeffrey 2016-05-15 18:33:54 -07:00
parent 5ac4621b0e
commit a5b8da17fc
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 24 additions and 22 deletions

View File

@ -939,14 +939,17 @@ Peer.prototype._handleGetBlocks = function _handleGetBlocks(payload) {
}; };
Peer.prototype._handleVersion = function handleVersion(payload) { Peer.prototype._handleVersion = function handleVersion(payload) {
if (payload.version < constants.MIN_VERSION) { var version = payload.version;
var services = payload.services;
if (version < constants.MIN_VERSION) {
this._error('Peer doesn\'t support required protocol version.'); this._error('Peer doesn\'t support required protocol version.');
this.setMisbehavior(100); this.setMisbehavior(100);
return; return;
} }
if (this.options.headers) { if (this.options.headers) {
if (payload.version < 31800) { if (version < 31800) {
this._error('Peer doesn\'t support getheaders.'); this._error('Peer doesn\'t support getheaders.');
this.setMisbehavior(100); this.setMisbehavior(100);
return; return;
@ -954,7 +957,7 @@ Peer.prototype._handleVersion = function handleVersion(payload) {
} }
if (this.options.network) { if (this.options.network) {
if (!payload.network) { if (!(services & constants.services.NETWORK)) {
this._error('Peer does not support network services.'); this._error('Peer does not support network services.');
this.setMisbehavior(100); this.setMisbehavior(100);
return; return;
@ -962,7 +965,7 @@ Peer.prototype._handleVersion = function handleVersion(payload) {
} }
if (this.options.spv) { if (this.options.spv) {
if (!payload.bloom && payload.version < 70011) { if (version < 70011 || !(services & constants.services.BLOOM)) {
this._error('Peer does not support bip37.'); this._error('Peer does not support bip37.');
this.setMisbehavior(100); this.setMisbehavior(100);
return; return;
@ -970,12 +973,11 @@ Peer.prototype._handleVersion = function handleVersion(payload) {
} }
if (this.options.witness) { if (this.options.witness) {
if (!payload.witness) { if (!(services & constants.services.WITNESS)) {
this._req('havewitness', function(err) { this._req('havewitness', function(err) {
if (err) { if (err) {
self._error('Peer does not support segregated witness.'); self._error('Peer does not support segregated witness.');
self.setMisbehavior(100); self.setMisbehavior(100);
return;
} }
}); });
} }
@ -1210,16 +1212,11 @@ Peer.prototype._handleAddr = function handleAddr(addrs) {
ts = now - 5 * 24 * 60 * 60; ts = now - 5 * 24 * 60 * 60;
this.emit('addr', { this.emit('addr', {
version: addr.version,
ts: ts, ts: ts,
services: addr.services, services: addr.services,
host: host, host: host,
port: addr.port || this.network.port, port: addr.port || this.network.port
network: addr.network,
bloom: addr.bloom,
getutxo: addr.getutxo,
witness: addr.witness,
headers: addr.version >= 31800,
spv: addr.bloom && addr.version >= 70011
}); });
} }

View File

@ -954,14 +954,23 @@ Pool.prototype._createPeer = function _createPeer(options) {
if (self.options.discoverPeers === false) if (self.options.discoverPeers === false)
return; return;
if (!data.network) if (!(data.services & constants.services.NETWORK))
return; return;
if (self.options.spv && !data.spv) if (self.options.headers) {
return; if (data.version < 31800)
return;
}
if (self.options.witness && !data.witness) if (self.options.spv) {
return; if (data.version < 70011 || !(data.services & constants.services.BLOOM))
return;
}
if (self.options.witness) {
if (!(data.services & constants.services.WITNESS))
return;
}
if (self.seeds.length > 300) if (self.seeds.length > 300)
self.setSeeds(self.seeds.slice(-150)); self.setSeeds(self.seeds.slice(-150));

View File

@ -485,10 +485,6 @@ Parser.parseVersion = function parseVersion(p) {
return { return {
version: version, version: version,
services: services, services: services,
network: (services & constants.services.NETWORK) !== 0,
getutxo: (services & constants.services.GETUTXO) !== 0,
bloom: (services & constants.services.BLOOM) !== 0,
witness: (services & constants.services.WITNESS) !== 0,
ts: ts, ts: ts,
local: recv, local: recv,
remote: from, remote: from,