refactor(proxy): rename server TLS config field
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
b6b44b1f7b
commit
8cf01f2618
2 changed files with 19 additions and 19 deletions
|
|
@ -18,7 +18,7 @@ import (
|
|||
// }
|
||||
type Server struct {
|
||||
addr BindAddr
|
||||
tlsCfg *tls.Config // nil for plain TCP
|
||||
tlsConfig *tls.Config // nil for plain TCP
|
||||
limiter *RateLimiter
|
||||
onAccept func(net.Conn, uint16)
|
||||
listener net.Listener
|
||||
|
|
|
|||
|
|
@ -210,20 +210,20 @@ func (p *Proxy) Start() {
|
|||
return
|
||||
}
|
||||
for _, bind := range p.config.Bind {
|
||||
var tlsCfg *tls.Config
|
||||
var tlsConfig *tls.Config
|
||||
if bind.TLS {
|
||||
if !p.config.TLS.Enabled {
|
||||
p.Stop()
|
||||
return
|
||||
}
|
||||
var result Result
|
||||
tlsCfg, result = buildTLSConfig(p.config.TLS)
|
||||
tlsConfig, result = buildTLSConfig(p.config.TLS)
|
||||
if !result.OK {
|
||||
p.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
server, result := NewServer(bind, tlsCfg, p.rateLimit, p.acceptMiner)
|
||||
server, result := NewServer(bind, tlsConfig, p.rateLimit, p.acceptMiner)
|
||||
if !result.OK {
|
||||
p.Stop()
|
||||
return
|
||||
|
|
@ -1742,17 +1742,17 @@ func (cd *CustomDiff) Apply(miner *Miner) {
|
|||
|
||||
// NewServer constructs a server instance.
|
||||
//
|
||||
// server, result := proxy.NewServer(bind, tlsCfg, limiter, func(conn net.Conn, port uint16) {
|
||||
// server, result := proxy.NewServer(bind, tlsConfig, limiter, func(conn net.Conn, port uint16) {
|
||||
// _ = conn
|
||||
// _ = port
|
||||
// })
|
||||
func NewServer(bind BindAddr, tlsCfg *tls.Config, limiter *RateLimiter, onAccept func(net.Conn, uint16)) (*Server, Result) {
|
||||
func NewServer(bind BindAddr, tlsConfig *tls.Config, limiter *RateLimiter, onAccept func(net.Conn, uint16)) (*Server, Result) {
|
||||
if onAccept == nil {
|
||||
onAccept = func(net.Conn, uint16) {}
|
||||
}
|
||||
server := &Server{
|
||||
addr: bind,
|
||||
tlsCfg: tlsCfg,
|
||||
tlsConfig: tlsConfig,
|
||||
limiter: limiter,
|
||||
onAccept: onAccept,
|
||||
done: make(chan struct{}),
|
||||
|
|
@ -1819,15 +1819,15 @@ func (s *Server) listen() Result {
|
|||
if s.listener != nil {
|
||||
return newSuccessResult()
|
||||
}
|
||||
if s.addr.TLS && s.tlsCfg == nil {
|
||||
if s.addr.TLS && s.tlsConfig == nil {
|
||||
return newErrorResult(NewScopedError("proxy.server", "tls listener requires a tls config", nil))
|
||||
}
|
||||
ln, err := net.Listen("tcp", net.JoinHostPort(s.addr.Host, strconv.Itoa(int(s.addr.Port))))
|
||||
if err != nil {
|
||||
return newErrorResult(NewScopedError("proxy.server", "listen failed", err))
|
||||
}
|
||||
if s.tlsCfg != nil {
|
||||
ln = tls.NewListener(ln, s.tlsCfg)
|
||||
if s.tlsConfig != nil {
|
||||
ln = tls.NewListener(ln, s.tlsConfig)
|
||||
}
|
||||
s.listener = ln
|
||||
return newSuccessResult()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue