docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
listlengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
frontend, err := frontendFromOpts(opts, embeddedFrontend) check(err) confMgrConf := &configmgr.Config{ Frontend: frontend, WebAddr: opts.webAddr, Start: start, FileName: opts.confFile, } confMgr, err := newConfigMgr(confMgrConf)
<mask> err = os.Chdir(opts.workDir) <mask> check(err) <mask> } <mask> <mask> confMgr, err := newConfigMgr(opts.confFile, frontend, start) <mask> check(err) <mask> <mask> web := confMgr.Web() <mask> err = web.Start() <mask> check(err) </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove confMgr, err := newConfigMgr(h.confFile, h.frontend, h.start) </s> add confMgr, err := newConfigMgr(h.confMgrConf) </s> remove opts.confFile, frontend, start, </s> add confMgrConf, opts.pidFile, </s> remove err = m.assemble(ctx, conf, frontend, start) </s> add err = m.assemble(ctx, conf, c.Frontend, c.WebAddr, c.Start) </s> remove fileName: fileName, </s> add fileName: c.FileName, </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/cmd.go
confMgrConf, opts.pidFile,
<mask> err = dns.Start() <mask> check(err) <mask> <mask> sigHdlr := newSignalHandler( <mask> opts.confFile, <mask> frontend, <mask> start, <mask> web, <mask> dns, <mask> ) <mask> <mask> sigHdlr.handle() </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove confMgr, err := newConfigMgr(opts.confFile, frontend, start) </s> add frontend, err := frontendFromOpts(opts, embeddedFrontend) check(err) confMgrConf := &configmgr.Config{ Frontend: frontend, WebAddr: opts.webAddr, Start: start, FileName: opts.confFile, } confMgr, err := newConfigMgr(confMgrConf) </s> remove signal: make(chan os.Signal, 1), confFile: confFile, frontend: frontend, start: start, services: svcs, </s> add confMgrConf: confMgrConf, signal: make(chan os.Signal, 1), pidFile: pidFile, services: svcs, </s> remove confMgr, err := newConfigMgr(h.confFile, h.frontend, h.start) </s> add confMgr, err := newConfigMgr(h.confMgrConf) </s> remove confFile string, frontend fs.FS, start time.Time, </s> add confMgrConf *configmgr.Config, pidFile string,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/cmd.go
func newConfigMgr(c *configmgr.Config) (m *configmgr.Manager, err error) {
<mask> } <mask> <mask> // newConfigMgr returns a new configuration manager using defaultTimeout as the <mask> // context timeout. <mask> func newConfigMgr(confFile string, frontend fs.FS, start time.Time) (m *configmgr.Manager, err error) { <mask> ctx, cancel := ctxWithDefaultTimeout() <mask> defer cancel() <mask> <mask> return configmgr.New(ctx, confFile, frontend, start) <mask> } </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove return configmgr.New(ctx, confFile, frontend, start) </s> add return configmgr.New(ctx, c) </s> remove confFile string, frontend fs.FS, start time.Time, </s> add confMgrConf *configmgr.Config, pidFile string, </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName) </s> remove statusSuccess = 0 statusError = 1 </s> add statusSuccess = 0 statusError = 1 statusArgumentError = 2
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/cmd.go
return configmgr.New(ctx, c)
<mask> func newConfigMgr(confFile string, frontend fs.FS, start time.Time) (m *configmgr.Manager, err error) { <mask> ctx, cancel := ctxWithDefaultTimeout() <mask> defer cancel() <mask> <mask> return configmgr.New(ctx, confFile, frontend, start) <mask> } <mask> <mask> // check is a simple error-checking helper. It must only be used within Main. <mask> func check(err error) { <mask> if err != nil { </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove func newConfigMgr(confFile string, frontend fs.FS, start time.Time) (m *configmgr.Manager, err error) { </s> add func newConfigMgr(c *configmgr.Config) (m *configmgr.Manager, err error) { </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName) </s> remove confFile string, frontend fs.FS, start time.Time, </s> add confMgrConf *configmgr.Config, pidFile string,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/cmd.go
"encoding"
<mask> package cmd <mask> <mask> import ( <mask> "flag" <mask> "fmt" <mask> "io" <mask> "io/fs" <mask> "net/netip" <mask> "os" </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove "io/fs" </s> add </s> remove "time" </s> add "strconv" </s> remove statusSuccess = 0 statusError = 1 </s> add statusSuccess = 0 statusError = 1 statusArgumentError = 2
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
"io/fs"
<mask> "flag" <mask> "fmt" <mask> "io" <mask> "net/netip" <mask> "os" <mask> "strings" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/next/configmgr" </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove "io/fs" </s> add </s> remove "time" </s> add "strconv"
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
"github.com/AdguardTeam/golibs/log"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/next/configmgr" <mask> "github.com/AdguardTeam/AdGuardHome/internal/version" <mask> "golang.org/x/exp/slices" <mask> ) <mask> <mask> // options contains all command-line options for the AdGuardHome(.exe) binary. <mask> type options struct { </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
<mask> // - "syslog": Write to the system log. <mask> logFile string <mask> <mask> // pidFile is the path to the file where to store the PID. <mask> // <mask> // TODO(a.garipov): Use. <mask> pidFile string <mask> <mask> // serviceAction is the service control action to perform: <mask> // <mask> // - "install": Installs AdGuard Home as a system service. </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // confFile is the path to the configuration file. confFile string // frontend is the filesystem with the frontend and other statically // compiled files. frontend fs.FS // start is the time at which AdGuard Home has been started. start time.Time </s> add // pidFile is the path to the file where to store the PID, if any. pidFile string </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
// webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort
<mask> // workDir is the path to the working directory. It is applied before all <mask> // other configuration is read, so all relative paths are relative to it. <mask> workDir string <mask> <mask> // webAddrs contains the addresses on which to serve the web UI. <mask> // <mask> // TODO(a.garipov): Use. <mask> webAddrs []netip.AddrPort <mask> <mask> // checkConfig, if true, instructs AdGuard Home to check the configuration <mask> // file, optionally print an error message to stdout, and exit with a <mask> // corresponding exit code. <mask> checkConfig bool </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // confFile is the path to the configuration file. confFile string // frontend is the filesystem with the frontend and other statically // compiled files. frontend fs.FS // start is the time at which AdGuard Home has been started. start time.Time </s> add // pidFile is the path to the file where to store the PID, if any. pidFile string </s> remove // // TODO(a.garipov): Use. </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
webAddrIdx
<mask> logFileIdx <mask> pidFileIdx <mask> serviceActionIdx <mask> workDirIdx <mask> webAddrsIdx <mask> checkConfigIdx <mask> disableUpdateIdx <mask> glinetModeIdx <mask> helpIdx <mask> localFrontend </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // srv.Serve will set TLSConfig to an almost empty value, so, instead of // relying only on the nilness of TLSConfig, check the length of the </s> add // [srv.Serve] will set TLSConfig to an almost empty value, so, instead // of relying only on the nilness of TLSConfig, check the length of the </s> remove case *[]netip.AddrPort: flags.Func(o.long, o.description, func(s string) (err error) { addr, err := netip.ParseAddrPort(s) if err != nil { // Don't wrap the error, because it's informative enough as is. return err } *fieldPtr = append(*fieldPtr, addr) return nil }) </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
webAddrIdx: { defaultValue: netip.AddrPort{}, description: `Address to serve the web UI on, in the host:port format.`, long: "web-addr", short: "", valueType: "host:port",
<mask> short: "w", <mask> valueType: "path", <mask> }, <mask> <mask> webAddrsIdx: { <mask> defaultValue: []netip.AddrPort(nil), <mask> description: `Address(es) to serve the web UI on, in the host:port format. ` + <mask> `Can be used multiple times.`, <mask> long: "web-addr", <mask> short: "", <mask> valueType: "host:port", <mask> }, <mask> <mask> checkConfigIdx: { <mask> defaultValue: false, <mask> description: "Check configuration, print errors to stdout, and quit.", </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort </s> remove confMgr, err := newConfigMgr(h.confFile, h.frontend, h.start) </s> add confMgr, err := newConfigMgr(h.confMgrConf)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
webAddrIdx: &opts.webAddr,
<mask> logFileIdx: &opts.logFile, <mask> pidFileIdx: &opts.pidFile, <mask> serviceActionIdx: &opts.serviceAction, <mask> workDirIdx: &opts.workDir, <mask> webAddrsIdx: &opts.webAddrs, <mask> checkConfigIdx: &opts.checkConfig, <mask> disableUpdateIdx: &opts.disableUpdate, <mask> glinetModeIdx: &opts.glinetMode, <mask> helpIdx: &opts.help, <mask> localFrontend: &opts.localFrontend, </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove webAddrsIdx: { defaultValue: []netip.AddrPort(nil), description: `Address(es) to serve the web UI on, in the host:port format. ` + `Can be used multiple times.`, long: "web-addr", short: "", valueType: "host:port", </s> add webAddrIdx: { defaultValue: netip.AddrPort{}, description: `Address to serve the web UI on, in the host:port format.`, long: "web-addr", short: "", valueType: "host:port", </s> remove case *[]netip.AddrPort: flags.Func(o.long, o.description, func(s string) (err error) { addr, err := netip.ParseAddrPort(s) if err != nil { // Don't wrap the error, because it's informative enough as is. return err } *fieldPtr = append(*fieldPtr, addr) return nil }) </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
<mask> flags.StringVar(fieldPtr, o.long, o.defaultValue.(string), o.description) <mask> if o.short != "" { <mask> flags.StringVar(fieldPtr, o.short, o.defaultValue.(string), o.description) <mask> } <mask> case *[]netip.AddrPort: <mask> flags.Func(o.long, o.description, func(s string) (err error) { <mask> addr, err := netip.ParseAddrPort(s) <mask> if err != nil { <mask> // Don't wrap the error, because it's informative enough as is. <mask> return err <mask> } <mask> <mask> *fieldPtr = append(*fieldPtr, addr) <mask> <mask> return nil <mask> }) <mask> case *bool: <mask> flags.BoolVar(fieldPtr, o.long, o.defaultValue.(bool), o.description) <mask> if o.short != "" { <mask> flags.BoolVar(fieldPtr, o.short, o.defaultValue.(bool), o.description) <mask> } </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName) </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644) </s> remove return 0, true </s> add return statusSuccess, true
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
case encoding.TextUnmarshaler: flags.TextVar(fieldPtr, o.long, o.defaultValue.(encoding.TextMarshaler), o.description) if o.short != "" { flags.TextVar(fieldPtr, o.short, o.defaultValue.(encoding.TextMarshaler), o.description) }
<mask> if o.short != "" { <mask> flags.BoolVar(fieldPtr, o.short, o.defaultValue.(bool), o.description) <mask> } <mask> default: <mask> panic(fmt.Errorf("unexpected field pointer type %T", fieldPtr)) <mask> } <mask> } </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove case *[]netip.AddrPort: flags.Func(o.long, o.description, func(s string) (err error) { addr, err := netip.ParseAddrPort(s) if err != nil { // Don't wrap the error, because it's informative enough as is. return err } *fieldPtr = append(*fieldPtr, addr) return nil }) </s> add </s> remove return 0, true </s> add return statusSuccess, true </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644) </s> remove return 1, true </s> add return statusError, true </s> remove // // TODO(a.garipov): Validate. </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
return statusArgumentError, true
<mask> parseErr error, <mask> ) (exitCode int, needExit bool) { <mask> if parseErr != nil { <mask> // Assume that usage has already been printed. <mask> return 2, true <mask> } <mask> <mask> if opts.help { <mask> usage(cmdName, os.Stdout) <mask> </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 1, true </s> add return statusError, true </s> remove case *[]netip.AddrPort: flags.Func(o.long, o.description, func(s string) (err error) { addr, err := netip.ParseAddrPort(s) if err != nil { // Don't wrap the error, because it's informative enough as is. return err } *fieldPtr = append(*fieldPtr, addr) return nil }) </s> add </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
return statusSuccess, true
<mask> <mask> if opts.help { <mask> usage(cmdName, os.Stdout) <mask> <mask> return 0, true <mask> } <mask> <mask> if opts.version { <mask> if opts.verbose { <mask> fmt.Println(version.Verbose()) </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove return 2, true </s> add return statusArgumentError, true </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 1, true </s> add return statusError, true </s> remove return 0, true </s> add return statusSuccess, true </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
return statusSuccess, true
<mask> } else { <mask> fmt.Printf("AdGuard Home %s\n", version.Version()) <mask> } <mask> <mask> return 0, true <mask> } <mask> <mask> if opts.checkConfig { <mask> err := configmgr.Validate(opts.confFile) <mask> if err != nil { </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove return 1, true </s> add return statusError, true </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 0, true </s> add return statusSuccess, true </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644) </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
return statusError, true
<mask> err := configmgr.Validate(opts.confFile) <mask> if err != nil { <mask> _, _ = io.WriteString(os.Stdout, err.Error()+"\n") <mask> <mask> return 1, true <mask> } <mask> <mask> return 0, true <mask> } <mask> </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 2, true </s> add return statusArgumentError, true </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
return statusSuccess, true
<mask> <mask> return 1, true <mask> } <mask> <mask> return 0, true <mask> } <mask> <mask> return 0, false <mask> } </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove return 1, true </s> add return statusError, true </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 2, true </s> add return statusArgumentError, true </s> remove verbose: true </s> add log: verbose: true
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/opt.go
<mask> package cmd <mask> <mask> import ( <mask> "io/fs" <mask> "os" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghos" <mask> "github.com/AdguardTeam/AdGuardHome/internal/next/agh" </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove "time" </s> add "strconv"
[ "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
"strconv"
<mask> <mask> import ( <mask> "io/fs" <mask> "os" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghos" <mask> "github.com/AdguardTeam/AdGuardHome/internal/next/agh" <mask> "github.com/AdguardTeam/golibs/log" <mask> ) </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove "io/fs" </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
"github.com/AdguardTeam/AdGuardHome/internal/next/configmgr"
<mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghos" <mask> "github.com/AdguardTeam/AdGuardHome/internal/next/agh" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/google/renameio/maybe" <mask> ) <mask> <mask> // signalHandler processes incoming signals and shuts services down. </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove "time" </s> add "strconv" </s> remove "io/fs" </s> add </s> remove // confFile is the path to the configuration file. confFile string // frontend is the filesystem with the frontend and other statically // compiled files. frontend fs.FS // start is the time at which AdGuard Home has been started. start time.Time </s> add // pidFile is the path to the file where to store the PID, if any. pidFile string
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
"github.com/google/renameio/maybe"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/next/configmgr" <mask> "github.com/AdguardTeam/golibs/log" <mask> ) <mask> <mask> // signalHandler processes incoming signals and shuts services down. <mask> type signalHandler struct { <mask> // confMgrConf contains the configuration parameters for the configuration <mask> // manager. </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // confFile is the path to the configuration file. confFile string // frontend is the filesystem with the frontend and other statically // compiled files. frontend fs.FS // start is the time at which AdGuard Home has been started. start time.Time </s> add // pidFile is the path to the file where to store the PID, if any. pidFile string
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
// confMgrConf contains the configuration parameters for the configuration // manager. confMgrConf *configmgr.Config
<mask> // signalHandler processes incoming signals and shuts services down. <mask> type signalHandler struct { <mask> // signal is the channel to which OS signals are sent. <mask> signal chan os.Signal <mask> <mask> // pidFile is the path to the file where to store the PID, if any. </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // confFile is the path to the configuration file. confFile string // frontend is the filesystem with the frontend and other statically // compiled files. frontend fs.FS // start is the time at which AdGuard Home has been started. start time.Time </s> add // pidFile is the path to the file where to store the PID, if any. pidFile string </s> remove // // TODO(a.garipov): Use. </s> add </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
// pidFile is the path to the file where to store the PID, if any. pidFile string
<mask> type signalHandler struct { <mask> // signal is the channel to which OS signals are sent. <mask> signal chan os.Signal <mask> <mask> // confFile is the path to the configuration file. <mask> confFile string <mask> <mask> // frontend is the filesystem with the frontend and other statically <mask> // compiled files. <mask> frontend fs.FS <mask> <mask> // start is the time at which AdGuard Home has been started. <mask> start time.Time <mask> <mask> // services are the services that are shut down before application exiting. <mask> services []agh.Service <mask> } <mask> </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort </s> remove confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time servers []*http.Server timeout time.Duration forceHTTPS bool </s> add confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time overrideAddr netip.AddrPort servers []*http.Server timeout time.Duration forceHTTPS bool
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
h.writePID()
<mask> func (h *signalHandler) handle() { <mask> defer log.OnPanic("signalHandler.handle") <mask> <mask> for sig := range h.signal { <mask> log.Info("sighdlr: received signal %q", sig) <mask> <mask> if aghos.IsReconfigureSignal(sig) { <mask> h.reconfigure() </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove statusSuccess = 0 statusError = 1 </s> add statusSuccess = 0 statusError = 1 statusArgumentError = 2 </s> remove confFile string, frontend fs.FS, start time.Time, </s> add confMgrConf *configmgr.Config, pidFile string, </s> remove return configmgr.New(ctx, confFile, frontend, start) </s> add return configmgr.New(ctx, c)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
h.removePID()
<mask> h.reconfigure() <mask> } else if aghos.IsShutdownSignal(sig) { <mask> status := h.shutdown() <mask> log.Info("sighdlr: exiting with status %d", status) <mask> <mask> os.Exit(status) <mask> } <mask> } </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove statusSuccess = 0 statusError = 1 </s> add statusSuccess = 0 statusError = 1 statusArgumentError = 2 </s> remove return 0, true </s> add return statusSuccess, true </s> remove for _, a := range c.Addresses { addr := a.String() errLog := log.StdLog("websvc: plain http: "+addr, log.ERROR) svc.servers = append(svc.servers, &http.Server{ Addr: addr, Handler: mux, ErrorLog: errLog, ReadTimeout: c.Timeout, WriteTimeout: c.Timeout, IdleTimeout: c.Timeout, ReadHeaderTimeout: c.Timeout, }) } </s> add if svc.overrideAddr != (netip.AddrPort{}) { svc.servers = []*http.Server{newSrv(svc.overrideAddr, nil, mux, c.Timeout)} } else { for _, a := range c.Addresses { svc.servers = append(svc.servers, newSrv(a, nil, mux, c.Timeout)) }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
confMgr, err := newConfigMgr(h.confMgrConf)
<mask> // TODO(a.garipov): This is a very rough way to do it. Some services can be <mask> // reconfigured without the full shutdown, and the error handling is <mask> // currently not the best. <mask> <mask> confMgr, err := newConfigMgr(h.confFile, h.frontend, h.start) <mask> check(err) <mask> <mask> web := confMgr.Web() <mask> err = web.Start() <mask> check(err) </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove confMgr, err := newConfigMgr(opts.confFile, frontend, start) </s> add frontend, err := frontendFromOpts(opts, embeddedFrontend) check(err) confMgrConf := &configmgr.Config{ Frontend: frontend, WebAddr: opts.webAddr, Start: start, FileName: opts.confFile, } confMgr, err := newConfigMgr(confMgrConf) </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort </s> remove opts.confFile, frontend, start, </s> add confMgrConf, opts.pidFile, </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
statusSuccess = 0 statusError = 1 statusArgumentError = 2
<mask> } <mask> <mask> // Exit status constants. <mask> const ( <mask> statusSuccess = 0 <mask> statusError = 1 <mask> ) <mask> <mask> // shutdown gracefully shuts down all services. <mask> func (h *signalHandler) shutdown() (status int) { <mask> ctx, cancel := ctxWithDefaultTimeout() </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove confFile string, frontend fs.FS, start time.Time, </s> add confMgrConf *configmgr.Config, pidFile string, </s> remove func newConfigMgr(confFile string, frontend fs.FS, start time.Time) (m *configmgr.Manager, err error) { </s> add func newConfigMgr(c *configmgr.Config) (m *configmgr.Manager, err error) { </s> remove return configmgr.New(ctx, confFile, frontend, start) </s> add return configmgr.New(ctx, c) </s> remove signal: make(chan os.Signal, 1), confFile: confFile, frontend: frontend, start: start, services: svcs, </s> add confMgrConf: confMgrConf, signal: make(chan os.Signal, 1), pidFile: pidFile, services: svcs,
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
confMgrConf *configmgr.Config, pidFile string,
<mask> } <mask> <mask> // newSignalHandler returns a new signalHandler that shuts down svcs. <mask> func newSignalHandler( <mask> confFile string, <mask> frontend fs.FS, <mask> start time.Time, <mask> svcs ...agh.Service, <mask> ) (h *signalHandler) { <mask> h = &signalHandler{ <mask> signal: make(chan os.Signal, 1), <mask> confFile: confFile, </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove signal: make(chan os.Signal, 1), confFile: confFile, frontend: frontend, start: start, services: svcs, </s> add confMgrConf: confMgrConf, signal: make(chan os.Signal, 1), pidFile: pidFile, services: svcs, </s> remove func newConfigMgr(confFile string, frontend fs.FS, start time.Time) (m *configmgr.Manager, err error) { </s> add func newConfigMgr(c *configmgr.Config) (m *configmgr.Manager, err error) { </s> remove statusSuccess = 0 statusError = 1 </s> add statusSuccess = 0 statusError = 1 statusArgumentError = 2 </s> remove return configmgr.New(ctx, confFile, frontend, start) </s> add return configmgr.New(ctx, c) </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
confMgrConf: confMgrConf, signal: make(chan os.Signal, 1), pidFile: pidFile, services: svcs,
<mask> start time.Time, <mask> svcs ...agh.Service, <mask> ) (h *signalHandler) { <mask> h = &signalHandler{ <mask> signal: make(chan os.Signal, 1), <mask> confFile: confFile, <mask> frontend: frontend, <mask> start: start, <mask> services: svcs, <mask> } <mask> <mask> aghos.NotifyShutdownSignal(h.signal) <mask> aghos.NotifyReconfigureSignal(h.signal) <mask> </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove confFile string, frontend fs.FS, start time.Time, </s> add confMgrConf *configmgr.Config, pidFile string, </s> remove confMgr: c.ConfigManager, frontend: frontend, tls: c.TLS, start: c.Start, timeout: c.Timeout, forceHTTPS: c.ForceHTTPS, </s> add confMgr: c.ConfigManager, frontend: c.Frontend, tls: c.TLS, start: c.Start, overrideAddr: c.OverrideAddress, timeout: c.Timeout, forceHTTPS: c.ForceHTTPS, </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add </s> remove statusSuccess = 0 statusError = 1 </s> add statusSuccess = 0 statusError = 1 statusArgumentError = 2 </s> remove opts.confFile, frontend, start, </s> add confMgrConf, opts.pidFile,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/cmd/signal.go
Log *logConfig `yaml:"log"`
<mask> type config struct { <mask> DNS *dnsConfig `yaml:"dns"` <mask> HTTP *httpConfig `yaml:"http"` <mask> // TODO(a.garipov): Use. <mask> SchemaVersion int `yaml:"schema_version"` <mask> // TODO(a.garipov): Use. <mask> DebugPprof bool `yaml:"debug_pprof"` <mask> } <mask> </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove Verbose bool `yaml:"verbose"` </s> add </s> remove // // TODO(a.garipov): Validate. </s> add </s> remove // // TODO(a.garipov): Validate. </s> add </s> remove // // TODO(a.garipov): Use. </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/config.go
<mask> // TODO(a.garipov): Use. <mask> SchemaVersion int `yaml:"schema_version"` <mask> // TODO(a.garipov): Use. <mask> DebugPprof bool `yaml:"debug_pprof"` <mask> Verbose bool `yaml:"verbose"` <mask> } <mask> <mask> const errNoConf errors.Error = "configuration not found" <mask> <mask> // validate returns an error if the configuration structure is invalid. </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort </s> remove // // TODO(a.garipov): Validate. </s> add </s> remove confMgr, err := newConfigMgr(h.confFile, h.frontend, h.start) </s> add confMgr, err := newConfigMgr(h.confMgrConf)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/config.go
}, { validate: c.Log.validate, name: "log",
<mask> name: "dns", <mask> }, { <mask> validate: c.HTTP.validate, <mask> name: "http", <mask> }} <mask> <mask> for _, v := range validators { <mask> err = v.validate() <mask> if err != nil { </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove for _, a := range c.Addresses { addr := a.String() errLog := log.StdLog("websvc: plain http: "+addr, log.ERROR) svc.servers = append(svc.servers, &http.Server{ Addr: addr, Handler: mux, ErrorLog: errLog, ReadTimeout: c.Timeout, WriteTimeout: c.Timeout, IdleTimeout: c.Timeout, ReadHeaderTimeout: c.Timeout, }) } </s> add if svc.overrideAddr != (netip.AddrPort{}) { svc.servers = []*http.Server{newSrv(svc.overrideAddr, nil, mux, c.Timeout)} } else { for _, a := range c.Addresses { svc.servers = append(svc.servers, newSrv(a, nil, mux, c.Timeout)) } </s> remove return 1, true </s> add return statusError, true </s> remove for _, a := range c.SecureAddresses { addr := a.String() errLog := log.StdLog("websvc: https: "+addr, log.ERROR) svc.servers = append(svc.servers, &http.Server{ Addr: addr, Handler: mux, TLSConfig: c.TLS, ErrorLog: errLog, ReadTimeout: c.Timeout, WriteTimeout: c.Timeout, IdleTimeout: c.Timeout, ReadHeaderTimeout: c.Timeout, }) </s> add for _, a := range c.SecureAddresses { svc.servers = append(svc.servers, newSrv(a, c.TLS, mux, c.Timeout)) } </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/config.go
<mask> return nil <mask> } <mask> <mask> // dnsConfig is the on-disk DNS configuration. <mask> // <mask> // TODO(a.garipov): Validate. <mask> type dnsConfig struct { <mask> Addresses []netip.AddrPort `yaml:"addresses"` <mask> BootstrapDNS []string `yaml:"bootstrap_dns"` <mask> UpstreamDNS []string `yaml:"upstream_dns"` <mask> DNS64Prefixes []netip.Prefix `yaml:"dns64_prefixes"` </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // // TODO(a.garipov): Validate. </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/config.go
<mask> } <mask> } <mask> <mask> // httpConfig is the on-disk web API configuration. <mask> // <mask> // TODO(a.garipov): Validate. <mask> type httpConfig struct { <mask> Addresses []netip.AddrPort `yaml:"addresses"` <mask> SecureAddresses []netip.AddrPort `yaml:"secure_addresses"` <mask> Timeout timeutil.Duration `yaml:"timeout"` <mask> ForceHTTPS bool `yaml:"force_https"` </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // // TODO(a.garipov): Validate. </s> add </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/config.go
// TODO(a.garipov): Document the configuration change.
<mask> // httpConfig is the on-disk web API configuration. <mask> type httpConfig struct { <mask> Addresses []netip.AddrPort `yaml:"addresses"` <mask> SecureAddresses []netip.AddrPort `yaml:"secure_addresses"` <mask> Timeout timeutil.Duration `yaml:"timeout"` <mask> ForceHTTPS bool `yaml:"force_https"` <mask> } </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // // TODO(a.garipov): Validate. </s> add </s> remove // // TODO(a.garipov): Validate. </s> add </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort </s> remove confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time servers []*http.Server timeout time.Duration forceHTTPS bool </s> add confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time overrideAddr netip.AddrPort servers []*http.Server timeout time.Duration forceHTTPS bool
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/config.go
"net/netip"
<mask> import ( <mask> "context" <mask> "fmt" <mask> "io/fs" <mask> "os" <mask> "sync" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/next/agh" <mask> "github.com/AdguardTeam/AdGuardHome/internal/next/dnssvc" </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove "io/fs" </s> add </s> remove "time" </s> add "strconv"
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/configmgr.go
// // TODO(a.garipov): Support missing configs and default values.
<mask> <mask> // Manager handles full and partial changes in the configuration, persisting <mask> // them to disk if necessary. <mask> type Manager struct { <mask> // updMu makes sure that at most one reconfiguration is performed at a time. <mask> // updMu protects all fields below. <mask> updMu *sync.RWMutex </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // confFile is the path to the configuration file. confFile string // frontend is the filesystem with the frontend and other statically // compiled files. frontend fs.FS // start is the time at which AdGuard Home has been started. start time.Time </s> add // pidFile is the path to the file where to store the PID, if any. pidFile string </s> remove webAddrsIdx: { defaultValue: []netip.AddrPort(nil), description: `Address(es) to serve the web UI on, in the host:port format. ` + `Can be used multiple times.`, long: "web-addr", short: "", valueType: "host:port", </s> add webAddrIdx: { defaultValue: netip.AddrPort{}, description: `Address to serve the web UI on, in the host:port format.`, long: "web-addr", short: "", valueType: "host:port", </s> remove confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time servers []*http.Server timeout time.Duration forceHTTPS bool </s> add confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time overrideAddr netip.AddrPort servers []*http.Server timeout time.Duration forceHTTPS bool
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/configmgr.go
// Config contains the configuration parameters for the configuration manager. type Config struct { // Frontend is the filesystem with the frontend files. Frontend fs.FS // WebAddr is the initial or override address for the Web UI. It is not // written to the configuration file. WebAddr netip.AddrPort // Start is the time of start of AdGuard Home. Start time.Time // FileName is the path to the configuration file. FileName string }
<mask> // Don't wrap the error, because it's informative enough as is. <mask> return conf.validate() <mask> } <mask> <mask> // New creates a new *Manager that persists changes to the file pointed to by <mask> // c.FileName. It reads the configuration file and populates the service <mask> // fields. c must not be nil. <mask> func New(ctx context.Context, c *Config) (m *Manager, err error) { <mask> conf, err := read(c.FileName) <mask> if err != nil { </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName) </s> remove case *[]netip.AddrPort: flags.Func(o.long, o.description, func(s string) (err error) { addr, err := netip.ParseAddrPort(s) if err != nil { // Don't wrap the error, because it's informative enough as is. return err } *fieldPtr = append(*fieldPtr, addr) return nil }) </s> add </s> remove func newConfigMgr(confFile string, frontend fs.FS, start time.Time) (m *configmgr.Manager, err error) { </s> add func newConfigMgr(c *configmgr.Config) (m *configmgr.Manager, err error) { </s> remove return configmgr.New(ctx, confFile, frontend, start) </s> add return configmgr.New(ctx, c) </s> remove confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time servers []*http.Server timeout time.Duration forceHTTPS bool </s> add confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time overrideAddr netip.AddrPort servers []*http.Server timeout time.Duration forceHTTPS bool
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/configmgr.go
// c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName)
<mask> return conf.validate() <mask> } <mask> <mask> // New creates a new *Manager that persists changes to the file pointed to by <mask> // fileName. It reads the configuration file and populates the service fields. <mask> // start is the startup time of AdGuard Home. <mask> func New( <mask> ctx context.Context, <mask> fileName string, <mask> frontend fs.FS, <mask> start time.Time, <mask> ) (m *Manager, err error) { <mask> conf, err := read(fileName) <mask> if err != nil { <mask> // Don't wrap the error, because it's informative enough as is. <mask> return nil, err <mask> } <mask> </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove func newConfigMgr(confFile string, frontend fs.FS, start time.Time) (m *configmgr.Manager, err error) { </s> add func newConfigMgr(c *configmgr.Config) (m *configmgr.Manager, err error) { </s> remove case *[]netip.AddrPort: flags.Func(o.long, o.description, func(s string) (err error) { addr, err := netip.ParseAddrPort(s) if err != nil { // Don't wrap the error, because it's informative enough as is. return err } *fieldPtr = append(*fieldPtr, addr) return nil }) </s> add </s> remove return configmgr.New(ctx, confFile, frontend, start) </s> add return configmgr.New(ctx, c) </s> remove confFile string, frontend fs.FS, start time.Time, </s> add confMgrConf *configmgr.Config, pidFile string,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/configmgr.go
fileName: c.FileName,
<mask> <mask> m = &Manager{ <mask> updMu: &sync.RWMutex{}, <mask> current: conf, <mask> fileName: fileName, <mask> } <mask> <mask> err = m.assemble(ctx, conf, frontend, start) <mask> if err != nil { <mask> return nil, fmt.Errorf("creating config manager: %w", err) </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove err = m.assemble(ctx, conf, frontend, start) </s> add err = m.assemble(ctx, conf, c.Frontend, c.WebAddr, c.Start) </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644) </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName) </s> remove confMgr, err := newConfigMgr(opts.confFile, frontend, start) </s> add frontend, err := frontendFromOpts(opts, embeddedFrontend) check(err) confMgrConf := &configmgr.Config{ Frontend: frontend, WebAddr: opts.webAddr, Start: start, FileName: opts.confFile, } confMgr, err := newConfigMgr(confMgrConf)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/configmgr.go
err = m.assemble(ctx, conf, c.Frontend, c.WebAddr, c.Start)
<mask> current: conf, <mask> fileName: fileName, <mask> } <mask> <mask> err = m.assemble(ctx, conf, frontend, start) <mask> if err != nil { <mask> return nil, fmt.Errorf("creating config manager: %w", err) <mask> } <mask> <mask> return m, nil </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove fileName: fileName, </s> add fileName: c.FileName, </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644) </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName) </s> remove return 1, true </s> add return statusError, true
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/configmgr.go
webAddr netip.AddrPort,
<mask> conf *config, <mask> frontend fs.FS, <mask> start time.Time, <mask> ) (err error) { <mask> dnsConf := &dnssvc.Config{ <mask> Addresses: conf.DNS.Addresses, <mask> BootstrapServers: conf.DNS.BootstrapDNS, </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove confFile string, frontend fs.FS, start time.Time, </s> add confMgrConf *configmgr.Config, pidFile string, </s> remove func newConfigMgr(confFile string, frontend fs.FS, start time.Time) (m *configmgr.Manager, err error) { </s> add func newConfigMgr(c *configmgr.Config) (m *configmgr.Manager, err error) { </s> remove return configmgr.New(ctx, confFile, frontend, start) </s> add return configmgr.New(ctx, c) </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName) </s> remove signal: make(chan os.Signal, 1), confFile: confFile, frontend: frontend, start: start, services: svcs, </s> add confMgrConf: confMgrConf, signal: make(chan os.Signal, 1), pidFile: pidFile, services: svcs,
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/configmgr.go
OverrideAddress: webAddr,
<mask> TLS: nil, <mask> Start: start, <mask> Addresses: conf.HTTP.Addresses, <mask> SecureAddresses: conf.HTTP.SecureAddresses, <mask> Timeout: conf.HTTP.Timeout.Duration, <mask> ForceHTTPS: conf.HTTP.ForceHTTPS, <mask> } <mask> <mask> err = m.updateWeb(ctx, webSvcConf) </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove confMgr, err := newConfigMgr(opts.confFile, frontend, start) </s> add frontend, err := frontendFromOpts(opts, embeddedFrontend) check(err) confMgrConf := &configmgr.Config{ Frontend: frontend, WebAddr: opts.webAddr, Start: start, FileName: opts.confFile, } confMgr, err := newConfigMgr(confMgrConf) </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add </s> remove err = m.assemble(ctx, conf, frontend, start) </s> add err = m.assemble(ctx, conf, c.Frontend, c.WebAddr, c.Start) </s> remove opts.confFile, frontend, start, </s> add confMgrConf, opts.pidFile, </s> remove fileName: fileName, </s> add fileName: c.FileName,
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/configmgr.go
err = maybe.WriteFile(m.fileName, b, 0o644)
<mask> if err != nil { <mask> return fmt.Errorf("encoding: %w", err) <mask> } <mask> <mask> err = maybe.WriteFile(m.fileName, b, 0o755) <mask> if err != nil { <mask> return fmt.Errorf("writing: %w", err) <mask> } <mask> <mask> log.Info("configmgr: written to %q", m.fileName) </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove err = m.assemble(ctx, conf, frontend, start) </s> add err = m.assemble(ctx, conf, c.Frontend, c.WebAddr, c.Start) </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add </s> remove fileName: fileName, </s> add fileName: c.FileName, </s> remove return 0, true </s> add return statusSuccess, true </s> remove return 1, true </s> add return statusError, true
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/configmgr/configmgr.go
// OverrideAddress is the initial or override address for the HTTP API. If // set, it is used instead of [Addresses] and [SecureAddresses]. OverrideAddress netip.AddrPort
<mask> // Start is the time of start of AdGuard Home. <mask> Start time.Time <mask> <mask> // Addresses are the addresses on which to serve the plain HTTP API. <mask> Addresses []netip.AddrPort <mask> <mask> // SecureAddresses are the addresses on which to serve the HTTPS API. If <mask> // SecureAddresses is not empty, TLS must not be nil. <mask> SecureAddresses []netip.AddrPort </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // webAddrs contains the addresses on which to serve the web UI. // // TODO(a.garipov): Use. webAddrs []netip.AddrPort </s> add // webAddr contains the address on which to serve the web UI. webAddr netip.AddrPort </s> remove // confFile is the path to the configuration file. confFile string // frontend is the filesystem with the frontend and other statically // compiled files. frontend fs.FS // start is the time at which AdGuard Home has been started. start time.Time </s> add // pidFile is the path to the file where to store the PID, if any. pidFile string </s> remove // // TODO(a.garipov): Validate. </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/websvc/websvc.go
confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time overrideAddr netip.AddrPort servers []*http.Server timeout time.Duration forceHTTPS bool
<mask> <mask> // Service is the AdGuard Home web service. A nil *Service is a valid <mask> // [agh.Service] that does nothing. <mask> type Service struct { <mask> confMgr ConfigManager <mask> frontend fs.FS <mask> tls *tls.Config <mask> start time.Time <mask> servers []*http.Server <mask> timeout time.Duration <mask> forceHTTPS bool <mask> } <mask> <mask> // New returns a new properly initialized *Service. If c is nil, svc is a nil <mask> // *Service that does nothing. The fields of c must not be modified after <mask> // calling New. </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName) </s> remove // confFile is the path to the configuration file. confFile string // frontend is the filesystem with the frontend and other statically // compiled files. frontend fs.FS // start is the time at which AdGuard Home has been started. start time.Time </s> add // pidFile is the path to the file where to store the PID, if any. pidFile string </s> remove addrPort, err := netip.ParseAddrPort(srv.Addr) if err != nil { // Technically shouldn't happen, since all servers must have a valid // address. panic(fmt.Errorf("websvc: server %q: bad address: %w", srv.Addr, err)) } </s> add // Use MustParseAddrPort, since no errors should technically happen // here, because all servers must have a valid address. addrPort := netip.MustParseAddrPort(srv.Addr)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/websvc/websvc.go
<mask> if c == nil { <mask> return nil, nil <mask> } <mask> <mask> frontend, err := fs.Sub(c.Frontend, "build/static") <mask> if err != nil { <mask> return nil, fmt.Errorf("frontend fs: %w", err) <mask> } <mask> <mask> svc = &Service{ <mask> confMgr: c.ConfigManager, <mask> frontend: frontend, <mask> tls: c.TLS, <mask> start: c.Start, </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove confMgr: c.ConfigManager, frontend: frontend, tls: c.TLS, start: c.Start, timeout: c.Timeout, forceHTTPS: c.ForceHTTPS, </s> add confMgr: c.ConfigManager, frontend: c.Frontend, tls: c.TLS, start: c.Start, overrideAddr: c.OverrideAddress, timeout: c.Timeout, forceHTTPS: c.ForceHTTPS, </s> remove err = m.assemble(ctx, conf, frontend, start) </s> add err = m.assemble(ctx, conf, c.Frontend, c.WebAddr, c.Start) </s> remove fileName: fileName, </s> add fileName: c.FileName, </s> remove err = maybe.WriteFile(m.fileName, b, 0o755) </s> add err = maybe.WriteFile(m.fileName, b, 0o644) </s> remove return 0, true </s> add return statusSuccess, true
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/websvc/websvc.go
confMgr: c.ConfigManager, frontend: c.Frontend, tls: c.TLS, start: c.Start, overrideAddr: c.OverrideAddress, timeout: c.Timeout, forceHTTPS: c.ForceHTTPS,
<mask> return nil, fmt.Errorf("frontend fs: %w", err) <mask> } <mask> <mask> svc = &Service{ <mask> confMgr: c.ConfigManager, <mask> frontend: frontend, <mask> tls: c.TLS, <mask> start: c.Start, <mask> timeout: c.Timeout, <mask> forceHTTPS: c.ForceHTTPS, <mask> } <mask> <mask> mux := newMux(svc) <mask> <mask> for _, a := range c.Addresses { </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add </s> remove for _, a := range c.Addresses { addr := a.String() errLog := log.StdLog("websvc: plain http: "+addr, log.ERROR) svc.servers = append(svc.servers, &http.Server{ Addr: addr, Handler: mux, ErrorLog: errLog, ReadTimeout: c.Timeout, WriteTimeout: c.Timeout, IdleTimeout: c.Timeout, ReadHeaderTimeout: c.Timeout, }) } </s> add if svc.overrideAddr != (netip.AddrPort{}) { svc.servers = []*http.Server{newSrv(svc.overrideAddr, nil, mux, c.Timeout)} } else { for _, a := range c.Addresses { svc.servers = append(svc.servers, newSrv(a, nil, mux, c.Timeout)) } </s> remove for _, a := range c.SecureAddresses { addr := a.String() errLog := log.StdLog("websvc: https: "+addr, log.ERROR) svc.servers = append(svc.servers, &http.Server{ Addr: addr, Handler: mux, TLSConfig: c.TLS, ErrorLog: errLog, ReadTimeout: c.Timeout, WriteTimeout: c.Timeout, IdleTimeout: c.Timeout, ReadHeaderTimeout: c.Timeout, }) </s> add for _, a := range c.SecureAddresses { svc.servers = append(svc.servers, newSrv(a, c.TLS, mux, c.Timeout)) } </s> remove err = m.assemble(ctx, conf, frontend, start) </s> add err = m.assemble(ctx, conf, c.Frontend, c.WebAddr, c.Start) </s> remove fileName: fileName, </s> add fileName: c.FileName,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/websvc/websvc.go
if svc.overrideAddr != (netip.AddrPort{}) { svc.servers = []*http.Server{newSrv(svc.overrideAddr, nil, mux, c.Timeout)} } else { for _, a := range c.Addresses { svc.servers = append(svc.servers, newSrv(a, nil, mux, c.Timeout)) }
<mask> } <mask> <mask> mux := newMux(svc) <mask> <mask> for _, a := range c.Addresses { <mask> addr := a.String() <mask> errLog := log.StdLog("websvc: plain http: "+addr, log.ERROR) <mask> svc.servers = append(svc.servers, &http.Server{ <mask> Addr: addr, <mask> Handler: mux, <mask> ErrorLog: errLog, <mask> ReadTimeout: c.Timeout, <mask> WriteTimeout: c.Timeout, <mask> IdleTimeout: c.Timeout, <mask> ReadHeaderTimeout: c.Timeout, <mask> }) <mask> } <mask> <mask> for _, a := range c.SecureAddresses { <mask> addr := a.String() <mask> errLog := log.StdLog("websvc: https: "+addr, log.ERROR) <mask> svc.servers = append(svc.servers, &http.Server{ </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove for _, a := range c.SecureAddresses { addr := a.String() errLog := log.StdLog("websvc: https: "+addr, log.ERROR) svc.servers = append(svc.servers, &http.Server{ Addr: addr, Handler: mux, TLSConfig: c.TLS, ErrorLog: errLog, ReadTimeout: c.Timeout, WriteTimeout: c.Timeout, IdleTimeout: c.Timeout, ReadHeaderTimeout: c.Timeout, }) </s> add for _, a := range c.SecureAddresses { svc.servers = append(svc.servers, newSrv(a, c.TLS, mux, c.Timeout)) } </s> remove confMgr: c.ConfigManager, frontend: frontend, tls: c.TLS, start: c.Start, timeout: c.Timeout, forceHTTPS: c.ForceHTTPS, </s> add confMgr: c.ConfigManager, frontend: c.Frontend, tls: c.TLS, start: c.Start, overrideAddr: c.OverrideAddress, timeout: c.Timeout, forceHTTPS: c.ForceHTTPS, </s> remove addrPort, err := netip.ParseAddrPort(srv.Addr) if err != nil { // Technically shouldn't happen, since all servers must have a valid // address. panic(fmt.Errorf("websvc: server %q: bad address: %w", srv.Addr, err)) } </s> add // Use MustParseAddrPort, since no errors should technically happen // here, because all servers must have a valid address. addrPort := netip.MustParseAddrPort(srv.Addr)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/websvc/websvc.go
for _, a := range c.SecureAddresses { svc.servers = append(svc.servers, newSrv(a, c.TLS, mux, c.Timeout)) }
<mask> ReadHeaderTimeout: c.Timeout, <mask> }) <mask> } <mask> <mask> for _, a := range c.SecureAddresses { <mask> addr := a.String() <mask> errLog := log.StdLog("websvc: https: "+addr, log.ERROR) <mask> svc.servers = append(svc.servers, &http.Server{ <mask> Addr: addr, <mask> Handler: mux, <mask> TLSConfig: c.TLS, <mask> ErrorLog: errLog, <mask> ReadTimeout: c.Timeout, <mask> WriteTimeout: c.Timeout, <mask> IdleTimeout: c.Timeout, <mask> ReadHeaderTimeout: c.Timeout, <mask> }) <mask> } <mask> <mask> return svc, nil <mask> } <mask> </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove for _, a := range c.Addresses { addr := a.String() errLog := log.StdLog("websvc: plain http: "+addr, log.ERROR) svc.servers = append(svc.servers, &http.Server{ Addr: addr, Handler: mux, ErrorLog: errLog, ReadTimeout: c.Timeout, WriteTimeout: c.Timeout, IdleTimeout: c.Timeout, ReadHeaderTimeout: c.Timeout, }) } </s> add if svc.overrideAddr != (netip.AddrPort{}) { svc.servers = []*http.Server{newSrv(svc.overrideAddr, nil, mux, c.Timeout)} } else { for _, a := range c.Addresses { svc.servers = append(svc.servers, newSrv(a, nil, mux, c.Timeout)) } </s> remove confMgr: c.ConfigManager, frontend: frontend, tls: c.TLS, start: c.Start, timeout: c.Timeout, forceHTTPS: c.ForceHTTPS, </s> add confMgr: c.ConfigManager, frontend: c.Frontend, tls: c.TLS, start: c.Start, overrideAddr: c.OverrideAddress, timeout: c.Timeout, forceHTTPS: c.ForceHTTPS, </s> remove case *[]netip.AddrPort: flags.Func(o.long, o.description, func(s string) (err error) { addr, err := netip.ParseAddrPort(s) if err != nil { // Don't wrap the error, because it's informative enough as is. return err } *fieldPtr = append(*fieldPtr, addr) return nil }) </s> add </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/websvc/websvc.go
if svc.overrideAddr != (netip.AddrPort{}) { return []netip.AddrPort{svc.overrideAddr}, nil }
<mask> // ":0" addresses, addrs will not return the actual bound ports until Start is <mask> // finished. <mask> func (svc *Service) addrs() (addrs, secureAddrs []netip.AddrPort) { <mask> for _, srv := range svc.servers { <mask> // Use MustParseAddrPort, since no errors should technically happen <mask> // here, because all servers must have a valid address. <mask> addrPort := netip.MustParseAddrPort(srv.Addr) </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove addrPort, err := netip.ParseAddrPort(srv.Addr) if err != nil { // Technically shouldn't happen, since all servers must have a valid // address. panic(fmt.Errorf("websvc: server %q: bad address: %w", srv.Addr, err)) } </s> add // Use MustParseAddrPort, since no errors should technically happen // here, because all servers must have a valid address. addrPort := netip.MustParseAddrPort(srv.Addr) </s> remove for _, a := range c.Addresses { addr := a.String() errLog := log.StdLog("websvc: plain http: "+addr, log.ERROR) svc.servers = append(svc.servers, &http.Server{ Addr: addr, Handler: mux, ErrorLog: errLog, ReadTimeout: c.Timeout, WriteTimeout: c.Timeout, IdleTimeout: c.Timeout, ReadHeaderTimeout: c.Timeout, }) } </s> add if svc.overrideAddr != (netip.AddrPort{}) { svc.servers = []*http.Server{newSrv(svc.overrideAddr, nil, mux, c.Timeout)} } else { for _, a := range c.Addresses { svc.servers = append(svc.servers, newSrv(a, nil, mux, c.Timeout)) } </s> remove for _, a := range c.SecureAddresses { addr := a.String() errLog := log.StdLog("websvc: https: "+addr, log.ERROR) svc.servers = append(svc.servers, &http.Server{ Addr: addr, Handler: mux, TLSConfig: c.TLS, ErrorLog: errLog, ReadTimeout: c.Timeout, WriteTimeout: c.Timeout, IdleTimeout: c.Timeout, ReadHeaderTimeout: c.Timeout, }) </s> add for _, a := range c.SecureAddresses { svc.servers = append(svc.servers, newSrv(a, c.TLS, mux, c.Timeout)) } </s> remove confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time servers []*http.Server timeout time.Duration forceHTTPS bool </s> add confMgr ConfigManager frontend fs.FS tls *tls.Config start time.Time overrideAddr netip.AddrPort servers []*http.Server timeout time.Duration forceHTTPS bool
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/websvc/websvc.go
// Use MustParseAddrPort, since no errors should technically happen // here, because all servers must have a valid address. addrPort := netip.MustParseAddrPort(srv.Addr)
<mask> // ":0" addresses, addrs will not return the actual bound ports until Start is <mask> // finished. <mask> func (svc *Service) addrs() (addrs, secureAddrs []netip.AddrPort) { <mask> for _, srv := range svc.servers { <mask> addrPort, err := netip.ParseAddrPort(srv.Addr) <mask> if err != nil { <mask> // Technically shouldn't happen, since all servers must have a valid <mask> // address. <mask> panic(fmt.Errorf("websvc: server %q: bad address: %w", srv.Addr, err)) <mask> } <mask> <mask> // srv.Serve will set TLSConfig to an almost empty value, so, instead of <mask> // relying only on the nilness of TLSConfig, check the length of the <mask> // certificates field as well. <mask> if srv.TLSConfig == nil || len(srv.TLSConfig.Certificates) == 0 { </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove // srv.Serve will set TLSConfig to an almost empty value, so, instead of // relying only on the nilness of TLSConfig, check the length of the </s> add // [srv.Serve] will set TLSConfig to an almost empty value, so, instead // of relying only on the nilness of TLSConfig, check the length of the </s> remove // fileName. It reads the configuration file and populates the service fields. // start is the startup time of AdGuard Home. func New( ctx context.Context, fileName string, frontend fs.FS, start time.Time, ) (m *Manager, err error) { conf, err := read(fileName) </s> add // c.FileName. It reads the configuration file and populates the service // fields. c must not be nil. func New(ctx context.Context, c *Config) (m *Manager, err error) { conf, err := read(c.FileName)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/websvc/websvc.go
// [srv.Serve] will set TLSConfig to an almost empty value, so, instead // of relying only on the nilness of TLSConfig, check the length of the
<mask> // address. <mask> panic(fmt.Errorf("websvc: server %q: bad address: %w", srv.Addr, err)) <mask> } <mask> <mask> // srv.Serve will set TLSConfig to an almost empty value, so, instead of <mask> // relying only on the nilness of TLSConfig, check the length of the <mask> // certificates field as well. <mask> if srv.TLSConfig == nil || len(srv.TLSConfig.Certificates) == 0 { <mask> addrs = append(addrs, addrPort) <mask> } else { <mask> secureAddrs = append(secureAddrs, addrPort) </s> Pull request 1899: nextapi-pidfile-webaddr Squashed commit of the following: commit 73b97b638016dd3992376c2cd7d11b2e85b2c3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:43:05 2023 +0300 next: use maybe; sync conf commit 99e18b8fbfad11343a1e66f746085d54be7aafea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jun 29 18:13:13 2023 +0300 next: add local frontend, pidfile, webaddr </s> remove addrPort, err := netip.ParseAddrPort(srv.Addr) if err != nil { // Technically shouldn't happen, since all servers must have a valid // address. panic(fmt.Errorf("websvc: server %q: bad address: %w", srv.Addr, err)) } </s> add // Use MustParseAddrPort, since no errors should technically happen // here, because all servers must have a valid address. addrPort := netip.MustParseAddrPort(srv.Addr) </s> remove frontend, err := fs.Sub(c.Frontend, "build/static") if err != nil { return nil, fmt.Errorf("frontend fs: %w", err) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/ee8eb1d8a6b09cae706f0a8159b37828de54d76c
internal/next/websvc/websvc.go
return addClientInfo(logs, clients, 'client_id', 'client');
<mask> const clientsParams = getParamsForClientsSearch(logs, 'client', 'client_id'); <mask> <mask> if (Object.keys(clientsParams).length > 0) { <mask> const clients = await apiClient.findClients(clientsParams); <mask> return addClientInfo(logs, clients, 'client'); <mask> } <mask> <mask> return logs; <mask> }; <mask> </s> Pull request: all: fix client id handling in querylog Merge in DNS/adguard-home from 2607-querylog-client-id to master Closes #2607. Squashed commit of the following: commit 95367a82469af3b042489fb650b962b48cb73236 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 19:02:02 2021 +0300 all: fix client, imp docs commit b652a7ef2373a75f7e897d29f5c9e36b0e076f8e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 18:36:17 2021 +0300 all: fix client id handling in querylog </s> remove export const addClientInfo = (data, clients, param) => data.map((row) => { const clientIp = row[param]; const info = clients.find((item) => item[clientIp]) || ''; </s> add export const addClientInfo = (data, clients, ...params) => data.map((row) => { let info = ''; params.find((param) => { const id = row[param]; if (id) { const client = clients.find((item) => item[id]) || ''; info = client?.[id] ?? ''; } return info; }); </s> remove if ip != nil { cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) } </s> add cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) </s> remove info: info?.[clientIp] ?? '', </s> add info, </s> remove if !ok && ip != nil { </s> add if !ok {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/eeeb03839a14029d47685666f7869d908ffadbd2
client/src/actions/queryLogs.js
export const addClientInfo = (data, clients, ...params) => data.map((row) => { let info = ''; params.find((param) => { const id = row[param]; if (id) { const client = clients.find((item) => item[id]) || ''; info = client?.[id] ?? ''; } return info; });
<mask> count: Object.values(item)[0], <mask> })) <mask> ); <mask> <mask> export const addClientInfo = (data, clients, param) => data.map((row) => { <mask> const clientIp = row[param]; <mask> const info = clients.find((item) => item[clientIp]) || ''; <mask> return { <mask> ...row, <mask> info: info?.[clientIp] ?? '', <mask> }; <mask> }); </s> Pull request: all: fix client id handling in querylog Merge in DNS/adguard-home from 2607-querylog-client-id to master Closes #2607. Squashed commit of the following: commit 95367a82469af3b042489fb650b962b48cb73236 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 19:02:02 2021 +0300 all: fix client, imp docs commit b652a7ef2373a75f7e897d29f5c9e36b0e076f8e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 18:36:17 2021 +0300 all: fix client id handling in querylog </s> remove info: info?.[clientIp] ?? '', </s> add info, </s> remove return addClientInfo(logs, clients, 'client'); </s> add return addClientInfo(logs, clients, 'client_id', 'client'); </s> remove if ip != nil { cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) } </s> add cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) </s> remove if !ok && ip != nil { </s> add if !ok {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/eeeb03839a14029d47685666f7869d908ffadbd2
client/src/helpers/helpers.js
info,
<mask> const clientIp = row[param]; <mask> const info = clients.find((item) => item[clientIp]) || ''; <mask> return { <mask> ...row, <mask> info: info?.[clientIp] ?? '', <mask> }; <mask> }); <mask> <mask> export const normalizeFilters = (filters) => ( <mask> filters ? filters.map((filter) => { </s> Pull request: all: fix client id handling in querylog Merge in DNS/adguard-home from 2607-querylog-client-id to master Closes #2607. Squashed commit of the following: commit 95367a82469af3b042489fb650b962b48cb73236 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 19:02:02 2021 +0300 all: fix client, imp docs commit b652a7ef2373a75f7e897d29f5c9e36b0e076f8e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 18:36:17 2021 +0300 all: fix client id handling in querylog </s> remove export const addClientInfo = (data, clients, param) => data.map((row) => { const clientIp = row[param]; const info = clients.find((item) => item[clientIp]) || ''; </s> add export const addClientInfo = (data, clients, ...params) => data.map((row) => { let info = ''; params.find((param) => { const id = row[param]; if (id) { const client = clients.find((item) => item[id]) || ''; info = client?.[id] ?? ''; } return info; }); </s> remove if ip != nil { cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) } </s> add cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) </s> remove return addClientInfo(logs, clients, 'client'); </s> add return addClientInfo(logs, clients, 'client_id', 'client'); </s> remove if !ok && ip != nil { </s> add if !ok {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/eeeb03839a14029d47685666f7869d908ffadbd2
client/src/helpers/helpers.js
if ip == nil { return cj, false }
<mask> // blocklists. <mask> func (clients *clientsContainer) findTemporary(ip net.IP, idStr string) (cj clientJSON, found bool) { <mask> ch, ok := clients.FindAutoClient(idStr) <mask> if !ok { <mask> // It is still possible that the IP used to be in the runtime <mask> // clients list, but then the server was reloaded. So, check <mask> // the DNS server's blocked IP list. </s> Pull request: all: fix client id handling in querylog Merge in DNS/adguard-home from 2607-querylog-client-id to master Closes #2607. Squashed commit of the following: commit 95367a82469af3b042489fb650b962b48cb73236 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 19:02:02 2021 +0300 all: fix client, imp docs commit b652a7ef2373a75f7e897d29f5c9e36b0e076f8e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 18:36:17 2021 +0300 all: fix client id handling in querylog </s> remove if !ok && ip != nil { </s> add if !ok { </s> remove export const addClientInfo = (data, clients, param) => data.map((row) => { const clientIp = row[param]; const info = clients.find((item) => item[clientIp]) || ''; </s> add export const addClientInfo = (data, clients, ...params) => data.map((row) => { let info = ''; params.find((param) => { const id = row[param]; if (id) { const client = clients.find((item) => item[id]) || ''; info = client?.[id] ?? ''; } return info; }); </s> remove return addClientInfo(logs, clients, 'client'); </s> add return addClientInfo(logs, clients, 'client_id', 'client'); </s> remove if ip != nil { cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) } </s> add cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) </s> remove info: info?.[clientIp] ?? '', </s> add info,
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/eeeb03839a14029d47685666f7869d908ffadbd2
internal/home/clientshttp.go
if !ok {
<mask> // findTemporary looks up the IP in temporary storages, like autohosts or <mask> // blocklists. <mask> func (clients *clientsContainer) findTemporary(ip net.IP, idStr string) (cj clientJSON, found bool) { <mask> ch, ok := clients.FindAutoClient(idStr) <mask> if !ok && ip != nil { <mask> // It is still possible that the IP used to be in the runtime <mask> // clients list, but then the server was reloaded. So, check <mask> // the DNS server's blocked IP list. <mask> // <mask> // See https://github.com/AdguardTeam/AdGuardHome/issues/2428. </s> Pull request: all: fix client id handling in querylog Merge in DNS/adguard-home from 2607-querylog-client-id to master Closes #2607. Squashed commit of the following: commit 95367a82469af3b042489fb650b962b48cb73236 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 19:02:02 2021 +0300 all: fix client, imp docs commit b652a7ef2373a75f7e897d29f5c9e36b0e076f8e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 18:36:17 2021 +0300 all: fix client id handling in querylog </s> remove if ip != nil { cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) } </s> add cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) </s> remove export const addClientInfo = (data, clients, param) => data.map((row) => { const clientIp = row[param]; const info = clients.find((item) => item[clientIp]) || ''; </s> add export const addClientInfo = (data, clients, ...params) => data.map((row) => { let info = ''; params.find((param) => { const id = row[param]; if (id) { const client = clients.find((item) => item[id]) || ''; info = client?.[id] ?? ''; } return info; }); </s> remove return addClientInfo(logs, clients, 'client'); </s> add return addClientInfo(logs, clients, 'client_id', 'client'); </s> remove info: info?.[clientIp] ?? '', </s> add info,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/eeeb03839a14029d47685666f7869d908ffadbd2
internal/home/clientshttp.go
cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip)
<mask> return cj, true <mask> } <mask> <mask> cj = clientHostToJSON(idStr, ch) <mask> if ip != nil { <mask> cj.Disallowed, cj.DisallowedRule = clients.dnsServer.IsBlockedIP(ip) <mask> } <mask> <mask> return cj, true <mask> } <mask> <mask> // RegisterClientsHandlers registers HTTP handlers </s> Pull request: all: fix client id handling in querylog Merge in DNS/adguard-home from 2607-querylog-client-id to master Closes #2607. Squashed commit of the following: commit 95367a82469af3b042489fb650b962b48cb73236 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 19:02:02 2021 +0300 all: fix client, imp docs commit b652a7ef2373a75f7e897d29f5c9e36b0e076f8e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 28 18:36:17 2021 +0300 all: fix client id handling in querylog </s> remove return addClientInfo(logs, clients, 'client'); </s> add return addClientInfo(logs, clients, 'client_id', 'client'); </s> remove export const addClientInfo = (data, clients, param) => data.map((row) => { const clientIp = row[param]; const info = clients.find((item) => item[clientIp]) || ''; </s> add export const addClientInfo = (data, clients, ...params) => data.map((row) => { let info = ''; params.find((param) => { const id = row[param]; if (id) { const client = clients.find((item) => item[id]) || ''; info = client?.[id] ?? ''; } return info; }); </s> remove info: info?.[clientIp] ?? '', </s> add info, </s> remove if !ok && ip != nil { </s> add if !ok {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/eeeb03839a14029d47685666f7869d908ffadbd2
internal/home/clientshttp.go
// Discover and reserve an IP
<mask> } <mask> <mask> p = make(dhcp4.Packet, 241) <mask> <mask> // Reserve an IP <mask> hw = []byte{3, 2, 3, 4, 5, 6} <mask> p.SetCHAddr(hw) <mask> lease, _ = s.reserveLease(p) <mask> check(t, bytes.Equal(lease.HWAddr, hw), "lease.HWAddr") <mask> check(t, bytes.Equal(lease.IP, []byte{1, 1, 1, 1}), "lease.IP") </s> + dhcpd, clients: add more tests </s> remove lease, _ = s.reserveLease(p) check(t, bytes.Equal(lease.HWAddr, hw), "lease.HWAddr") check(t, bytes.Equal(lease.IP, []byte{1, 1, 1, 1}), "lease.IP") </s> add p.SetCIAddr([]byte{0, 0, 0, 0}) opt = make(dhcp4.Options, 10) p2 = s.handleDiscover(p, opt) opt = p2.ParseOptions() check(t, bytes.Equal(opt[dhcp4.OptionDHCPMessageType], []byte{byte(dhcp4.Offer)}), "dhcp4.Offer") check(t, bytes.Equal(p2.YIAddr(), []byte{1, 1, 1, 1}), "p2.YIAddr") check(t, bytes.Equal(p2.CHAddr(), hw), "p2.CHAddr") check(t, bytes.Equal(opt[dhcp4.OptionIPAddressLeaseTime], dhcp4.OptionsLeaseTime(5*time.Second)), "OptionIPAddressLeaseTime") check(t, bytes.Equal(opt[dhcp4.OptionServerIdentifier], s.ipnet.IP), "OptionServerIdentifier")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efaaeb58ebd6571c545569ad18f1396cc701870b
dhcpd/dhcpd_test.go
p.SetCIAddr([]byte{0, 0, 0, 0}) opt = make(dhcp4.Options, 10) p2 = s.handleDiscover(p, opt) opt = p2.ParseOptions() check(t, bytes.Equal(opt[dhcp4.OptionDHCPMessageType], []byte{byte(dhcp4.Offer)}), "dhcp4.Offer") check(t, bytes.Equal(p2.YIAddr(), []byte{1, 1, 1, 1}), "p2.YIAddr") check(t, bytes.Equal(p2.CHAddr(), hw), "p2.CHAddr") check(t, bytes.Equal(opt[dhcp4.OptionIPAddressLeaseTime], dhcp4.OptionsLeaseTime(5*time.Second)), "OptionIPAddressLeaseTime") check(t, bytes.Equal(opt[dhcp4.OptionServerIdentifier], s.ipnet.IP), "OptionServerIdentifier")
<mask> <mask> // Reserve an IP <mask> hw = []byte{3, 2, 3, 4, 5, 6} <mask> p.SetCHAddr(hw) <mask> lease, _ = s.reserveLease(p) <mask> check(t, bytes.Equal(lease.HWAddr, hw), "lease.HWAddr") <mask> check(t, bytes.Equal(lease.IP, []byte{1, 1, 1, 1}), "lease.IP") <mask> lease = s.findLease(p) <mask> check(t, bytes.Equal(lease.HWAddr, hw), "lease.HWAddr") <mask> check(t, bytes.Equal(lease.IP, []byte{1, 1, 1, 1}), "lease.IP") <mask> <mask> // Reserve an IP - the next IP from the range </s> + dhcpd, clients: add more tests </s> remove // Reserve an IP </s> add // Discover and reserve an IP
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efaaeb58ebd6571c545569ad18f1396cc701870b
dhcpd/dhcpd_test.go
check(t, bytes.Equal(s.FindIPbyMAC(hw), []byte{1, 1, 1, 1}), "FindIPbyMAC")
<mask> check(t, bytes.Equal(p2.CHAddr(), hw), "p2.CHAddr") <mask> check(t, bytes.Equal(opt[dhcp4.OptionIPAddressLeaseTime], dhcp4.OptionsLeaseTime(5*time.Second)), "OptionIPAddressLeaseTime") <mask> check(t, bytes.Equal(opt[dhcp4.OptionServerIdentifier], s.ipnet.IP), "OptionServerIdentifier") <mask> <mask> // Commit the previously reserved lease #2 <mask> hw = []byte{2, 2, 3, 4, 5, 6} <mask> p.SetCHAddr(hw) <mask> p.SetCIAddr([]byte{0, 0, 0, 0}) <mask> opt = make(dhcp4.Options, 10) </s> + dhcpd, clients: add more tests </s> remove lease, _ = s.reserveLease(p) check(t, bytes.Equal(lease.HWAddr, hw), "lease.HWAddr") check(t, bytes.Equal(lease.IP, []byte{1, 1, 1, 1}), "lease.IP") </s> add p.SetCIAddr([]byte{0, 0, 0, 0}) opt = make(dhcp4.Options, 10) p2 = s.handleDiscover(p, opt) opt = p2.ParseOptions() check(t, bytes.Equal(opt[dhcp4.OptionDHCPMessageType], []byte{byte(dhcp4.Offer)}), "dhcp4.Offer") check(t, bytes.Equal(p2.YIAddr(), []byte{1, 1, 1, 1}), "p2.YIAddr") check(t, bytes.Equal(p2.CHAddr(), hw), "p2.CHAddr") check(t, bytes.Equal(opt[dhcp4.OptionIPAddressLeaseTime], dhcp4.OptionsLeaseTime(5*time.Second)), "OptionIPAddressLeaseTime") check(t, bytes.Equal(opt[dhcp4.OptionServerIdentifier], s.ipnet.IP), "OptionServerIdentifier") </s> remove // Reserve an IP </s> add // Discover and reserve an IP
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efaaeb58ebd6571c545569ad18f1396cc701870b
dhcpd/dhcpd_test.go
s.reset() testStaticLeases(t, &s)
<mask> p.SetCHAddr(hw) <mask> lease, _ = s.reserveLease(p) <mask> check(t, lease == nil, "lease == nil") <mask> <mask> s.reset() <mask> misc(t, &s) <mask> } <mask> <mask> func testStaticLeases(t *testing.T, s *Server) { </s> + dhcpd, clients: add more tests </s> remove // Reserve an IP </s> add // Discover and reserve an IP </s> remove lease, _ = s.reserveLease(p) check(t, bytes.Equal(lease.HWAddr, hw), "lease.HWAddr") check(t, bytes.Equal(lease.IP, []byte{1, 1, 1, 1}), "lease.IP") </s> add p.SetCIAddr([]byte{0, 0, 0, 0}) opt = make(dhcp4.Options, 10) p2 = s.handleDiscover(p, opt) opt = p2.ParseOptions() check(t, bytes.Equal(opt[dhcp4.OptionDHCPMessageType], []byte{byte(dhcp4.Offer)}), "dhcp4.Offer") check(t, bytes.Equal(p2.YIAddr(), []byte{1, 1, 1, 1}), "p2.YIAddr") check(t, bytes.Equal(p2.CHAddr(), hw), "p2.CHAddr") check(t, bytes.Equal(opt[dhcp4.OptionIPAddressLeaseTime], dhcp4.OptionsLeaseTime(5*time.Second)), "OptionIPAddressLeaseTime") check(t, bytes.Equal(opt[dhcp4.OptionServerIdentifier], s.ipnet.IP), "OptionServerIdentifier")
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efaaeb58ebd6571c545569ad18f1396cc701870b
dhcpd/dhcpd_test.go
func testStaticLeases(t *testing.T, s *Server) { var err error var l Lease l.IP = []byte{1, 1, 1, 1} l.HWAddr = []byte{2, 2, 3, 4, 5, 6} err = s.AddStaticLease(l) check(t, err == nil, "AddStaticLease") ll := s.StaticLeases() check(t, len(ll) != 0 && bytes.Equal(ll[0].IP, []byte{1, 1, 1, 1}), "StaticLeases") err = s.RemoveStaticLease(l) check(t, err == nil, "RemoveStaticLease") }
<mask> } <mask> <mask> // Small tests that don't require a static server's state <mask> func misc(t *testing.T, s *Server) { <mask> var p, p2 dhcp4.Packet <mask> var hw net.HardwareAddr <mask> var opt dhcp4.Options </s> + dhcpd, clients: add more tests </s> remove lease, _ = s.reserveLease(p) check(t, bytes.Equal(lease.HWAddr, hw), "lease.HWAddr") check(t, bytes.Equal(lease.IP, []byte{1, 1, 1, 1}), "lease.IP") </s> add p.SetCIAddr([]byte{0, 0, 0, 0}) opt = make(dhcp4.Options, 10) p2 = s.handleDiscover(p, opt) opt = p2.ParseOptions() check(t, bytes.Equal(opt[dhcp4.OptionDHCPMessageType], []byte{byte(dhcp4.Offer)}), "dhcp4.Offer") check(t, bytes.Equal(p2.YIAddr(), []byte{1, 1, 1, 1}), "p2.YIAddr") check(t, bytes.Equal(p2.CHAddr(), hw), "p2.CHAddr") check(t, bytes.Equal(opt[dhcp4.OptionIPAddressLeaseTime], dhcp4.OptionsLeaseTime(5*time.Second)), "OptionIPAddressLeaseTime") check(t, bytes.Equal(opt[dhcp4.OptionServerIdentifier], s.ipnet.IP), "OptionServerIdentifier") </s> remove // Reserve an IP </s> add // Discover and reserve an IP
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efaaeb58ebd6571c545569ad18f1396cc701870b
dhcpd/dhcpd_test.go
c, b = clientFind("1.1.1.1") if !b || c.Name != "client1" { t.Fatalf("clientFind #1") } c, b = clientFind("2.2.2.2") if !b || c.Name != "client2" { t.Fatalf("clientFind #2") }
<mask> } <mask> <mask> // failed add - name in use <mask> c = Client{ <mask> IP: "1.2.3.5", <mask> Name: "client1", </s> + dhcpd, clients: add more tests </s> remove lease, _ = s.reserveLease(p) check(t, bytes.Equal(lease.HWAddr, hw), "lease.HWAddr") check(t, bytes.Equal(lease.IP, []byte{1, 1, 1, 1}), "lease.IP") </s> add p.SetCIAddr([]byte{0, 0, 0, 0}) opt = make(dhcp4.Options, 10) p2 = s.handleDiscover(p, opt) opt = p2.ParseOptions() check(t, bytes.Equal(opt[dhcp4.OptionDHCPMessageType], []byte{byte(dhcp4.Offer)}), "dhcp4.Offer") check(t, bytes.Equal(p2.YIAddr(), []byte{1, 1, 1, 1}), "p2.YIAddr") check(t, bytes.Equal(p2.CHAddr(), hw), "p2.CHAddr") check(t, bytes.Equal(opt[dhcp4.OptionIPAddressLeaseTime], dhcp4.OptionsLeaseTime(5*time.Second)), "OptionIPAddressLeaseTime") check(t, bytes.Equal(opt[dhcp4.OptionServerIdentifier], s.ipnet.IP), "OptionServerIdentifier") </s> remove // Reserve an IP </s> add // Discover and reserve an IP
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efaaeb58ebd6571c545569ad18f1396cc701870b
home/clients_test.go
{{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap 8.8.8.8:53 }{{end}}
<mask> {{.Pprof}} <mask> hosts { <mask> fallthrough <mask> } <mask> {{if .UpstreamDNS}}forward . {{range .UpstreamDNS}}{{.}} {{end}}{{end}} <mask> {{.Cache}} <mask> {{.Prometheus}} <mask> } <mask> ` <mask> </s> Added CoreDNS plugin setup and replaced forward </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add </s> remove p := &UpstreamPlugin{} </s> add p := &UpstreamPlugin{ Upstreams: []Upstream{}, } </s> remove resp, err := u.Exchange(nil, &req) </s> add resp, err := u.Exchange(context.Background(), &req) </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
config.go
_ "github.com/AdguardTeam/AdGuardHome/upstream"
<mask> "path/filepath" <mask> "sync" // Include all plugins. <mask> <mask> _ "github.com/AdguardTeam/AdGuardHome/coredns_plugin" <mask> "github.com/coredns/coredns/core/dnsserver" <mask> "github.com/coredns/coredns/coremain" <mask> _ "github.com/coredns/coredns/plugin/auto" <mask> _ "github.com/coredns/coredns/plugin/autopath" <mask> _ "github.com/coredns/coredns/plugin/bind" </s> Added CoreDNS plugin setup and replaced forward </s> remove p := &UpstreamPlugin{} </s> add p := &UpstreamPlugin{ Upstreams: []Upstream{}, } </s> remove // Make sure all resources are cleaned up runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer) </s> add </s> remove conn, err := u.transport.Dial(u.proto) </s> add conn, err := u.transport.Dial(proto) </s> remove func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { </s> add func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) { </s> remove resp, err := u.Exchange(nil, ping) </s> add resp, err := u.Exchange(context.Background(), ping)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
coredns.go
"upstream",
<mask> "forward", <mask> "proxy", <mask> "erratic", <mask> "whoami", <mask> "on", <mask> } <mask> <mask> func init() { </s> Added CoreDNS plugin setup and replaced forward </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add </s> remove p := &UpstreamPlugin{} </s> add p := &UpstreamPlugin{ Upstreams: []Upstream{}, } </s> remove // Make sure all resources are cleaned up runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer) </s> add </s> remove func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { </s> add func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) { </s> remove {{if .UpstreamDNS}}forward . {{range .UpstreamDNS}}{{.}} {{end}}{{end}} </s> add {{if .UpstreamDNS}}upstream {{range .UpstreamDNS}}{{.}} {{end}} { bootstrap 8.8.8.8:53 }{{end}}
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
coredns.go
resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil }
<mask> <mask> // Exchange provides an implementation for the Upstream interface <mask> func (u *DnsUpstream) Exchange(ctx context.Context, query *dns.Msg) (*dns.Msg, error) { <mask> <mask> resp, err := u.exchange(query) <mask> <mask> if err != nil { <mask> resp = &dns.Msg{} <mask> resp.SetRcode(resp, dns.RcodeServerFailure) <mask> } </s> Added CoreDNS plugin setup and replaced forward </s> remove // TODO: Add a helper method for health-checking an upstream (see health.go in coredns) </s> add </s> remove func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { </s> add func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) { </s> remove conn, err := u.transport.Dial(u.proto) </s> add conn, err := u.transport.Dial(proto) </s> remove resp, err := u.Exchange(nil, &req) </s> add resp, err := u.Exchange(context.Background(), &req) </s> remove // Make sure all resources are cleaned up runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer) </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/dns_upstream.go
func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) {
<mask> } <mask> <mask> // Performs a synchronous query. It sends the message m via the conn <mask> // c and waits for a reply. The conn c is not closed. <mask> func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { <mask> <mask> // Establish a connection if needed (or reuse cached) <mask> conn, err := u.transport.Dial(u.proto) <mask> if err != nil { <mask> return nil, err </s> Added CoreDNS plugin setup and replaced forward </s> remove conn, err := u.transport.Dial(u.proto) </s> add conn, err := u.transport.Dial(proto) </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil } </s> remove resp, err := u.Exchange(nil, ping) </s> add resp, err := u.Exchange(context.Background(), ping) </s> remove // TODO: Add a helper method for health-checking an upstream (see health.go in coredns) </s> add </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/dns_upstream.go
conn, err := u.transport.Dial(proto)
<mask> // c and waits for a reply. The conn c is not closed. <mask> func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { <mask> <mask> // Establish a connection if needed (or reuse cached) <mask> conn, err := u.transport.Dial(u.proto) <mask> if err != nil { <mask> return nil, err <mask> } <mask> <mask> // Write the request with a timeout </s> Added CoreDNS plugin setup and replaced forward </s> remove func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { </s> add func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) { </s> remove resp, err := u.Exchange(nil, ping) </s> add resp, err := u.Exchange(context.Background(), ping) </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil } </s> remove // TODO: Add a helper method for health-checking an upstream (see health.go in coredns) </s> add </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/dns_upstream.go
resp, err := u.Exchange(context.Background(), ping)
<mask> // Using ipv4only.arpa. domain as it is a part of DNS64 RFC and it should exist everywhere <mask> ping := new(dns.Msg) <mask> ping.SetQuestion("ipv4only.arpa.", dns.TypeA) <mask> <mask> resp, err := u.Exchange(nil, ping) <mask> <mask> // If we got a header, we're alright, basically only care about I/O errors 'n stuff. <mask> if err != nil && resp != nil { <mask> // Silly check, something sane came back. <mask> if resp.Response || resp.Opcode == dns.OpcodeQuery { </s> Added CoreDNS plugin setup and replaced forward </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil } </s> remove conn, err := u.transport.Dial(u.proto) </s> add conn, err := u.transport.Dial(proto) </s> remove func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { </s> add func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) { </s> remove resp, err := u.Exchange(nil, &req) </s> add resp, err := u.Exchange(context.Background(), &req) </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/helpers.go
<mask> "github.com/coredns/coredns/plugin" <mask> "github.com/miekg/dns" <mask> "github.com/pkg/errors" <mask> "golang.org/x/net/context" <mask> "log" <mask> "runtime" <mask> "time" <mask> ) <mask> <mask> const ( <mask> defaultTimeout = 5 * time.Second </s> Added CoreDNS plugin setup and replaced forward </s> remove // TODO: Add a helper method for health-checking an upstream (see health.go in coredns) </s> add </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil } </s> remove resp, err := u.Exchange(nil, &req) </s> add resp, err := u.Exchange(context.Background(), &req) </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/upstream.go
<mask> const ( <mask> defaultTimeout = 5 * time.Second <mask> ) <mask> <mask> // TODO: Add a helper method for health-checking an upstream (see health.go in coredns) <mask> <mask> // Upstream is a simplified interface for proxy destination <mask> type Upstream interface { <mask> Exchange(ctx context.Context, query *dns.Msg) (*dns.Msg, error) <mask> Close() error <mask> } </s> Added CoreDNS plugin setup and replaced forward </s> remove "log" "runtime" </s> add </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil } </s> remove // Make sure all resources are cleaned up runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer) </s> add </s> remove func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { </s> add func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) { </s> remove conn, err := u.transport.Dial(u.proto) </s> add conn, err := u.transport.Dial(proto)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/upstream.go
p := &UpstreamPlugin{ Upstreams: []Upstream{}, }
<mask> } <mask> <mask> // Initialize the upstream plugin <mask> func New() *UpstreamPlugin { <mask> p := &UpstreamPlugin{} <mask> <mask> // Make sure all resources are cleaned up <mask> runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer) <mask> return p <mask> } </s> Added CoreDNS plugin setup and replaced forward </s> remove // Make sure all resources are cleaned up runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer) </s> add </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add </s> remove conn, err := u.transport.Dial(u.proto) </s> add conn, err := u.transport.Dial(proto) </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil } </s> remove func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { </s> add func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/upstream.go
<mask> // Initialize the upstream plugin <mask> func New() *UpstreamPlugin { <mask> p := &UpstreamPlugin{} <mask> <mask> // Make sure all resources are cleaned up <mask> runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer) <mask> return p <mask> } <mask> <mask> // ServeDNS implements interface for CoreDNS plugin <mask> func (p *UpstreamPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { </s> Added CoreDNS plugin setup and replaced forward </s> remove p := &UpstreamPlugin{} </s> add p := &UpstreamPlugin{ Upstreams: []Upstream{}, } </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add </s> remove // TODO: Add a helper method for health-checking an upstream (see health.go in coredns) </s> add </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil } </s> remove func (u *DnsUpstream) exchange(query *dns.Msg) (r *dns.Msg, err error) { </s> add func (u *DnsUpstream) exchange(proto string, query *dns.Msg) (r *dns.Msg, err error) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/upstream.go
<mask> } <mask> <mask> // Name implements interface for CoreDNS plugin <mask> func (p *UpstreamPlugin) Name() string { return "upstream" } <mask> <mask> func (p *UpstreamPlugin) finalizer() { <mask> <mask> for i := range p.Upstreams { <mask> <mask> u := p.Upstreams[i] <mask> err := u.Close() <mask> if err != nil { <mask> log.Printf("Error while closing the upstream: %s", err) <mask> } <mask> } <mask> } </s> Added CoreDNS plugin setup and replaced forward </s> remove // Make sure all resources are cleaned up runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer) </s> add </s> remove resp, err := u.Exchange(nil, &req) </s> add resp, err := u.Exchange(context.Background(), &req) </s> remove p := &UpstreamPlugin{} </s> add p := &UpstreamPlugin{ Upstreams: []Upstream{}, } </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil } </s> remove conn, err := u.transport.Dial(u.proto) </s> add conn, err := u.transport.Dial(proto)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/upstream.go
"golang.org/x/net/context"
<mask> import ( <mask> "github.com/miekg/dns" <mask> "net" <mask> "testing" <mask> ) <mask> <mask> func TestDnsUpstreamIsAlive(t *testing.T) { <mask> </s> Added CoreDNS plugin setup and replaced forward </s> remove "log" "runtime" </s> add </s> remove // TODO: Add a helper method for health-checking an upstream (see health.go in coredns) </s> add </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add </s> remove // Make sure all resources are cleaned up runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer) </s> add
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/upstream_test.go
resp, err := u.Exchange(context.Background(), &req)
<mask> req.Question = []dns.Question{ <mask> {Name: test.name, Qtype: dns.TypeA, Qclass: dns.ClassINET}, <mask> } <mask> <mask> resp, err := u.Exchange(nil, &req) <mask> <mask> if err != nil { <mask> t.Errorf("error while making an upstream request: %s", err) <mask> } <mask> </s> Added CoreDNS plugin setup and replaced forward </s> remove func (p *UpstreamPlugin) finalizer() { for i := range p.Upstreams { u := p.Upstreams[i] err := u.Close() if err != nil { log.Printf("Error while closing the upstream: %s", err) } } } </s> add </s> remove resp, err := u.exchange(query) </s> add resp, err := u.exchange(u.proto, query) // Retry over TCP if response is truncated if err == dns.ErrTruncated && u.proto == "udp" { resp, err = u.exchange("tcp", query) } else if err == dns.ErrTruncated && resp != nil { // Reassemble something to be sent to client m := new(dns.Msg) m.SetReply(query) m.Truncated = true m.Authoritative = true m.Rcode = dns.RcodeSuccess return m, nil } </s> remove resp, err := u.Exchange(nil, ping) </s> add resp, err := u.Exchange(context.Background(), ping) </s> remove // TODO: Add a helper method for health-checking an upstream (see health.go in coredns) </s> add </s> remove p := &UpstreamPlugin{} </s> add p := &UpstreamPlugin{ Upstreams: []Upstream{}, }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/efdd1c1ff2aff4643f0982734462e11c0218b02f
upstream/upstream_test.go
github.com/AdguardTeam/golibs v0.10.5
<mask> go 1.17 <mask> <mask> require ( <mask> github.com/AdguardTeam/dnsproxy v0.41.1 <mask> github.com/AdguardTeam/golibs v0.10.4 <mask> github.com/AdguardTeam/urlfilter v0.15.2 <mask> github.com/NYTimes/gziphandler v1.1.1 <mask> github.com/ameshkov/dnscrypt/v2 v2.2.3 <mask> github.com/digineo/go-ipset/v2 v2.2.1 <mask> github.com/fsnotify/fsnotify v1.5.1 </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove github.com/AdguardTeam/golibs v0.10.4 h1:TMBkablZC0IZOpRgg9fzAKlxxNhSN2YJq7qbgtuZ7PQ= </s> add </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil </s> remove req := dnsConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> add req := &dnsConfig{} err := json.NewDecoder(r.Body).Decode(req) </s> remove return "", nil </s> add switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
go.mod
<mask> github.com/AdguardTeam/dnsproxy v0.41.1/go.mod h1:PZ9l22h3Er+5mxFQB7oHZMTvx+aa9R6LbzA/ikXQlS0= <mask> github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/golibs v0.10.3/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw= <mask> github.com/AdguardTeam/golibs v0.10.4 h1:TMBkablZC0IZOpRgg9fzAKlxxNhSN2YJq7qbgtuZ7PQ= <mask> github.com/AdguardTeam/golibs v0.10.4/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw= <mask> github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU= <mask> github.com/AdguardTeam/urlfilter v0.15.2 h1:LZGgrm4l4Ys9eAqB+UUmZfiC6vHlDlYFhx0WXqo6LtQ= <mask> github.com/AdguardTeam/urlfilter v0.15.2/go.mod h1:46YZDOV1+qtdRDuhZKVPSSp7JWWes0KayqHrKAFBdEI= <mask> github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove github.com/AdguardTeam/golibs v0.10.4 </s> add github.com/AdguardTeam/golibs v0.10.5 </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil </s> remove req := dnsConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> add req := &dnsConfig{} err := json.NewDecoder(r.Body).Decode(req) </s> remove return "", nil </s> add switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
go.sum
github.com/AdguardTeam/golibs v0.10.5 h1:4/nl1yIBJOv5luVu9SURW8LfgOjI3zQ2moIUy/1k0y4= github.com/AdguardTeam/golibs v0.10.5/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw=
<mask> github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/golibs v0.10.3/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw= <mask> github.com/AdguardTeam/golibs v0.10.4/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw= <mask> github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU= <mask> github.com/AdguardTeam/urlfilter v0.15.2 h1:LZGgrm4l4Ys9eAqB+UUmZfiC6vHlDlYFhx0WXqo6LtQ= <mask> github.com/AdguardTeam/urlfilter v0.15.2/go.mod h1:46YZDOV1+qtdRDuhZKVPSSp7JWWes0KayqHrKAFBdEI= <mask> github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= <mask> github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= <mask> github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove github.com/AdguardTeam/golibs v0.10.4 h1:TMBkablZC0IZOpRgg9fzAKlxxNhSN2YJq7qbgtuZ7PQ= </s> add </s> remove github.com/AdguardTeam/golibs v0.10.4 </s> add github.com/AdguardTeam/golibs v0.10.5 </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil </s> remove req := dnsConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> add req := &dnsConfig{} err := json.NewDecoder(r.Body).Decode(req) </s> remove return "", nil </s> add switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil }
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
go.sum
// spNets is the collection of special-purpose address registries as defined // by RFC 6890.
<mask> ) <mask> <mask> // SubnetDetector describes IP address properties. <mask> type SubnetDetector struct { <mask> // spNets is the slice of special-purpose address registries as defined <mask> // by RFC-6890 (https://tools.ietf.org/html/rfc6890). <mask> spNets []*net.IPNet <mask> <mask> // locServedNets is the slice of locally-served networks as defined by <mask> // RFC-6303 (https://tools.ietf.org/html/rfc6303). <mask> locServedNets []*net.IPNet </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove // locServedNets is the slice of locally-served networks as defined by // RFC-6303 (https://tools.ietf.org/html/rfc6303). </s> add // locServedNets is the collection of locally-served networks as defined by // RFC 6303. </s> remove // ValidateUpstreams validates each upstream and returns an error if any // upstream is invalid or if there are no default upstreams specified. </s> add // LocalNetChecker is used to check if the IP address belongs to a local // network. type LocalNetChecker interface { // IsLocallyServedNetwork returns true if ip is contained in any of address // registries defined by RFC 6303. IsLocallyServedNetwork(ip net.IP) (ok bool) } // type check var _ LocalNetChecker = (*aghnet.SubnetDetector)(nil) // newUpstreamConfig validates upstreams and returns an appropriate upstream // configuration or nil if it can't be built. </s> remove dnsConfig: s.getDNSConfig(), </s> add dnsConfig: *s.getDNSConfig(), </s> remove // IsCommentOrEmpty returns true of the string starts with a "#" character or is // an empty string. This function is useful for filtering out non-upstream // lines from upstream configs. </s> add // IsCommentOrEmpty returns true if s starts with a "#" character or is empty. // This function is useful for filtering out non-upstream lines from upstream // configs.
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/aghnet/subnetdetector.go
// locServedNets is the collection of locally-served networks as defined by // RFC 6303.
<mask> // spNets is the slice of special-purpose address registries as defined <mask> // by RFC-6890 (https://tools.ietf.org/html/rfc6890). <mask> spNets []*net.IPNet <mask> <mask> // locServedNets is the slice of locally-served networks as defined by <mask> // RFC-6303 (https://tools.ietf.org/html/rfc6303). <mask> locServedNets []*net.IPNet <mask> } <mask> <mask> // NewSubnetDetector returns a new IP detector. <mask> func NewSubnetDetector() (snd *SubnetDetector, err error) { </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove // spNets is the slice of special-purpose address registries as defined // by RFC-6890 (https://tools.ietf.org/html/rfc6890). </s> add // spNets is the collection of special-purpose address registries as defined // by RFC 6890. </s> remove // ValidateUpstreams validates each upstream and returns an error if any // upstream is invalid or if there are no default upstreams specified. </s> add // LocalNetChecker is used to check if the IP address belongs to a local // network. type LocalNetChecker interface { // IsLocallyServedNetwork returns true if ip is contained in any of address // registries defined by RFC 6303. IsLocallyServedNetwork(ip net.IP) (ok bool) } // type check var _ LocalNetChecker = (*aghnet.SubnetDetector)(nil) // newUpstreamConfig validates upstreams and returns an appropriate upstream // configuration or nil if it can't be built. </s> remove // IsCommentOrEmpty returns true of the string starts with a "#" character or is // an empty string. This function is useful for filtering out non-upstream // lines from upstream configs. </s> add // IsCommentOrEmpty returns true if s starts with a "#" character or is empty. // This function is useful for filtering out non-upstream lines from upstream // configs. </s> remove return err </s> add return nil, err } } return conf, nil } // ValidateUpstreams validates each upstream and returns an error if any // upstream is invalid or if there are no default upstreams specified. // // TODO(e.burkov): Move into aghnet or even into dnsproxy. func ValidateUpstreams(upstreams []string) (err error) { _, err = newUpstreamConfig(upstreams) return err } // stringKeysSorted returns the sorted slice of string keys of m. // // TODO(e.burkov): Use generics in Go 1.18. Move into golibs. func stringKeysSorted(m map[string][]upstream.Upstream) (sorted []string) { sorted = make([]string, 0, len(m)) for s := range m { sorted = append(sorted, s) } sort.Strings(sorted) return sorted } // ValidateUpstreamsPrivate validates each upstream and returns an error if any // upstream is invalid or if there are no default upstreams specified. It also // checks each domain of domain-specific upstreams for being ARPA pointing to // a locally-served network. lnc must not be nil. func ValidateUpstreamsPrivate(upstreams []string, lnc LocalNetChecker) (err error) { conf, err := newUpstreamConfig(upstreams) if err != nil { return err } if conf == nil { return nil } var errs []error for _, domain := range stringKeysSorted(conf.DomainReservedUpstreams) { var subnet *net.IPNet subnet, err = netutil.SubnetFromReversedAddr(domain) if err != nil { errs = append(errs, err) continue
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/aghnet/subnetdetector.go
// // TODO(a.garipov): Decide whether an error is actually needed.
<mask> } <mask> <mask> // NewSubnetDetector returns a new IP detector. <mask> func NewSubnetDetector() (snd *SubnetDetector, err error) { <mask> spNets := []string{ <mask> // "This" network. <mask> "0.0.0.0/8", <mask> // Private-Use Networks. </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove // locServedNets is the slice of locally-served networks as defined by // RFC-6303 (https://tools.ietf.org/html/rfc6303). </s> add // locServedNets is the collection of locally-served networks as defined by // RFC 6303. </s> remove // ValidateUpstreams validates each upstream and returns an error if any // upstream is invalid or if there are no default upstreams specified. </s> add // LocalNetChecker is used to check if the IP address belongs to a local // network. type LocalNetChecker interface { // IsLocallyServedNetwork returns true if ip is contained in any of address // registries defined by RFC 6303. IsLocallyServedNetwork(ip net.IP) (ok bool) } // type check var _ LocalNetChecker = (*aghnet.SubnetDetector)(nil) // newUpstreamConfig validates upstreams and returns an appropriate upstream // configuration or nil if it can't be built. </s> remove // spNets is the slice of special-purpose address registries as defined // by RFC-6890 (https://tools.ietf.org/html/rfc6890). </s> add // spNets is the collection of special-purpose address registries as defined // by RFC 6890. </s> remove return err </s> add return nil, err } } return conf, nil } // ValidateUpstreams validates each upstream and returns an error if any // upstream is invalid or if there are no default upstreams specified. // // TODO(e.burkov): Move into aghnet or even into dnsproxy. func ValidateUpstreams(upstreams []string) (err error) { _, err = newUpstreamConfig(upstreams) return err } // stringKeysSorted returns the sorted slice of string keys of m. // // TODO(e.burkov): Use generics in Go 1.18. Move into golibs. func stringKeysSorted(m map[string][]upstream.Upstream) (sorted []string) { sorted = make([]string, 0, len(m)) for s := range m { sorted = append(sorted, s) } sort.Strings(sorted) return sorted } // ValidateUpstreamsPrivate validates each upstream and returns an error if any // upstream is invalid or if there are no default upstreams specified. It also // checks each domain of domain-specific upstreams for being ARPA pointing to // a locally-served network. lnc must not be nil. func ValidateUpstreamsPrivate(upstreams []string, lnc LocalNetChecker) (err error) { conf, err := newUpstreamConfig(upstreams) if err != nil { return err } if conf == nil { return nil } var errs []error for _, domain := range stringKeysSorted(conf.DomainReservedUpstreams) { var subnet *net.IPNet subnet, err = netutil.SubnetFromReversedAddr(domain) if err != nil { errs = append(errs, err) continue </s> remove // IsCommentOrEmpty returns true of the string starts with a "#" character or is // an empty string. This function is useful for filtering out non-upstream // lines from upstream configs. </s> add // IsCommentOrEmpty returns true if s starts with a "#" character or is empty. // This function is useful for filtering out non-upstream lines from upstream // configs.
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/aghnet/subnetdetector.go
"sort"
<mask> "fmt" <mask> "net" <mask> "net/http" <mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghnet" </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove func TestValidateUpstreamsSet(t *testing.T) { </s> add func TestValidateUpstreams(t *testing.T) { </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil </s> remove req := dnsConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> add req := &dnsConfig{} err := json.NewDecoder(r.Body).Decode(req) </s> remove return "", nil </s> add switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
<mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/dnsproxy/proxy" <mask> "github.com/AdguardTeam/dnsproxy/upstream" <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/log" </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove func TestValidateUpstreamsSet(t *testing.T) { </s> add func TestValidateUpstreams(t *testing.T) { </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil </s> remove req := dnsConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> add req := &dnsConfig{} err := json.NewDecoder(r.Body).Decode(req) </s> remove return "", nil </s> add switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil }
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
func (s *Server) getDNSConfig() (c *dnsConfig) {
<mask> UsePrivateRDNS *bool `json:"use_private_ptr_resolvers"` <mask> LocalPTRUpstreams *[]string `json:"local_ptr_upstreams"` <mask> } <mask> <mask> func (s *Server) getDNSConfig() dnsConfig { <mask> s.serverLock.RLock() <mask> defer s.serverLock.RUnlock() <mask> <mask> upstreams := stringutil.CloneSliceOrEmpty(s.conf.UpstreamDNS) <mask> upstreamFile := s.conf.UpstreamDNSFileName </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove func (s *Server) setConfig(dc dnsConfig) (restart bool) { </s> add func (s *Server) setConfig(dc *dnsConfig) (restart bool) { </s> remove func (s *Server) setConfigRestartable(dc dnsConfig) (restart bool) { </s> add func (s *Server) setConfigRestartable(dc *dnsConfig) (restart bool) { </s> remove req := dnsConfig{} err := json.NewDecoder(r.Body).Decode(&req) </s> add req := &dnsConfig{} err := json.NewDecoder(r.Body).Decode(req) </s> remove aghhttp.Error(r, w, http.StatusBadRequest, "json Encode: %s", err) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "decoding request: %s", err) </s> remove for _, valid := range []string{ "", "fastest_addr", "parallel", } { if *req.UpstreamMode == valid { return true </s> add var b string defer func() { err = errors.Annotate(err, "checking bootstrap %s: invalid address: %w", b) }() for _, b = range *req.Bootstraps { if b == "" { return errors.Error("empty") } if _, err = upstream.NewResolver(b, nil); err != nil { return err
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
return &dnsConfig{
<mask> } else if s.conf.AllServers { <mask> upstreamMode = "parallel" <mask> } <mask> <mask> return dnsConfig{ <mask> Upstreams: &upstreams, <mask> UpstreamsFile: &upstreamFile, <mask> Bootstraps: &bootstraps, <mask> ProtectionEnabled: &protectionEnabled, <mask> BlockingMode: &blockingMode, </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove return err </s> add return nil, err } else if len(conf.Upstreams) == 0 { return nil, errors.Error("no default upstreams specified") </s> remove for _, valid := range []string{ "", "fastest_addr", "parallel", } { if *req.UpstreamMode == valid { return true </s> add var b string defer func() { err = errors.Annotate(err, "checking bootstrap %s: invalid address: %w", b) }() for _, b = range *req.Bootstraps { if b == "" { return errors.Error("empty") } if _, err = upstream.NewResolver(b, nil); err != nil { return err </s> remove if !defaultUpstreamFound { return fmt.Errorf("no default upstreams specified") </s> add if len(errs) > 0 { return errors.List("checking domain-specific upstreams", errs...) </s> remove if !defaultUpstreamFound { defaultUpstreamFound = useDefault </s> add if !lnc.IsLocallyServedNetwork(subnet.IP) { errs = append( errs, fmt.Errorf("arpa domain %q should point to a locally-served network", domain), )
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
dnsConfig: *s.getDNSConfig(),
<mask> // systemResolvers to the front-end. It's not a pointer to the slice <mask> // since there is no need to omit it while decoding from JSON. <mask> DefautLocalPTRUpstreams []string `json:"default_local_ptr_upstreams,omitempty"` <mask> }{ <mask> dnsConfig: s.getDNSConfig(), <mask> DefautLocalPTRUpstreams: defLocalPTRUps, <mask> } <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove // ValidateUpstreams validates each upstream and returns an error if any // upstream is invalid or if there are no default upstreams specified. </s> add // LocalNetChecker is used to check if the IP address belongs to a local // network. type LocalNetChecker interface { // IsLocallyServedNetwork returns true if ip is contained in any of address // registries defined by RFC 6303. IsLocallyServedNetwork(ip net.IP) (ok bool) } // type check var _ LocalNetChecker = (*aghnet.SubnetDetector)(nil) // newUpstreamConfig validates upstreams and returns an appropriate upstream // configuration or nil if it can't be built. </s> remove // TODO(e.burkov): Move into aghnet or even into dnsproxy. func ValidateUpstreams(upstreams []string) (err error) { // No need to validate comments </s> add // TODO(e.burkov): Perhaps proxy.ParseUpstreamsConfig should validate upstreams // slice already so that this function may be considered useless. func newUpstreamConfig(upstreams []string) (conf *proxy.UpstreamConfig, err error) { // No need to validate comments and empty lines. </s> remove // IsCommentOrEmpty returns true of the string starts with a "#" character or is // an empty string. This function is useful for filtering out non-upstream // lines from upstream configs. </s> add // IsCommentOrEmpty returns true if s starts with a "#" character or is empty. // This function is useful for filtering out non-upstream lines from upstream // configs. </s> remove // locServedNets is the slice of locally-served networks as defined by // RFC-6303 (https://tools.ietf.org/html/rfc6303). </s> add // locServedNets is the collection of locally-served networks as defined by // RFC 6303. </s> remove // spNets is the slice of special-purpose address registries as defined // by RFC-6890 (https://tools.ietf.org/html/rfc6890). </s> add // spNets is the collection of special-purpose address registries as defined // by RFC 6890.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil
<mask> } <mask> } <mask> <mask> func (req *dnsConfig) checkUpstreamsMode() bool { <mask> if req.UpstreamMode == nil { <mask> return true <mask> } <mask> <mask> for _, valid := range []string{ <mask> "", <mask> "fastest_addr", </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove for _, valid := range []string{ "", "fastest_addr", "parallel", } { if *req.UpstreamMode == valid { return true </s> add var b string defer func() { err = errors.Annotate(err, "checking bootstrap %s: invalid address: %w", b) }() for _, b = range *req.Bootstraps { if b == "" { return errors.Error("empty") } if _, err = upstream.NewResolver(b, nil); err != nil { return err </s> remove return false </s> add return nil </s> remove func (req *dnsConfig) checkBootstrap() (string, error) { if req.Bootstraps == nil { return "", nil </s> add // validate returns an error if any field of req is invalid. func (req *dnsConfig) validate(snd *aghnet.SubnetDetector) (err error) { if req.Upstreams != nil { err = ValidateUpstreams(*req.Upstreams) if err != nil { return fmt.Errorf("validating upstream servers: %w", err) } </s> remove return "", nil </s> add switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil } </s> remove var useDefault bool useDefault, err = validateUpstream(u) </s> add _, err = validateUpstream(u)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
var b string defer func() { err = errors.Annotate(err, "checking bootstrap %s: invalid address: %w", b) }() for _, b = range *req.Bootstraps { if b == "" { return errors.Error("empty") } if _, err = upstream.NewResolver(b, nil); err != nil { return err
<mask> if req.UpstreamMode == nil { <mask> return true <mask> } <mask> <mask> for _, valid := range []string{ <mask> "", <mask> "fastest_addr", <mask> "parallel", <mask> } { <mask> if *req.UpstreamMode == valid { <mask> return true <mask> } <mask> } <mask> <mask> return false <mask> } </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil </s> remove return false </s> add return nil </s> remove func (req *dnsConfig) checkBootstrap() (string, error) { if req.Bootstraps == nil { return "", nil </s> add // validate returns an error if any field of req is invalid. func (req *dnsConfig) validate(snd *aghnet.SubnetDetector) (err error) { if req.Upstreams != nil { err = ValidateUpstreams(*req.Upstreams) if err != nil { return fmt.Errorf("validating upstream servers: %w", err) } </s> remove for _, boot := range *req.Bootstraps { if boot == "" { return boot, fmt.Errorf("invalid bootstrap server address: empty") </s> add if req.LocalPTRUpstreams != nil { err = ValidateUpstreamsPrivate(*req.LocalPTRUpstreams, snd) if err != nil { return fmt.Errorf("validating private upstream servers: %w", err) </s> remove if _, err := upstream.NewResolver(boot, nil); err != nil { return boot, fmt.Errorf("invalid bootstrap server address: %w", err) } </s> add err = req.checkBootstrap() if err != nil { return err
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
return nil
<mask> return true <mask> } <mask> } <mask> <mask> return false <mask> } <mask> <mask> func (req *dnsConfig) checkBootstrap() (string, error) { <mask> if req.Bootstraps == nil { <mask> return "", nil </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove func (req *dnsConfig) checkBootstrap() (string, error) { if req.Bootstraps == nil { return "", nil </s> add // validate returns an error if any field of req is invalid. func (req *dnsConfig) validate(snd *aghnet.SubnetDetector) (err error) { if req.Upstreams != nil { err = ValidateUpstreams(*req.Upstreams) if err != nil { return fmt.Errorf("validating upstream servers: %w", err) } </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil </s> remove return "", nil </s> add switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil } </s> remove for _, valid := range []string{ "", "fastest_addr", "parallel", } { if *req.UpstreamMode == valid { return true </s> add var b string defer func() { err = errors.Annotate(err, "checking bootstrap %s: invalid address: %w", b) }() for _, b = range *req.Bootstraps { if b == "" { return errors.Error("empty") } if _, err = upstream.NewResolver(b, nil); err != nil { return err </s> remove for _, boot := range *req.Bootstraps { if boot == "" { return boot, fmt.Errorf("invalid bootstrap server address: empty") </s> add if req.LocalPTRUpstreams != nil { err = ValidateUpstreamsPrivate(*req.LocalPTRUpstreams, snd) if err != nil { return fmt.Errorf("validating private upstream servers: %w", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
// validate returns an error if any field of req is invalid. func (req *dnsConfig) validate(snd *aghnet.SubnetDetector) (err error) { if req.Upstreams != nil { err = ValidateUpstreams(*req.Upstreams) if err != nil { return fmt.Errorf("validating upstream servers: %w", err) }
<mask> <mask> return false <mask> } <mask> <mask> func (req *dnsConfig) checkBootstrap() (string, error) { <mask> if req.Bootstraps == nil { <mask> return "", nil <mask> } <mask> <mask> for _, boot := range *req.Bootstraps { <mask> if boot == "" { <mask> return boot, fmt.Errorf("invalid bootstrap server address: empty") </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove for _, boot := range *req.Bootstraps { if boot == "" { return boot, fmt.Errorf("invalid bootstrap server address: empty") </s> add if req.LocalPTRUpstreams != nil { err = ValidateUpstreamsPrivate(*req.LocalPTRUpstreams, snd) if err != nil { return fmt.Errorf("validating private upstream servers: %w", err) </s> remove if _, err := upstream.NewResolver(boot, nil); err != nil { return boot, fmt.Errorf("invalid bootstrap server address: %w", err) } </s> add err = req.checkBootstrap() if err != nil { return err </s> remove return false </s> add return nil </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil </s> remove for _, valid := range []string{ "", "fastest_addr", "parallel", } { if *req.UpstreamMode == valid { return true </s> add var b string defer func() { err = errors.Annotate(err, "checking bootstrap %s: invalid address: %w", b) }() for _, b = range *req.Bootstraps { if b == "" { return errors.Error("empty") } if _, err = upstream.NewResolver(b, nil); err != nil { return err
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
if req.LocalPTRUpstreams != nil { err = ValidateUpstreamsPrivate(*req.LocalPTRUpstreams, snd) if err != nil { return fmt.Errorf("validating private upstream servers: %w", err)
<mask> if req.Bootstraps == nil { <mask> return "", nil <mask> } <mask> <mask> for _, boot := range *req.Bootstraps { <mask> if boot == "" { <mask> return boot, fmt.Errorf("invalid bootstrap server address: empty") <mask> } <mask> <mask> if _, err := upstream.NewResolver(boot, nil); err != nil { <mask> return boot, fmt.Errorf("invalid bootstrap server address: %w", err) <mask> } </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove if _, err := upstream.NewResolver(boot, nil); err != nil { return boot, fmt.Errorf("invalid bootstrap server address: %w", err) } </s> add err = req.checkBootstrap() if err != nil { return err </s> remove func (req *dnsConfig) checkBootstrap() (string, error) { if req.Bootstraps == nil { return "", nil </s> add // validate returns an error if any field of req is invalid. func (req *dnsConfig) validate(snd *aghnet.SubnetDetector) (err error) { if req.Upstreams != nil { err = ValidateUpstreams(*req.Upstreams) if err != nil { return fmt.Errorf("validating upstream servers: %w", err) } </s> remove for _, valid := range []string{ "", "fastest_addr", "parallel", } { if *req.UpstreamMode == valid { return true </s> add var b string defer func() { err = errors.Annotate(err, "checking bootstrap %s: invalid address: %w", b) }() for _, b = range *req.Bootstraps { if b == "" { return errors.Error("empty") } if _, err = upstream.NewResolver(b, nil); err != nil { return err </s> remove return "", nil </s> add switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil } </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
}
<mask> if err != nil { <mask> return fmt.Errorf("validating private upstream servers: %w", err) <mask> } <mask> <mask> err = req.checkBootstrap() <mask> if err != nil { <mask> return err <mask> } <mask> </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove for _, boot := range *req.Bootstraps { if boot == "" { return boot, fmt.Errorf("invalid bootstrap server address: empty") </s> add if req.LocalPTRUpstreams != nil { err = ValidateUpstreamsPrivate(*req.LocalPTRUpstreams, snd) if err != nil { return fmt.Errorf("validating private upstream servers: %w", err) </s> remove if _, err := upstream.NewResolver(boot, nil); err != nil { return boot, fmt.Errorf("invalid bootstrap server address: %w", err) } </s> add err = req.checkBootstrap() if err != nil { return err </s> remove func (req *dnsConfig) checkBootstrap() (string, error) { if req.Bootstraps == nil { return "", nil </s> add // validate returns an error if any field of req is invalid. func (req *dnsConfig) validate(snd *aghnet.SubnetDetector) (err error) { if req.Upstreams != nil { err = ValidateUpstreams(*req.Upstreams) if err != nil { return fmt.Errorf("validating upstream servers: %w", err) } </s> remove for _, valid := range []string{ "", "fastest_addr", "parallel", } { if *req.UpstreamMode == valid { return true </s> add var b string defer func() { err = errors.Annotate(err, "checking bootstrap %s: invalid address: %w", b) }() for _, b = range *req.Bootstraps { if b == "" { return errors.Error("empty") } if _, err = upstream.NewResolver(b, nil); err != nil { return err </s> remove if req.Upstreams != nil { if err = ValidateUpstreams(*req.Upstreams); err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "wrong upstreams specification: %s", err) return } } var errBoot string if errBoot, err = req.checkBootstrap(); err != nil { aghhttp.Error( r, w, http.StatusBadRequest, "%s can not be used as bootstrap dns cause: %s", errBoot, err, ) return } switch { case !req.checkBlockingMode(): aghhttp.Error(r, w, http.StatusBadRequest, "blocking_mode: incorrect value") return case !req.checkUpstreamsMode(): aghhttp.Error(r, w, http.StatusBadRequest, "upstream_mode: incorrect value") return case !req.checkCacheTTL(): aghhttp.Error( r, w, http.StatusBadRequest, "cache_ttl_min must be less or equal than cache_ttl_max", ) </s> add err = req.validate(s.subnetDetector) if err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
err = req.checkBootstrap() if err != nil { return err
<mask> if boot == "" { <mask> return boot, fmt.Errorf("invalid bootstrap server address: empty") <mask> } <mask> <mask> if _, err := upstream.NewResolver(boot, nil); err != nil { <mask> return boot, fmt.Errorf("invalid bootstrap server address: %w", err) <mask> } <mask> } <mask> <mask> return "", nil <mask> } <mask> </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove for _, boot := range *req.Bootstraps { if boot == "" { return boot, fmt.Errorf("invalid bootstrap server address: empty") </s> add if req.LocalPTRUpstreams != nil { err = ValidateUpstreamsPrivate(*req.LocalPTRUpstreams, snd) if err != nil { return fmt.Errorf("validating private upstream servers: %w", err) </s> remove func (req *dnsConfig) checkBootstrap() (string, error) { if req.Bootstraps == nil { return "", nil </s> add // validate returns an error if any field of req is invalid. func (req *dnsConfig) validate(snd *aghnet.SubnetDetector) (err error) { if req.Upstreams != nil { err = ValidateUpstreams(*req.Upstreams) if err != nil { return fmt.Errorf("validating upstream servers: %w", err) } </s> remove return "", nil </s> add switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil } </s> remove for _, valid := range []string{ "", "fastest_addr", "parallel", } { if *req.UpstreamMode == valid { return true </s> add var b string defer func() { err = errors.Annotate(err, "checking bootstrap %s: invalid address: %w", b) }() for _, b = range *req.Bootstraps { if b == "" { return errors.Error("empty") } if _, err = upstream.NewResolver(b, nil); err != nil { return err
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go
switch { case !req.checkBlockingMode(): return errors.Error("blocking_mode: incorrect value") case !req.checkUpstreamsMode(): return errors.Error("upstream_mode: incorrect value") case !req.checkCacheTTL(): return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") default: return nil }
<mask> return boot, fmt.Errorf("invalid bootstrap server address: %w", err) <mask> } <mask> } <mask> <mask> return "", nil <mask> } <mask> <mask> func (req *dnsConfig) checkCacheTTL() bool { <mask> if req.CacheMinTTL == nil && req.CacheMaxTTL == nil { <mask> return true </s> Pull request: 3381 check private domains Merge in DNS/adguard-home from 3381-validate-privateness to master Closes #3381. Squashed commit of the following: commit 21cb12d10b07bb0bf0578db74ca9ac7b3ac5ae14 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 16:29:59 2022 +0300 all: imp code, docs commit 39793551438cbea71e6ec78d0e05bee2d8dba3e5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 15:08:36 2022 +0300 all: imp code, docs commit 6b71848fd0980582b1bfe24a34f48608795e9b7d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Feb 14 14:22:00 2022 +0300 all: check private domains </s> remove if _, err := upstream.NewResolver(boot, nil); err != nil { return boot, fmt.Errorf("invalid bootstrap server address: %w", err) } </s> add err = req.checkBootstrap() if err != nil { return err </s> remove for _, boot := range *req.Bootstraps { if boot == "" { return boot, fmt.Errorf("invalid bootstrap server address: empty") </s> add if req.LocalPTRUpstreams != nil { err = ValidateUpstreamsPrivate(*req.LocalPTRUpstreams, snd) if err != nil { return fmt.Errorf("validating private upstream servers: %w", err) </s> remove func (req *dnsConfig) checkBootstrap() (string, error) { if req.Bootstraps == nil { return "", nil </s> add // validate returns an error if any field of req is invalid. func (req *dnsConfig) validate(snd *aghnet.SubnetDetector) (err error) { if req.Upstreams != nil { err = ValidateUpstreams(*req.Upstreams) if err != nil { return fmt.Errorf("validating upstream servers: %w", err) } </s> remove if req.UpstreamMode == nil { return true </s> add valid := []string{"", "fastest_addr", "parallel"} return req.UpstreamMode == nil || stringutil.InSlice(valid, *req.UpstreamMode) } func (req *dnsConfig) checkBootstrap() (err error) { if req.Bootstraps == nil { return nil </s> remove return false </s> add return nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f13106727890c2bd265ab9e3bbb29b5d5430101b
internal/dnsforward/http.go