Fix SOCKS5_ENABLED being ignored

This commit is contained in:
Quentin McGaw
2026-05-19 14:29:34 +00:00
parent 5cd7bc7f74
commit f021d8faf8
3 changed files with 28 additions and 1 deletions
+23 -1
View File
@@ -4,6 +4,8 @@ import (
"context"
"sync"
"time"
"github.com/qdm12/goservices"
)
type Loop struct {
@@ -45,7 +47,13 @@ func run(ctx context.Context, done chan<- error, settings Settings) {
logger := settings.Logger
for ctx.Err() == nil {
server := newServer(settings)
var server goservices.Service
if settings.Enabled {
server = newServer(settings)
} else {
server = new(noopService)
}
errorCh, err := server.Start(ctx)
if err != nil {
logger.Warnf("failed starting SOCKS5 server: %s", err)
@@ -83,3 +91,17 @@ func waitBeforeRetry(ctx context.Context) {
case <-ctx.Done():
}
}
type noopService struct{}
func (s noopService) Start(_ context.Context) (runErr <-chan error, err error) {
return nil, nil //nolint:nilnil
}
func (s noopService) Stop() error {
return nil
}
func (s noopService) String() string {
return "noop service"
}
+4
View File
@@ -32,6 +32,10 @@ func newServer(settings Settings) *server {
}
}
func (s *server) String() string {
return "SOCKS5 server"
}
func (s *server) Start(ctx context.Context) (runErr <-chan error, err error) {
s.socksConnCtx, s.socksConnCancel = context.WithCancel(context.Background())
config := &net.ListenConfig{}
+1
View File
@@ -1,6 +1,7 @@
package socks5
type Settings struct {
Enabled bool
Username string
Password string
Address string