Commit 94d35a38 authored by aliiohs's avatar aliiohs

add tls support

parent b89c0bb5
......@@ -153,7 +153,7 @@ func (c *client) dialTCP() Session {
if c.IsClosed() {
return nil
}
if c.sslConfig != nil {
if c.sslEnabled && c.sslConfig != nil {
d := &net.Dialer{Timeout: connectTimeout}
conn, err = tls.DialWithDialer(d, "tcp", c.addr, c.sslConfig)
} else {
......
module github.com/dubbogo/getty
go 1.14
require (
github.com/dubbogo/gost v1.9.0
github.com/golang/snappy v0.0.1
......@@ -8,5 +10,3 @@ require (
github.com/stretchr/testify v1.5.1
go.uber.org/zap v1.15.0
)
go 1.13
......@@ -17,6 +17,8 @@
package getty
import "crypto/tls"
/////////////////////////////////////////
// Server Options
/////////////////////////////////////////
......@@ -25,6 +27,9 @@ type ServerOption func(*ServerOptions)
type ServerOptions struct {
addr string
//tls
sslEnabled bool
sslConfig *tls.Config
// websocket
path string
......@@ -79,6 +84,10 @@ type ClientOptions struct {
number int
reconnectInterval int // reConnect Interval
//tls
sslEnabled bool
sslConfig *tls.Config
// the cert file of wss server which may contain server domain, server ip, the starting effective date, effective
// duration, the hash alg, the len of the private key.
// wss client will use it.
......
......@@ -56,7 +56,6 @@ type server struct {
lock sync.Mutex // for server
endPointType EndPointType
server *http.Server // for ws or wss server
sslConfig *tls.Config
sync.Once
done chan struct{}
wg sync.WaitGroup
......@@ -175,7 +174,7 @@ func (s *server) listenTCP() error {
return perrors.Wrapf(err, "gxnet.ListenOnTCPRandomPort(addr:%s)", s.addr)
}
} else {
if s.sslConfig != nil {
if s.sslEnabled && s.sslConfig != nil {
streamListener, err = tls.Listen("tcp", s.addr, s.sslConfig)
} else {
streamListener, err = net.Listen("tcp", s.addr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment