add connect timeout.
This commit is contained in:
parent
e8ee4d3c18
commit
ce9fe104b3
@ -97,6 +97,7 @@ function Peer(pool, options) {
|
|||||||
this.waiting = 0;
|
this.waiting = 0;
|
||||||
this.syncSent = false;
|
this.syncSent = false;
|
||||||
this.loader = options.loader || false;
|
this.loader = options.loader || false;
|
||||||
|
this._connectTimeout = null;
|
||||||
|
|
||||||
this.challenge = null;
|
this.challenge = null;
|
||||||
this.lastPong = -1;
|
this.lastPong = -1;
|
||||||
@ -158,6 +159,10 @@ Peer.prototype._init = function init() {
|
|||||||
self.ts = utils.now();
|
self.ts = utils.now();
|
||||||
self.connected = true;
|
self.connected = true;
|
||||||
self.emit('connect');
|
self.emit('connect');
|
||||||
|
if (self._connectTimeout != null) {
|
||||||
|
clearTimeout(self._connectTimeout);
|
||||||
|
self._connectTimeout = null;
|
||||||
|
}
|
||||||
self._onconnect();
|
self._onconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -246,6 +251,8 @@ Peer.prototype._onconnect = function _onconnect() {
|
|||||||
if (self.loader && self.pool.synced)
|
if (self.loader && self.pool.synced)
|
||||||
self.sendMempool();
|
self.sendMempool();
|
||||||
|
|
||||||
|
bcoin.debug('Received verack (%s).', self.hostname);
|
||||||
|
|
||||||
// Finally we can let the pool know
|
// Finally we can let the pool know
|
||||||
// that this peer is ready to go.
|
// that this peer is ready to go.
|
||||||
self.emit('ack');
|
self.emit('ack');
|
||||||
@ -290,6 +297,7 @@ Peer.prototype._onconnect = function _onconnect() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Peer.prototype.createSocket = function createSocket(port, host) {
|
Peer.prototype.createSocket = function createSocket(port, host) {
|
||||||
|
var self = this;
|
||||||
var hostname = IP.hostname(host, port);
|
var hostname = IP.hostname(host, port);
|
||||||
var socket, proxy, net;
|
var socket, proxy, net;
|
||||||
|
|
||||||
@ -311,6 +319,10 @@ Peer.prototype.createSocket = function createSocket(port, host) {
|
|||||||
bcoin.debug('Connected to %s.', hostname);
|
bcoin.debug('Connected to %s.', hostname);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._connectTimeout = setTimeout(function() {
|
||||||
|
self.destroy();
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
return socket;
|
return socket;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user