@@ -25,6 +25,11 @@ const (
25
25
connClosed = 2
26
26
)
27
27
28
+ const (
29
+ connTransportNone = ""
30
+ connTransportSsl = "ssl"
31
+ )
32
+
28
33
type ConnEventKind int
29
34
type ConnLogKind int
30
35
@@ -207,6 +212,32 @@ type Opts struct {
207
212
Handle interface {}
208
213
// Logger is user specified logger used for error messages.
209
214
Logger Logger
215
+ // Transport is the connection type, by default the connection is unencrypted.
216
+ Transport string
217
+ // SslOpts is used only if the Transport == 'ssl' is set.
218
+ Ssl SslOpts
219
+ }
220
+
221
+ // SslOpts is a way to configure ssl transport.
222
+ type SslOpts struct {
223
+ // KeyFile is a path to a private SSL key file.
224
+ KeyFile string
225
+ // CertFile is a path to an SSL sertificate file.
226
+ CertFile string
227
+ // CaFile is a path to a trusted certificate authorities (CA) file.
228
+ CaFile string
229
+ // Ciphers is a colon-separated (:) list of SSL cipher suites the connection
230
+ // can use.
231
+ //
232
+ // We don't provide a list of supported ciphers. This is what OpenSSL
233
+ // does. The only limitation is usage of TLSv1.2 (because other protocol
234
+ // versions don't seem to support the GOST cipher). To add additional
235
+ // ciphers (GOST cipher), you must configure OpenSSL.
236
+ //
237
+ // See also
238
+ //
239
+ // * https://www.openssl.org/docs/man1.1.1/man1/ciphers.html
240
+ Ciphers string
210
241
}
211
242
212
243
// Connect creates and configures a new Connection.
@@ -358,8 +389,10 @@ func (conn *Connection) Handle() interface{} {
358
389
func (conn * Connection ) dial () (err error ) {
359
390
var connection net.Conn
360
391
network := "tcp"
392
+ opts := conn .opts
361
393
address := conn .addr
362
- timeout := conn .opts .Reconnect / 2
394
+ timeout := opts .Reconnect / 2
395
+ transport := opts .Transport
363
396
if timeout == 0 {
364
397
timeout = 500 * time .Millisecond
365
398
} else if timeout > 5 * time .Second {
@@ -383,11 +416,17 @@ func (conn *Connection) dial() (err error) {
383
416
} else if addrLen >= 4 && address [0 :4 ] == "tcp:" {
384
417
address = address [4 :]
385
418
}
386
- connection , err = net .DialTimeout (network , address , timeout )
419
+ if transport == connTransportNone {
420
+ connection , err = net .DialTimeout (network , address , timeout )
421
+ } else if transport == connTransportSsl {
422
+ connection , err = sslDialTimeout (network , address , timeout , opts .Ssl )
423
+ } else {
424
+ err = errors .New ("An unsupported transport type: " + transport )
425
+ }
387
426
if err != nil {
388
427
return
389
428
}
390
- dc := & DeadlineIO {to : conn . opts .Timeout , c : connection }
429
+ dc := & DeadlineIO {to : opts .Timeout , c : connection }
391
430
r := bufio .NewReaderSize (dc , 128 * 1024 )
392
431
w := bufio .NewWriterSize (dc , 128 * 1024 )
393
432
greeting := make ([]byte , 128 )
@@ -400,8 +439,8 @@ func (conn *Connection) dial() (err error) {
400
439
conn .Greeting .auth = bytes .NewBuffer (greeting [64 :108 ]).String ()
401
440
402
441
// Auth
403
- if conn . opts .User != "" {
404
- scr , err := scramble (conn .Greeting .auth , conn . opts .Pass )
442
+ if opts .User != "" {
443
+ scr , err := scramble (conn .Greeting .auth , opts .Pass )
405
444
if err != nil {
406
445
err = errors .New ("auth: scrambling failure " + err .Error ())
407
446
connection .Close ()
0 commit comments