commit
013a85c6a5
@ -97,7 +97,13 @@ Peer.prototype._init = function init() {
|
|||||||
}, this._ping.interval);
|
}, this._ping.interval);
|
||||||
|
|
||||||
// Send hello
|
// Send hello
|
||||||
this._write(this.framer.version());
|
this._write(this.framer.version({
|
||||||
|
height: this.options.startHeight != null
|
||||||
|
? this.options.startHeight
|
||||||
|
: 0,
|
||||||
|
relay: this.options.relay
|
||||||
|
}));
|
||||||
|
|
||||||
this._req('verack', function(err, payload) {
|
this._req('verack', function(err, payload) {
|
||||||
if (err)
|
if (err)
|
||||||
return self._error(err);
|
return self._error(err);
|
||||||
|
|||||||
@ -111,7 +111,9 @@ Pool.prototype._addLoader = function _addLoader() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var peer = new bcoin.peer(this, this.createConnection, {
|
var peer = new bcoin.peer(this, this.createConnection, {
|
||||||
backoff: 750 * Math.random()
|
backoff: 750 * Math.random(),
|
||||||
|
startHeight: this.options.startHeight,
|
||||||
|
relay: this.options.relay
|
||||||
});
|
});
|
||||||
this.peers.load = peer;
|
this.peers.load = peer;
|
||||||
|
|
||||||
@ -248,7 +250,9 @@ Pool.prototype._addPeer = function _addPeer(backoff) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var peer = new bcoin.peer(this, this.createConnection, {
|
var peer = new bcoin.peer(this, this.createConnection, {
|
||||||
backoff: backoff
|
backoff: backoff,
|
||||||
|
startHeight: this.options.startHeight,
|
||||||
|
relay: this.options.relay
|
||||||
});
|
});
|
||||||
|
|
||||||
this.peers.pending.push(peer);
|
this.peers.pending.push(peer);
|
||||||
@ -356,17 +360,19 @@ Pool.prototype.watch = function watch(id) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var hid = utils.toHex(id);
|
if (id) {
|
||||||
if (this.watchMap[hid])
|
var hid = utils.toHex(id);
|
||||||
this.watchMap[hid]++;
|
if (this.watchMap[hid])
|
||||||
else
|
this.watchMap[hid]++;
|
||||||
this.watchMap[hid] = 1;
|
else
|
||||||
|
this.watchMap[hid] = 1;
|
||||||
|
|
||||||
if (this.bloom.test(id, 'hex'))
|
if (this.bloom.test(id, 'hex'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (id)
|
|
||||||
this.bloom.add(id, 'hex');
|
this.bloom.add(id, 'hex');
|
||||||
|
}
|
||||||
|
|
||||||
if (this.peers.load)
|
if (this.peers.load)
|
||||||
this.peers.load.updateWatch();
|
this.peers.load.updateWatch();
|
||||||
for (var i = 0; i < this.peers.block.length; i++)
|
for (var i = 0; i < this.peers.block.length; i++)
|
||||||
|
|||||||
@ -97,7 +97,7 @@ Framer.prototype.version = function version(packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start height
|
// Start height
|
||||||
off += writeU32(p, packet.height, off);
|
off += writeU32(p, packet.height || 0, off);
|
||||||
|
|
||||||
// Relay
|
// Relay
|
||||||
p[off++] = packet.relay ? 1 : 0;
|
p[off++] = packet.relay ? 1 : 0;
|
||||||
|
|||||||
@ -123,7 +123,7 @@ Parser.prototype.parseVersion = function parseVersion(p) {
|
|||||||
var nonce = { lo: readU32(p, 72), hi: readU32(p, 76) };
|
var nonce = { lo: readU32(p, 72), hi: readU32(p, 76) };
|
||||||
|
|
||||||
// Start height
|
// Start height
|
||||||
var weight = readU32(p, 81);
|
var height = readU32(p, 81);
|
||||||
|
|
||||||
// Relay
|
// Relay
|
||||||
var relay = p.length >= 86 ? p[85] === 1 : true;
|
var relay = p.length >= 86 ? p[85] === 1 : true;
|
||||||
@ -133,7 +133,7 @@ Parser.prototype.parseVersion = function parseVersion(p) {
|
|||||||
services: services,
|
services: services,
|
||||||
ts: ts,
|
ts: ts,
|
||||||
nonce: nonce,
|
nonce: nonce,
|
||||||
weight: weight,
|
height: height,
|
||||||
relay: relay
|
relay: relay
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -25,6 +25,13 @@ describe('Protocol', function() {
|
|||||||
packetTest('version', {}, function(payload) {
|
packetTest('version', {}, function(payload) {
|
||||||
assert.equal(payload.v, 70002);
|
assert.equal(payload.v, 70002);
|
||||||
assert.equal(payload.relay, false);
|
assert.equal(payload.relay, false);
|
||||||
|
assert.equal(payload.height, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
packetTest('version', { relay: true, height: 10 }, function(payload) {
|
||||||
|
assert.equal(payload.v, 70002);
|
||||||
|
assert.equal(payload.relay, true);
|
||||||
|
assert.equal(payload.height, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
packetTest('verack', {}, function(payload) {
|
packetTest('verack', {}, function(payload) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user