mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-23 07:10:21 +03:00
388583cefe
Merge in DNS/adguard-home from custom-ups-cache to master Squashed commit of the following: commit 98428a87520f70cb522701d8eccfe4c529be1e40 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 10:53:32 2023 +0200 all: upd dep commit 775a639af4a2a45220b17e8b0037edc126ff62e4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 09:52:31 2023 +0200 dnsforward: imp test commit e9e2a58b48e8588dfcb28df319d4651e1fe77af5 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 09:44:46 2023 +0200 docs: changelog commit a6d67218f037c8fec29e5fa2967476d63c3cfc32 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 17 09:37:17 2023 +0200 all: upd dep commit b101ff6e0cf393dacdee6fb68d33ba8f11c36280 Merge: d61f4eb888bb1aad73
Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Nov 16 15:54:05 2023 +0200 Merge remote-tracking branch 'origin/master' into custom-ups-cache commit d61f4eb8871f8ae8504259998bf9015b29001cfb Merge: 567a8a4affdf60eeed
Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Nov 13 10:32:22 2023 +0200 Merge remote-tracking branch 'origin/master' into custom-ups-cache commit 567a8a4af34ad001d0e6d7d2efdc123205569e8c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Nov 13 10:30:24 2023 +0200 home: imp code commit a3c16facbebc166e5c0c731c1e892b61c0950d9e Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 14:34:04 2023 +0200 all: imp code commit 84160eafee1d0f2d0cd3f025f2d5070e4f597ad6 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 14:31:26 2023 +0200 all: conf custom ups cache commit b7f6581901ebad96c87e765a305a1fa5b336efbb Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 14:29:47 2023 +0200 all: conf custom ups cache commit d07df945d4e7614a679ef5dc77756096abf1e66c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 09:26:29 2023 +0200 all: docs commit 998124bac08889c7d354dd1a099929726725bccc Merge: f665e2f8553170d871
Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 09:24:28 2023 +0200 Merge remote-tracking branch 'origin/master' into custom-ups-cache commit f665e2f85bce12d95f80aba6614b6bfd4874b122 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Nov 10 09:22:46 2023 +0200 all: conf custom ups cache commit a4b26973bef4f3b339198ffbe52a50baca303daf Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Nov 9 12:46:39 2023 +0200 all: conf custom ups cache
100 lines
2.7 KiB
Go
100 lines
2.7 KiB
Go
package home
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/client"
|
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
|
|
"github.com/AdguardTeam/AdGuardHome/internal/whois"
|
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
|
"github.com/AdguardTeam/golibs/stringutil"
|
|
)
|
|
|
|
// Client contains information about persistent clients.
|
|
type Client struct {
|
|
// upstreamConfig is the custom upstream configuration for this client. If
|
|
// it's nil, it has not been initialized yet. If it's non-nil and empty,
|
|
// there are no valid upstreams. If it's non-nil and non-empty, these
|
|
// upstream must be used.
|
|
upstreamConfig *proxy.CustomUpstreamConfig
|
|
|
|
safeSearchConf filtering.SafeSearchConfig
|
|
SafeSearch filtering.SafeSearch
|
|
|
|
// BlockedServices is the configuration of blocked services of a client.
|
|
BlockedServices *filtering.BlockedServices
|
|
|
|
Name string
|
|
|
|
IDs []string
|
|
Tags []string
|
|
Upstreams []string
|
|
|
|
UpstreamsCacheSize uint32
|
|
UpstreamsCacheEnabled bool
|
|
|
|
UseOwnSettings bool
|
|
FilteringEnabled bool
|
|
SafeBrowsingEnabled bool
|
|
ParentalEnabled bool
|
|
UseOwnBlockedServices bool
|
|
IgnoreQueryLog bool
|
|
IgnoreStatistics bool
|
|
}
|
|
|
|
// ShallowClone returns a deep copy of the client, except upstreamConfig,
|
|
// safeSearchConf, SafeSearch fields, because it's difficult to copy them.
|
|
func (c *Client) ShallowClone() (sh *Client) {
|
|
clone := *c
|
|
|
|
clone.BlockedServices = c.BlockedServices.Clone()
|
|
clone.IDs = stringutil.CloneSlice(c.IDs)
|
|
clone.Tags = stringutil.CloneSlice(c.Tags)
|
|
clone.Upstreams = stringutil.CloneSlice(c.Upstreams)
|
|
|
|
return &clone
|
|
}
|
|
|
|
// closeUpstreams closes the client-specific upstream config of c if any.
|
|
func (c *Client) closeUpstreams() (err error) {
|
|
if c.upstreamConfig != nil {
|
|
if err = c.upstreamConfig.Close(); err != nil {
|
|
return fmt.Errorf("closing upstreams of client %q: %w", c.Name, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// setSafeSearch initializes and sets the safe search filter for this client.
|
|
func (c *Client) setSafeSearch(
|
|
conf filtering.SafeSearchConfig,
|
|
cacheSize uint,
|
|
cacheTTL time.Duration,
|
|
) (err error) {
|
|
ss, err := safesearch.NewDefault(conf, fmt.Sprintf("client %q", c.Name), cacheSize, cacheTTL)
|
|
if err != nil {
|
|
// Don't wrap the error, because it's informative enough as is.
|
|
return err
|
|
}
|
|
|
|
c.SafeSearch = ss
|
|
|
|
return nil
|
|
}
|
|
|
|
// RuntimeClient is a client information about which has been obtained using the
|
|
// source described in the Source field.
|
|
type RuntimeClient struct {
|
|
// WHOIS is the filtered WHOIS data of a client.
|
|
WHOIS *whois.Info
|
|
|
|
// Host is the host name of a client.
|
|
Host string
|
|
|
|
// Source is the source from which the information about the client has
|
|
// been obtained.
|
|
Source client.Source
|
|
}
|