@@ -90,15 +90,15 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
90
90
reconnects := v [0 ].(uint )
91
91
err := v [1 ].(error )
92
92
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 )
94
94
case LogLastReconnectFailed :
95
95
err := v [0 ].(error )
96
96
log .Printf ("tarantool: last reconnect to %s failed: %s, giving it up" ,
97
- conn .addr , err )
97
+ conn .Addr () , err )
98
98
case LogUnexpectedResultId :
99
99
resp := v [0 ].(* Response )
100
100
log .Printf ("tarantool: connection %s got unexpected resultId (%d) in response" ,
101
- conn .addr , resp .RequestId )
101
+ conn .Addr () , resp .RequestId )
102
102
case LogWatchEventReadFailed :
103
103
err := v [0 ].(error )
104
104
log .Printf ("tarantool: unable to parse watch event: %s" , err )
@@ -156,10 +156,10 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
156
156
// More on graceful shutdown:
157
157
// https://www.tarantool.io/en/doc/latest/dev_guide/internals/iproto/graceful_shutdown/
158
158
type 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
163
163
// Schema contains schema loaded on connection.
164
164
Schema * Schema
165
165
// requestId contains the last request ID for requests with nil context.
@@ -260,11 +260,6 @@ const (
260
260
261
261
// Opts is a way to configure Connection
262
262
type 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
268
263
// Timeout for response to a particular request. The timeout is reset when
269
264
// push messages are received. If Timeout is zero, any request can be
270
265
// blocked infinitely.
@@ -287,10 +282,6 @@ type Opts struct {
287
282
// endlessly.
288
283
// After MaxReconnects attempts Connection becomes closed.
289
284
MaxReconnects uint
290
- // Username for logging in to Tarantool.
291
- User string
292
- // User password for logging in to Tarantool.
293
- Pass string
294
285
// RateLimit limits number of 'in-fly' request, i.e. already put into
295
286
// requests queue, but not yet answered by server or timeouted.
296
287
// It is disabled by default.
@@ -315,69 +306,20 @@ type Opts struct {
315
306
Handle interface {}
316
307
// Logger is user specified logger used for error messages.
317
308
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
309
}
357
310
358
311
// Clone returns a copy of the Opts object.
359
312
// Any changes in copy RequiredProtocolInfo will not affect the original
360
313
// RequiredProtocolInfo value.
361
314
func (opts Opts ) Clone () Opts {
362
315
optsCopy := opts
363
- optsCopy .RequiredProtocolInfo = opts .RequiredProtocolInfo .Clone ()
364
-
365
316
return optsCopy
366
317
}
367
318
368
319
// 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 ) {
320
+ func Connect (ctx context.Context , dialer Dialer , opts Opts ) (conn * Connection , err error ) {
379
321
conn = & Connection {
380
- addr : addr ,
322
+ dialer : dialer ,
381
323
requestId : 0 ,
382
324
contextRequestId : 1 ,
383
325
Greeting : & Greeting {},
@@ -389,9 +331,6 @@ func Connect(ctx context.Context, addr string, opts Opts) (conn *Connection, err
389
331
if conn .opts .Concurrency == 0 || conn .opts .Concurrency > maxprocs * 128 {
390
332
conn .opts .Concurrency = maxprocs * 4
391
333
}
392
- if conn .opts .Dialer == nil {
393
- conn .opts .Dialer = TtDialer {}
394
- }
395
334
if c := conn .opts .Concurrency ; c & (c - 1 ) != 0 {
396
335
for i := uint (1 ); i < 32 ; i *= 2 {
397
336
c |= c >> i
@@ -473,27 +412,7 @@ func (conn *Connection) CloseGraceful() error {
473
412
474
413
// Addr returns a configured address of Tarantool socket.
475
414
func (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 ()
415
+ return conn .c .GetAddr ()
497
416
}
498
417
499
418
// Handle returns a user-specified handle from Opts.
@@ -512,14 +431,8 @@ func (conn *Connection) dial(ctx context.Context) error {
512
431
opts := conn .opts
513
432
514
433
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 ,
434
+ c , err := conn .dialer .Dial (ctx , DialOpts {
435
+ IoTimeout : opts .Timeout ,
523
436
})
524
437
if err != nil {
525
438
return err
@@ -1474,7 +1387,7 @@ func (conn *Connection) NewWatcher(key string, callback WatchCallback) (Watcher,
1474
1387
// That's why we can't just check the Tarantool response for an unsupported
1475
1388
// request error.
1476
1389
if ! isFeatureInSlice (iproto .IPROTO_FEATURE_WATCHERS ,
1477
- conn .opts . RequiredProtocolInfo .Features ) {
1390
+ conn .c . ProtocolInfo () .Features ) {
1478
1391
err := fmt .Errorf ("the feature %s must be required by connection " +
1479
1392
"options to create a watcher" , iproto .IPROTO_FEATURE_WATCHERS )
1480
1393
return nil , err
@@ -1580,7 +1493,7 @@ func (conn *Connection) ServerProtocolInfo() ProtocolInfo {
1580
1493
// Since 1.10.0
1581
1494
func (conn * Connection ) ClientProtocolInfo () ProtocolInfo {
1582
1495
info := clientProtocolInfo .Clone ()
1583
- info .Auth = conn .opts .Auth
1496
+ info .Auth = conn .serverProtocolInfo .Auth
1584
1497
return info
1585
1498
}
1586
1499
0 commit comments