bip151: cleanup handshake properly.
This commit is contained in:
parent
9affb11b22
commit
1e9b7363c2
@ -323,6 +323,7 @@ function BIP151(cipher) {
|
||||
|
||||
this.timeout = null;
|
||||
this.job = null;
|
||||
this.onShake = null;
|
||||
|
||||
this.bip150 = null;
|
||||
}
|
||||
@ -472,8 +473,15 @@ BIP151.prototype.cleanup = function cleanup() {
|
||||
this.completed = true;
|
||||
this.job = null;
|
||||
|
||||
clearTimeout(this.timeout);
|
||||
this.timeout = null;
|
||||
if (this.timeout != null) {
|
||||
clearTimeout(this.timeout);
|
||||
this.timeout = null;
|
||||
}
|
||||
|
||||
if (this.onShake) {
|
||||
this.removeListener('handshake', this.onShake);
|
||||
this.onShake = null;
|
||||
}
|
||||
|
||||
return job;
|
||||
};
|
||||
@ -530,9 +538,8 @@ BIP151.prototype._wait = function wait(timeout, resolve, reject) {
|
||||
self.reject(new Error('BIP151 handshake timed out.'));
|
||||
}, timeout);
|
||||
|
||||
this.once('handshake', function() {
|
||||
self.resolve();
|
||||
});
|
||||
this.onShake = this.resolve.bind(this);
|
||||
this.once('handshake', this.onShake);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -544,6 +551,11 @@ BIP151.prototype.destroy = function destroy() {
|
||||
clearTimeout(this.timeout);
|
||||
this.timeout = null;
|
||||
}
|
||||
|
||||
if (this.onShake) {
|
||||
this.removeListener('handshake', this.onShake);
|
||||
this.onShake = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user