@@ -110,23 +110,14 @@ function Client (options) {
110
110
EventEmitter . call ( this , options )
111
111
112
112
var self = this
113
- this . servers = [ ]
114
- if ( options . url ) {
115
- var urls = options . url
116
-
117
- if ( typeof options . url === 'string' ) {
118
- var [ , protocol , hosts , path ] = options . url . match ( / ^ ( [ a - z A - Z ] + : \/ \/ ) ( [ ^ / ] * ) ( .* ) / )
119
-
120
- urls = hosts . split ( ',' ) . map ( ( host ) => {
121
- return `${ protocol } ${ host } ${ path } `
122
- } )
123
- }
124
-
125
- this . servers = urls . map ( url . parse )
126
- }
127
-
113
+ this . urls = options . url ? [ ] . concat ( options . url ) . map ( url . parse ) : [ ]
128
114
// select random server at the start
129
- this . nextServer = Math . floor ( Math . random ( ) * this . servers . length )
115
+ this . _nextServer = Math . floor ( Math . random ( ) * this . urls . length )
116
+ // updated in connectSocket() after each connect
117
+ this . host = undefined
118
+ this . port = false
119
+ this . secure = false
120
+ this . url = undefined
130
121
this . tlsOptions = options . tlsOptions
131
122
this . socketPath = options . socketPath || false
132
123
@@ -803,8 +794,15 @@ Client.prototype.connect = function connect () {
803
794
804
795
// Establish basic socket connection
805
796
function connectSocket ( cb ) {
806
- self . nextServer = ( self . nextServer + 1 ) % self . servers . length
807
- self . url = self . servers [ self . nextServer ]
797
+ self . _nextServer = ( self . _nextServer + 1 ) % self . urls . length
798
+ self . url = self . urls [ self . _nextServer ]
799
+
800
+ if ( self . url ) {
801
+ self . host = url . hostname
802
+ self . port = url . port
803
+ self . secure = url . secure
804
+ }
805
+
808
806
cb = once ( cb )
809
807
810
808
function onResult ( err , res ) {
@@ -833,8 +831,8 @@ Client.prototype.connect = function connect () {
833
831
setupClient ( cb )
834
832
}
835
833
836
- var port = ( self . servers . length && self . servers [ self . nextServer ] . port ) || self . socketPath
837
- var hostname = ( self . servers . length && self . servers [ self . nextServer ] . hostname ) || undefined
834
+ var port = ( self . urls . length && self . urls [ self . _nextServer ] . port ) || self . socketPath
835
+ var hostname = ( self . urls . length && self . urls [ self . _nextServer ] . hostname ) || undefined
838
836
if ( self . secure ) {
839
837
socket = tls . connect ( port , hostname , self . tlsOptions )
840
838
socket . once ( 'secureConnect' , onConnect )
@@ -843,7 +841,7 @@ Client.prototype.connect = function connect () {
843
841
socket . once ( 'connect' , onConnect )
844
842
}
845
843
socket . once ( 'error' , onResult )
846
- initSocket ( )
844
+ initSocket ( self . url )
847
845
848
846
// Setup connection timeout handling, if desired
849
847
if ( self . connectTimeout ) {
@@ -858,9 +856,9 @@ Client.prototype.connect = function connect () {
858
856
}
859
857
860
858
// Initialize socket events and LDAP parser.
861
- function initSocket ( ) {
859
+ function initSocket ( url ) {
862
860
tracker = messageTrackerFactory ( {
863
- id : self . url ? self . url . href : self . socketPath ,
861
+ id : url ? url . href : self . socketPath ,
864
862
parser : new Parser ( { log : log } )
865
863
} )
866
864
@@ -989,8 +987,8 @@ Client.prototype.connect = function connect () {
989
987
maxDelay : this . reconnect . maxDelay
990
988
} )
991
989
failAfter = this . reconnect . failAfter
992
- if ( this . servers . length > 1 && failAfter ) {
993
- failAfter *= this . servers . length
990
+ if ( this . urls . length > 1 && failAfter ) {
991
+ failAfter *= this . urls . length
994
992
}
995
993
} else {
996
994
retry = backoff . exponential ( {
0 commit comments