Skip to content

Commit 57e38ee

Browse files
committed
Replace github.com/opencoff/go-sieve with jedisct1/go-sieve-cache
1 parent a948436 commit 57e38ee

14 files changed

Lines changed: 1150 additions & 494 deletions

File tree

dnscrypt-proxy/plugin_cache.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"sync"
88
"time"
99

10+
"github.com/jedisct1/go-sieve-cache/pkg/sievecache"
1011
"github.com/miekg/dns"
11-
sieve "github.com/opencoff/go-sieve"
1212
)
1313

1414
const StaleResponseTTL = 30 * time.Second
@@ -20,7 +20,7 @@ type CachedResponse struct {
2020

2121
type CachedResponses struct {
2222
sync.RWMutex
23-
cache *sieve.Sieve[[32]byte, CachedResponse]
23+
cache *sievecache.SyncSieveCache[[32]byte, CachedResponse]
2424
}
2525

2626
var cachedResponses CachedResponses
@@ -150,13 +150,14 @@ func (plugin *PluginCacheResponse) Eval(pluginsState *PluginsState, msg *dns.Msg
150150
}
151151
cachedResponses.Lock()
152152
if cachedResponses.cache == nil {
153-
cachedResponses.cache = sieve.New[[32]byte, CachedResponse](pluginsState.cacheSize)
154-
if cachedResponses.cache == nil {
153+
cache, err := sievecache.NewSync[[32]byte, CachedResponse](pluginsState.cacheSize)
154+
if err != nil {
155155
cachedResponses.Unlock()
156-
return fmt.Errorf("failed to initialize the cache")
156+
return fmt.Errorf("failed to initialize the cache: %w", err)
157157
}
158+
cachedResponses.cache = cache
158159
}
159-
cachedResponses.cache.Add(cacheKey, cachedResponse)
160+
cachedResponses.cache.Insert(cacheKey, cachedResponse)
160161
cachedResponses.Unlock()
161162
updateTTL(msg, cachedResponse.expiration)
162163

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ require (
2020
github.com/kardianos/service v1.2.2
2121
github.com/lifenjoiner/dhcpdns v0.0.7
2222
github.com/miekg/dns v1.1.66
23-
github.com/opencoff/go-sieve v0.3.0
2423
github.com/powerman/check v1.8.0
2524
github.com/quic-go/quic-go v0.52.0
2625
golang.org/x/crypto v0.38.0
@@ -36,6 +35,7 @@ require (
3635
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
3736
github.com/hashicorp/go-syslog v1.0.0 // indirect
3837
github.com/hashicorp/golang-lru v0.5.0 // indirect
38+
github.com/jedisct1/go-sieve-cache v0.0.0
3939
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
4040
github.com/pkg/errors v0.9.1 // indirect
4141
github.com/pmezard/go-difflib v1.0.0 // indirect
@@ -51,3 +51,5 @@ require (
5151
google.golang.org/grpc v1.56.3 // indirect
5252
google.golang.org/protobuf v1.34.2 // indirect
5353
)
54+
55+
replace github.com/jedisct1/go-sieve-cache => ./tmp/go-sieve

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
6565
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
6666
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
6767
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
68-
github.com/opencoff/go-sieve v0.3.0 h1:G68ZixLqQ5KsIJzUFTFpe7lvL+o+PtyHz2a+EbhUVlo=
69-
github.com/opencoff/go-sieve v0.3.0/go.mod h1:4o5VwfXUsdua7gnmsxR3py04/L23lSsIWIEgdn1WKBg=
7068
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
7169
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
7270
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

vendor/github.com/jedisct1/go-sieve-cache/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/jedisct1/go-sieve-cache/pkg/sievecache/doc.go

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/jedisct1/go-sieve-cache/pkg/sievecache/node.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)