mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-01 13:41:07 +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{},
|
mu: &sync.Mutex{},
|
||||||
index: newIndex(),
|
index: newIndex(),
|
||||||
runtimeIndex: newRuntimeIndex(),
|
runtimeIndex: newRuntimeIndex(),
|
||||||
upstreamManager: newUpstreamManager(),
|
upstreamManager: newUpstreamManager(conf.Logger),
|
||||||
dhcp: conf.DHCP,
|
dhcp: conf.DHCP,
|
||||||
etcHosts: conf.EtcHosts,
|
etcHosts: conf.EtcHosts,
|
||||||
arpDB: conf.ARPDB,
|
arpDB: conf.ARPDB,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log/slog"
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@ import (
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||||
"github.com/AdguardTeam/golibs/errors"
|
"github.com/AdguardTeam/golibs/errors"
|
||||||
|
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
||||||
"github.com/AdguardTeam/golibs/stringutil"
|
"github.com/AdguardTeam/golibs/stringutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,6 +35,12 @@ type customUpstreamConfig struct {
|
||||||
|
|
||||||
// upstreamManager stores and updates custom client upstream configurations.
|
// upstreamManager stores and updates custom client upstream configurations.
|
||||||
type upstreamManager struct {
|
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
|
// uidToCustomConf maps persistent client UID to the custom client upstream
|
||||||
// configuration.
|
// configuration.
|
||||||
uidToCustomConf map[UID]*customUpstreamConfig
|
uidToCustomConf map[UID]*customUpstreamConfig
|
||||||
|
@ -46,8 +54,9 @@ type upstreamManager struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newUpstreamManager returns the new properly initialized upstream manager.
|
// newUpstreamManager returns the new properly initialized upstream manager.
|
||||||
func newUpstreamManager() (m *upstreamManager) {
|
func newUpstreamManager(logger *slog.Logger) (m *upstreamManager) {
|
||||||
return &upstreamManager{
|
return &upstreamManager{
|
||||||
|
logger: logger,
|
||||||
uidToCustomConf: make(map[UID]*customUpstreamConfig),
|
uidToCustomConf: make(map[UID]*customUpstreamConfig),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +77,14 @@ func (m *upstreamManager) customUpstreamConfig(
|
||||||
return cliConf.prxConf
|
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)
|
prxConf = newCustomUpstreamConfig(c, m.commonConf)
|
||||||
m.uidToCustomConf[c.UID] = &customUpstreamConfig{
|
m.uidToCustomConf[c.UID] = &customUpstreamConfig{
|
||||||
prxConf: prxConf,
|
prxConf: prxConf,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue