Skip to content

Commit

Permalink
feat: Add TLS configuration for WssClient and WssServer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Sep 1, 2024
1 parent 51d36ef commit ed79c15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *Config) Adjust() error {
}
// init tls when need
for _, r := range c.RelayConfigs {
if r.ListenType == constant.RelayTypeWSS {
if r.ListenType == constant.RelayTypeWSS || r.TransportType == constant.RelayTypeWSS {
if err := tls.InitTlsCfg(); err != nil {
return err
}
Expand Down
21 changes: 9 additions & 12 deletions internal/transporter/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,19 @@ var (
)

type WsClient struct {
dialer *ws.Dialer
cfg *conf.Config
netDialer *net.Dialer
l *zap.SugaredLogger
dialer *ws.Dialer
cfg *conf.Config
l *zap.SugaredLogger
}

func newWsClient(cfg *conf.Config) (*WsClient, error) {
s := &WsClient{
cfg: cfg,
netDialer: NewNetDialer(cfg),
l: zap.S().Named(string(cfg.TransportType)),
dialer: &ws.DefaultDialer, // todo config buffer size
}
s.dialer.NetDial = func(ctx context.Context, network, addr string) (net.Conn, error) {
return s.netDialer.Dial(network, addr)
cfg: cfg,
l: zap.S().Named(string(cfg.TransportType)),
// todo config buffer size
dialer: &ws.Dialer{
Timeout: cfg.Options.DialTimeout,
},
}
return s, nil
}
Expand All @@ -64,7 +62,6 @@ func (s *WsClient) HandShake(ctx context.Context, remote *lb.Node, isTCP bool) (
if !isTCP {
addr = s.addUDPQueryParam(addr)
}

wsc, _, _, err := s.dialer.Dial(ctx, addr)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions internal/transporter/wss.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func newWssClient(cfg *conf.Config) (*WssClient, error) {
}
// insert tls config
wc.dialer.TLSConfig = mytls.DefaultTLSConfig
wc.dialer.TLSConfig.InsecureSkipVerify = true
return &WssClient{WsClient: wc}, nil
}

Expand All @@ -44,6 +45,8 @@ func (s *WssServer) ListenAndServe(ctx context.Context) error {
if err != nil {
return err
}
tlsCfg := mytls.DefaultTLSConfig
tlsCfg.InsecureSkipVerify = true
tlsListener := tls.NewListener(listener, mytls.DefaultTLSConfig)
return s.httpServer.Serve(tlsListener)
}

0 comments on commit ed79c15

Please sign in to comment.