Skip to content

Commit

Permalink
Pull request #66: upd-all
Browse files Browse the repository at this point in the history
Merge in GO/adguarddnsclient from upd-all to master

Squashed commit of the following:

commit 6e0d63a
Author: Eugene Burkov <[email protected]>
Date:   Tue Dec 17 19:05:49 2024 +0300

    all: fix go version in readme

commit b200e61
Author: Eugene Burkov <[email protected]>
Date:   Tue Dec 17 17:59:23 2024 +0300

    all: imp code

commit e190383
Author: Eugene Burkov <[email protected]>
Date:   Tue Dec 17 14:54:49 2024 +0300

    all: upd go, libs
  • Loading branch information
EugeneOne1 committed Dec 18, 2024
1 parent c0922dd commit 734a7ce
Show file tree
Hide file tree
Showing 27 changed files with 316 additions and 508 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'name': 'build'

'env':
'GO_VERSION': '1.23.3'
'GO_VERSION': '1.23.4'

'on':
'push':
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'name': 'lint'

'env':
'GO_VERSION': '1.23.3'
'GO_VERSION': '1.23.4'

'on':
'push':
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ DIST_DIR = dist
GOAMD64 = v1
GOPROXY = https://proxy.golang.org|direct
GOTELEMETRY = off
GOTOOLCHAIN = go1.23.3
GOTOOLCHAIN = go1.23.4
GPG_KEY = [email protected]
GPG_KEY_PASSPHRASE = not-a-real-password
MSI = 1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ See [`CONTRIBUTING.md`][contr] for more details on how to contribute.

### <a href="#dev-start" id="dev-start" name="dev-start">Development quick start</a>

You will need Go 1.22 or later. First, register our pre-commit hooks:
You will need Go 1.23 or later. First, register our pre-commit hooks:

