fix leech peers.
This commit is contained in:
parent
d38de71468
commit
9d771fe0b6
@ -112,6 +112,7 @@ function Peer(pool, options) {
|
||||
this.socket = options.socket;
|
||||
this.host = IP.normalize(this.socket.remoteAddress);
|
||||
this.port = this.socket.remotePort;
|
||||
this.connected = true;
|
||||
} else if (options.host) {
|
||||
this.host = options.host.host;
|
||||
this.port = options.host.port;
|
||||
@ -158,14 +159,7 @@ Peer.prototype._init = function init() {
|
||||
var self = this;
|
||||
|
||||
this.socket.once('connect', function() {
|
||||
self.ts = utils.now();
|
||||
self.connected = true;
|
||||
self.emit('connect');
|
||||
if (self._connectTimeout != null) {
|
||||
clearTimeout(self._connectTimeout);
|
||||
self._connectTimeout = null;
|
||||
}
|
||||
self._onconnect();
|
||||
self._onConnect();
|
||||
});
|
||||
|
||||
this.socket.once('error', function(err) {
|
||||
@ -190,11 +184,27 @@ Peer.prototype._init = function init() {
|
||||
self.reject(null, 'malformed', 'error parsing message', 10);
|
||||
self._error(err, true);
|
||||
});
|
||||
|
||||
if (this.connected) {
|
||||
utils.nextTick(function() {
|
||||
self._onConnect();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Peer.prototype._onconnect = function _onconnect() {
|
||||
Peer.prototype._onConnect = function _onConnect() {
|
||||
var self = this;
|
||||
|
||||
this.ts = utils.now();
|
||||
this.connected = true;
|
||||
|
||||
this.emit('connect');
|
||||
|
||||
if (this._connectTimeout != null) {
|
||||
clearTimeout(this._connectTimeout);
|
||||
this._connectTimeout = null;
|
||||
}
|
||||
|
||||
this.request('verack', function callee(err) {
|
||||
if (err) {
|
||||
self._error(err);
|
||||
|
||||
@ -839,8 +839,7 @@ Pool.prototype._createPeer = function _createPeer(options) {
|
||||
network: options.network,
|
||||
spv: options.spv,
|
||||
witness: options.witness,
|
||||
headers: this.options.headers,
|
||||
ts: options.ts
|
||||
headers: this.options.headers
|
||||
});
|
||||
|
||||
peer.once('close', function() {
|
||||
@ -1122,8 +1121,7 @@ Pool.prototype._addLeech = function _addLeech(socket) {
|
||||
socket: socket,
|
||||
network: false,
|
||||
spv: false,
|
||||
witness: false,
|
||||
ts: utils.now()
|
||||
witness: false
|
||||
});
|
||||
|
||||
bcoin.debug('Added leech peer (%s).', peer.hostname);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user