mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-04-30 13:11:37 +03:00
Pull request 1786: rm-context-fields
Merge in DNS/adguard-home from rm-context-fields to master Squashed commit of the following: commit 402bbba6a68f163cd6a3751a50ecd544eebc875f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Mar 28 13:07:11 2023 +0300 aghnet: names commit 209a2bb7878ee9110595f1fcf09df7f83777b80f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Mar 28 13:03:33 2023 +0300 home: typo commit 61684815c260d5d7a34be612e06714456399a833 Merge: 7adfcf15132ec556
Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Mar 28 13:02:18 2023 +0300 Merge branch 'master' into rm-context-fields commit 7adfcf1576b52f80137aa9044355bfbec6243e28 Merge: 0d5b85f50df32601
Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Sun Mar 26 14:25:27 2023 +0300 Merge branch 'master' into rm-context-fields commit 0d5b85f51b3eb72c3e905d5ad82c17cd932b246b Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Sun Mar 26 13:21:26 2023 +0300 all: rm unnecessary home context fields
This commit is contained in:
parent
132ec556dc
commit
487675b9ad
3 changed files with 54 additions and 57 deletions
internal/home
|
@ -61,11 +61,10 @@ type homeContext struct {
|
|||
filters *filtering.DNSFilter // DNS filtering module
|
||||
web *Web // Web (HTTP, HTTPS) module
|
||||
tls *tlsManager // TLS module
|
||||
// etcHosts is an IP-hostname pairs set taken from system configuration
|
||||
// (e.g. /etc/hosts) files.
|
||||
|
||||
// etcHosts contains IP-hostname mappings taken from the OS-specific hosts
|
||||
// configuration files, for example /etc/hosts.
|
||||
etcHosts *aghnet.HostsContainer
|
||||
// hostsWatcher is the watcher to detect changes in the hosts files.
|
||||
hostsWatcher aghos.FSWatcher
|
||||
|
||||
updater *updater.Updater
|
||||
|
||||
|
@ -80,7 +79,6 @@ type homeContext struct {
|
|||
pidFileName string // PID file name. Empty if no PID file was created.
|
||||
controlLock sync.Mutex
|
||||
tlsRoots *x509.CertPool // list of root CAs for TLSv1.2
|
||||
transport *http.Transport
|
||||
client *http.Client
|
||||
appSignalChannel chan os.Signal // Channel for receiving OS signals by the console app
|
||||
|
||||
|
@ -150,18 +148,17 @@ func setupContext(opts options) {
|
|||
setupContextFlags(opts)
|
||||
|
||||
Context.tlsRoots = aghtls.SystemRootCAs()
|
||||
Context.transport = &http.Transport{
|
||||
DialContext: customDialContext,
|
||||
Proxy: getHTTPProxy,
|
||||
TLSClientConfig: &tls.Config{
|
||||
RootCAs: Context.tlsRoots,
|
||||
CipherSuites: Context.tlsCipherIDs,
|
||||
MinVersion: tls.VersionTLS12,
|
||||
},
|
||||
}
|
||||
Context.client = &http.Client{
|
||||
Timeout: time.Minute * 5,
|
||||
Transport: Context.transport,
|
||||
Timeout: time.Minute * 5,
|
||||
Transport: &http.Transport{
|
||||
DialContext: customDialContext,
|
||||
Proxy: getHTTPProxy,
|
||||
TLSClientConfig: &tls.Config{
|
||||
RootCAs: Context.tlsRoots,
|
||||
CipherSuites: Context.tlsCipherIDs,
|
||||
MinVersion: tls.VersionTLS12,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if !Context.firstRun {
|
||||
|
@ -264,7 +261,7 @@ func configureOS(conf *configuration) (err error) {
|
|||
// setupHostsContainer initializes the structures to keep up-to-date the hosts
|
||||
// provided by the OS.
|
||||
func setupHostsContainer() (err error) {
|
||||
Context.hostsWatcher, err = aghos.NewOSWritesWatcher()
|
||||
hostsWatcher, err := aghos.NewOSWritesWatcher()
|
||||
if err != nil {
|
||||
return fmt.Errorf("initing hosts watcher: %w", err)
|
||||
}
|
||||
|
@ -272,18 +269,18 @@ func setupHostsContainer() (err error) {
|
|||
Context.etcHosts, err = aghnet.NewHostsContainer(
|
||||
filtering.SysHostsListID,
|
||||
aghos.RootDirFS(),
|
||||
Context.hostsWatcher,
|
||||
hostsWatcher,
|
||||
aghnet.DefaultHostsPaths()...,
|
||||
)
|
||||
if err != nil {
|
||||
cerr := Context.hostsWatcher.Close()
|
||||
if errors.Is(err, aghnet.ErrNoHostsPaths) && cerr == nil {
|
||||
closeErr := hostsWatcher.Close()
|
||||
if errors.Is(err, aghnet.ErrNoHostsPaths) && closeErr == nil {
|
||||
log.Info("warning: initing hosts container: %s", err)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.WithDeferred(fmt.Errorf("initing hosts container: %w", err), cerr)
|
||||
return errors.WithDeferred(fmt.Errorf("initing hosts container: %w", err), closeErr)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -755,13 +752,6 @@ func cleanup(ctx context.Context) {
|
|||
}
|
||||
|
||||
if Context.etcHosts != nil {
|
||||
// Currently Context.hostsWatcher is only used in Context.etcHosts and
|
||||
// needs closing only in case of the successful initialization of
|
||||
// Context.etcHosts.
|
||||
if err = Context.hostsWatcher.Close(); err != nil {
|
||||
log.Error("closing hosts watcher: %s", err)
|
||||
}
|
||||
|
||||
if err = Context.etcHosts.Close(); err != nil {
|
||||
log.Error("closing hosts container: %s", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue