Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 5972-ip-dupl-ans
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
Mizzick committed Jul 11, 2023
2 parents 03641b0 + 61ed743 commit 39527c0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ In this release, the schema version has changed from 23 to 24.
### Fixed

- Two unspecified IPs when a host is blocked in two filter lists ([#5972]).
- Incorrect setting of Parental Control cache size.
- Excessive RAM and CPU consumption by Safe Browsing and Parental Control
filters ([#5896]).

Expand Down
22 changes: 12 additions & 10 deletions internal/filtering/hashprefix/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func fromCacheItem(item *cacheItem) (data []byte) {
data = binary.BigEndian.AppendUint64(data, uint64(expiry))

for _, v := range item.hashes {
// nolint:looppointer // The subsilce is used for a copy.
// nolint:looppointer // The subsilce of v is used for a copy.
data = append(data, v[:]...)
}

Expand All @@ -63,7 +63,7 @@ func (c *Checker) findInCache(

i := 0
for _, hash := range hashes {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
// nolint:looppointer // The has subsilce is used for a cache lookup.
data := c.cache.Get(hash[:prefixLen])
if data == nil {
hashes[i] = hash
Expand Down Expand Up @@ -98,34 +98,36 @@ func (c *Checker) storeInCache(hashesToRequest, respHashes []hostnameHash) {

for _, hash := range respHashes {
var pref prefix
// nolint:looppointer // The subsilce is used for a copy.
// nolint:looppointer // The hash subsilce is used for a copy.
copy(pref[:], hash[:])

hashToStore[pref] = append(hashToStore[pref], hash)
}

for pref, hash := range hashToStore {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
c.setCache(pref[:], hash)
c.setCache(pref, hash)
}

for _, hash := range hashesToRequest {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
pref := hash[:prefixLen]
val := c.cache.Get(pref)
// nolint:looppointer // The hash subsilce is used for a cache lookup.
val := c.cache.Get(hash[:prefixLen])
if val == nil {
var pref prefix
// nolint:looppointer // The hash subsilce is used for a copy.
copy(pref[:], hash[:])

c.setCache(pref, nil)
}
}
}

// setCache stores hash in cache.
func (c *Checker) setCache(pref []byte, hashes []hostnameHash) {
func (c *Checker) setCache(pref prefix, hashes []hostnameHash) {
item := &cacheItem{
expiry: time.Now().Add(c.cacheTime),
hashes: hashes,
}

c.cache.Set(pref, fromCacheItem(item))
c.cache.Set(pref[:], fromCacheItem(item))
log.Debug("%s: stored in cache: %v", c.svc, pref)
}
2 changes: 1 addition & 1 deletion internal/filtering/hashprefix/hashprefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (c *Checker) getQuestion(hashes []hostnameHash) (q string) {
b := &strings.Builder{}

for _, hash := range hashes {
// nolint:looppointer // The subsilce is used for safe hex encoding.
// nolint:looppointer // The hash subsilce is used for hex encoding.
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[:prefixLen]), ".")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func setupDNSFilteringConf(conf *filtering.Config) (err error) {
ServiceName: pcService,
TXTSuffix: pcTXTSuffix,
CacheTime: cacheTime,
CacheSize: conf.SafeBrowsingCacheSize,
CacheSize: conf.ParentalCacheSize,
})

conf.SafeSearchConf.CustomResolver = safeSearchResolver{}
Expand Down

0 comments on commit 39527c0

Please sign in to comment.