chore(settings): refactor settings processing (#756)
- Better settings tree structure logged using `qdm12/gotree` - Read settings from environment variables, then files, then secret files - Settings methods to default them, merge them and override them - `DNS_PLAINTEXT_ADDRESS` default changed to `127.0.0.1` to use DoT. Warning added if set to something else. - `HTTPPROXY_LISTENING_ADDRESS` instead of `HTTPPROXY_PORT` (with retro-compatibility)
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
shadowsockslib "github.com/qdm12/ss-server/pkg/tcpudp"
|
||||
@@ -17,8 +17,8 @@ type Looper interface {
|
||||
SetStatus(ctx context.Context, status models.LoopStatus) (
|
||||
outcome string, err error)
|
||||
GetStatus() (status models.LoopStatus)
|
||||
GetSettings() (settings configuration.ShadowSocks)
|
||||
SetSettings(ctx context.Context, settings configuration.ShadowSocks) (
|
||||
GetSettings() (settings settings.Shadowsocks)
|
||||
SetSettings(ctx context.Context, settings settings.Shadowsocks) (
|
||||
outcome string)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func (l *looper) logAndWait(ctx context.Context, err error) {
|
||||
|
||||
const defaultBackoffTime = 10 * time.Second
|
||||
|
||||
func NewLooper(settings configuration.ShadowSocks, logger Logger) Looper {
|
||||
func NewLooper(settings settings.Shadowsocks, logger Logger) Looper {
|
||||
return &looper{
|
||||
state: state{
|
||||
status: constants.Stopped,
|
||||
@@ -72,7 +72,7 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) {
|
||||
|
||||
crashed := false
|
||||
|
||||
if l.GetSettings().Enabled {
|
||||
if *l.GetSettings().Enabled {
|
||||
go func() {
|
||||
_, _ = l.SetStatus(ctx, constants.Running)
|
||||
}()
|
||||
|
||||
@@ -7,14 +7,14 @@ import (
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type state struct {
|
||||
status models.LoopStatus
|
||||
settings configuration.ShadowSocks
|
||||
settings settings.Shadowsocks
|
||||
statusMu sync.RWMutex
|
||||
settingsMu sync.RWMutex
|
||||
}
|
||||
@@ -84,13 +84,13 @@ func (l *looper) SetStatus(ctx context.Context, status models.LoopStatus) (
|
||||
}
|
||||
}
|
||||
|
||||
func (l *looper) GetSettings() (settings configuration.ShadowSocks) {
|
||||
func (l *looper) GetSettings() (settings settings.Shadowsocks) {
|
||||
l.state.settingsMu.RLock()
|
||||
defer l.state.settingsMu.RUnlock()
|
||||
return l.state.settings
|
||||
}
|
||||
|
||||
func (l *looper) SetSettings(ctx context.Context, settings configuration.ShadowSocks) (
|
||||
func (l *looper) SetSettings(ctx context.Context, settings settings.Shadowsocks) (
|
||||
outcome string) {
|
||||
l.state.settingsMu.Lock()
|
||||
settingsUnchanged := reflect.DeepEqual(settings, l.state.settings)
|
||||
@@ -98,8 +98,8 @@ func (l *looper) SetSettings(ctx context.Context, settings configuration.ShadowS
|
||||
l.state.settingsMu.Unlock()
|
||||
return "settings left unchanged"
|
||||
}
|
||||
newEnabled := settings.Enabled
|
||||
previousEnabled := l.state.settings.Enabled
|
||||
newEnabled := *settings.Enabled
|
||||
previousEnabled := *l.state.settings.Enabled
|
||||
l.state.settings = settings
|
||||
l.state.settingsMu.Unlock()
|
||||
// Either restart or set changed status
|
||||
|
||||
Reference in New Issue
Block a user