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.requestMap = new Map();
|
||||||
this.compactBlocks = new Map();
|
this.compactBlocks = new Map();
|
||||||
this.invMap = new Map();
|
this.invMap = new Map();
|
||||||
this.pendingWatch = null;
|
this.pendingFilter = null;
|
||||||
this.pendingRefill = null;
|
this.pendingRefill = null;
|
||||||
|
|
||||||
this.headersFirst = false;
|
this.headersFirst = false;
|
||||||
@ -360,9 +360,9 @@ Pool.prototype._disconnect = co(function* disconnect() {
|
|||||||
|
|
||||||
this.requestMap.reset();
|
this.requestMap.reset();
|
||||||
|
|
||||||
if (this.pendingWatch != null) {
|
if (this.pendingFilter != null) {
|
||||||
clearTimeout(this.pendingWatch);
|
clearTimeout(this.pendingFilter);
|
||||||
this.pendingWatch = null;
|
this.pendingFilter = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.pendingRefill != null) {
|
if (this.pendingRefill != null) {
|
||||||
@ -2755,7 +2755,7 @@ Pool.prototype.setFilter = function setFilter(filter) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
this.spvFilter = filter;
|
this.spvFilter = filter;
|
||||||
this.sendFilterLoad();
|
this.queueFilterLoad();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2769,7 +2769,7 @@ Pool.prototype.watch = function watch(data, enc) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
this.spvFilter.add(data, enc);
|
this.spvFilter.add(data, enc);
|
||||||
this.sendFilterLoad();
|
this.queueFilterLoad();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2781,7 +2781,26 @@ Pool.prototype.unwatch = function unwatch() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
this.spvFilter.reset();
|
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() {
|
Pool.prototype.sendFilterLoad = function sendFilterLoad() {
|
||||||
var self = this;
|
|
||||||
var peer;
|
var peer;
|
||||||
|
|
||||||
if (this.pendingWatch != null)
|
if (!this.options.spv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.spvFilter);
|
assert(this.spvFilter);
|
||||||
|
|
||||||
this.pendingWatch = setTimeout(function() {
|
for (peer = this.peers.head(); peer; peer = peer.next)
|
||||||
self.pendingWatch = null;
|
peer.sendFilterLoad(this.spvFilter);
|
||||||
for (peer = self.peers.head(); peer; peer = peer.next)
|
|
||||||
peer.sendFilterLoad(self.spvFilter);
|
|
||||||
}, 50);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -146,6 +146,7 @@ NodeClient.prototype.setFilter = function setFilter(filter) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
NodeClient.prototype.addFilter = function addFilter(data) {
|
NodeClient.prototype.addFilter = function addFilter(data) {
|
||||||
|
this.node.pool.queueFilterLoad();
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,6 +156,7 @@ NodeClient.prototype.addFilter = function addFilter(data) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
NodeClient.prototype.resetFilter = function resetFilter() {
|
NodeClient.prototype.resetFilter = function resetFilter() {
|
||||||
|
this.node.pool.queueFilterLoad();
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user