net/nodeclient: always resend bloom filter. see #119.
This commit is contained in:
parent
39b941516d
commit
51a25bf15f
@ -111,7 +111,7 @@ function Pool(options) {
|
||||
this.requestMap = new Map();
|
||||
this.compactBlocks = new Map();
|
||||
this.invMap = new Map();
|
||||
this.pendingWatch = null;
|
||||
this.pendingFilter = null;
|
||||
this.pendingRefill = null;
|
||||
|
||||
this.headersFirst = false;
|
||||
@ -360,9 +360,9 @@ Pool.prototype._disconnect = co(function* disconnect() {
|
||||
|
||||
this.requestMap.reset();
|
||||
|
||||
if (this.pendingWatch != null) {
|
||||
clearTimeout(this.pendingWatch);
|
||||
this.pendingWatch = null;
|
||||
if (this.pendingFilter != null) {
|
||||
clearTimeout(this.pendingFilter);
|
||||
this.pendingFilter = null;
|
||||
}
|
||||
|
||||
if (this.pendingRefill != null) {
|
||||
@ -2755,7 +2755,7 @@ Pool.prototype.setFilter = function setFilter(filter) {
|
||||
return;
|
||||
|
||||
this.spvFilter = filter;
|
||||
this.sendFilterLoad();
|
||||
this.queueFilterLoad();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2769,7 +2769,7 @@ Pool.prototype.watch = function watch(data, enc) {
|
||||
return;
|
||||
|
||||
this.spvFilter.add(data, enc);
|
||||
this.sendFilterLoad();
|
||||
this.queueFilterLoad();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2781,7 +2781,26 @@ Pool.prototype.unwatch = function unwatch() {
|
||||
return;
|
||||
|
||||
this.spvFilter.reset();
|
||||
this.sendFilterLoad();
|
||||
this.queueFilterLoad();
|
||||
};
|
||||
|
||||
/**
|
||||
* Queue a resend of the bloom filter.
|
||||
*/
|
||||
|
||||
Pool.prototype.queueFilterLoad = function queueFilterLoad() {
|
||||
var self = this;
|
||||
|
||||
if (!this.options.spv)
|
||||
return;
|
||||
|
||||
if (this.pendingFilter != null)
|
||||
return;
|
||||
|
||||
this.pendingFilter = setTimeout(function() {
|
||||
self.pendingFilter = null;
|
||||
self.sendFilterLoad();
|
||||
}, 100);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2789,19 +2808,15 @@ Pool.prototype.unwatch = function unwatch() {
|
||||
*/
|
||||
|
||||
Pool.prototype.sendFilterLoad = function sendFilterLoad() {
|
||||
var self = this;
|
||||
var peer;
|
||||
|
||||
if (this.pendingWatch != null)
|
||||
if (!this.options.spv)
|
||||
return;
|
||||
|
||||
assert(this.spvFilter);
|
||||
|
||||
this.pendingWatch = setTimeout(function() {
|
||||
self.pendingWatch = null;
|
||||
for (peer = self.peers.head(); peer; peer = peer.next)
|
||||
peer.sendFilterLoad(self.spvFilter);
|
||||
}, 50);
|
||||
for (peer = this.peers.head(); peer; peer = peer.next)
|
||||
peer.sendFilterLoad(this.spvFilter);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -146,6 +146,7 @@ NodeClient.prototype.setFilter = function setFilter(filter) {
|
||||
*/
|
||||
|
||||
NodeClient.prototype.addFilter = function addFilter(data) {
|
||||
this.node.pool.queueFilterLoad();
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
@ -155,6 +156,7 @@ NodeClient.prototype.addFilter = function addFilter(data) {
|
||||
*/
|
||||
|
||||
NodeClient.prototype.resetFilter = function resetFilter() {
|
||||
this.node.pool.queueFilterLoad();
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user