Pull request 1955: Upd libraries
Merge in DNS/adguard-home from upd-libs to master
Squashed commit of the following:
commit 72f4fb7d5ab8eaecb917a843dec56e3fa38b725c
Merge: 8defe106f 111005b8d
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Aug 10 19:50:33 2023 +0300
Merge branch 'master' into upd-libs
commit 8defe106fc982ba916f42d5722f1cc0152042d04
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Aug 10 19:38:01 2023 +0300
dnsforward: revert behavior
commit 8ccb2f675373772f8a6f829b80b317fda0c5f730
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Aug 9 18:35:12 2023 +0300
all: imp code
commit a3112d3438a466bae515e56a6ee97394066ba481
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Aug 9 17:26:52 2023 +0300
filtering: revert type
commit 56d2528fb4c8ee5504de0c6ec24050d63c8e6330
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Aug 9 14:57:04 2023 +0300
stats: fix sort
commit 0dbb446602b7536df508a8e53c4a532455c9d064
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Aug 9 14:52:28 2023 +0300
all: upd golibs & dnsproxy
This commit is contained in:
parent
111005b8d4
commit
94cf50a53d
14
go.mod
14
go.mod
|
@ -3,8 +3,8 @@ module github.com/AdguardTeam/AdGuardHome
|
|||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/AdguardTeam/dnsproxy v0.52.1-0.20230726165924-30c459b0cdef
|
||||
github.com/AdguardTeam/golibs v0.13.6
|
||||
github.com/AdguardTeam/dnsproxy v0.53.1
|
||||
github.com/AdguardTeam/golibs v0.14.0
|
||||
github.com/AdguardTeam/urlfilter v0.16.2
|
||||
github.com/NYTimes/gziphandler v1.1.1
|
||||
github.com/ameshkov/dnscrypt/v2 v2.2.7
|
||||
|
@ -27,15 +27,12 @@ require (
|
|||
// own code for that. Perhaps, use gopacket.
|
||||
github.com/mdlayher/raw v0.1.0
|
||||
github.com/miekg/dns v1.1.55
|
||||
// TODO(a.garipov): Update to ≥ v0.37.0 once we update to Go 1.20.
|
||||
github.com/quic-go/quic-go v0.36.2
|
||||
github.com/quic-go/quic-go v0.37.4
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/ti-mo/netfilter v0.5.0
|
||||
go.etcd.io/bbolt v1.3.7
|
||||
golang.org/x/crypto v0.11.0
|
||||
// TODO(a.garipov): Update after updating slices.Sort and friends to
|
||||
// stdlib versions in dnsproxy and golibs in Go 1.20.
|
||||
golang.org/x/exp v0.0.0-20230724220655-d98519c11495
|
||||
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de
|
||||
golang.org/x/net v0.12.0
|
||||
golang.org/x/sys v0.10.0
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||
|
@ -59,8 +56,7 @@ require (
|
|||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/quic-go/qpack v0.4.0 // indirect
|
||||
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
|
||||
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
|
||||
github.com/quic-go/qtls-go1-20 v0.3.1 // indirect
|
||||
github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 // indirect
|
||||
golang.org/x/mod v0.12.0 // indirect
|
||||
golang.org/x/sync v0.3.0 // indirect
|
||||
|
|
22
go.sum
22
go.sum
|
@ -1,9 +1,9 @@
|
|||
github.com/AdguardTeam/dnsproxy v0.52.1-0.20230726165924-30c459b0cdef h1:3ZJieG+PV+wJEXLgUndW4yL9/7iubyipbDmA0w3sa7Y=
|
||||
github.com/AdguardTeam/dnsproxy v0.52.1-0.20230726165924-30c459b0cdef/go.mod h1:Jo2zeRe97Rxt3yikXc+fn0LdLtqCj0Xlyh1PNBj6bpM=
|
||||
github.com/AdguardTeam/dnsproxy v0.53.1 h1:+zYKKO9s8lJhf/Yc2hsmb6cbGA6D5xy0rUb0XElxD4c=
|
||||
github.com/AdguardTeam/dnsproxy v0.53.1/go.mod h1:ycgSY+bYn6958PXvZD5If0YI0lZ9bGQH4FJ9HzwXKu0=
|
||||
github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
|
||||
github.com/AdguardTeam/golibs v0.10.4/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw=
|
||||
github.com/AdguardTeam/golibs v0.13.6 h1:z/0Q25pRLdaQxtoxvfSaooz5mdv8wj0R8KREj54q8yQ=
|
||||
github.com/AdguardTeam/golibs v0.13.6/go.mod h1:hOtcb8dPfKcFjWTPA904hTA4dl1aWvzeebdJpE72IPk=
|
||||
github.com/AdguardTeam/golibs v0.14.0 h1:/vfJshXBVaevMuBgzAIr+F64XdNqZL+j9F33GXJmgeQ=
|
||||
github.com/AdguardTeam/golibs v0.14.0/go.mod h1:hOtcb8dPfKcFjWTPA904hTA4dl1aWvzeebdJpE72IPk=
|
||||
github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU=
|
||||
github.com/AdguardTeam/urlfilter v0.16.2 h1:k9m9dUYVJ3sTswYa2/ukVNjicfGcz0oqFDO13hPmfHE=
|
||||
github.com/AdguardTeam/urlfilter v0.16.2/go.mod h1:46YZDOV1+qtdRDuhZKVPSSp7JWWes0KayqHrKAFBdEI=
|
||||
|
@ -104,12 +104,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||
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/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U=
|
||||
github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI=
|
||||
github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E=
|
||||
github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM=
|
||||
github.com/quic-go/quic-go v0.36.2 h1:ZX/UNQ4gvpCv2RmwdbA6lrRjF6EBm5yZ7TMoT4NQVrA=
|
||||
github.com/quic-go/quic-go v0.36.2/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ=
|
||||
github.com/quic-go/qtls-go1-20 v0.3.1 h1:O4BLOM3hwfVF3AcktIylQXyl7Yi2iBNVy5QsV+ySxbg=
|
||||
github.com/quic-go/qtls-go1-20 v0.3.1/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k=
|
||||
github.com/quic-go/quic-go v0.37.4 h1:ke8B73yMCWGq9MfrCCAw0Uzdm7GaViC3i39dsIdDlH4=
|
||||
github.com/quic-go/quic-go v0.37.4/go.mod h1:YsbH1r4mSHPJcLF4k4zruUkLBqctEMBDR6VPvcYjIsU=
|
||||
github.com/shirou/gopsutil/v3 v3.21.8 h1:nKct+uP0TV8DjjNiHanKf8SAuub+GNsbrOtM9Nl9biA=
|
||||
github.com/shirou/gopsutil/v3 v3.21.8/go.mod h1:YWp/H8Qs5fVmf17v7JNZzA0mPJ+mS2e9JdiUF9LlKzQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
@ -136,8 +134,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
|||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
||||
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||
golang.org/x/exp v0.0.0-20230724220655-d98519c11495 h1:zKGKw2WlGb8oPoRGqQ2PT8g2YoCN1w/YbbQjHXCdUWE=
|
||||
golang.org/x/exp v0.0.0-20230724220655-d98519c11495/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de h1:l5Za6utMv/HsBWWqzt4S8X17j+kt1uVETUX5UFhn2rE=
|
||||
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
|
@ -99,8 +100,8 @@ func (s *server) dbStore() (err error) {
|
|||
func writeDB(path string, leases []*Lease) (err error) {
|
||||
defer func() { err = errors.Annotate(err, "writing db: %w") }()
|
||||
|
||||
slices.SortFunc(leases, func(a, b *Lease) bool {
|
||||
return a.Hostname < b.Hostname
|
||||
slices.SortFunc(leases, func(a, b *Lease) (res int) {
|
||||
return strings.Compare(a.Hostname, b.Hostname)
|
||||
})
|
||||
|
||||
dl := &dataLeases{
|
||||
|
|
|
@ -254,28 +254,38 @@ func sortNetIPAddrs(addrs []net.IP, preferIPv6 bool) {
|
|||
return
|
||||
}
|
||||
|
||||
slices.SortStableFunc(addrs, func(addrA, addrB net.IP) (sortsBefore bool) {
|
||||
slices.SortStableFunc(addrs, func(addrA, addrB net.IP) (res int) {
|
||||
switch len(addrA) {
|
||||
case net.IPv4len, net.IPv6len:
|
||||
switch len(addrB) {
|
||||
case net.IPv4len, net.IPv6len:
|
||||
// Go on.
|
||||
default:
|
||||
return true
|
||||
return -1
|
||||
}
|
||||
default:
|
||||
return false
|
||||
return 1
|
||||
}
|
||||
|
||||
if aIs4, bIs4 := addrA.To4() != nil, addrB.To4() != nil; aIs4 != bIs4 {
|
||||
if aIs4 {
|
||||
return !preferIPv6
|
||||
// Treat IPv6-mapped IPv4 addresses as IPv6 addresses.
|
||||
aIs4, bIs4 := addrA.To4() != nil, addrB.To4() != nil
|
||||
if aIs4 == bIs4 {
|
||||
return bytes.Compare(addrA, addrB)
|
||||
}
|
||||
|
||||
if aIs4 {
|
||||
if preferIPv6 {
|
||||
return 1
|
||||
}
|
||||
|
||||
return preferIPv6
|
||||
return -1
|
||||
}
|
||||
|
||||
return bytes.Compare(addrA, addrB) < 0
|
||||
if preferIPv6 {
|
||||
return -1
|
||||
}
|
||||
|
||||
return 1
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ func TestChcker_getQuestion(t *testing.T) {
|
|||
hashes := hostnameToHashes("1.2.3.sub.host.com")
|
||||
assert.Len(t, hashes, 3)
|
||||
|
||||
hash := sha256.Sum256([]byte("3.sub.host.com"))
|
||||
hash := hostnameHash(sha256.Sum256([]byte("3.sub.host.com")))
|
||||
hexPref1 := hex.EncodeToString(hash[:prefixLen])
|
||||
assert.True(t, slices.Contains(hashes, hash))
|
||||
|
||||
|
@ -105,7 +105,7 @@ func TestChecker_storeInCache(t *testing.T) {
|
|||
// store in cache hashes for "3.sub.host.com" and "host.com"
|
||||
// and empty data for hash-prefix for "sub.host.com"
|
||||
hashes := []hostnameHash{}
|
||||
hash := sha256.Sum256([]byte("sub.host.com"))
|
||||
hash := hostnameHash(sha256.Sum256([]byte("sub.host.com")))
|
||||
hashes = append(hashes, hash)
|
||||
var hashesArray []hostnameHash
|
||||
hash4 := sha256.Sum256([]byte("3.sub.host.com"))
|
||||
|
|
|
@ -122,24 +122,29 @@ func matchDomainWildcard(host, wildcard string) (ok bool) {
|
|||
return isWildcard(wildcard) && strings.HasSuffix(host, wildcard[1:])
|
||||
}
|
||||
|
||||
// legacyRewriteSortsBefore sorts rewrites according to the following priority:
|
||||
// Compare is used to sort rewrites according to the following priority:
|
||||
//
|
||||
// 1. A and AAAA > CNAME;
|
||||
// 2. wildcard > exact;
|
||||
// 3. lower level wildcard > higher level wildcard;
|
||||
func legacyRewriteSortsBefore(a, b *LegacyRewrite) (sortsBefore bool) {
|
||||
if a.Type == dns.TypeCNAME && b.Type != dns.TypeCNAME {
|
||||
return true
|
||||
} else if a.Type != dns.TypeCNAME && b.Type == dns.TypeCNAME {
|
||||
return false
|
||||
func (rw *LegacyRewrite) Compare(b *LegacyRewrite) (res int) {
|
||||
if rw.Type == dns.TypeCNAME && b.Type != dns.TypeCNAME {
|
||||
return -1
|
||||
} else if rw.Type != dns.TypeCNAME && b.Type == dns.TypeCNAME {
|
||||
return 1
|
||||
}
|
||||
|
||||
if aIsWld, bIsWld := isWildcard(a.Domain), isWildcard(b.Domain); aIsWld != bIsWld {
|
||||
return bIsWld
|
||||
aIsWld, bIsWld := isWildcard(rw.Domain), isWildcard(b.Domain)
|
||||
if aIsWld == bIsWld {
|
||||
// Both are either wildcards or both aren't.
|
||||
return len(rw.Domain) - len(b.Domain)
|
||||
}
|
||||
|
||||
// Both are either wildcards or both aren't.
|
||||
return len(a.Domain) > len(b.Domain)
|
||||
if aIsWld {
|
||||
return 1
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
// prepareRewrites normalizes and validates all legacy DNS rewrites.
|
||||
|
@ -181,7 +186,7 @@ func findRewrites(
|
|||
return nil, matched
|
||||
}
|
||||
|
||||
slices.SortFunc(rewrites, legacyRewriteSortsBefore)
|
||||
slices.SortFunc(rewrites, (*LegacyRewrite).Compare)
|
||||
|
||||
for i, r := range rewrites {
|
||||
if isWildcard(r.Domain) {
|
||||
|
|
|
@ -290,8 +290,8 @@ func (clients *clientsContainer) forConfig() (objs []*clientObject) {
|
|||
// above loop can generate different orderings when writing to the config
|
||||
// file: this produces lots of diffs in config files, so sort objects by
|
||||
// name before writing.
|
||||
slices.SortStableFunc(objs, func(a, b *clientObject) (sortsBefore bool) {
|
||||
return a.Name < b.Name
|
||||
slices.SortStableFunc(objs, func(a, b *clientObject) (res int) {
|
||||
return strings.Compare(a.Name, b.Name)
|
||||
})
|
||||
|
||||
return objs
|
||||
|
@ -907,7 +907,9 @@ func (clients *clientsContainer) addFromSystemARP() {
|
|||
// the persistent clients.
|
||||
func (clients *clientsContainer) close() (err error) {
|
||||
persistent := maps.Values(clients.list)
|
||||
slices.SortFunc(persistent, func(a, b *Client) (less bool) { return a.Name < b.Name })
|
||||
slices.SortFunc(persistent, func(a, b *Client) (res int) {
|
||||
return strings.Compare(a.Name, b.Name)
|
||||
})
|
||||
|
||||
var errs []error
|
||||
|
||||
|
|
|
@ -309,8 +309,8 @@ func addOption(flags *flag.FlagSet, fieldPtr any, o *commandLineOption) {
|
|||
// value hints.
|
||||
func usage(cmdName string, output io.Writer) {
|
||||
options := slices.Clone(commandLineOptions)
|
||||
slices.SortStableFunc(options, func(a, b *commandLineOption) (sortsBefore bool) {
|
||||
return a.long < b.long
|
||||
slices.SortStableFunc(options, func(a, b *commandLineOption) (res int) {
|
||||
return strings.Compare(a.long, b.long)
|
||||
})
|
||||
|
||||
b := &strings.Builder{}
|
||||
|
|
|
@ -107,8 +107,8 @@ func (l *queryLog) search(params *searchParams) (entries []*logEntry, oldest tim
|
|||
// weird on the frontend.
|
||||
//
|
||||
// See https://github.com/AdguardTeam/AdGuardHome/issues/2293.
|
||||
slices.SortStableFunc(entries, func(a, b *logEntry) (sortsBefore bool) {
|
||||
return a.Time.After(b.Time)
|
||||
slices.SortStableFunc(entries, func(a, b *logEntry) (res int) {
|
||||
return -a.Time.Compare(b.Time)
|
||||
})
|
||||
|
||||
if params.offset > 0 {
|
||||
|
|
|
@ -221,15 +221,25 @@ func unitNameToID(name []byte) (id uint32, ok bool) {
|
|||
return uint32(binary.BigEndian.Uint64(name)), true
|
||||
}
|
||||
|
||||
// compareCount used to sort countPair by Count in descending order.
|
||||
func (a countPair) compareCount(b countPair) (res int) {
|
||||
switch x, y := a.Count, b.Count; {
|
||||
case x > y:
|
||||
return -1
|
||||
case x < y:
|
||||
return +1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func convertMapToSlice(m map[string]uint64, max int) (s []countPair) {
|
||||
s = make([]countPair, 0, len(m))
|
||||
for k, v := range m {
|
||||
s = append(s, countPair{Name: k, Count: v})
|
||||
}
|
||||
|
||||
slices.SortFunc(s, func(a, b countPair) (sortsBefore bool) {
|
||||
return a.Count > b.Count
|
||||
})
|
||||
slices.SortFunc(s, countPair.compareCount)
|
||||
if max > len(s) {
|
||||
max = len(s)
|
||||
}
|
||||
|
@ -589,8 +599,15 @@ func prepareTopUpstreamsAvgTime(
|
|||
) (topUpstreamsAvgTime []topAddrsFloat) {
|
||||
keys := maps.Keys(upstreamsAvgTime)
|
||||
|
||||
slices.SortFunc(keys, func(a, b string) (sortsBefore bool) {
|
||||
return upstreamsAvgTime[a] > upstreamsAvgTime[b]
|
||||
slices.SortFunc(keys, func(a, b string) (res int) {
|
||||
switch x, y := upstreamsAvgTime[a], upstreamsAvgTime[b]; {
|
||||
case x > y:
|
||||
return -1
|
||||
case x < y:
|
||||
return +1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
})
|
||||
|
||||
topUpstreamsAvgTime = make([]topAddrsFloat, 0, len(upstreamsAvgTime))
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
|
@ -43,8 +44,8 @@ func main() {
|
|||
check(err)
|
||||
|
||||
// Sort all services and rules to make the output more predictable.
|
||||
slices.SortStableFunc(hlSvcs.BlockedServices, func(a, b *hlServicesService) (less bool) {
|
||||
return a.ID < b.ID
|
||||
slices.SortStableFunc(hlSvcs.BlockedServices, func(a, b *hlServicesService) (res int) {
|
||||
return strings.Compare(a.ID, b.ID)
|
||||
})
|
||||
for _, s := range hlSvcs.BlockedServices {
|
||||
slices.Sort(s.Rules)
|
||||
|
|
Loading…
Reference in New Issue