```sh
make init
Expand Down
6 changes: 3 additions & 3 deletions bamboo-specs/bamboo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'key': 'DNSCLIENT'
'name': 'AdGuardDNSClient'
'variables':
'dockerGo': 'adguard/go-builder:1.23.3--1'
'dockerGo': 'adguard/go-builder:1.23.4--1'
'maintainer': 'Adguard Go Team'
'name': 'AdGuardDNSClient'
'channel': 'development'
Expand Down Expand Up @@ -355,7 +355,7 @@
# "candidate" pseudo-channel is used to generate version.
- '^rc-v[0-9]+\.[0-9]+\.[0-9]+':
'variables':
'dockerGo': 'adguard/go-builder:1.23.3--1'
'dockerGo': 'adguard/go-builder:1.23.4--1'
'channel': 'candidate'
'stages':
- 'Go Lint':
Expand Down Expand Up @@ -386,7 +386,7 @@
# Set the default release channel on the final branch to release, as
# these are the ones that actually get released.
'variables':
'dockerGo': 'adguard/go-builder:1.23.3--1'
'dockerGo': 'adguard/go-builder:1.23.4--1'
'channel': 'release'
'stages':
- 'Go Lint':
Expand Down
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/AdguardTeam/AdGuardDNSClient

go 1.23.3
go 1.23.4

require (
github.com/AdguardTeam/dnsproxy v0.73.3
github.com/AdguardTeam/golibs v0.30.2
github.com/AdguardTeam/dnsproxy v0.73.4
github.com/AdguardTeam/golibs v0.31.0
github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500
github.com/miekg/dns v1.1.62
github.com/stretchr/testify v1.9.0
golang.org/x/sys v0.26.0
github.com/stretchr/testify v1.10.0
golang.org/x/sys v0.28.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -26,15 +26,15 @@ require (
github.com/onsi/ginkgo/v2 v2.20.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.46.0 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.48.2 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/tools v0.26.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.27.0 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
)
52 changes: 26 additions & 26 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/AdguardTeam/dnsproxy v0.73.3 h1:aacr6Wu0ed94DDD+gSB6EwF8nvyq0+DAc7oFOgtgUpA=
github.com/AdguardTeam/dnsproxy v0.73.3/go.mod h1:18ssqhDgOCiVIwYmmVuXVM05wSwrzkO2yjKhVRWJX/g=
github.com/AdguardTeam/golibs v0.30.2 h1:urU/NAyIvQOeArBqDmKCDpaRkfTCJ26uSiSuDMKQfuY=
github.com/AdguardTeam/golibs v0.30.2/go.mod h1:FkwcNQEJoGsgDGXcalrVa/4gWbE68KsmE2guXWtBQUE=
github.com/AdguardTeam/dnsproxy v0.73.4 h1:FTIXX34wQqePjtWUD1I4QfWTq2B2N1gfOW/TzZDdR4o=
github.com/AdguardTeam/dnsproxy v0.73.4/go.mod h1:18ssqhDgOCiVIwYmmVuXVM05wSwrzkO2yjKhVRWJX/g=
github.com/AdguardTeam/golibs v0.31.0 h1:Z0oPfLTLw6iZmpE58dePy2Bel0MaX+lnDwtFEE5EmIo=
github.com/AdguardTeam/golibs v0.31.0/go.mod h1:wIkZ9o2UnppeW6/YD7yJB71dYbMhiuC1Fh/I2ElW7GQ=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 h1:52m0LGchQBBVqJRyYYufQuIbVqRawmubW3OFGqK1ekw=
Expand Down Expand Up @@ -42,33 +42,33 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
github.com/quic-go/quic-go v0.46.0 h1:uuwLClEEyk1DNvchH8uCByQVjo3yKL9opKulExNDs7Y=
github.com/quic-go/quic-go v0.46.0/go.mod h1:1dLehS7TIR64+vxGR70GDcatWTOtMX2PUtnKsjbTurI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
github.com/quic-go/quic-go v0.48.2 h1:wsKXZPeGWpMpCGSWqOcqpW2wZYic/8T3aqiOID0/KWE=
github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=
gonum.org/v1/gonum v0.15.0 h1:2lYxjRbTYyxkJxlhC+LvJIx3SsANPdRybu1tGj9/OrQ=
gonum.org/v1/gonum v0.15.0/go.mod h1:xzZVBJBtS+Mz4q0Yl2LJTk+OxOg4jiXZ7qBoM0uISGo=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
Expand Down
35 changes: 17 additions & 18 deletions internal/cmd/bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package cmd

import (
"fmt"
"net/netip"
"time"

"github.com/AdguardTeam/AdGuardDNSClient/internal/dnssvc"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/timeutil"
"github.com/AdguardTeam/golibs/validate"
)

// bootstrapConfig is the configuration for resolving upstream's hostnames.
type bootstrapConfig struct {
// Servers is the list of DNS servers to use for resolving upstream's
// hostnames.
Servers ipPortConfigs `yaml:"servers"`
Servers []*ipPortConfig `yaml:"servers"`

// Timeout constrains the time for sending requests and receiving responses.
Timeout timeutil.Duration `yaml:"timeout"`
Expand All @@ -21,33 +23,30 @@ type bootstrapConfig struct {
// toInternal converts the bootstrap configuration to the internal
// representation. c must be valid.
func (c *bootstrapConfig) toInternal() (conf *dnssvc.BootstrapConfig) {
addrs := make([]netip.AddrPort, 0, len(c.Servers))
for _, s := range c.Servers {
addrs = append(addrs, s.Address)
}

return &dnssvc.BootstrapConfig{
Timeout: c.Timeout.Duration,
Addresses: c.Servers.toInternal(),
Timeout: time.Duration(c.Timeout),
Addresses: addrs,
}
}

// type check
var _ validator = (*bootstrapConfig)(nil)
var _ validate.Interface = (*bootstrapConfig)(nil)

// validate implements the [validator] interface for *bootstrapConfig.
func (c *bootstrapConfig) validate() (err error) {
// Validate implements the [validate.Interface] interface for *bootstrapConfig.
func (c *bootstrapConfig) Validate() (err error) {
if c == nil {
return errors.ErrNoValue
}

var errs []error

if c.Timeout.Duration <= 0 {
err = fmt.Errorf("got timeout %s: %w", c.Timeout, errors.ErrNotPositive)
errs = append(errs, err)
}

err = c.Servers.validate()
if err != nil {
err = fmt.Errorf("servers: %w", err)
errs = append(errs, err)
errs := []error{
validate.Positive("timeout", c.Timeout),
}
errs = validate.AppendSlice(errs, "servers", c.Servers)

return errors.Join(errs...)
}
44 changes: 13 additions & 31 deletions internal/cmd/cache.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmd

import (
"fmt"
"math"

"github.com/AdguardTeam/AdGuardDNSClient/internal/dnssvc"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/validate"
"github.com/c2h5oh/datasize"
)

Expand Down Expand Up @@ -34,41 +34,23 @@ func (c *cacheConfig) toInternal() (conf *dnssvc.CacheConfig) {
}

// type check
var _ validator = (*cacheConfig)(nil)
var _ validate.Interface = (*cacheConfig)(nil)

// validate implements the [validator] interface for *cacheConfig.
func (c *cacheConfig) validate() (err error) {
// Validate implements the [validate.Interface] interface for *cacheConfig.
func (c *cacheConfig) Validate() (err error) {
if c == nil {
return errors.ErrNoValue
} else if !c.Enabled {
// Don't validate cache settings if it's disabled.
return nil
}

var errs []error

// TODO(e.burkov): Remove [math.MaxInt] constraint when [datasize.ByteSize]
// is supported by proxy.

if c.Size == 0 || c.Size > math.MaxInt {
err = fmt.Errorf(
"size: %w: must be positive and less than %d; got %d",
errors.ErrOutOfRange,
math.MaxInt,
c.Size,
)
errs = append(errs, err)
}

if c.Size == 0 || c.Size > math.MaxInt {
err = fmt.Errorf(
"client_size: %w: must be positive and less than %d; got %d",
errors.ErrOutOfRange,
math.MaxInt,
c.Size,
)
errs = append(errs, err)
if !c.Enabled {
// Don't validate cache settings if it's disabled.
return nil
}

return errors.Join(errs...)
return errors.Join(
// TODO(e.burkov): Remove [math.MaxInt] constraint when
// [datasize.ByteSize] is supported by proxy.
validate.InRange("size", c.Size, 1, math.MaxInt),
validate.InRange("client_size", c.ClientSize, 1, math.MaxInt),
)
}
18 changes: 9 additions & 9 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func Main() {
conf, err := handleServiceConfig(opts.serviceAction)
l, logFile, confLoggerErrs := newConfigLogger(l, logFile, opts, envs, conf)

reportPrevErrs(ctx, l, envsErrs, envsLoggerErr, confLoggerErrs)

prog := &program{
conf: conf,
done: make(chan struct{}),
Expand All @@ -47,24 +49,22 @@ func Main() {
logFile: logFile,
}

reportPrevErrs(ctx, l, envsErrs, envsLoggerErr, confLoggerErrs)

check(ctx, prog, err)

svc, err := osservice.New(prog, newServiceConfig())
check(ctx, prog, err)

if opts.serviceAction != "" {
exitCode := control(svc, opts.serviceAction)
prog.closeLogs()
prog.closeLogs(ctx)

os.Exit(exitCode)
}

err = svc.Run()
check(ctx, prog, err)

prog.closeLogs()
prog.closeLogs(ctx)
}

// reportPrevErrs reports errors that were collected while there was no logger.
Expand All @@ -75,16 +75,16 @@ func reportPrevErrs(
loggerErr error,
confLoggerErrs []error,
) {
if len(envsErrs) > 0 {
l.ErrorContext(ctx, "parsing environment", slogutil.KeyError, errors.Join(envsErrs...))
if err := errors.Join(envsErrs...); err != nil {
l.ErrorContext(ctx, "parsing environment", slogutil.KeyError, err)
}

if loggerErr != nil {
l.ErrorContext(ctx, "creating env logger", slogutil.KeyError, loggerErr)
}

if len(confLoggerErrs) > 0 {
l.ErrorContext(ctx, "creating conf logger", slogutil.KeyError, errors.Join(confLoggerErrs...))
if err := errors.Join(confLoggerErrs...); err != nil {
l.ErrorContext(ctx, "creating conf logger", slogutil.KeyError, err)
}
}

Expand All @@ -97,7 +97,7 @@ func check(ctx context.Context, prog *program, err error) {
}

prog.logger.ErrorContext(ctx, "fatal error", slogutil.KeyError, err)
prog.closeLogs()
prog.closeLogs(ctx)

os.Exit(osutil.ExitCodeFailure)
}
Loading

0 comments on commit 734a7ce

Please sign in to comment.