mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-04-27 03:31:05 +03:00
client: imp code
This commit is contained in:
parent
ab897f64c8
commit
ed158ef09f
2 changed files with 19 additions and 2 deletions
internal/client
|
@ -167,7 +167,7 @@ func NewStorage(ctx context.Context, conf *StorageConfig) (s *Storage, err error
|
|||
mu: &sync.Mutex{},
|
||||
index: newIndex(),
|
||||
runtimeIndex: newRuntimeIndex(),
|
||||
upstreamManager: newUpstreamManager(),
|
||||
upstreamManager: newUpstreamManager(conf.Logger),
|
||||
dhcp: conf.DHCP,
|
||||
etcHosts: conf.EtcHosts,
|
||||
arpDB: conf.ARPDB,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
|
@ -8,6 +9,7 @@ import (
|
|||
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
||||
"github.com/AdguardTeam/golibs/stringutil"
|
||||
)
|
||||
|
||||
|
@ -33,6 +35,12 @@ type customUpstreamConfig struct {
|
|||
|
||||
// upstreamManager stores and updates custom client upstream configurations.
|
||||
type upstreamManager struct {
|
||||
// logger is used for logging the operation of the upstream manager. It
|
||||
// must not be nil.
|
||||
//
|
||||
// TODO(s.chzhen): Consider using a logger with its own prefix.
|
||||
logger *slog.Logger
|
||||
|
||||
// uidToCustomConf maps persistent client UID to the custom client upstream
|
||||
// configuration.
|
||||
uidToCustomConf map[UID]*customUpstreamConfig
|
||||
|
@ -46,8 +54,9 @@ type upstreamManager struct {
|
|||
}
|
||||
|
||||
// newUpstreamManager returns the new properly initialized upstream manager.
|
||||
func newUpstreamManager() (m *upstreamManager) {
|
||||
func newUpstreamManager(logger *slog.Logger) (m *upstreamManager) {
|
||||
return &upstreamManager{
|
||||
logger: logger,
|
||||
uidToCustomConf: make(map[UID]*customUpstreamConfig),
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +77,14 @@ func (m *upstreamManager) customUpstreamConfig(
|
|||
return cliConf.prxConf
|
||||
}
|
||||
|
||||
if ok && cliConf.prxConf != nil {
|
||||
err := cliConf.prxConf.Close()
|
||||
if err != nil {
|
||||
// TODO(s.chzhen): Pass context.
|
||||
m.logger.Debug("closing custom upstream config", slogutil.KeyError, err)
|
||||
}
|
||||
}
|
||||
|
||||
prxConf = newCustomUpstreamConfig(c, m.commonConf)
|
||||
m.uidToCustomConf[c.UID] = &customUpstreamConfig{
|
||||
prxConf: prxConf,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue