diff --git a/internal/next/agh/agh.go b/internal/next/agh/agh.go index c70207f1d0c..52855524734 100644 --- a/internal/next/agh/agh.go +++ b/internal/next/agh/agh.go @@ -50,10 +50,10 @@ var _ ServiceWithConfig[struct{}] = (*EmptyServiceWithConfig[struct{}])(nil) // method returns Conf. // // TODO(a.garipov): Remove if unnecessary. -type EmptyServiceWithConfig[T any] struct { +type EmptyServiceWithConfig[ConfigType any] struct { EmptyService - Conf T + Conf ConfigType } // Config implements the [ServiceWithConfig] interface for diff --git a/internal/next/cmd/cmd.go b/internal/next/cmd/cmd.go index 1d526afc172..9a3e4e95b01 100644 --- a/internal/next/cmd/cmd.go +++ b/internal/next/cmd/cmd.go @@ -11,7 +11,7 @@ import ( "os" "time" - "github.com/AdguardTeam/AdGuardHome/internal/next/svc" + "github.com/AdguardTeam/AdGuardHome/internal/next/configmgr" "github.com/AdguardTeam/AdGuardHome/internal/version" "github.com/AdguardTeam/golibs/log" ) @@ -35,7 +35,7 @@ func Main(clientBuildFS fs.FS) { // TODO(a.garipov): Set up configuration file name. const confFile = "AdGuardHome.1.yaml" - confMgr, err := svc.New(confFile, start) + confMgr, err := configmgr.New(confFile, start) fatalOnError(err) web := confMgr.Web() diff --git a/internal/next/cmd/signal.go b/internal/next/cmd/signal.go index 5ae35d4f37c..15fad264d4e 100644 --- a/internal/next/cmd/signal.go +++ b/internal/next/cmd/signal.go @@ -6,7 +6,7 @@ import ( "github.com/AdguardTeam/AdGuardHome/internal/aghos" "github.com/AdguardTeam/AdGuardHome/internal/next/agh" - "github.com/AdguardTeam/AdGuardHome/internal/next/svc" + "github.com/AdguardTeam/AdGuardHome/internal/next/configmgr" "github.com/AdguardTeam/golibs/log" ) @@ -44,7 +44,7 @@ func (h *signalHandler) reconfigure(confFile string, start time.Time) { // reconfigured without the full shutdown, and the error handling is // currently not the best. - confMgr, err := svc.New(confFile, start) + confMgr, err := configmgr.New(confFile, start) fatalOnError(err) web := confMgr.Web() diff --git a/internal/next/svc/config.go b/internal/next/configmgr/config.go similarity index 98% rename from internal/next/svc/config.go rename to internal/next/configmgr/config.go index 480995aba02..d11d8c1a79b 100644 --- a/internal/next/svc/config.go +++ b/internal/next/configmgr/config.go @@ -1,4 +1,4 @@ -package svc +package configmgr import ( "net/netip" diff --git a/internal/next/svc/configmanager.go b/internal/next/configmgr/configmgr.go similarity index 70% rename from internal/next/svc/configmanager.go rename to internal/next/configmgr/configmgr.go index bad74e8e799..5b0422743e6 100644 --- a/internal/next/svc/configmanager.go +++ b/internal/next/configmgr/configmgr.go @@ -1,4 +1,6 @@ -package svc +// Package configmgr defines the AdGuard Home on-disk configuration entities and +// configuration manager. +package configmgr import ( "context" @@ -17,9 +19,9 @@ import ( // Configuration Manager -// ConfigManager handles full and partial changes in the configuration, -// persisting them to disk if necessary. -type ConfigManager struct { +// Manager handles full and partial changes in the configuration, persisting +// them to disk if necessary. +type Manager struct { // updMu makes sure that at most one reconfiguration is performed at a time. // updMu protects all fields below. updMu *sync.RWMutex @@ -37,10 +39,10 @@ type ConfigManager struct { fileName string } -// New creates a new ConfigManager that persists changes to the file pointed to -// by fileName. It reads the configuration file and populates the service -// fields. start is the startup time of AdGuard Home. -func New(fileName string, start time.Time) (m *ConfigManager, err error) { +// New creates a new *Manager that persists changes to the file pointed to by +// fileName. It reads the configuration file and populates the service fields. +// start is the startup time of AdGuard Home. +func New(fileName string, start time.Time) (m *Manager, err error) { defer func() { err = errors.Annotate(err, "reading config") }() conf := &config{} @@ -66,14 +68,15 @@ func New(fileName string, start time.Time) (m *ConfigManager, err error) { // TODO(a.garipov): Validate the configuration structure. Return an error // if it's incorrect. - m = &ConfigManager{ + m = &Manager{ updMu: &sync.RWMutex{}, current: conf, fileName: fileName, } - // TODO(a.garipov): Get the context from the arguments? - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + // TODO(a.garipov): Get the context with the timeout from the arguments? + const assemblyTimeout = 5 * time.Second + ctx, cancel := context.WithTimeout(context.Background(), assemblyTimeout) defer cancel() err = m.assemble(ctx, conf, start) @@ -87,7 +90,7 @@ func New(fileName string, start time.Time) (m *ConfigManager, err error) { // assemble creates all services and puts them into the corresponding fields. // The fields of conf must not be modified after calling assemble. -func (m *ConfigManager) assemble(ctx context.Context, conf *config, start time.Time) (err error) { +func (m *Manager) assemble(ctx context.Context, conf *config, start time.Time) (err error) { dnsConf := &dnssvc.Config{ Addresses: conf.DNS.Addresses, BootstrapServers: conf.DNS.BootstrapDNS, @@ -101,7 +104,7 @@ func (m *ConfigManager) assemble(ctx context.Context, conf *config, start time.T webSvcConf := &websvc.Config{ ConfigManager: m, - // TODO(a.garipov): this. + // TODO(a.garipov): Fill from config file. TLS: nil, Start: start, Addresses: conf.HTTP.Addresses, @@ -119,16 +122,16 @@ func (m *ConfigManager) assemble(ctx context.Context, conf *config, start time.T } // DNS returns the current DNS service. It is safe for concurrent use. -func (m *ConfigManager) DNS() (dns agh.ServiceWithConfig[*dnssvc.Config]) { +func (m *Manager) DNS() (dns agh.ServiceWithConfig[*dnssvc.Config]) { m.updMu.RLock() defer m.updMu.RUnlock() return m.dns } -// UpdateDNS implements the websvc.ConfigManager interface for *ConfigManager. -// The fields of c must not be modified after calling UpdateDNS. -func (m *ConfigManager) UpdateDNS(ctx context.Context, c *dnssvc.Config) (err error) { +// UpdateDNS implements the [websvc.ConfigManager] interface for *Manager. The +// fields of c must not be modified after calling UpdateDNS. +func (m *Manager) UpdateDNS(ctx context.Context, c *dnssvc.Config) (err error) { m.updMu.Lock() defer m.updMu.Unlock() @@ -144,7 +147,7 @@ func (m *ConfigManager) UpdateDNS(ctx context.Context, c *dnssvc.Config) (err er } // updateDNS recreates the DNS service. m.updMu is expected to be locked. -func (m *ConfigManager) updateDNS(ctx context.Context, c *dnssvc.Config) (err error) { +func (m *Manager) updateDNS(ctx context.Context, c *dnssvc.Config) (err error) { if prev := m.dns; prev != nil { err = prev.Shutdown(ctx) if err != nil { @@ -163,16 +166,16 @@ func (m *ConfigManager) updateDNS(ctx context.Context, c *dnssvc.Config) (err er } // Web returns the current web service. It is safe for concurrent use. -func (m *ConfigManager) Web() (web agh.ServiceWithConfig[*websvc.Config]) { +func (m *Manager) Web() (web agh.ServiceWithConfig[*websvc.Config]) { m.updMu.RLock() defer m.updMu.RUnlock() return m.web } -// UpdateWeb implements the websvc.ConfigManager interface for *ConfigManager. -// The fields of c must not be modified after calling UpdateWeb. -func (m *ConfigManager) UpdateWeb(ctx context.Context, c *websvc.Config) (err error) { +// UpdateWeb implements the [websvc.ConfigManager] interface for *Manager. The +// fields of c must not be modified after calling UpdateWeb. +func (m *Manager) UpdateWeb(ctx context.Context, c *websvc.Config) (err error) { m.updMu.Lock() defer m.updMu.Unlock() @@ -188,7 +191,7 @@ func (m *ConfigManager) UpdateWeb(ctx context.Context, c *websvc.Config) (err er } // updateWeb recreates the web service. m.upd is expected to be locked. -func (m *ConfigManager) updateWeb(ctx context.Context, c *websvc.Config) (err error) { +func (m *Manager) updateWeb(ctx context.Context, c *websvc.Config) (err error) { if prev := m.web; prev != nil { err = prev.Shutdown(ctx) if err != nil { diff --git a/internal/next/svc/svc.go b/internal/next/svc/svc.go deleted file mode 100644 index 6c98d73492e..00000000000 --- a/internal/next/svc/svc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package svc defines the AdGuard Home service locator, assembler, as well as -// on-disk configuration manager. -package svc