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
12
server.go
12
server.go
|
|
@ -17,10 +17,10 @@ import (
|
||||||
// srv.Start()
|
// srv.Start()
|
||||||
// }
|
// }
|
||||||
type Server struct {
|
type Server struct {
|
||||||
addr BindAddr
|
addr BindAddr
|
||||||
tlsCfg *tls.Config // nil for plain TCP
|
tlsConfig *tls.Config // nil for plain TCP
|
||||||
limiter *RateLimiter
|
limiter *RateLimiter
|
||||||
onAccept func(net.Conn, uint16)
|
onAccept func(net.Conn, uint16)
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -210,20 +210,20 @@ func (p *Proxy) Start() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, bind := range p.config.Bind {
|
for _, bind := range p.config.Bind {
|
||||||
var tlsCfg *tls.Config
|
var tlsConfig *tls.Config
|
||||||
if bind.TLS {
|
if bind.TLS {
|
||||||
if !p.config.TLS.Enabled {
|
if !p.config.TLS.Enabled {
|
||||||
p.Stop()
|
p.Stop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var result Result
|
var result Result
|
||||||
tlsCfg, result = buildTLSConfig(p.config.TLS)
|
tlsConfig, result = buildTLSConfig(p.config.TLS)
|
||||||
if !result.OK {
|
if !result.OK {
|
||||||
p.Stop()
|
p.Stop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
server, result := NewServer(bind, tlsCfg, p.rateLimit, p.acceptMiner)
|
server, result := NewServer(bind, tlsConfig, p.rateLimit, p.acceptMiner)
|
||||||
if !result.OK {
|
if !result.OK {
|
||||||
p.Stop()
|
p.Stop()
|
||||||
return
|
return
|
||||||
|
|
@ -1742,20 +1742,20 @@ func (cd *CustomDiff) Apply(miner *Miner) {
|
||||||
|
|
||||||
// NewServer constructs a server instance.
|
// 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
|
// _ = conn
|
||||||
// _ = port
|
// _ = 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 {
|
if onAccept == nil {
|
||||||
onAccept = func(net.Conn, uint16) {}
|
onAccept = func(net.Conn, uint16) {}
|
||||||
}
|
}
|
||||||
server := &Server{
|
server := &Server{
|
||||||
addr: bind,
|
addr: bind,
|
||||||
tlsCfg: tlsCfg,
|
tlsConfig: tlsConfig,
|
||||||
limiter: limiter,
|
limiter: limiter,
|
||||||
onAccept: onAccept,
|
onAccept: onAccept,
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
if result := server.listen(); !result.OK {
|
if result := server.listen(); !result.OK {
|
||||||
return nil, result
|
return nil, result
|
||||||
|
|
@ -1819,15 +1819,15 @@ func (s *Server) listen() Result {
|
||||||
if s.listener != nil {
|
if s.listener != nil {
|
||||||
return newSuccessResult()
|
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))
|
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))))
|
ln, err := net.Listen("tcp", net.JoinHostPort(s.addr.Host, strconv.Itoa(int(s.addr.Port))))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newErrorResult(NewScopedError("proxy.server", "listen failed", err))
|
return newErrorResult(NewScopedError("proxy.server", "listen failed", err))
|
||||||
}
|
}
|
||||||
if s.tlsCfg != nil {
|
if s.tlsConfig != nil {
|
||||||
ln = tls.NewListener(ln, s.tlsCfg)
|
ln = tls.NewListener(ln, s.tlsConfig)
|
||||||
}
|
}
|
||||||
s.listener = ln
|
s.listener = ln
|
||||||
return newSuccessResult()
|
return newSuccessResult()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue