Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get status of TLS from server service #629

Merged
merged 4 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func (a *API) GetServers(context.Context, *emptypb.Empty) (*structpb.Struct, err
"status": uint(server.Status),
"tickInterval": server.TickInterval.Nanoseconds(),
"loadBalancer": map[string]any{"strategy": server.LoadbalancerStrategyName},
"isTLSEnabled": server.IsTLSEnabled(),
}
}

Expand Down
29 changes: 23 additions & 6 deletions network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
Shutdown
)

//nolint:interfacebloat
type IServer interface {
OnBoot() Action
OnOpen(conn *ConnWrapper) ([]byte, Action)
Expand All @@ -44,7 +45,10 @@ type IServer interface {
Run() *gerr.GatewayDError
Shutdown()
IsRunning() bool
IsTLSEnabled() bool
CountConnections() int
GetProxyForConnection(conn *ConnWrapper) (IProxy, bool)
RemoveConnectionFromMap(conn *ConnWrapper)
}

type Server struct {
Expand All @@ -69,12 +73,13 @@ type Server struct {
KeyFile string
HandshakeTimeout time.Duration

listener net.Listener
host string
port int
connections uint32
running *atomic.Bool
stopServer chan struct{}
listener net.Listener
host string
port int
connections uint32
running *atomic.Bool
isTLSEnabled *atomic.Bool
stopServer chan struct{}

// loadbalancer
loadbalancerStrategy LoadBalancerStrategy
Expand Down Expand Up @@ -543,6 +548,9 @@ func (s *Server) Run() *gerr.GatewayDError {
return gerr.ErrCastFailed.Wrap(origErr)
}

s.isTLSEnabled = &atomic.Bool{}
s.running = &atomic.Bool{}

go func(server *Server) {
<-server.stopServer
server.OnShutdown()
Expand Down Expand Up @@ -582,6 +590,7 @@ func (s *Server) Run() *gerr.GatewayDError {
return gerr.ErrGetTLSConfigFailed.Wrap(origErr)
}
s.Logger.Info().Msg("TLS is enabled")
s.isTLSEnabled.Store(true)
} else {
s.Logger.Debug().Msg("TLS is disabled")
}
Expand Down Expand Up @@ -767,6 +776,14 @@ func (s *Server) CountConnections() int {
return int(s.connections)
}

// IsTLSEnabled returns true if TLS is enabled.
func (s *Server) IsTLSEnabled() bool {
if s.isTLSEnabled == nil {
return false
}
return s.isTLSEnabled.Load()
}

// GetProxyForConnection returns the proxy associated with the given connection.
func (s *Server) GetProxyForConnection(conn *ConnWrapper) (IProxy, bool) {
proxy, exists := s.connectionToProxyMap.Load(conn)
Expand Down