@@ -90,15 +90,15 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
9090 reconnects := v [0 ].(uint )
9191 err := v [1 ].(error )
9292 log .Printf ("tarantool: reconnect (%d/%d) to %s failed: %s" ,
93- reconnects , conn .opts .MaxReconnects , conn .addr , err )
93+ reconnects , conn .opts .MaxReconnects , conn .Addr () , err )
9494 case LogLastReconnectFailed :
9595 err := v [0 ].(error )
9696 log .Printf ("tarantool: last reconnect to %s failed: %s, giving it up" ,
97- conn .addr , err )
97+ conn .Addr () , err )
9898 case LogUnexpectedResultId :
9999 resp := v [0 ].(* Response )
100100 log .Printf ("tarantool: connection %s got unexpected resultId (%d) in response" ,
101- conn .addr , resp .RequestId )
101+ conn .Addr () , resp .RequestId )
102102 case LogWatchEventReadFailed :
103103 err := v [0 ].(error )
104104 log .Printf ("tarantool: unable to parse watch event: %s" , err )
@@ -156,10 +156,10 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
156156// More on graceful shutdown:
157157// https://www.tarantool.io/en/doc/latest/dev_guide/internals/iproto/graceful_shutdown/
158158type Connection struct {
159- addr string
160- c Conn
161- mutex sync.Mutex
162- cond * sync.Cond
159+ dialer Dialer
160+ c Conn
161+ mutex sync.Mutex
162+ cond * sync.Cond
163163 // Schema contains schema loaded on connection.
164164 Schema * Schema
165165 // requestId contains the last request ID for requests with nil context.
@@ -260,11 +260,6 @@ const (
260260
261261// Opts is a way to configure Connection
262262type Opts struct {
263- // Auth is an authentication method.
264- Auth Auth
265- // Dialer is a Dialer object used to create a new connection to a
266- // Tarantool instance. TtDialer is a default one.
267- Dialer Dialer
268263 // Timeout for response to a particular request. The timeout is reset when
269264 // push messages are received. If Timeout is zero, any request can be
270265 // blocked infinitely.
@@ -287,10 +282,6 @@ type Opts struct {
287282 // endlessly.
288283 // After MaxReconnects attempts Connection becomes closed.
289284 MaxReconnects uint
290- // Username for logging in to Tarantool.
291- User string
292- // User password for logging in to Tarantool.
293- Pass string
294285 // RateLimit limits number of 'in-fly' request, i.e. already put into
295286 // requests queue, but not yet answered by server or timeouted.
296287 // It is disabled by default.
@@ -315,83 +306,23 @@ type Opts struct {
315306 Handle interface {}
316307 // Logger is user specified logger used for error messages.
317308 Logger Logger
318- // Transport is the connection type, by default the connection is unencrypted.
319- Transport string
320- // SslOpts is used only if the Transport == 'ssl' is set.
321- Ssl SslOpts
322- // RequiredProtocolInfo contains minimal protocol version and
323- // list of protocol features that should be supported by
324- // Tarantool server. By default there are no restrictions.
325- RequiredProtocolInfo ProtocolInfo
326- }
327-
328- // SslOpts is a way to configure ssl transport.
329- type SslOpts struct {
330- // KeyFile is a path to a private SSL key file.
331- KeyFile string
332- // CertFile is a path to an SSL certificate file.
333- CertFile string
334- // CaFile is a path to a trusted certificate authorities (CA) file.
335- CaFile string
336- // Ciphers is a colon-separated (:) list of SSL cipher suites the connection
337- // can use.
338- //
339- // We don't provide a list of supported ciphers. This is what OpenSSL
340- // does. The only limitation is usage of TLSv1.2 (because other protocol
341- // versions don't seem to support the GOST cipher). To add additional
342- // ciphers (GOST cipher), you must configure OpenSSL.
343- //
344- // See also
345- //
346- // * https://www.openssl.org/docs/man1.1.1/man1/ciphers.html
347- Ciphers string
348- // Password is a password for decrypting the private SSL key file.
349- // The priority is as follows: try to decrypt with Password, then
350- // try PasswordFile.
351- Password string
352- // PasswordFile is a path to the list of passwords for decrypting
353- // the private SSL key file. The connection tries every line from the
354- // file as a password.
355- PasswordFile string
356- }
357-
358- // Clone returns a copy of the Opts object.
359- // Any changes in copy RequiredProtocolInfo will not affect the original
360- // RequiredProtocolInfo value.
361- func (opts Opts ) Clone () Opts {
362- optsCopy := opts
363- optsCopy .RequiredProtocolInfo = opts .RequiredProtocolInfo .Clone ()
364-
365- return optsCopy
366309}
367310
368311// Connect creates and configures a new Connection.
369- //
370- // Address could be specified in following ways:
371- //
372- // - TCP connections (tcp://192.168.1.1:3013, tcp://my.host:3013,
373- // tcp:192.168.1.1:3013, tcp:my.host:3013, 192.168.1.1:3013, my.host:3013)
374- //
375- // - Unix socket, first '/' or '.' indicates Unix socket
376- // (unix:///abs/path/tnt.sock, unix:path/tnt.sock, /abs/path/tnt.sock,
377- // ./rel/path/tnt.sock, unix/:path/tnt.sock)
378- func Connect (ctx context.Context , addr string , opts Opts ) (conn * Connection , err error ) {
312+ func Connect (ctx context.Context , dialer Dialer , opts Opts ) (conn * Connection , err error ) {
379313 conn = & Connection {
380- addr : addr ,
314+ dialer : dialer ,
381315 requestId : 0 ,
382316 contextRequestId : 1 ,
383317 Greeting : & Greeting {},
384318 control : make (chan struct {}),
385- opts : opts . Clone () ,
319+ opts : opts ,
386320 dec : msgpack .NewDecoder (& smallBuf {}),
387321 }
388322 maxprocs := uint32 (runtime .GOMAXPROCS (- 1 ))
389323 if conn .opts .Concurrency == 0 || conn .opts .Concurrency > maxprocs * 128 {
390324 conn .opts .Concurrency = maxprocs * 4
391325 }
392- if conn .opts .Dialer == nil {
393- conn .opts .Dialer = TtDialer {}
394- }
395326 if c := conn .opts .Concurrency ; c & (c - 1 ) != 0 {
396327 for i := uint (1 ); i < 32 ; i *= 2 {
397328 c |= c >> i
@@ -473,27 +404,7 @@ func (conn *Connection) CloseGraceful() error {
473404
474405// Addr returns a configured address of Tarantool socket.
475406func (conn * Connection ) Addr () string {
476- return conn .addr
477- }
478-
479- // RemoteAddr returns an address of Tarantool socket.
480- func (conn * Connection ) RemoteAddr () string {
481- conn .mutex .Lock ()
482- defer conn .mutex .Unlock ()
483- if conn .c == nil {
484- return ""
485- }
486- return conn .c .RemoteAddr ().String ()
487- }
488-
489- // LocalAddr returns an address of outgoing socket.
490- func (conn * Connection ) LocalAddr () string {
491- conn .mutex .Lock ()
492- defer conn .mutex .Unlock ()
493- if conn .c == nil {
494- return ""
495- }
496- return conn .c .LocalAddr ().String ()
407+ return conn .c .GetAddr ()
497408}
498409
499410// Handle returns a user-specified handle from Opts.
@@ -512,14 +423,8 @@ func (conn *Connection) dial(ctx context.Context) error {
512423 opts := conn .opts
513424
514425 var c Conn
515- c , err := conn .opts .Dialer .Dial (ctx , conn .addr , DialOpts {
516- IoTimeout : opts .Timeout ,
517- Transport : opts .Transport ,
518- Ssl : opts .Ssl ,
519- RequiredProtocol : opts .RequiredProtocolInfo ,
520- Auth : opts .Auth ,
521- User : opts .User ,
522- Password : opts .Pass ,
426+ c , err := conn .dialer .Dial (ctx , DialOpts {
427+ IoTimeout : opts .Timeout ,
523428 })
524429 if err != nil {
525430 return err
@@ -1474,7 +1379,7 @@ func (conn *Connection) NewWatcher(key string, callback WatchCallback) (Watcher,
14741379 // That's why we can't just check the Tarantool response for an unsupported
14751380 // request error.
14761381 if ! isFeatureInSlice (iproto .IPROTO_FEATURE_WATCHERS ,
1477- conn .opts . RequiredProtocolInfo .Features ) {
1382+ conn .c . ProtocolInfo () .Features ) {
14781383 err := fmt .Errorf ("the feature %s must be required by connection " +
14791384 "options to create a watcher" , iproto .IPROTO_FEATURE_WATCHERS )
14801385 return nil , err
@@ -1580,7 +1485,7 @@ func (conn *Connection) ServerProtocolInfo() ProtocolInfo {
15801485// Since 1.10.0
15811486func (conn * Connection ) ClientProtocolInfo () ProtocolInfo {
15821487 info := clientProtocolInfo .Clone ()
1583- info .Auth = conn .opts .Auth
1488+ info .Auth = conn .serverProtocolInfo .Auth
15841489 return info
15851490}
15861491
0 commit comments