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))
|
data = binary.BigEndian.AppendUint64(data, uint64(expiry))
|
||||||
|
|
||||||
for _, v := range item.hashes {
|
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[:]...)
|
data = append(data, v[:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ func (c *Checker) findInCache(
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for _, hash := range hashes {
|
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])
|
data := c.cache.Get(hash[:prefixLen])
|
||||||
if data == nil {
|
if data == nil {
|
||||||
hashes[i] = hash
|
hashes[i] = hash
|
||||||
|
@ -98,34 +98,36 @@ func (c *Checker) storeInCache(hashesToRequest, respHashes []hostnameHash) {
|
||||||
|
|
||||||
for _, hash := range respHashes {
|
for _, hash := range respHashes {
|
||||||
var pref prefix
|
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[:])
|
copy(pref[:], hash[:])
|
||||||
|
|
||||||
hashToStore[pref] = append(hashToStore[pref], hash)
|
hashToStore[pref] = append(hashToStore[pref], hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
for pref, hash := range hashToStore {
|
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 {
|
for _, hash := range hashesToRequest {
|
||||||
// nolint:looppointer // The subsilce is used for a safe cache lookup.
|
// nolint:looppointer // The hash subsilce is used for a cache lookup.
|
||||||
pref := hash[:prefixLen]
|
val := c.cache.Get(hash[:prefixLen])
|
||||||
val := c.cache.Get(pref)
|
|
||||||
if val == nil {
|
if val == nil {
|
||||||
|
var pref prefix
|
||||||
|
// nolint:looppointer // The hash subsilce is used for a copy.
|
||||||
|
copy(pref[:], hash[:])
|
||||||
|
|
||||||
c.setCache(pref, nil)
|
c.setCache(pref, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setCache stores hash in cache.
|
// setCache stores hash in cache.
|
||||||
func (c *Checker) setCache(pref []byte, hashes []hostnameHash) {
|
func (c *Checker) setCache(pref prefix, hashes []hostnameHash) {
|
||||||
item := &cacheItem{
|
item := &cacheItem{
|
||||||
expiry: time.Now().Add(c.cacheTime),
|
expiry: time.Now().Add(c.cacheTime),
|
||||||
hashes: hashes,
|
hashes: hashes,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.cache.Set(pref, fromCacheItem(item))
|
c.cache.Set(pref[:], fromCacheItem(item))
|
||||||
log.Debug("%s: stored in cache: %v", c.svc, pref)
|
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{}
|
b := &strings.Builder{}
|
||||||
|
|
||||||
for _, hash := range hashes {
|
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]), ".")
|
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[:prefixLen]), ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue