From a5b8da17fcafc5186e90e14ca587b519fadf71d8 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 15 May 2016 18:33:54 -0700 Subject: [PATCH] services. --- lib/bcoin/peer.js | 23 ++++++++++------------- lib/bcoin/pool.js | 19 ++++++++++++++----- lib/bcoin/protocol/parser.js | 4 ---- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 0d22ce41..96123ae9 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -939,14 +939,17 @@ Peer.prototype._handleGetBlocks = function _handleGetBlocks(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.setMisbehavior(100); return; } if (this.options.headers) { - if (payload.version < 31800) { + if (version < 31800) { this._error('Peer doesn\'t support getheaders.'); this.setMisbehavior(100); return; @@ -954,7 +957,7 @@ Peer.prototype._handleVersion = function handleVersion(payload) { } if (this.options.network) { - if (!payload.network) { + if (!(services & constants.services.NETWORK)) { this._error('Peer does not support network services.'); this.setMisbehavior(100); return; @@ -962,7 +965,7 @@ Peer.prototype._handleVersion = function handleVersion(payload) { } 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.setMisbehavior(100); return; @@ -970,12 +973,11 @@ Peer.prototype._handleVersion = function handleVersion(payload) { } if (this.options.witness) { - if (!payload.witness) { + if (!(services & constants.services.WITNESS)) { this._req('havewitness', function(err) { if (err) { self._error('Peer does not support segregated witness.'); self.setMisbehavior(100); - return; } }); } @@ -1210,16 +1212,11 @@ Peer.prototype._handleAddr = function handleAddr(addrs) { ts = now - 5 * 24 * 60 * 60; this.emit('addr', { + version: addr.version, ts: ts, services: addr.services, host: host, - 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 + port: addr.port || this.network.port }); } diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 4db17635..48b82c04 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -954,14 +954,23 @@ Pool.prototype._createPeer = function _createPeer(options) { if (self.options.discoverPeers === false) return; - if (!data.network) + if (!(data.services & constants.services.NETWORK)) return; - if (self.options.spv && !data.spv) - return; + if (self.options.headers) { + if (data.version < 31800) + return; + } - if (self.options.witness && !data.witness) - return; + if (self.options.spv) { + 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) self.setSeeds(self.seeds.slice(-150)); diff --git a/lib/bcoin/protocol/parser.js b/lib/bcoin/protocol/parser.js index c30927e7..f470b8c2 100644 --- a/lib/bcoin/protocol/parser.js +++ b/lib/bcoin/protocol/parser.js @@ -485,10 +485,6 @@ Parser.parseVersion = function parseVersion(p) { return { version: version, 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, local: recv, remote: from,