add connect timeout.

This commit is contained in:
Christopher Jeffrey 2016-06-13 00:04:34 -07:00
parent e8ee4d3c18
commit ce9fe104b3
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

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