mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-15 18:08:30 -07:00
Pull request 1912: 5896-safe-browsing-ptr
Updates #5896. Squashed commit of the following: commit 49340544a2a8762283397cdb54b91ed534591fa0 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Jul 10 17:59:45 2023 +0300 hashprefix: fix loop pointer
This commit is contained in:
parent
7b92d53b84
commit
c02a14117d
@ -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[:]...)
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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]), ".")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user