Comparing version 2.1.1 to 2.2.0
@@ -113,8 +113,9 @@ 'use strict' | ||
var self = this | ||
var _url | ||
if (options.url) { _url = url.parse(options.url) } | ||
this.host = _url ? _url.hostname : undefined | ||
this.port = _url ? _url.port : false | ||
this.secure = _url ? _url.secure : false | ||
this.url = _url | ||
this.urls = options.url ? [].concat(options.url).map(url.parse) : [] | ||
this._nextServer = 0 | ||
// updated in connectSocket() after each connect | ||
this.host = undefined | ||
this.port = undefined | ||
this.secure = undefined | ||
this.url = undefined | ||
this.tlsOptions = options.tlsOptions | ||
@@ -796,2 +797,5 @@ this.socketPath = options.socketPath || false | ||
function connectSocket (cb) { | ||
var server = self.urls[self._nextServer] | ||
self._nextServer = (self._nextServer + 1) % self.urls.length | ||
cb = once(cb) | ||
@@ -825,12 +829,13 @@ | ||
var port = (self.port || self.socketPath) | ||
if (self.secure) { | ||
socket = tls.connect(port, self.host, self.tlsOptions) | ||
var port = (server && server.port) || self.socketPath | ||
var host = server && server.hostname | ||
if (server && server.secure) { | ||
socket = tls.connect(port, host, self.tlsOptions) | ||
socket.once('secureConnect', onConnect) | ||
} else { | ||
socket = net.connect(port, self.host) | ||
socket = net.connect(port, host) | ||
socket.once('connect', onConnect) | ||
} | ||
socket.once('error', onResult) | ||
initSocket() | ||
initSocket(server) | ||
@@ -850,5 +855,5 @@ // Setup connection timeout handling, if desired | ||
// Initialize socket events and LDAP parser. | ||
function initSocket () { | ||
function initSocket (url) { | ||
tracker = messageTrackerFactory({ | ||
id: self.url ? self.url.href : self.socketPath, | ||
id: url ? url.href : self.socketPath, | ||
parser: new Parser({ log: log }) | ||
@@ -972,2 +977,9 @@ }) | ||
}) | ||
var server = self.urls[self._nextServer] | ||
if (server) { | ||
self.host = server.hostname | ||
self.port = server.port | ||
self.secure = server.secure | ||
} | ||
} | ||
@@ -983,2 +995,5 @@ | ||
failAfter = this.reconnect.failAfter | ||
if (this.urls.length > 1 && failAfter) { | ||
failAfter *= this.urls.length | ||
} | ||
} else { | ||
@@ -989,3 +1004,3 @@ retry = backoff.exponential({ | ||
}) | ||
failAfter = 1 | ||
failAfter = this.urls.length || 1 | ||
} | ||
@@ -992,0 +1007,0 @@ retry.failAfter(failAfter) |
@@ -10,3 +10,3 @@ 'use strict' | ||
if (isObject(options) === false) throw TypeError('options (object) required') | ||
if (options.url && typeof options.url !== 'string') throw TypeError('options.url (string) required') | ||
if (options.url && typeof options.url !== 'string' && !Array.isArray(options.url)) throw TypeError('options.url (string|array) required') | ||
if (options.socketPath && typeof options.socketPath !== 'string') throw TypeError('options.socketPath must be a string') | ||
@@ -13,0 +13,0 @@ if ((options.url && options.socketPath) || !(options.url || options.socketPath)) throw TypeError('options.url ^ options.socketPath (String) required') |
@@ -6,3 +6,3 @@ { | ||
"description": "LDAP client and server APIs", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"license": "MIT", | ||
@@ -9,0 +9,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
227563
6933